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
33 changes: 33 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlir::RegionSuccessor> &regions) {
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really NFC because you are changing the logic - cir::BreakOp is not there before (nor I did find anything in git history of it being there and getting removed). I understand the test for this will come later after we upstream some passes, and I'm fine with this as is, but the PR should have the accurate info!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ope that's my bad. I thought I had already done the pr to add this handling. Thanks for the catch

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> &regions) {
Expand Down
28 changes: 0 additions & 28 deletions clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,6 @@

namespace cir {

void LoopOpInterface::getLoopOpSuccessorRegions(
LoopOpInterface op, mlir::RegionBranchPoint point,
llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
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<LoopOpInterface>(op);
Expand Down
Loading