[clang] [CIR] Upstream TernaryOp (PR #137184)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 15:39:03 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.
+
+ Example:
+
+ ```mlir
+ // x = cond ? a : b;
+
+ %x = cir.ternary (%cond, true_region {
+ ...
+ cir.yield %a : i32
+ }, false_region {
+ ...
+ cir.yield %b : i32
+ }) -> i32
+ ```
+ }];
+ let arguments = (ins CIR_BoolType:$cond);
+ let regions = (region AnyRegion:$trueRegion,
+ AnyRegion:$falseRegion);
+ let results = (outs Optional<CIR_AnyType>:$result);
----------------
andykaylor wrote:
What does it mean for this to be optional? Can we have a TernaryOp that doesn't return a value?
https://github.com/llvm/llvm-project/pull/137184
More information about the cfe-commits
mailing list