9#ifndef MLIR_IR_BUILTINTYPES_H
10#define MLIR_IR_BUILTINTYPES_H
31class RankedTensorType;
42template <
typename ConcreteType>
71 Type elementType)
const;
91 operator ShapedType()
const {
return llvm::cast<ShapedType>(*
this); }
103 public PtrLikeTypeInterface::Trait<BaseMemRefType>,
104 public ShapedType::Trait<BaseMemRefType> {
120 Type elementType)
const;
125 FailureOr<PtrLikeTypeInterface>
156 operator ShapedType()
const {
return llvm::cast<ShapedType>(*
this); }
159 operator PtrLikeTypeInterface()
const {
160 return llvm::cast<PtrLikeTypeInterface>(*
this);
170#define GET_TYPEDEF_CLASSES
171#include "mlir/IR/BuiltinTypes.h.inc"
174#include "mlir/IR/BuiltinTypeConstraints.h.inc"
187 layout(other.getLayout()), memorySpace(other.getMemorySpace()) {}
191 : shape(shape), elementType(elementType) {}
199 elementType = newElementType;
209 memorySpace = newMemorySpace;
213 operator MemRefType() {
214 return MemRefType::get(shape, elementType, layout, memorySpace);
220 MemRefLayoutAttrInterface layout;
235 encoding(other.getEncoding()) {}
239 : shape(shape), elementType(elementType), encoding(encoding) {}
247 elementType = newElementType;
252 encoding = newEncoding;
258 assert(pos < shape.size() &&
"overflow");
265 assert(pos <= shape.size() &&
"overflow");
266 shape.insert(pos, val);
270 operator RankedTensorType() {
271 return RankedTensorType::get(shape, elementType, encoding);
291 scalableDims(other.getScalableDims()) {}
296 : elementType(elementType),
shape(
shape), scalableDims(scalableDims) {}
301 scalableDims = newIsScalableDim;
306 elementType = newElementType;
312 assert(pos < shape.size() &&
"overflow");
314 if (!scalableDims.empty())
315 scalableDims.erase(pos);
321 assert(pos < shape.size() &&
"overflow");
326 operator VectorType() {
327 return VectorType::get(shape, elementType, scalableDims);
349std::optional<llvm::SmallDenseSet<unsigned>>
352 bool matchDynamic =
false);
371 ShapedType candidateReducedType);
382 using VectorType::VectorType;
385 auto vecTy = llvm::dyn_cast<VectorType>(type);
388 return vecTy.isScalable();
395 using VectorType::VectorType;
398 auto vecTy = llvm::dyn_cast<VectorType>(type);
401 return !vecTy.isScalable();
410 return llvm::isa<MemRefType, UnrankedMemRefType>(type);
415 llvm::isa<ComplexType, MemRefType, VectorType, UnrankedMemRefType>(
417 llvm::isa<MemRefElementTypeInterface>(type);
421 return llvm::isa<RankedTensorType, UnrankedTensorType>(type);
static Type getElementType(Type type)
Determine the element type of type.
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Attributes are known-constant values of operations.
This class provides a shared interface for ranked and unranked memref types.
MemRefType clone(ArrayRef< int64_t > shape) const
Return a clone of this type with the given new shape.
ArrayRef< int64_t > getShape() const
Returns the shape of this memref type.
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a memref.
FailureOr< PtrLikeTypeInterface > clonePtrWith(Attribute memorySpace, std::optional< Type > elementType) const
Clone this type with the given memory space and element type.
bool hasPtrMetadata() const
Returns that this ptr-like object has non-empty ptr metadata.
Attribute getMemorySpace() const
Returns the memory space in which data referred to by this memref resides.
static bool classof(Type type)
Methods for support type inquiry through isa, cast, and dyn_cast.
unsigned getMemorySpaceAsInt() const
[deprecated] Returns the memory space in old raw integer representation.
BaseMemRefType cloneWith(std::optional< ArrayRef< int64_t > > shape, Type elementType) const
Clone this type with the given shape and element type.
bool hasRank() const
Returns if this type is ranked, i.e. it has a known number of dimensions.
Type getElementType() const
Returns the element type of this memref type.
MemRefType clone(ArrayRef< int64_t > shape, Type elementType) const
Return a clone of this type with the given new shape and element type.
A vector type with no scalable dimensions.
static bool classof(Type type)
MLIRContext is the top-level object for a collection of MLIR operations.
This is a builder type that keeps local references to arguments.
Builder(ArrayRef< int64_t > shape, Type elementType)
Builder & setShape(ArrayRef< int64_t > newShape)
Builder(MemRefType other)
Builder & setMemorySpace(Attribute newMemorySpace)
Builder & setElementType(Type newElementType)
Builder & setLayout(MemRefLayoutAttrInterface newLayout)
This is a builder type that keeps local references to arguments.
Builder & setEncoding(Attribute newEncoding)
Builder(ArrayRef< int64_t > shape, Type elementType, Attribute encoding)
Build from scratch.
Builder & setElementType(Type newElementType)
Builder & setShape(ArrayRef< int64_t > newShape)
Builder(RankedTensorType other)
Build from another RankedTensorType.
Builder & insertDim(int64_t val, unsigned pos)
Insert a val into shape @pos.
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
A vector type containing at least one scalable dimension.
static bool classof(Type type)
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
TensorType cloneWith(std::optional< ArrayRef< int64_t > > shape, Type elementType) const
Clone this type with the given shape and element type.
RankedTensorType clone(ArrayRef< int64_t > shape) const
Return a clone of this type with the given new shape.
static bool classof(Type type)
Methods for support type inquiry through isa, cast, and dyn_cast.
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a tensor.
ArrayRef< int64_t > getShape() const
Returns the shape of this tensor type.
bool hasRank() const
Returns if this type is ranked, i.e. it has a known number of dimensions.
RankedTensorType clone(ArrayRef< int64_t > shape, Type elementType) const
Return a clone of this type with the given new shape and element type.
Type getElementType() const
Returns the element type of this tensor type.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
Type trait indicating that the type has value semantics.
This is a builder type that keeps local references to arguments.
Builder & setElementType(Type newElementType)
Builder & setDim(unsigned pos, int64_t val)
Set a dim in shape @pos to val.
Builder(VectorType other)
Build from another VectorType.
Builder & setShape(ArrayRef< int64_t > newShape, ArrayRef< bool > newIsScalableDim={})
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
Builder(ArrayRef< int64_t > shape, Type elementType, ArrayRef< bool > scalableDims={})
Build from scratch.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
detail::StorageUserTraitBase< ConcreteType, TraitType > TraitBase
This class represents the base of a type trait.
Include the generated interface declarations.
SliceVerificationResult
Enum that captures information related to verifier error conditions on slice insert/extract type of o...
AffineExpr makeCanonicalStridedLayoutExpr(ArrayRef< int64_t > sizes, ArrayRef< AffineExpr > exprs, MLIRContext *context)
Given MemRef sizes that are either static or dynamic, returns the canonical "contiguous" strides Affi...
std::optional< llvm::SmallDenseSet< unsigned > > computeRankReductionMask(ArrayRef< int64_t > originalShape, ArrayRef< int64_t > reducedShape, bool matchDynamic=false)
Given an originalShape and a reducedShape assumed to be a subset of originalShape with some 1 entries...
SliceVerificationResult isRankReducedType(ShapedType originalType, ShapedType candidateReducedType)
Check if originalType can be rank reduced to candidateReducedType type by dropping some dimensions wi...
Function Type Storage and Uniquing.
Integer Type Storage and Uniquing.
A type representing a collection of other types.