Skip to content

Commit 905b0db

Browse files
committed
Address code review comments
1 parent 01e63fb commit 905b0db

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def CIR_AnyIntOrGlobalViewAttr
6161
string cppType = "::mlir::TypedAttr";
6262
}
6363

64-
def CIR_AnyGlobalViewOrCatchAllOrUnwindAttr
64+
def CIR_TryHandlerAttr
6565
: AnyAttrOf<[CIR_AnyGlobalViewAttr, CIR_AnyCatchAllAttr, CIR_AnyUnwindAttr],
6666
"catch all or unwind or global view attribute"> {
6767
string cppType = "::mlir::TypedAttr";
@@ -79,8 +79,7 @@ def CIR_IntOrGlobalViewArrayAttr : TypedArrayAttrBase<CIR_AnyIntOrGlobalViewAttr
7979
string cppType = "::mlir::ArrayAttr";
8080
}
8181

82-
def CIR_GlobalViewOrCatchAllOrUnwindArrayAttr
83-
: TypedArrayAttrBase<CIR_AnyGlobalViewOrCatchAllOrUnwindAttr,
82+
def CIR_TryHandlerArrayAttr : TypedArrayAttrBase<CIR_TryHandlerAttr,
8483
"catch all or unwind or global view array attribute">;
8584

8685
#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,19 +4366,19 @@ def CIR_TryOp : CIR_Op<"try",[
43664366
let arguments = (ins
43674367
UnitAttr:$synthetic,
43684368
UnitAttr:$cleanup,
4369-
CIR_GlobalViewOrCatchAllOrUnwindArrayAttr:$catch_types
4369+
CIR_TryHandlerArrayAttr:$handler_types
43704370
);
43714371

43724372
let regions = (region
43734373
AnyRegion:$try_region,
4374-
VariadicRegion<MinSizedRegion<1>>:$handlers
4374+
VariadicRegion<MinSizedRegion<1>>:$handler_regions
43754375
);
43764376

43774377
let assemblyFormat = [{
43784378
(`synthetic` $synthetic^)?
43794379
(`cleanup` $cleanup^)?
43804380
$try_region
4381-
custom<CatchRegions>($handlers, $catch_types)
4381+
custom<TryHandlerRegions>($handler_regions, $handler_types)
43824382
attr-dict
43834383
}];
43844384

@@ -4387,10 +4387,11 @@ def CIR_TryOp : CIR_Op<"try",[
43874387
"llvm::function_ref<void(mlir::OpBuilder &, "
43884388
"mlir::Location)>":$tryBuilder,
43894389
"llvm::function_ref<void(mlir::OpBuilder &, mlir::Location, "
4390-
"mlir::OperationState &)>":$catchBuilder),
4390+
"mlir::OperationState &)>":$handlersBuilder),
43914391
[{
43924392
assert(tryBuilder && "expected builder callback for 'cir.try' body");
4393-
assert(catchBuilder && "expected builder callback for 'catch' body");
4393+
assert(handlersBuilder
4394+
&& "expected builder callback for 'handlers' body");
43944395

43954396
OpBuilder::InsertionGuard guard($_builder);
43964397

@@ -4400,7 +4401,7 @@ def CIR_TryOp : CIR_Op<"try",[
44004401
// Create try body region and set insertion point
44014402
$_builder.createBlock(tryBodyRegion);
44024403
tryBuilder($_builder, $_state.location);
4403-
catchBuilder($_builder, $_state.location, $_state);
4404+
handlersBuilder($_builder, $_state.location, $_state);
44044405
}]>
44054406
];
44064407

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,47 +2931,49 @@ void cir::TryOp::getSuccessorRegions(
29312931

29322932
// TODO(CIR): If we know a target function never throws a specific type, we
29332933
// can remove the catch handler.
2934-
for (mlir::Region &handler : this->getHandlers())
2935-
regions.push_back(mlir::RegionSuccessor(&handler));
2934+
for (mlir::Region &handlerRegion : this->getHandlerRegions())
2935+
regions.push_back(mlir::RegionSuccessor(&handlerRegion));
29362936
}
29372937

