From 9f78566b62c4f82364177539202ff61f5cd6ffed Mon Sep 17 00:00:00 2001 From: Tommy McMichen Date: Wed, 10 Sep 2025 14:23:02 -0700 Subject: [PATCH] [CIR][NFC] Moved implementation of `cir::LoopOpInterface` into `CIRDialect.cpp` Moved implementation to avoid shared library error. --- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 33 +++++++++++++++++++ .../lib/CIR/Interfaces/CIRLoopOpInterface.cpp | 28 ---------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index d77e4fb0603e..8a6f451d57ad 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2071,6 +2071,39 @@ static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op, // LoopOpInterface Methods //===----------------------------------------------------------------------===// +void cir::LoopOpInterface::getLoopOpSuccessorRegions( + LoopOpInterface op, mlir::RegionBranchPoint point, + llvm::SmallVectorImpl ®ions) { + assert(point.isParent() || point.getRegionOrNull()); + + // Branching to first region: go to condition or body (do-while). + if (point.isParent()) { + regions.emplace_back(&op.getEntry(), op.getEntry().getArguments()); + } + // Branching from condition: go to body or exit. + else if (&op.getCond() == point.getRegionOrNull()) { + regions.emplace_back(mlir::RegionSuccessor(op->getResults())); + regions.emplace_back(&op.getBody(), op.getBody().getArguments()); + } + // Branching from body: go to step (for) or condition. + else if (&op.getBody() == point.getRegionOrNull()) { + // If there are any breaks in the body, also go to exit. + op.getBody().walk([&](cir::BreakOp breakOp) { + if (breakOp.getBreakTarget() == op) + regions.emplace_back(mlir::RegionSuccessor(op->getResults())); + }); + + auto *afterBody = (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond()); + regions.emplace_back(afterBody, afterBody->getArguments()); + } + // Branching from step: go to condition. + else if (op.maybeGetStep() == point.getRegionOrNull()) { + regions.emplace_back(&op.getCond(), op.getCond().getArguments()); + } else { + llvm_unreachable("unexpected branch origin"); + } +} + void cir::DoWhileOp::getSuccessorRegions( ::mlir::RegionBranchPoint point, ::llvm::SmallVectorImpl<::mlir::RegionSuccessor> ®ions) { diff --git a/clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp b/clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp index e3f508bcdf1c..008d000712b1 100644 --- a/clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp +++ b/clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp @@ -14,34 +14,6 @@ namespace cir { -void LoopOpInterface::getLoopOpSuccessorRegions( - LoopOpInterface op, mlir::RegionBranchPoint point, - llvm::SmallVectorImpl ®ions) { - assert(point.isParent() || point.getRegionOrNull()); - - // Branching to first region: go to condition or body (do-while). - if (point.isParent()) { - regions.emplace_back(&op.getEntry(), op.getEntry().getArguments()); - } - // Branching from condition: go to body or exit. - else if (&op.getCond() == point.getRegionOrNull()) { - regions.emplace_back(mlir::RegionSuccessor(op->getResults())); - regions.emplace_back(&op.getBody(), op.getBody().getArguments()); - } - // Branching from body: go to step (for) or condition. - else if (&op.getBody() == point.getRegionOrNull()) { - // FIXME(cir): Should we consider break/continue statements here? - auto *afterBody = (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond()); - regions.emplace_back(afterBody, afterBody->getArguments()); - } - // Branching from step: go to condition. - else if (op.maybeGetStep() == point.getRegionOrNull()) { - regions.emplace_back(&op.getCond(), op.getCond().getArguments()); - } else { - llvm_unreachable("unexpected branch origin"); - } -} - /// Verify invariants of the LoopOpInterface. llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) { auto loopOp = mlir::cast(op);