diff --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td --- a/mlir/include/mlir/Dialect/SCF/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td @@ -56,7 +56,8 @@ // ExecuteRegionOp //===----------------------------------------------------------------------===// -def ExecuteRegionOp : SCF_Op<"execute_region"> { +def ExecuteRegionOp : SCF_Op<"execute_region", [ + DeclareOpInterfaceMethods]> { let summary = "operation that executes its region exactly once"; let description = [{ The `execute_region` operation is used to allow multiple blocks within SCF diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp --- a/mlir/lib/Dialect/SCF/SCF.cpp +++ b/mlir/lib/Dialect/SCF/SCF.cpp @@ -236,6 +236,24 @@ results.add(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 index, ArrayRef operands, + SmallVectorImpl ®ions) { + // 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 //===----------------------------------------------------------------------===//