21template <
typename TermTy>
26 if (!isa<TermTy>(terminator))
28 Value blockReachingDef = reachingAtBlockEnd.lookup(block);
29 if (!blockReachingDef) {
32 blockReachingDef = defaultReachingDef;
62bool ExecuteRegionOp::isRegionPromotable(
const MemorySlot &slot,
Region *region,
63 bool hasValueStores) {
67void ExecuteRegionOp::setupPromotion(
69 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
70 regionsToProcess.insert({&getRegion(), reachingDef});
73Value ExecuteRegionOp::finalizePromotion(
82 for (
Block &block : getRegion().getBlocks())
86 resultTypes.push_back(slot.
elemType);
99 bool hasValueStores) {
103void ForOp::setupPromotion(
105 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
106 Region &bodyRegion = getBodyRegion();
107 if (!hasValueStores) {
108 regionsToProcess.insert({&bodyRegion, reachingDef});
112 getInitArgsMutable().append(reachingDef);
114 regionsToProcess.insert({&bodyRegion, bodyRegion.
getArguments().back()});
117Value ForOp::finalizePromotion(
129 resultTypes.push_back(slot.
elemType);
142 bool hasValueStores) {
145 return !hasValueStores;
148void ForallOp::setupPromotion(
149 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
150 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
151 assert(!hasValueStores &&
"ForallOp does not support stores");
152 regionsToProcess.insert({&getBodyRegion(), reachingDef});
155Value ForallOp::finalizePromotion(
156 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
157 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
158 OpBuilder &builder) {
159 assert(!hasValueStores &&
"ForallOp does not support stores");
167bool IfOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
168 bool hasValueStores) {
172void IfOp::setupPromotion(
173 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
174 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
175 regionsToProcess.insert({&getThenRegion(), reachingDef});
176 regionsToProcess.insert({&getElseRegion(), reachingDef});
179Value IfOp::finalizePromotion(
180 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
181 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
182 OpBuilder &builder) {
186 IRRewriter rewriter(builder);
192 if (getElseRegion().hasOneBlock()) {
196 OpBuilder::InsertionGuard guard(rewriter);
197 rewriter.createBlock(&getElseRegion());
198 YieldOp::create(rewriter, getOperation()->getLoc(), reachingDef);
201 SmallVector<Type> resultTypes(getResultTypes());
202 resultTypes.push_back(slot.
elemType);
213bool IndexSwitchOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
214 bool hasValueStores) {
218void IndexSwitchOp::setupPromotion(
219 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
220 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
221 regionsToProcess.insert({&getDefaultRegion(), reachingDef});
222 for (Region &caseRegion : getCaseRegions())
223 regionsToProcess.insert({&caseRegion, reachingDef});
226Value IndexSwitchOp::finalizePromotion(
227 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
228 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
229 OpBuilder &builder) {
233 IRRewriter rewriter(builder);
239 for (Region &caseRegion : getCaseRegions())
243 SmallVector<Type> resultTypes(getResultTypes());
244 resultTypes.push_back(slot.
elemType);
255bool ParallelOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
256 bool hasValueStores) {
259 return !hasValueStores;
262void ParallelOp::setupPromotion(
263 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
264 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
265 assert(!hasValueStores &&
"ParallelOp does not support stores");
266 regionsToProcess.insert({&getBodyRegion(), reachingDef});
269Value ParallelOp::finalizePromotion(
270 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
271 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
272 OpBuilder &builder) {
273 assert(!hasValueStores &&
"ParallelOp does not support stores");
281bool ReduceOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
282 bool hasValueStores) {
285 return !hasValueStores;
288void ReduceOp::setupPromotion(
289 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
290 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
291 assert(!hasValueStores &&
"ReduceOp does not support stores");
292 for (Region &reduction : getReductions())
293 regionsToProcess.insert({&reduction, reachingDef});
296Value ReduceOp::finalizePromotion(
297 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
298 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
299 OpBuilder &builder) {
300 assert(!hasValueStores &&
"ReduceOp does not support stores");
308bool WhileOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
309 bool hasValueStores) {
313void WhileOp::setupPromotion(
314 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
315 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
316 Region &beforeRegion = getBefore();
317 Region &afterRegion = getAfter();
318 if (!hasValueStores) {
319 regionsToProcess.insert({&beforeRegion, reachingDef});
320 regionsToProcess.insert({&afterRegion, reachingDef});
324 getInitsMutable().append(reachingDef);
327 regionsToProcess.insert({&beforeRegion, beforeRegion.
getArguments().back()});
330 regionsToProcess.insert({&afterRegion, afterRegion.
getArguments().back()});
333Value WhileOp::finalizePromotion(
334 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
335 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
336 OpBuilder &builder) {
343 getBefore().getArguments().back(),
346 &getAfter().back(), getAfter().getArguments().back(), reachingAtBlockEnd);
348 SmallVector<Type> resultTypes(getResultTypes());
349 resultTypes.push_back(slot.
elemType);
351 IRRewriter rewriter(builder);
static void updateTerminator(Block *block, Value defaultReachingDef, const llvm::DenseMap< Block *, Value > &reachingAtBlockEnd)
Adds the corresponding reaching definition to the terminator of the block if the terminator is of the...
static Operation * replaceWithNewResults(RewriterBase &rewriter, Operation *op, TypeRange resultTypes)
Creates a shallow copy of an operation with new result types, moving the regions out of the original ...
Block represents an ordered list of Operations.
Operation * getTerminator()
Get the terminator operation of this block.
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
void insertOperands(unsigned index, ValueRange operands)
Insert the given operands into the operand list at the given 'index'.
unsigned getNumRegions()
Returns the number of regions held by this operation.
unsigned getNumOperands()
operand_range getOperands()
Returns an iterator on the underlying Value's.
result_range getResults()
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockArgListType getArguments()
void takeBody(Region &other)
Takes body of another region (that region will have no body after this operation completes).
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void finalizeOpModification(Operation *op)
This method is used to signal the end of an in-place modification of the given operation.
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
void replaceAllOpUsesWith(Operation *from, ValueRange to)
Find uses of from and replace them with to.
virtual void startOpModification(Operation *op)
This method is used to notify the rewriter that an in-place operation modification is about to happen...
This class provides an abstraction over the various different ranges of value types.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Location getLoc() const
Return the location of this value.
Include the generated interface declarations.
Operation * cloneWithoutRegions(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
Represents a slot in memory.
Value ptr
Pointer to the memory slot, used by operations to refer to it.
Type elemType
Type of the value contained in the slot.