2938-
static void printCatchRegions(mlir::OpAsmPrinter &printer, cir::TryOp op,
2939-
mlir::MutableArrayRef<mlir::Region> regions,
2940-
mlir::ArrayAttr catchersAttr) {
2941-
if (!catchersAttr)
2938+
static void
2939+
printTryHandlerRegions(mlir::OpAsmPrinter &printer, cir::TryOp op,
2940+
mlir::MutableArrayRef<mlir::Region> handlerRegions,
2941+
mlir::ArrayAttr handlerTypes) {
2942+
if (!handlerTypes)
29422943
return;
29432944

2944-
for (const auto [catcherIdx, catcherAttr] : llvm::enumerate(catchersAttr)) {
2945-
if (catcherIdx)
2945+
for (const auto [typeIdx, typeAttr] : llvm::enumerate(handlerTypes)) {
2946+
if (typeIdx)
29462947
printer << " ";
29472948

2948-
if (mlir::isa<cir::CatchAllAttr>(catcherAttr)) {
2949+
if (mlir::isa<cir::CatchAllAttr>(typeAttr)) {
29492950
printer << "catch all ";
2950-
} else if (mlir::isa<cir::UnwindAttr>(catcherAttr)) {
2951+
} else if (mlir::isa<cir::UnwindAttr>(typeAttr)) {
29512952
printer << "unwind ";
29522953
} else {
29532954
printer << "catch [type ";
2954-
printer.printAttribute(catcherAttr);
2955+
printer.printAttribute(typeAttr);
29552956
printer << "] ";
29562957
}
29572958

2958-
printer.printRegion(regions[catcherIdx], /*printEntryBLockArgs=*/false,
2959+
printer.printRegion(handlerRegions[typeIdx],
2960+
/*printEntryBLockArgs=*/false,
29592961
/*printBlockTerminators=*/true);
29602962
}
29612963
}
29622964

2963-
static mlir::ParseResult
2964-
parseCatchRegions(mlir::OpAsmParser &parser,
2965-
llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &regions,
2966-
mlir::ArrayAttr &catchersAttr) {
2965+
static mlir::ParseResult parseTryHandlerRegions(
2966+
mlir::OpAsmParser &parser,
2967+
llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &handlerRegions,
2968+
mlir::ArrayAttr &handlerTypes) {
29672969

29682970
auto parseCheckedCatcherRegion = [&]() -> mlir::ParseResult {
2969-
regions.emplace_back(new mlir::Region);
2971+
handlerRegions.emplace_back(new mlir::Region);
29702972

2971-
mlir::Region &currRegion = *regions.back();
2973+
mlir::Region &currRegion = *handlerRegions.back();
29722974
mlir::SMLoc regionLoc = parser.getCurrentLocation();
29732975
if (parser.parseRegion(currRegion)) {
2974-
regions.clear();
2976+
handlerRegions.clear();
29752977
return failure();
29762978
}
29772979

@@ -3032,7 +3034,7 @@ parseCatchRegions(mlir::OpAsmParser &parser,
30323034
return mlir::failure();
30333035
}
30343036

3035-
catchersAttr = parser.getBuilder().getArrayAttr(catcherAttrs);
3037+
handlerTypes = parser.getBuilder().getArrayAttr(catcherAttrs);
30363038
return mlir::success();
30373039
}
30383040

clang/test/CIR/IR/invalid-try-catch.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module {
2222

2323
cir.func dso_local @invalid_catch_rtti_type() {
2424
cir.scope {
25-
// expected-error @below {{'cir.try' op attribute 'catch_types' failed to satisfy constraint: catch all or unwind or global view array attribute}}
25+
// expected-error @below {{'cir.try' op attribute 'handler_types' failed to satisfy constraint: catch all or unwind or global view array attribute}}
2626
cir.try {
2727
cir.yield
2828
} catch [type #cir.undef] {
@@ -40,7 +40,7 @@ module {
4040

4141
cir.func dso_local @invalid_catch_empty_block() {
4242
cir.scope {
43-
// expected-error @below {{'cir.try' op region #1 ('catch_regions') failed to verify constraint: region with at least 1 blocks}}
43+
// expected-error @below {{'cir.try' op region #1 ('handler_regions') failed to verify constraint: region with at least 1 blocks}}
4444
cir.try {
4545
cir.yield
4646
} catch all {

0 commit comments

Comments
 (0)