19bool ExecuteRegionOp::isRegionPromotable(
const MemorySlot &slot,
Region *region,
20 bool hasValueStores) {
24void ExecuteRegionOp::setupPromotion(
26 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
27 regionsToProcess.insert({&getRegion(), reachingDef});
30Value ExecuteRegionOp::finalizePromotion(
39 for (
Block &block : getRegion().getBlocks())
40 if (isa<YieldOp>(block.getTerminator()))
44 resultTypes.push_back(slot.
elemType);
57 bool hasValueStores) {
61void ForOp::setupPromotion(
63 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
64 Region &bodyRegion = getBodyRegion();
65 if (!hasValueStores) {
66 regionsToProcess.insert({&bodyRegion, reachingDef});
70 getInitArgsMutable().append(reachingDef);
72 regionsToProcess.insert({&bodyRegion, bodyRegion.
getArguments().back()});
75Value ForOp::finalizePromotion(
87 resultTypes.push_back(slot.
elemType);
100 bool hasValueStores) {
103 return !hasValueStores;
106void ForallOp::setupPromotion(
107 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
108 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
109 assert(!hasValueStores &&
"ForallOp does not support stores");
110 regionsToProcess.insert({&getBodyRegion(), reachingDef});
113Value ForallOp::finalizePromotion(
114 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
115 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
116 OpBuilder &builder) {
117 assert(!hasValueStores &&
"ForallOp does not support stores");
125bool IfOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
126 bool hasValueStores) {
130void IfOp::setupPromotion(
131 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
132 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
133 regionsToProcess.insert({&getThenRegion(), reachingDef});
134 regionsToProcess.insert({&getElseRegion(), reachingDef});
137Value IfOp::finalizePromotion(
138 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
139 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
140 OpBuilder &builder) {
144 IRRewriter rewriter(builder);
150 if (getElseRegion().hasOneBlock()) {
154 OpBuilder::InsertionGuard guard(rewriter);
155 rewriter.createBlock(&getElseRegion());
156 YieldOp::create(rewriter, getOperation()->getLoc(), reachingDef);
159 SmallVector<Type> resultTypes(getResultTypes());
160 resultTypes.push_back(slot.
elemType);
171bool IndexSwitchOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
172 bool hasValueStores) {
176void IndexSwitchOp::setupPromotion(
177 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
178 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
179 regionsToProcess.insert({&getDefaultRegion(), reachingDef});
180 for (Region &caseRegion : getCaseRegions())
181 regionsToProcess.insert({&caseRegion, reachingDef});
184Value IndexSwitchOp::finalizePromotion(
185 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
186 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
187 OpBuilder &builder) {
191 IRRewriter rewriter(builder);
197 for (Region &caseRegion : getCaseRegions())
201 SmallVector<Type> resultTypes(getResultTypes());
202 resultTypes.push_back(slot.
elemType);
213bool ParallelOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
214 bool hasValueStores) {
217 return !hasValueStores;
220void ParallelOp::setupPromotion(
221 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
222 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
223 assert(!hasValueStores &&
"ParallelOp does not support stores");
224 regionsToProcess.insert({&getBodyRegion(), reachingDef});
227Value ParallelOp::finalizePromotion(
228 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
229 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
230 OpBuilder &builder) {
231 assert(!hasValueStores &&
"ParallelOp does not support stores");
239bool ReduceOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
240 bool hasValueStores) {
243 return !hasValueStores;
246void ReduceOp::setupPromotion(
247 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
248 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
249 assert(!hasValueStores &&
"ReduceOp does not support stores");
250 for (Region &reduction : getReductions())
251 regionsToProcess.insert({&reduction, reachingDef});
254Value ReduceOp::finalizePromotion(
255 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
256 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
257 OpBuilder &builder) {
258 assert(!hasValueStores &&
"ReduceOp does not support stores");
266bool WhileOp::isRegionPromotable(
const MemorySlot &slot, Region *region,
267 bool hasValueStores) {
271void WhileOp::setupPromotion(
272 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
273 llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
274 Region &beforeRegion = getBefore();
275 Region &afterRegion = getAfter();
276 if (!hasValueStores) {
277 regionsToProcess.insert({&beforeRegion, reachingDef});
278 regionsToProcess.insert({&afterRegion, reachingDef});
282 getInitsMutable().append(reachingDef);
285 regionsToProcess.insert({&beforeRegion, beforeRegion.
getArguments().back()});
288 regionsToProcess.insert({&afterRegion, afterRegion.
getArguments().back()});
291Value WhileOp::finalizePromotion(
292 const MemorySlot &slot, Value reachingDef,
bool hasValueStores,
293 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
294 OpBuilder &builder) {
301 getBefore().getArguments().back(),
304 &getAfter().back(), getAfter().getArguments().back(), reachingAtBlockEnd);
306 SmallVector<Type> resultTypes(getResultTypes());
307 resultTypes.push_back(slot.
elemType);
309 IRRewriter rewriter(builder);
Block represents an ordered list of Operations.
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
result_range getResults()
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockArgListType getArguments()
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
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.
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 ...
void updateTerminator(Block *block, Value defaultReachingDef, const DenseMap< Block *, Value > &reachingAtBlockEnd)
Appends the reaching definition for the given block as an operand to its terminator.
Include the generated interface declarations.
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.