Skip to content

Commit

Permalink
[mlir][SCF] Implement RegionBranchOpInterface on ExecuteRegionOp
Browse files Browse the repository at this point in the history
This is needed for the BufferDeallocation pass.

Differential Revision: https://reviews.llvm.org/D121526
  • Loading branch information
matthias-springer committed Mar 16, 2022
1 parent 855a11e commit 75c1d91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mlir/include/mlir/Dialect/SCF/SCFOps.td
Expand Up @@ -56,7 +56,8 @@ def ConditionOp : SCF_Op<"condition", [
// ExecuteRegionOp
//===----------------------------------------------------------------------===//

def ExecuteRegionOp : SCF_Op<"execute_region"> {
def ExecuteRegionOp : SCF_Op<"execute_region", [
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
let summary = "operation that executes its region exactly once";
let description = [{
The `execute_region` operation is used to allow multiple blocks within SCF
Expand Down
18 changes: 18 additions & 0 deletions mlir/lib/Dialect/SCF/SCF.cpp
Expand Up @@ -236,6 +236,24 @@ void ExecuteRegionOp::getCanonicalizationPatterns(RewritePatternSet &results,
results.add<SingleBlockExecuteInliner, MultiBlockExecuteInliner>(context);
}

/// Given the region at `index`, or the parent operation if `index` is None,
/// return the successor regions. These are the regions that may be selected
/// during the flow of control. `operands` is a set of optional attributes that
/// correspond to a constant value for each operand, or null if that operand is
/// not a constant.
void ExecuteRegionOp::getSuccessorRegions(
Optional<unsigned> index, ArrayRef<Attribute> operands,
SmallVectorImpl<RegionSuccessor> &regions) {
// If the predecessor is the ExecuteRegionOp, branch into the body.
if (!index.hasValue()) {
regions.push_back(RegionSuccessor(&getRegion()));
return;
}

// Otherwise, the region branches back to the parent operation.
regions.push_back(RegionSuccessor(getResults()));
}

//===----------------------------------------------------------------------===//
// ConditionOp
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 75c1d91

Please sign in to comment.