Skip to content

Commit d0e0d7f

Browse files
authored
[CIR] Fix building ClangIR after RegionBranchOpInterface revamp (#165441)
Fix building ClangIR after RegionBranchOpInterface revamp (#165429)
1 parent cf1f489 commit d0e0d7f

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ void cir::ConditionOp::getSuccessorRegions(
286286
// Parent is a loop: condition may branch to the body or to the parent op.
287287
if (auto loopOp = dyn_cast<LoopOpInterface>(getOperation()->getParentOp())) {
288288
regions.emplace_back(&loopOp.getBody(), loopOp.getBody().getArguments());
289-
regions.emplace_back(loopOp->getResults());
289+
regions.emplace_back(getOperation(), loopOp->getResults());
290290
}
291291

292292
assert(!cir::MissingFeatures::awaitOp());
293293
}
294294

295295
MutableOperandRange
296-
cir::ConditionOp::getMutableSuccessorOperands(RegionBranchPoint point) {
296+
cir::ConditionOp::getMutableSuccessorOperands(RegionSuccessor point) {
297297
// No values are yielded to the successor region.
298298
return MutableOperandRange(getOperation(), 0, 0);
299299
}
@@ -989,7 +989,8 @@ void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
989989
SmallVectorImpl<RegionSuccessor> &regions) {
990990
// The `then` and the `else` region branch back to the parent operation.
991991
if (!point.isParent()) {
992-
regions.push_back(RegionSuccessor());
992+
regions.push_back(
993+
RegionSuccessor(getOperation(), getOperation()->getResults()));
993994
return;
994995
}
995996

@@ -1039,7 +1040,7 @@ void cir::ScopeOp::getSuccessorRegions(
10391040
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
10401041
// The only region always branch back to the parent operation.
10411042
if (!point.isParent()) {
1042-
regions.push_back(RegionSuccessor(getODSResults(0)));
1043+
regions.push_back(RegionSuccessor(getOperation(), getODSResults(0)));
10431044
return;
10441045
}
10451046

@@ -1124,7 +1125,8 @@ Block *cir::BrCondOp::getSuccessorForOperands(ArrayRef<Attribute> operands) {
11241125
void cir::CaseOp::getSuccessorRegions(
11251126
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
11261127
if (!point.isParent()) {
1127-
regions.push_back(RegionSuccessor());
1128+
regions.push_back(
1129+
RegionSuccessor(getOperation(), getOperation()->getResults()));
11281130
return;
11291131
}
11301132
regions.push_back(RegionSuccessor(&getCaseRegion()));
@@ -1188,7 +1190,8 @@ static void printSwitchOp(OpAsmPrinter &p, cir::SwitchOp op,
11881190
void cir::SwitchOp::getSuccessorRegions(
11891191
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &region) {
11901192
if (!point.isParent()) {
1191-
region.push_back(RegionSuccessor());
1193+
region.push_back(
1194+
RegionSuccessor(getOperation(), getOperation()->getResults()));
11921195
return;
11931196
}
11941197

@@ -1402,7 +1405,8 @@ void cir::GlobalOp::getSuccessorRegions(
14021405
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
14031406
// The `ctor` and `dtor` regions always branch back to the parent operation.
14041407
if (!point.isParent()) {
1405-
regions.push_back(RegionSuccessor());
1408+
regions.push_back(
1409+
RegionSuccessor(getOperation(), getOperation()->getResults()));
14061410
return;
14071411
}
14081412

@@ -1961,7 +1965,7 @@ void cir::TernaryOp::getSuccessorRegions(
19611965
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
19621966
// The `true` and the `false` region branch back to the parent operation.
19631967
if (!point.isParent()) {
1964-
regions.push_back(RegionSuccessor(this->getODSResults(0)));
1968+
regions.push_back(RegionSuccessor(getOperation(), this->getODSResults(0)));
19651969
return;
19661970
}
19671971

@@ -2978,7 +2982,8 @@ void cir::TryOp::getSuccessorRegions(
29782982
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
29792983
// The `try` and the `catchers` region branch back to the parent operation.
29802984
if (!point.isParent()) {
2981-
regions.push_back(mlir::RegionSuccessor());
2985+
regions.push_back(
2986+
RegionSuccessor(getOperation(), getOperation()->getResults()));
29822987
return;
29832988
}
29842989

clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@ namespace cir {
1717
void LoopOpInterface::getLoopOpSuccessorRegions(
1818
LoopOpInterface op, mlir::RegionBranchPoint point,
1919
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
20-
assert(point.isParent() || point.getRegionOrNull());
20+
assert(point.isParent() || point.getTerminatorPredecessorOrNull());
2121

2222
// Branching to first region: go to condition or body (do-while).
2323
if (point.isParent()) {
2424
regions.emplace_back(&op.getEntry(), op.getEntry().getArguments());
2525
return;
2626
}
2727

28+
mlir::Region *parentRegion =
29+
point.getTerminatorPredecessorOrNull()->getParentRegion();
30+
2831
// Branching from condition: go to body or exit.
29-
if (&op.getCond() == point.getRegionOrNull()) {
30-
regions.emplace_back(mlir::RegionSuccessor(op->getResults()));
32+
if (&op.getCond() == parentRegion) {
33+
regions.emplace_back(mlir::RegionSuccessor(op, op->getResults()));
3134
regions.emplace_back(&op.getBody(), op.getBody().getArguments());
3235
return;
3336
}
3437

3538
// Branching from body: go to step (for) or condition.
36-
if (&op.getBody() == point.getRegionOrNull()) {
39+
if (&op.getBody() == parentRegion) {
3740
// FIXME(cir): Should we consider break/continue statements here?
3841
mlir::Region *afterBody =
3942
(op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());
@@ -42,7 +45,7 @@ void LoopOpInterface::getLoopOpSuccessorRegions(
4245
}
4346

4447
// Branching from step: go to condition.
45-
if (op.maybeGetStep() == point.getRegionOrNull()) {
48+
if (op.maybeGetStep() == parentRegion) {
4649
regions.emplace_back(&op.getCond(), op.getCond().getArguments());
4750
return;
4851
}

0 commit comments

Comments
 (0)