Hendrik =?utf-8?q?Hübner?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>
================
@@ -958,6 +958,71 @@ def CIR_ScopeOp : CIR_Op<"scope", [
let hasLLVMLowering = false;
}
+//===----------------------------------------------------------------------===//
+// CmpThreeWayOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CmpThreeWayOp : CIR_Op<"cmp3way", [Pure, SameTypeOperands]> {
+ let summary = "Compare two values with C++ three-way comparison semantics";
+ let description = [{
+ The `cir.cmp3way` operation models the `<=>` operator in C++20. It takes
two
+ operands with the same type and produces a result indicating the ordering
+ between the two input operands.
+
+ The result of the operation is a signed integer that indicates the ordering
+ between the two input operands.
+
+ There are two kinds of ordering: strong ordering and partial ordering.
+ Comparing different types of values yields different kinds of orderings.
+ The `info` parameter gives the ordering kind and other necessary
information
+ about the comparison.
+
+ Example:
+
+ ```mlir
+ !s32i = !cir.int<s, 32>
+
+ #cmp3way_strong = #cmp3way_info<strong, lt = -1, eq = 0, gt = 1>
+ #cmp3way_partial = #cmp3way_info<strong, lt = -1, eq = 0, gt = 1,
unordered = 2>
+
+ %0 = cir.const #cir.int<0> : !s32i
+ %1 = cir.const #cir.int<1> : !s32i
+ %2 = cir.cmp3way(%0 : !s32i, %1, #cmp3way_strong) : !s8i
+
+ %3 = cir.const #cir.fp<0.0> : !cir.float
+ %4 = cir.const #cir.fp<1.0> : !cir.float
+ %5 = cir.cmp3way(%3 : !cir.float, %4, #cmp3way_partial) : !s8i
+ ```
+ }];
+
+ let arguments = (ins
+ CIR_AnyType:$lhs,
+ CIR_AnyType:$rhs,
+ CIR_CmpThreeWayInfoAttr:$info
+ );
+
+ let results = (outs CIR_AnySIntType:$result);
+
+ let assemblyFormat = [{
+ `(` $lhs `:` type($lhs) `,` $rhs `,` qualified($info) `)`
+ `:` type($result) attr-dict
+ }];
----------------
xlauko wrote:
I would suggest as we are also trying to get away from unnecessery parens:
```suggestion
let assemblyFormat = [{
qualified($info) $lhs, $rhs `:` qualified(type($lhs)) `->`
qualified(type($result)) attr-dict
}];
```
not sure about the `$info` though, in general it comes to me ugly and strange
to have that, as said before I believe ordering and maybe result kind is enough
here?
https://github.com/llvm/llvm-project/pull/169963
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits