Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ void cir::ConditionOp::getSuccessorRegions(
// Parent is a loop: condition may branch to the body or to the parent op.
if (auto loopOp = dyn_cast<LoopOpInterface>(getOperation()->getParentOp())) {
regions.emplace_back(&loopOp.getBody(), loopOp.getBody().getArguments());
regions.emplace_back(loopOp->getResults());
regions.emplace_back(getOperation(), loopOp->getResults());
}

assert(!cir::MissingFeatures::awaitOp());
}

MutableOperandRange
cir::ConditionOp::getMutableSuccessorOperands(RegionBranchPoint point) {
cir::ConditionOp::getMutableSuccessorOperands(RegionSuccessor point) {
// No values are yielded to the successor region.
return MutableOperandRange(getOperation(), 0, 0);
}
Expand Down Expand Up @@ -989,7 +989,8 @@ void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
SmallVectorImpl<RegionSuccessor> &regions) {
// The `then` and the `else` region branch back to the parent operation.
if (!point.isParent()) {
regions.push_back(RegionSuccessor());
regions.push_back(
RegionSuccessor(getOperation(), getOperation()->getResults()));
return;
}

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

Expand Down Expand Up @@ -1124,7 +1125,8 @@ Block *cir::BrCondOp::getSuccessorForOperands(ArrayRef<Attribute> operands) {
void cir::CaseOp::getSuccessorRegions(
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
if (!point.isParent()) {
regions.push_back(RegionSuccessor());
regions.push_back(
RegionSuccessor(getOperation(), getOperation()->getResults()));
return;
}
regions.push_back(RegionSuccessor(&getCaseRegion()));
Expand Down Expand Up @@ -1188,7 +1190,8 @@ static void printSwitchOp(OpAsmPrinter &p, cir::SwitchOp op,
void cir::SwitchOp::getSuccessorRegions(
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &region) {
if (!point.isParent()) {
region.push_back(RegionSuccessor());
region.push_back(
RegionSuccessor(getOperation(), getOperation()->getResults()));
return;
}

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

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

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

Expand Down
13 changes: 8 additions & 5 deletions clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@ namespace cir {
void LoopOpInterface::getLoopOpSuccessorRegions(
LoopOpInterface op, mlir::RegionBranchPoint point,
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
assert(point.isParent() || point.getRegionOrNull());
assert(point.isParent() || point.getTerminatorPredecessorOrNull());

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

mlir::Region *parentRegion =
point.getTerminatorPredecessorOrNull()->getParentRegion();

// Branching from condition: go to body or exit.
if (&op.getCond() == point.getRegionOrNull()) {
regions.emplace_back(mlir::RegionSuccessor(op->getResults()));
if (&op.getCond() == parentRegion) {
regions.emplace_back(mlir::RegionSuccessor(op, op->getResults()));
regions.emplace_back(&op.getBody(), op.getBody().getArguments());
return;
}

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

// Branching from step: go to condition.
if (op.maybeGetStep() == point.getRegionOrNull()) {
if (op.maybeGetStep() == parentRegion) {
regions.emplace_back(&op.getCond(), op.getCond().getArguments());
return;
}
Expand Down
Loading