Skip to content

Commit 8e3be5c

Browse files
authored
[mlir][arith] Clean up select op implementation (#93351)
Inline traits used by `arith.select` only into `ArithOps.td`. Trim trailing whitespace in op description.
1 parent be83f5c commit 8e3be5c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,18 @@ def Arith_CmpFOp : Arith_CompareOp<"cmpf",
15401540
// SelectOp
15411541
//===----------------------------------------------------------------------===//
15421542

1543+
class AnyBooleanTypeMatch<list<string> names> :
1544+
AnyMatchOperatorTrait<names, "$_self.getType().isSignlessInteger(1)",
1545+
"scalar type">;
1546+
1547+
class ScalarConditionOrMatchingShape<list<string> names> :
1548+
PredOpTrait<
1549+
!head(names) # " is scalar or has matching shape",
1550+
Or<[AnyBooleanTypeMatch<[!head(names)]>.predicate,
1551+
AllShapesMatch<names>.predicate]>> {
1552+
list<string> values = names;
1553+
}
1554+
15431555
def SelectOp : Arith_Op<"select", [Pure,
15441556
AllTypesMatch<["true_value", "false_value", "result"]>,
15451557
ScalarConditionOrMatchingShape<["condition", "result"]>,
@@ -1548,16 +1560,16 @@ def SelectOp : Arith_Op<"select", [Pure,
15481560
let summary = "select operation";
15491561
let description = [{
15501562
The `arith.select` operation chooses one value based on a binary condition
1551-
supplied as its first operand.
1552-
1553-
If the value of the first operand (the condition) is `1`, then the second
1554-
operand is returned, and the third operand is ignored, even if it was poison.
1555-
1556-
If the value of the first operand (the condition) is `0`, then the third
1557-
operand is returned, and the second operand is ignored, even if it was poison.
1558-
1559-
If the value of the first operand (the condition) is poison, then the
1560-
operation returns poison.
1563+
supplied as its first operand.
1564+
1565+
If the value of the first operand (the condition) is `1`, then the second
1566+
operand is returned, and the third operand is ignored, even if it was poison.
1567+
1568+
If the value of the first operand (the condition) is `0`, then the third
1569+
operand is returned, and the second operand is ignored, even if it was poison.
1570+
1571+
If the value of the first operand (the condition) is poison, then the
1572+
operation returns poison.
15611573

15621574
The operation applies to vectors and tensors elementwise given the _shape_
15631575
of all operands is identical. The choice is made for each element

mlir/include/mlir/IR/OpBase.td

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,4 @@ class TCopVTEtAreSameAt<list<int> indices> : CPred<
670670
"[this](unsigned i) { return getElementTypeOrSelf(this->getOperand(i)); "
671671
"}))">;
672672

673-
class AnyScalarTypeMatch<list<string> names> :
674-
AnyMatchOperatorTrait<names, "$_self.getType().isSignlessInteger(1)",
675-
"scalar type">;
676-
677-
class ScalarConditionOrMatchingShape<list<string> names> :
678-
PredOpTrait<
679-
!head(names) # " is scalar or has matching shape",
680-
Or<[AnyScalarTypeMatch<[!head(names)]>.predicate,
681-
AllShapesMatch<names>.predicate]>> {
682-
list<string> values = names;
683-
}
684-
685673
#endif // OP_BASE

0 commit comments

Comments
 (0)