[clang] [CIR] Upstream TryCallOp (PR #165303)

Amr Hesham via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 23 09:45:23 PST 2025


================
@@ -2707,6 +2707,98 @@ def CIR_CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
   ];
 }
 
+def CIR_TryCallOp : CIR_CallOpBase<"try_call",[
+  DeclareOpInterfaceMethods<BranchOpInterface>,
+  Terminator, AttrSizedOperandSegments
+]> {
+  let summary = "try_call operation";
+
+  let description = [{
+    Mostly similar to cir.call but requires two destination
+    branches, one for handling exceptions in case its thrown and
+    the other one to follow on regular control-flow.
+
+    Example:
+
+    ```mlir
+    // Direct call
+    %result = cir.try_call @division(%a, %b) ^continue, ^landing_pad 
+      : (f32, f32) -> f32
+    ```
+  }];
+
+  let arguments = !con((ins
+    Variadic<CIR_AnyType>:$contOperands,
+    Variadic<CIR_AnyType>:$landingPadOperands
----------------
AmrDeveloper wrote:

They are arguments for the destinations, similar to what we have in BrCond when we pass the exception to pass it to another block. I can't see any case in TryCallOp that needs operands for destinations, but confirm the BranchOpInterface we need to have them to not lose some verification for now 🤔.

I was thinking of keeping them in the op but ignore them from builder, parser, and printer until we need them or if we realize we will not need them in the future, we can copy the verify to TryCallOp itself and remove those operands 🤔, what do you think?
@andykaylor @bcardosolopes

https://github.com/llvm/llvm-project/pull/165303


More information about the cfe-commits mailing list