Skip to content

Commit 46de857

Browse files
tommymcmTommy McMichen
andauthored
[CIR] Fix shared library build caused by interface->IR dependence (#1900)
After #1878, we introduced a dependency from the LoopOpInterface on BreakOp. While here add the BreakOp handling, which will be tests by a pass coming soon. Co-authored-by: Tommy McMichen <[email protected]>
1 parent 4c067c9 commit 46de857

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
@@ -2071,6 +2071,39 @@ static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op,
20712071
// LoopOpInterface Methods
20722072
//===----------------------------------------------------------------------===//
20732073

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