diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td @@ -43,9 +43,8 @@ let emitAccessorPrefix = kEmitAccessorPrefix_Prefixed; } -def Shape_ShapeType : DialectType()">, "shape">, - BuildableType<"$_builder.getType<::mlir::shape::ShapeType>()"> { +def Shape_ShapeType : TypeWithDialect< + SimpleBuildableType<"::mlir::shape::ShapeType", "shape">, ShapeDialect> { let description = [{ `shape.shape` represents either an unranked shape, a ranked shape with possibly unknown dimensions or an invalid shape. The rank is of type @@ -62,9 +61,8 @@ }]; } -def Shape_SizeType : DialectType()">, "size">, - BuildableType<"$_builder.getType<::mlir::shape::SizeType>()"> { +def Shape_SizeType : TypeWithDialect< + SimpleBuildableType<"::mlir::shape::SizeType", "size">, ShapeDialect> { let description = [{ `shape.size` represents a non-negative integer with support for being unknown and invalid. @@ -75,10 +73,9 @@ }]; } -def Shape_ValueShapeType : DialectType()">, "value shape">, - BuildableType<"::mlir::shape::ValueShapeType::get($_builder.getContext())"> -{ +def Shape_ValueShapeType : TypeWithDialect< + SimpleBuildableType<"::mlir::shape::ValueShapeType", "value shape">, + ShapeDialect> { let description = [{ `shape.value_shape` represents the value produced by an operation (this corresponds to `Value` in the compiler) and a shape. Conceptually this is a @@ -112,9 +109,9 @@ def Shape_SizeOrIndexType : AnyTypeOf<[Shape_SizeType, Index], "size or index">; -def Shape_WitnessType : DialectType()">, "witness">, - BuildableType<"$_builder.getType<::mlir::shape::WitnessType>()"> { +def Shape_WitnessType : TypeWithDialect< + SimpleBuildableType<"::mlir::shape::WitnessType", "witness">, + ShapeDialect> { let description = [{ A witness is a structural device in the compiler to maintain ordering of code relying on information obtained from passing assertions. Witnesses do diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -270,6 +270,7 @@ TypeConstraint { string description = ""; string builderCall = ""; + Dialect dialect = ?; } // Allows providing an alternative name and summary to an existing type def. @@ -279,13 +280,6 @@ let builderCall = t.builderCall; } -// A type of a specific dialect. -class DialectType : - Type { - Dialect dialect = d; -} - // A variadic type constraint. It expands to zero or more of the base type. This // class is used for supporting variadic operands/results. class Variadic : TypeConstraint : + Type { + let dialect = d; + let builderCall = t.builderCall; +} +class TypeWithBuilder : + Type, BuildableType { + let dialect = t.dialect; +} + +// A type of a specific dialect. +class DialectType : + TypeWithDialect, d>; + +// Type whose membership is via isa. +class SimpleType : + Type()">, desc, cppTypeClass>; +// Type whose membership is via isa and whose construction is trivial. +class SimpleBuildableType : + TypeWithBuilder< + SimpleType, + "$_builder.getType<" # cppTypeClass # ">()">; + // A type that's buildable iff the type passed as an argument is buildable. // This is intended for use by types like container types, which are only // buildable if the type of their elements is buildable. @@ -333,9 +352,7 @@ def AnyType : Type, "any type">; // None type -def NoneType : Type()">, "none type", - "::mlir::NoneType">, - BuildableType<"$_builder.getType<::mlir::NoneType>()">; +def NoneType : SimpleBuildableType<"::mlir::NoneType", "none type">; // Any type from the given list class AnyTypeOf allowedTypes, string summary = "", @@ -440,9 +457,7 @@ def UI64 : UI<64>; // Index type. -def Index : Type()">, "index", - "::mlir::IndexType">, - BuildableType<"$_builder.getIndexType()">; +def Index : SimpleBuildableType<"::mlir::IndexType", "index">; // Any signless integer type or index type. def AnySignlessIntegerOrIndex : Type,