[clang] [CIR] Upstream CIR Dialect TryOp with Catch Attrs (PR #162897)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 14:48:19 PDT 2025
================
@@ -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 [";
+ llvm::interleaveComma(catchersAttr, printer, [&](const Attribute &a) {
+ if (mlir::isa<cir::CatchUnwindAttr>(a)) {
+ printer.printAttribute(a);
+ printer << " ";
+ } else if (!a) {
----------------
andykaylor wrote:
Shouldn't this be handled by a CatchAllAttr?
https://github.com/llvm/llvm-project/pull/162897
More information about the cfe-commits
mailing list