================
@@ -2878,6 +2878,120 @@ LogicalResult cir::TypeInfoAttr::verify(
return success();
}
+//===----------------------------------------------------------------------===//
+// TryOp
+//===----------------------------------------------------------------------===//
+
+void cir::TryOp::getSuccessorRegions(
+ mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
+ // If any index all the underlying regions branch back to the parent
+ // operation.
+ if (!point.isParent()) {
+ regions.push_back(RegionSuccessor());
+ return;
+ }
+
+ // If the condition isn't constant, both regions may be executed.
+ regions.push_back(RegionSuccessor(&getTryRegion()));
+
+ // FIXME: optimize, ideas include:
+ // - If we know a target function never throws a specific type, we can
+ // remove the catch handler.
+ for (mlir::Region &r : this->getCatchRegions())
+ regions.push_back(RegionSuccessor(&r));
+}
+
+static void printCatchRegions(OpAsmPrinter &printer, cir::TryOp op,
+ mlir::MutableArrayRef<::mlir::Region> regions,
+ mlir::ArrayAttr catchersAttr) {
+ if (!catchersAttr)
+ return;
+
+ int currCatchIdx = 0;
+ printer << "catch [";
----------------
andykaylor wrote:
I don't like the square brackets around the catch region. Is there some
precedent for that in other dialects?
Currently we have something that looks like this in the incubator:
```
cir.try {
cir.call exception @_Z3foov() : () -> ()
cir.yield
} catch [type #cir.global_view<@_ZTIPi> : !cir.ptr<!u8i> {
%1 = cir.catch_param -> !cir.ptr<!s32i>
cir.store align(8) %1, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
cir.yield
}, type #cir.global_view<@_ZTIPf> : !cir.ptr<!u8i> {
%2 = cir.catch_param -> !cir.ptr<!cir.float>
cir.store align(8) %2, %0 : !cir.ptr<!cir.float>,
!cir.ptr<!cir.ptr<!cir.float>>
cir.yield
}, #cir.unwind {
cir.resume
}]
```
I'd prefer to see something like this:
```
cir.try {
cir.call exception @_Z3foov() : () -> ()
cir.yield
} catch [type #cir.global_view<@_ZTIPi> : !cir.ptr<!u8i>] {
%1 = cir.catch_param -> !cir.ptr<!s32i>
cir.store align(8) %1, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
cir.yield
} catch [type #cir.global_view<@_ZTIPf> : !cir.ptr<!u8i>] {
%2 = cir.catch_param -> !cir.ptr<!cir.float>
cir.store align(8) %2, %0 : !cir.ptr<!cir.float>,
!cir.ptr<!cir.ptr<!cir.float>>
cir.yield
} unwind {
cir.resume
}
```
https://github.com/llvm/llvm-project/pull/162897
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits