Skip to content

Commit 15e50b1

Browse files
[mlir][IR] Clean up type constraints around ValueSemanticsContainerOf (llvm#126075)
* Remove duplicate `TypeOrContainer`. There is an identical class with the same name: `TypeOrValueSemanticsContainer`. * Remove `TypeOrContainerOfAnyRank` and use `TypeOrValueSemanticsContainer` instead. `TypeOrContainerOfAnyRank` is inconsistent with the other classes because it explicitly checks for `VectorType` and `TensorType` instead of utilizing the value semantics type trait. * Remove `SignlessIntegerOrIndexLikeOfAnyRank` etc. and use `SignlessIntegerOrIndexLike` instead. `SignlessIntegerOrIndexLike` etc. already allow 0-d vectors, so there is no difference with `SignlessIntegerOrIndexLikeOfAnyRank`.
1 parent 26ecddb commit 15e50b1

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,6 @@ class Arith_CompareOp<string mnemonic, list<Trait> traits = []> :
144144
let assemblyFormat = "$predicate `,` $lhs `,` $rhs attr-dict `:` type($lhs)";
145145
}
146146

147-
// Just like `Arith_CompareOp` but also admits 0-D vectors. Introduced
148-
// temporarily to allow gradual transition to 0-D vectors.
149-
class Arith_CompareOpOfAnyRank<string mnemonic, list<Trait> traits = []> :
150-
Arith_CompareOp<mnemonic, traits> {
151-
let results = (outs BoolLikeOfAnyRank:$result);
152-
}
153-
154147
class Arith_IntBinaryOpWithOverflowFlags<string mnemonic, list<Trait> traits = []> :
155148
Arith_BinaryOp<mnemonic, traits #
156149
[Pure, DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
@@ -1426,9 +1419,9 @@ def Arith_BitcastOp : Arith_CastOp<"bitcast", BitcastTypeConstraint,
14261419
// CmpIOp
14271420
//===----------------------------------------------------------------------===//
14281421

1429-
def Arith_CmpIOp
1430-
: Arith_CompareOpOfAnyRank<"cmpi",
1431-
[DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>]> {
1422+
def Arith_CmpIOp : Arith_CompareOp<"cmpi",
1423+
[DeclareOpInterfaceMethods<InferIntRangeInterface,
1424+
["inferResultRanges"]>]> {
14321425
let summary = "integer comparison operation";
14331426
let description = [{
14341427
The `cmpi` operation is a generic comparison for integer-like types. Its two
@@ -1495,8 +1488,8 @@ def Arith_CmpIOp
14951488
}];
14961489

14971490
let arguments = (ins Arith_CmpIPredicateAttr:$predicate,
1498-
SignlessIntegerOrIndexLikeOfAnyRank:$lhs,
1499-
SignlessIntegerOrIndexLikeOfAnyRank:$rhs);
1491+
SignlessIntegerOrIndexLike:$lhs,
1492+
SignlessIntegerOrIndexLike:$rhs);
15001493

15011494
let hasFolder = 1;
15021495
let hasCanonicalizer = 1;

mlir/include/mlir/Dialect/Polynomial/IR/PolynomialTypes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def Polynomial_PolynomialType : Polynomial_Type<"Polynomial", "polynomial"> {
2626
let assemblyFormat = "`<` struct(params) `>`";
2727
}
2828

29-
def PolynomialLike: TypeOrContainer<Polynomial_PolynomialType, "polynomial-like">;
29+
def PolynomialLike : TypeOrValueSemanticsContainer<
30+
Polynomial_PolynomialType, "polynomial-like">;
3031

3132

3233
#endif // POLYNOMIAL_TYPES

mlir/include/mlir/IR/CommonTypeConstraints.td

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,6 @@ class NestedTupleOf<list<Type> allowedTypes> :
879879
//===----------------------------------------------------------------------===//
880880
// Common type constraints
881881
//===----------------------------------------------------------------------===//
882-
// Type constraint for types that are "like" some type or set of types T, that is
883-
// they're either a T, a vector of Ts, or a tensor of Ts.
884-
class TypeOrContainer<Type allowedType, string name> : TypeConstraint<Or<[
885-
allowedType.predicate,
886-
ValueSemanticsContainerOf<[allowedType]>.predicate]>,
887-
name>;
888882

889883
// Type constraint for types that are "like" some type or set of types T, that is
890884
// they're either a T or a mapable container of Ts.
@@ -894,36 +888,23 @@ class TypeOrValueSemanticsContainer<Type allowedType, string name>
894888
ValueSemanticsContainerOf<[allowedType]>.predicate]>,
895889
name>;
896890

897-
// Temporary constraint to allow gradual transition to supporting 0-D vectors.
898-
// TODO: Remove this when all ops support 0-D vectors.
899-
class TypeOrContainerOfAnyRank<Type allowedType, string name> : TypeConstraint<Or<[
900-
allowedType.predicate, VectorOfAnyRankOf<[allowedType]>.predicate,
901-
TensorOf<[allowedType]>.predicate]>,
902-
name>;
903-
904-
905891
// Type constraint for bool-like types: bools, vectors of bools, tensors of
906892
// bools.
907-
def BoolLike : TypeOrContainer<I1, "bool-like">;
893+
def BoolLike : TypeOrValueSemanticsContainer<I1, "bool-like">;
908894

909-
def BoolLikeOfAnyRank : TypeOrContainerOfAnyRank<I1, "bool-like">;
910-
911-
// Type constraint for signless-integer-like types: signless integers,
912-
// vectors of signless integers or tensors of signless integers.
895+
// Type constraint for signless-integer-like types: signless integers or
896+
// value-semantics containers of signless integers.
913897
def SignlessIntegerLike : TypeOrValueSemanticsContainer<
914898
AnySignlessInteger, "signless-integer">;
915899

916900
// Type constraint for signless-integer-like types: signless integers, indices,
917-
// vectors of signless integers or indices, tensors of signless integers.
901+
// or value-semantics containers of signless integers or indices.
918902
def SignlessIntegerOrIndexLike : TypeOrValueSemanticsContainer<
919903
AnySignlessIntegerOrIndex, "signless-integer-like">;
920904

921-
def SignlessIntegerOrIndexLikeOfAnyRank : TypeOrContainerOfAnyRank<
922-
AnySignlessIntegerOrIndex,
923-
"signless-integer-like">;
924-
925-
// Type constraint for float-like types: floats, vectors or tensors thereof.
926-
def FloatLike : TypeOrContainer<AnyFloat, "floating-point-like">;
905+
// Type constraint for float-like types: floats or value-semantics containers
906+
// of floats.
907+
def FloatLike : TypeOrValueSemanticsContainer<AnyFloat, "floating-point-like">;
927908

928909
// Type constraint for signless-integer-or-index-like or float-like types.
929910
def SignlessIntegerOrFloatLike : TypeConstraint<Or<[

0 commit comments

Comments
 (0)