9 #ifndef MLIR_IR_BUILTINTYPES_H
10 #define MLIR_IR_BUILTINTYPES_H
31 class RankedTensorType;
36 struct FunctionTypeStorage;
37 struct IntegerTypeStorage;
38 struct TupleTypeStorage;
42 template <
typename ConcreteType>
71 Type elementType)
const;
91 operator ShapedType()
const {
return llvm::cast<ShapedType>(*
this); }
118 Type elementType)
const;
145 operator ShapedType()
const {
return llvm::cast<ShapedType>(*
this); }
154 #define GET_TYPEDEF_CLASSES
155 #include "mlir/IR/BuiltinTypes.h.inc"
158 #include "mlir/IR/BuiltinTypeConstraints.h.inc"
171 layout(other.getLayout()), memorySpace(other.getMemorySpace()) {}
175 : shape(shape), elementType(elementType) {}
183 elementType = newElementType;
193 memorySpace = newMemorySpace;
197 operator MemRefType() {
204 MemRefLayoutAttrInterface layout;
219 encoding(other.getEncoding()) {}
223 : shape(shape), elementType(elementType), encoding(encoding) {}
231 elementType = newElementType;
236 encoding = newEncoding;
242 assert(pos < shape.
size() &&
"overflow");
249 assert(pos <= shape.
size() &&
"overflow");
254 operator RankedTensorType() {
275 scalableDims(other.getScalableDims()) {}
280 : elementType(elementType), shape(shape), scalableDims(scalableDims) {}
285 scalableDims = newIsScalableDim;
290 elementType = newElementType;
296 assert(pos < shape.size() &&
"overflow");
298 if (!scalableDims.
empty())
299 scalableDims.
erase(pos);
305 assert(pos < shape.size() &&
"overflow");
310 operator VectorType() {
333 std::optional<llvm::SmallDenseSet<unsigned>>
336 bool matchDynamic =
false);
355 ShapedType candidateReducedType);
366 using VectorType::VectorType;
369 auto vecTy = llvm::dyn_cast<VectorType>(type);
372 return vecTy.isScalable();
379 using VectorType::VectorType;
382 auto vecTy = llvm::dyn_cast<VectorType>(type);
385 return !vecTy.isScalable();
394 return llvm::isa<MemRefType, UnrankedMemRefType>(type);
399 llvm::isa<ComplexType, MemRefType, VectorType, UnrankedMemRefType>(
401 llvm::isa<MemRefElementTypeInterface>(type);
405 return llvm::isa<RankedTensorType, UnrankedTensorType>(type);
static Type getElementType(Type type, ArrayRef< int32_t > indices, function_ref< InFlightDiagnostic(StringRef)> emitErrorFn)
Walks the given type hierarchy with the given indices, potentially down to component granularity,...
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
Base type for affine expression.
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.
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.
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.
BaseMemRefType cloneWith(std::optional< ArrayRef< int64_t >> shape, Type elementType) const
Clone this type with the given shape and element type.
void insert(size_t index, T value)
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 & setLayout(MemRefLayoutAttrInterface newLayout)
Builder & setElementType(Type newElementType)
Builder(MemRefType other)
Builder & setShape(ArrayRef< int64_t > newShape)
Builder & setMemorySpace(Attribute newMemorySpace)
This is a builder type that keeps local references to arguments.
Builder(ArrayRef< int64_t > shape, Type elementType, Attribute encoding)
Build from scratch.
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
Builder & setShape(ArrayRef< int64_t > newShape)
Builder & insertDim(int64_t val, unsigned pos)
Insert a val into shape @pos.
Builder(RankedTensorType other)
Build from another RankedTensorType.
Builder & setElementType(Type newElementType)
Builder & setEncoding(Attribute newEncoding)
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...
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.
TensorType cloneWith(std::optional< ArrayRef< int64_t >> shape, Type elementType) const
Clone this type with the given shape and element type.
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.
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 & dropDim(unsigned pos)
Erase a dim from shape @pos.
Builder & setDim(unsigned pos, int64_t val)
Set a dim in shape @pos to val.
Builder & setShape(ArrayRef< int64_t > newShape, ArrayRef< bool > newIsScalableDim={})
Builder & setElementType(Type newElementType)
Builder(VectorType other)
Build from another VectorType.
Builder(ArrayRef< int64_t > shape, Type elementType, ArrayRef< bool > scalableDims={})
Build from scratch.
Helper class for implementing traits for storage classes.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
SliceVerificationResult
Enum that captures information related to verifier error conditions on slice insert/extract type of o...
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
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...