Skip to content

Commit a70a81f

Browse files
committed
Address code review comments
1 parent d1d32ce commit a70a81f

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,9 +2860,10 @@ def CIR_TryCallOp : CIR_CallOpBase<"try_call",[
28602860
]> {
28612861
let summary = "try_call operation";
28622862
let description = [{
2863-
Mostly similar to `cir.call` but requires two destination
2864-
branches, one for follow on regular control-flow, and the other
2865-
one for handling exceptions in case it's thrown.
2863+
Similar to `cir.call` but requires two destination blocks,
2864+
one which is used if the call returns without throwing an
2865+
exception (the "normal" destination) and another which is used
2866+
if an exception is thrown (the "unwind" destination).
28662867

28672868
This operation is used only after the CFG flatterning pass.
28682869

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,8 @@ static void printCallCommon(mlir::Operation *op,
827827
printer << "(" << ops << ")";
828828

829829
if (normalDest) {
830-
assert(landingPad && "expected two successors");
831-
auto tryCall = dyn_cast<cir::TryCallOp>(op);
832-
assert(tryCall && "regular calls do not branch");
830+
assert(unwindDest && "expected two successors");
831+
auto tryCall = cast<cir::TryCallOp>(op);
833832
printer << ' ' << tryCall.getNormalDest();
834833
printer << ",";
835834
printer << ' ';
@@ -850,7 +849,6 @@ static void printCallCommon(mlir::Operation *op,
850849
CIRDialect::getSideEffectAttrName(),
851850
CIRDialect::getOperandSegmentSizesAttrName()};
852851
printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
853-
854852
printer << " : ";
855853
printer.printFunctionalType(op->getOperands().getTypes(),
856854
op->getResultTypes());

clang/test/CIR/IR/try-call.cir

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ cir.func private @division(%a: !s32i, %b: !s32i) -> !s32i
99
cir.func @flatten_structure_with_try_call_op() {
1010
%a = cir.const #cir.int<1> : !s32i
1111
%b = cir.const #cir.int<2> : !s32i
12-
%3 = cir.try_call @division(%a, %b) ^continue, ^landing_pad : (!s32i, !s32i) -> !s32i
13-
^continue:
14-
cir.br ^landing_pad
15-
^landing_pad:
12+
%3 = cir.try_call @division(%a, %b) ^normal, ^unwind : (!s32i, !s32i) -> !s32i
13+
^normal:
14+
cir.br ^end
15+
^unwind:
16+
cir.br ^end
17+
^end:
1618
cir.return
1719
}
1820

1921
// CHECK: cir.func private @division(!s32i, !s32i) -> !s32i
2022

2123
// CHECK: cir.func @flatten_structure_with_try_call_op() {
22-
// CHECK-NEXT: %[[CONST_0:.*]] = cir.const #cir.int<1> : !s32i
23-
// CHECK-NEXT: %[[CONST_1:.*]] = cir.const #cir.int<2> : !s32i
24-
// CHECK-NEXT: %[[CALL:.*]] = cir.try_call @division(%0, %1) ^[[CONTINUE:.*]], ^[[LANDING_PAD:.*]] : (!s32i, !s32i) -> !s32i
25-
// CHECK-NEXT: ^[[CONTINUE]]:
26-
// CHECK-NEXT: cir.br ^[[LANDING_PAD]]
27-
// CHECK-NEXT: ^[[LANDING_PAD]]:
24+
// CHECK-NEXT: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
25+
// CHECK-NEXT: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
26+
// CHECK-NEXT: %[[CALL:.*]] = cir.try_call @division(%[[CONST_1]], %[[CONST_2]]) ^[[NORMAL:.*]], ^[[UNWIND:.*]] : (!s32i, !s32i) -> !s32i
27+
// CHECK-NEXT: ^[[normal]]:
28+
// CHECK-NEXT: cir.br ^[[END:.*]]
29+
// CHECK-NEXT: ^[[unwind]]:
30+
// CHECK-NEXT: cir.br ^[[END:.*]]
31+
// CHECK-NEXT: ^[[END]]:
2832
// CHECK-NEXT: cir.return
2933
// CHECK-NEXT: }
3034

0 commit comments

Comments
 (0)