9 #ifndef MLIR_IR_BUILTINTYPES_H
10 #define MLIR_IR_BUILTINTYPES_H
93 Type elementType)
const;
102 operator ShapedType()
const {
return cast<ShapedType>(); }
129 Type elementType)
const;
145 operator ShapedType()
const {
return cast<ShapedType>(); }
154 #define GET_TYPEDEF_CLASSES
155 #include "mlir/IR/BuiltinTypes.h.inc"
170 layout(other.getLayout()), memorySpace(other.getMemorySpace()) {}
174 : shape(shape), elementType(elementType) {}
182 elementType = newElementType;
192 memorySpace = newMemorySpace;
196 operator MemRefType() {
197 return MemRefType::get(shape, elementType, layout, memorySpace);
203 MemRefLayoutAttrInterface layout;
218 encoding(other.getEncoding()) {}
222 : shape(shape), elementType(elementType), encoding(encoding) {}
230 elementType = newElementType;
235 encoding = newEncoding;
241 assert(pos < shape.size() &&
"overflow");
243 storage.append(shape.begin(), shape.end());
244 storage.erase(storage.begin() + pos);
245 shape = {storage.data(), storage.size()};
251 assert(pos <= shape.size() &&
"overflow");
253 storage.append(shape.begin(), shape.end());
254 storage.insert(storage.begin() + pos, val);
255 shape = {storage.data(), storage.size()};
259 operator RankedTensorType() {
260 return RankedTensorType::get(shape, elementType, encoding);
282 numScalableDims(other.getNumScalableDims()) {}
286 unsigned numScalableDims = 0)
287 : shape(shape), elementType(elementType),
288 numScalableDims(numScalableDims) {}
291 unsigned newNumScalableDims = 0) {
292 numScalableDims = newNumScalableDims;
298 elementType = newElementType;
304 assert(pos < shape.size() &&
"overflow");
305 if (pos >= shape.size() - numScalableDims)
308 storage.append(shape.begin(), shape.end());
309 storage.erase(storage.begin() + pos);
310 shape = {storage.data(), storage.size()};
320 return VectorType::get(shape, elementType, numScalableDims);
328 unsigned numScalableDims;
339 std::optional<llvm::SmallDenseSet<unsigned>>
360 ShapedType candidateReducedType);
373 type.
isa<MemRefElementTypeInterface>();
377 return type.
isa<Float8E5M2Type, Float8E4M3FNType, BFloat16Type, Float16Type,
378 Float32Type, Float64Type, Float80Type, Float128Type>();
382 return Float8E5M2Type::get(ctx);
386 return Float8E4M3FNType::get(ctx);
390 return BFloat16Type::get(ctx);
394 return Float16Type::get(ctx);
398 return Float32Type::get(ctx);
402 return Float64Type::get(ctx);
406 return Float80Type::get(ctx);
410 return Float128Type::get(ctx);
414 return type.
isa<RankedTensorType, UnrankedTensorType>();
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.
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.
BaseMemRefType cloneWith(std::optional< ArrayRef< int64_t >> shape, Type elementType) const
Clone this type with the given shape and element type.
static FloatType getF64(MLIRContext *ctx)
FloatType scaleElementBitwidth(unsigned scale)
Get or create a new FloatType with bitwidth scaled by scale.
static FloatType getFloat8E5M2(MLIRContext *ctx)
static FloatType getF80(MLIRContext *ctx)
static FloatType getFloat8E4M3FN(MLIRContext *ctx)
static FloatType getF16(MLIRContext *ctx)
const llvm::fltSemantics & getFloatSemantics()
Return the floating semantics of this float type.
static FloatType getBF16(MLIRContext *ctx)
unsigned getFPMantissaWidth()
Return the width of the mantissa of this type.
static FloatType getF128(MLIRContext *ctx)
unsigned getWidth()
Return the bitwidth of this float type.
static bool classof(Type type)
Methods for support type inquiry through isa, cast, and dyn_cast.
static FloatType getF32(MLIRContext *ctx)
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)
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
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.
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.
This is a builder type that keeps local references to arguments.
Builder(ArrayRef< int64_t > shape, Type elementType, unsigned numScalableDims=0)
Build from scratch.
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
Builder & setElementType(Type newElementType)
Builder(VectorType other)
Build from another VectorType.
Builder & setShape(ArrayRef< int64_t > newShape, unsigned newNumScalableDims=0)
Include the generated interface declarations.
Include the generated interface declarations.
SliceVerificationResult
Enum that captures information related to verifier error conditions on slice insert/extract type of o...
LogicalResult getStridesAndOffset(MemRefType t, SmallVectorImpl< int64_t > &strides, int64_t &offset)
Returns the strides of the MemRef if the layout map is in strided form.
MemRefType canonicalizeStridedLayout(MemRefType t)
Return a version of t with identity layout if it can be determined statically that the layout is the ...
std::optional< llvm::SmallDenseSet< unsigned > > computeRankReductionMask(ArrayRef< int64_t > originalShape, ArrayRef< int64_t > reducedShape)
Given an originalShape and a reducedShape assumed to be a subset of originalShape with some 1 entries...
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...
bool isStrided(MemRefType t)
Return true if the layout for t is compatible with strided semantics.
SliceVerificationResult isRankReducedType(ShapedType originalType, ShapedType candidateReducedType)
Check if originalType can be rank reduced to candidateReducedType type by dropping some dimensions wi...
This class represents an efficient way to signal success or failure.