Skip to content

Commit 69801b4

Browse files
committed
[CIR][NFC] Add getBreakTarget method to cir::BreakOp
1 parent 3d04a3d commit 69801b4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,10 @@ def CIR_BreakOp : CIR_Op<"break", [Terminator]> {
10531053
}];
10541054
let assemblyFormat = "attr-dict";
10551055
let hasVerifier = 1;
1056+
let extraClassDeclaration = [{
1057+
/// Find the parent operation corresponding to this break.
1058+
mlir::Operation *getBreakTarget();
1059+
}];
10561060
}
10571061

10581062
//===----------------------------------------------------------------------===//

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ void cir::AllocaOp::build(::mlir::OpBuilder &odsBuilder,
324324
// BreakOp
325325
//===----------------------------------------------------------------------===//
326326

327+
mlir::Operation *cir::BreakOp::getBreakTarget() {
328+
// Find the innermost loop or switch parent operation.
329+
mlir::Operation *parentOp = getOperation()->getParentOp();
330+
while (::mlir::isa_and_present<cir::LoopOpInterface, cir::SwitchOp>(parentOp))
331+
parentOp = parentOp->getParentOp();
332+
333+
return parentOp;
334+
}
335+
327336
LogicalResult cir::BreakOp::verify() {
328337
if (!getOperation()->getParentOfType<LoopOpInterface>() &&
329338
!getOperation()->getParentOfType<SwitchOp>())

0 commit comments

Comments
 (0)