MLIR  20.0.0git
PassDetail.cpp
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 https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PassDetail.h"
10 #include "mlir/IR/Builders.h"
12 
13 using namespace mlir;
14 
16  OpBuilder builder(&region);
17  cloneConstantsIntoTheRegion(region, builder);
18 }
19 
21  OpBuilder &builder) {
22  // Values implicitly captured by the region.
23  llvm::SetVector<Value> captures;
24  getUsedValuesDefinedAbove(region, region, captures);
25 
26  OpBuilder::InsertionGuard guard(builder);
27  builder.setInsertionPointToStart(&region.front());
28 
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;
34 
35  Operation *cloned = builder.clone(*op);
36 
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:357
This class helps build Operations.
Definition: Builders.h:216
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:588
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Definition: Builders.h:440
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:750
result_range getResults()
Definition: Operation.h:415
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:32
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:67