@@ -423,8 +423,8 @@ def Builtin_Integer : Builtin_Type<"Integer", "integer"> {
423423//===----------------------------------------------------------------------===//
424424
425425def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
426- ShapedTypeInterface
427- ], "BaseMemRefType" > {
426+ BaseMemRefTypeInterface
427+ ]> {
428428 let summary = "Shaped reference to a region of memory";
429429 let description = [{
430430 Syntax:
@@ -675,7 +675,7 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
675675 "unsigned":$memorySpaceInd)>
676676 ];
677677 let extraClassDeclaration = [{
678- using BaseMemRefType ::clone;
678+ using ShapedType::Trait<MemRefType> ::clone;
679679 using ShapedType::Trait<MemRefType>::getElementTypeBitWidth;
680680 using ShapedType::Trait<MemRefType>::getRank;
681681 using ShapedType::Trait<MemRefType>::getNumElements;
@@ -693,6 +693,13 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
693693 /// New `Attribute getMemorySpace()` method should be used instead.
694694 unsigned getMemorySpaceAsInt() const;
695695
696+ /// Returns if this type is ranked (always true).
697+ bool hasRank() const { return true; }
698+
699+ /// Returns a clone of this type with the given shape and element
700+ /// type. If a shape is not provided, the current shape of the type is used.
701+ MemRefType cloneWith(std::optional<ArrayRef<int64_t>> shape,
702+ Type elementType) const;
696703 }];
697704 let skipDefaultBuilders = 1;
698705 let genVerifyDecl = 1;
@@ -773,8 +780,8 @@ def Builtin_Opaque : Builtin_Type<"Opaque", "opaque"> {
773780//===----------------------------------------------------------------------===//
774781
775782def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
776- ShapedTypeInterface , ValueSemantics
777- ], "TensorType" > {
783+ TensorTypeInterface , ValueSemantics
784+ ]> {
778785 let summary = "Multi-dimensional array with a fixed number of dimensions";
779786 let description = [{
780787 Syntax:
@@ -855,7 +862,7 @@ def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
855862 }]>
856863 ];
857864 let extraClassDeclaration = [{
858- using TensorType ::clone;
865+ using ShapedType::Trait<RankedTensorType> ::clone;
859866 using ShapedType::Trait<RankedTensorType>::getElementTypeBitWidth;
860867 using ShapedType::Trait<RankedTensorType>::getRank;
861868 using ShapedType::Trait<RankedTensorType>::getNumElements;
@@ -869,11 +876,12 @@ def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
869876 /// Arguments that are passed into the builder must outlive the builder.
870877 class Builder;
871878
872- /// Return a clone of this type with the given new element type and the same
873- /// shape as this type.
874- RankedTensorType clone(::mlir::Type elementType) {
875- return ::llvm::cast<RankedTensorType>(cloneWith(getShape(), elementType));
876- }
879+ /// Returns if this type is ranked (always true).
880+ bool hasRank() const { return true; }
881+
882+ /// Returns a clone of this type with the given shape and element type.
883+ RankedTensorType cloneWith(std::optional<ArrayRef<int64_t>> shape,
884+ Type elementType) const;
877885 }];
878886 let skipDefaultBuilders = 1;
879887 let genVerifyDecl = 1;
@@ -951,8 +959,8 @@ def Builtin_Tuple : Builtin_Type<"Tuple", "tuple"> {
951959//===----------------------------------------------------------------------===//
952960
953961def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
954- ShapedTypeInterface
955- ], "BaseMemRefType" > {
962+ BaseMemRefTypeInterface
963+ ]> {
956964 let summary = "Shaped reference, with unknown rank, to a region of memory";
957965 let description = [{
958966 Syntax:
@@ -998,7 +1006,7 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
9981006 }]>
9991007 ];
10001008 let extraClassDeclaration = [{
1001- using BaseMemRefType ::clone;
1009+ using ShapedType::Trait<UnrankedMemRefType> ::clone;
10021010 using ShapedType::Trait<UnrankedMemRefType>::getElementTypeBitWidth;
10031011 using ShapedType::Trait<UnrankedMemRefType>::getRank;
10041012 using ShapedType::Trait<UnrankedMemRefType>::getNumElements;
@@ -1014,11 +1022,12 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
10141022 /// New `Attribute getMemorySpace()` method should be used instead.
10151023 unsigned getMemorySpaceAsInt() const;
10161024
1017- /// Return a clone of this type with the given new element type and the same
1018- /// shape as this type.
1019- MemRefType clone(::mlir::Type elementType) {
1020- return ::llvm::cast<MemRefType>(cloneWith(getShape(), elementType));
1021- }
1025+ /// Returns if this type is ranked (always false).
1026+ bool hasRank() const { return false; }
1027+
1028+ /// Returns a clone of this type with the given shape and element type.
1029+ BaseMemRefType cloneWith(std::optional<ArrayRef<int64_t>> shape,
1030+ Type elementType) const;
10221031 }];
10231032 let skipDefaultBuilders = 1;
10241033 let genVerifyDecl = 1;
@@ -1029,8 +1038,8 @@ def Builtin_UnrankedMemRef : Builtin_Type<"UnrankedMemRef", "unranked_memref", [
10291038//===----------------------------------------------------------------------===//
10301039
10311040def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
1032- ShapedTypeInterface , ValueSemantics
1033- ], "TensorType" > {
1041+ TensorTypeInterface , ValueSemantics
1042+ ]> {
10341043 let summary = "Multi-dimensional array with unknown dimensions";
10351044 let description = [{
10361045 Syntax:
@@ -1057,7 +1066,7 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
10571066 }]>
10581067 ];
10591068 let extraClassDeclaration = [{
1060- using TensorType ::clone;
1069+ using ShapedType::Trait<UnrankedTensorType> ::clone;
10611070 using ShapedType::Trait<UnrankedTensorType>::getElementTypeBitWidth;
10621071 using ShapedType::Trait<UnrankedTensorType>::getRank;
10631072 using ShapedType::Trait<UnrankedTensorType>::getNumElements;
@@ -1068,6 +1077,13 @@ def Builtin_UnrankedTensor : Builtin_Type<"UnrankedTensor", "unranked_tensor", [
10681077 using ShapedType::Trait<UnrankedTensorType>::getDynamicDimIndex;
10691078
10701079 ArrayRef<int64_t> getShape() const { return std::nullopt; }
1080+
1081+ /// Returns if this type is ranked (always false).
1082+ bool hasRank() const { return false; }
1083+
1084+ /// Returns a clone of this type with the given shape and element type.
1085+ TensorType cloneWith(std::optional<ArrayRef<int64_t>> shape,
1086+ Type elementType) const;
10711087 }];
10721088 let skipDefaultBuilders = 1;
10731089 let genVerifyDecl = 1;
0 commit comments