Skip to content

Commit c080949

Browse files
author
Tommy McMichen
committed
[CIR][NFC] Moved implementation of cir::LoopOpInterface into CIRDialect.cpp
Moved implementation to avoid shared library error.
1 parent c543481 commit c080949

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,39 @@ static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op,
20702070
// LoopOpInterface Methods
20712071
//===----------------------------------------------------------------------===//
20722072

2073+
void cir::LoopOpInterface::getLoopOpSuccessorRegions(
2074+
LoopOpInterface op, mlir::RegionBranchPoint point,
2075+
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
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+
20732106
void cir::DoWhileOp::getSuccessorRegions(
20742107
::mlir::RegionBranchPoint point,
20752108
::llvm::SmallVectorImpl<::mlir::RegionSuccessor> &regions) {

clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@
1414

1515
namespace cir {
1616

17-
void LoopOpInterface::getLoopOpSuccessorRegions(
18-
LoopOpInterface op, mlir::RegionBranchPoint point,
19-
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
20-
assert(point.isParent() || point.getRegionOrNull());
21-
22-
// Branching to first region: go to condition or body (do-while).
23-
if (point.isParent()) {
24-
regions.emplace_back(&op.getEntry(), op.getEntry().getArguments());
25-
}
26-
// Branching from condition: go to body or exit.
27-
else if (&op.getCond() == point.getRegionOrNull()) {
28-
regions.emplace_back(mlir::RegionSuccessor(op->getResults()));
29-
regions.emplace_back(&op.getBody(), op.getBody().getArguments());
30-
}
31-
// Branching from body: go to step (for) or condition.
32-
else if (&op.getBody() == point.getRegionOrNull()) {
33-
// FIXME(cir): Should we consider break/continue statements here?
34-
auto *afterBody = (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());
35-
regions.emplace_back(afterBody, afterBody->getArguments());
36-
}
37-
// Branching from step: go to condition.
38-
else if (op.maybeGetStep() == point.getRegionOrNull()) {
39-
regions.emplace_back(&op.getCond(), op.getCond().getArguments());
40-
} else {
41-
llvm_unreachable("unexpected branch origin");
42-
}
43-
}
44-
4517
/// Verify invariants of the LoopOpInterface.
4618
llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) {
4719
auto loopOp = mlir::cast<LoopOpInterface>(op);

0 commit comments

Comments
 (0)