@@ -2070,6 +2070,39 @@ static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op,
2070
2070
// LoopOpInterface Methods
2071
2071
// ===----------------------------------------------------------------------===//
2072
2072
2073
+ void cir::LoopOpInterface::getLoopOpSuccessorRegions (
2074
+ LoopOpInterface op, mlir::RegionBranchPoint point,
2075
+ llvm::SmallVectorImpl<mlir::RegionSuccessor> ®ions) {
2076
+ assert (point.isParent () || point.getRegionOrNull ());
2077
+
2078
+ // Branching to first region: go to condition or body (do-while).
2079
+ if (point.isParent ()) {
2080
+ regions.emplace_back (&op.getEntry (), op.getEntry ().getArguments ());
2081
+ }
2082
+ // Branching from condition: go to body or exit.
2083
+ else if (&op.getCond () == point.getRegionOrNull ()) {
2084
+ regions.emplace_back (mlir::RegionSuccessor (op->getResults ()));
2085
+ regions.emplace_back (&op.getBody (), op.getBody ().getArguments ());
2086
+ }
2087
+ // Branching from body: go to step (for) or condition.
2088
+ else if (&op.getBody () == point.getRegionOrNull ()) {
2089
+ // If there are any breaks in the body, also go to exit.
2090
+ op.getBody ().walk ([&](cir::BreakOp breakOp) {
2091
+ if (breakOp.getBreakTarget () == op)
2092
+ regions.emplace_back (mlir::RegionSuccessor (op->getResults ()));
2093
+ });
2094
+
2095
+ auto *afterBody = (op.maybeGetStep () ? op.maybeGetStep () : &op.getCond ());
2096
+ regions.emplace_back (afterBody, afterBody->getArguments ());
2097
+ }
2098
+ // Branching from step: go to condition.
2099
+ else if (op.maybeGetStep () == point.getRegionOrNull ()) {
2100
+ regions.emplace_back (&op.getCond (), op.getCond ().getArguments ());
2101
+ } else {
2102
+ llvm_unreachable (" unexpected branch origin" );
2103
+ }
2104
+ }
2105
+
2073
2106
void cir::DoWhileOp::getSuccessorRegions (
2074
2107
::mlir::RegionBranchPoint point,
2075
2108
::llvm::SmallVectorImpl<::mlir::RegionSuccessor> ®ions) {
0 commit comments