[clang] [CIR] Upstream TernaryOp (PR #137184)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 24 08:07:09 PDT 2025


================
@@ -1246,6 +1246,59 @@ def SelectOp : CIR_Op<"select", [Pure,
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// TernaryOp
+//===----------------------------------------------------------------------===//
+
+def TernaryOp : CIR_Op<"ternary",
+      [DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+       RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]> {
+  let summary = "The `cond ? a : b` C/C++ ternary operation";
+  let description = [{
+    The `cir.ternary` operation represents C/C++ ternary, much like a `select`
+    operation. The first argument is a `cir.bool` condition to evaluate, followed
+    by two regions to execute (true or false). This is different from `cir.if`
+    since each region is one block sized and the `cir.yield` closing the block
+    scope should have one argument.
----------------
erichkeane wrote:

Can we document it here?  One of the 'features' of it IIRC is that it only evaluates `Thing1` 1x instead of 2x (like in a traditional ternary), so it might be nice to document how that is represented here.

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


More information about the cfe-commits mailing list