MLIR  19.0.0git
Go to the documentation of this file.
1 //===- PassDetail.cpp - Async Pass class details ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "PassDetail.h"
10 #include "mlir/IR/Builders.h"
13 using namespace mlir;
16  OpBuilder builder(&region);
17  cloneConstantsIntoTheRegion(region, builder);
18 }
21  OpBuilder &builder) {
22  // Values implicitly captured by the region.
23  llvm::SetVector<Value> captures;
24  getUsedValuesDefinedAbove(region, region, captures);
26  OpBuilder::InsertionGuard guard(builder);
27  builder.setInsertionPointToStart(&region.front());
29  // Clone ConstantLike operations into the region.
30  for (Value capture : captures) {
31  Operation *op = capture.getDefiningOp();
32  if (!op || !op->hasTrait<OpTrait::ConstantLike>())
33  continue;
35  Operation *cloned = builder.clone(*op);
37  for (auto tuple : llvm::zip(op->getResults(), cloned->getResults())) {
38  Value orig = std::get<0>(tuple);
39  Value replacement = std::get<1>(tuple);
40  replaceAllUsesInRegionWith(orig, replacement, region);
41  }
42  }
43 }
RAII guard to reset the insertion point of the builder when destroyed.
Definition: Builders.h:350
This class helps build Operations.
Definition: Builders.h:209
Operation * clone(Operation &op, IRMapping &mapper)
Creates a deep copy of the specified operation, remapping any operands that use values outside of the...
Definition: Builders.cpp:555
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Definition: Builders.h:433
This class provides the API for a sub-set of ops that are known to be constant-like.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Definition: Operation.h:745
result_range getResults()
Definition: Operation.h:410
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
Block & front()
Definition: Region.h:65
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
void cloneConstantsIntoTheRegion(Region &region)
Clone ConstantLike operations that are defined above the given region and have users in the region in...
Definition: PassDetail.cpp:15
Include the generated interface declarations.
void replaceAllUsesInRegionWith(Value orig, Value replacement, Region &region)
Replace all uses of orig within the given region with replacement.
Definition: RegionUtils.cpp:27
void getUsedValuesDefinedAbove(Region &region, Region &limit, SetVector< Value > &values)
Fill values with a list of values defined at the ancestors of the limit region and used within region...
Definition: RegionUtils.cpp:62