Skip to content

Commit 75c1d91

Browse files
[mlir][SCF] Implement RegionBranchOpInterface on ExecuteRegionOp
This is needed for the BufferDeallocation pass. Differential Revision: https://reviews.llvm.org/D121526
1 parent 855a11e commit 75c1d91

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mlir/include/mlir/Dialect/SCF/SCFOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def ConditionOp : SCF_Op<"condition", [
5656
// ExecuteRegionOp
5757
//===----------------------------------------------------------------------===//
5858

59-
def ExecuteRegionOp : SCF_Op<"execute_region"> {
59+
def ExecuteRegionOp : SCF_Op<"execute_region", [
60+
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
6061
let summary = "operation that executes its region exactly once";
6162
let description = [{
6263
The `execute_region` operation is used to allow multiple blocks within SCF

mlir/lib/Dialect/SCF/SCF.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ void ExecuteRegionOp::getCanonicalizationPatterns(RewritePatternSet &results,
236236
results.add<SingleBlockExecuteInliner, MultiBlockExecuteInliner>(context);
237237
}
238238

239+
/// Given the region at `index`, or the parent operation if `index` is None,
240+
/// return the successor regions. These are the regions that may be selected
241+
/// during the flow of control. `operands` is a set of optional attributes that
242+
/// correspond to a constant value for each operand, or null if that operand is
243+
/// not a constant.
244+
void ExecuteRegionOp::getSuccessorRegions(
245+
Optional<unsigned> index, ArrayRef<Attribute> operands,
246+
SmallVectorImpl<RegionSuccessor> &regions) {
247+
// If the predecessor is the ExecuteRegionOp, branch into the body.
248+
if (!index.hasValue()) {
249+
regions.push_back(RegionSuccessor(&getRegion()));
250+
return;
251+
}
252+
253+
// Otherwise, the region branches back to the parent operation.
254+
regions.push_back(RegionSuccessor(getResults()));
255+
}
256+
239257
//===----------------------------------------------------------------------===//
240258
// ConditionOp
241259
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)