MLIR  20.0.0git
BuiltinTypes.h
Go to the documentation of this file.
1 //===- BuiltinTypes.h - MLIR Builtin Type Classes ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_IR_BUILTINTYPES_H
10 #define MLIR_IR_BUILTINTYPES_H
11 
14 #include "mlir/Support/ADTExtras.h"
15 
16 namespace llvm {
17 class BitVector;
18 struct fltSemantics;
19 } // namespace llvm
20 
21 //===----------------------------------------------------------------------===//
22 // Tablegen Interface Declarations
23 //===----------------------------------------------------------------------===//
24 
25 namespace mlir {
26 class AffineExpr;
27 class AffineMap;
28 class FloatType;
29 class IndexType;
30 class IntegerType;
31 class MemRefType;
32 class RankedTensorType;
33 class StringAttr;
34 class TypeRange;
35 
36 namespace detail {
37 struct FunctionTypeStorage;
38 struct IntegerTypeStorage;
39 struct TupleTypeStorage;
40 } // namespace detail
41 
42 /// Type trait indicating that the type has value semantics.
43 template <typename ConcreteType>
45  : public TypeTrait::TraitBase<ConcreteType, ValueSemantics> {};
46 
47 //===----------------------------------------------------------------------===//
48 // FloatType
49 //===----------------------------------------------------------------------===//
50 
51 class FloatType : public Type {
52 public:
53  using Type::Type;
54 
55  // Convenience factories.
56  static FloatType getBF16(MLIRContext *ctx);
57  static FloatType getF16(MLIRContext *ctx);
58  static FloatType getF32(MLIRContext *ctx);
59  static FloatType getTF32(MLIRContext *ctx);
60  static FloatType getF64(MLIRContext *ctx);
61  static FloatType getF80(MLIRContext *ctx);
62  static FloatType getF128(MLIRContext *ctx);
63  static FloatType getFloat8E5M2(MLIRContext *ctx);
64  static FloatType getFloat8E4M3(MLIRContext *ctx);
69 
70  /// Methods for support type inquiry through isa, cast, and dyn_cast.
71  static bool classof(Type type);
72 
73  /// Return the bitwidth of this float type.
74  unsigned getWidth();
75 
76  /// Return the width of the mantissa of this type.
77  /// The width includes the integer bit.
78  unsigned getFPMantissaWidth();
79 
80  /// Get or create a new FloatType with bitwidth scaled by `scale`.
81  /// Return null if the scaled element type cannot be represented.
82  FloatType scaleElementBitwidth(unsigned scale);
83 
84  /// Return the floating semantics of this float type.
85  const llvm::fltSemantics &getFloatSemantics();
86 };
87 
88 //===----------------------------------------------------------------------===//
89 // TensorType
90 //===----------------------------------------------------------------------===//
91 
92 /// Tensor types represent multi-dimensional arrays, and have two variants:
93 /// RankedTensorType and UnrankedTensorType.
94 /// Note: This class attaches the ShapedType trait to act as a mixin to
95 /// provide many useful utility functions. This inheritance has no effect
96 /// on derived tensor types.
97 class TensorType : public Type, public ShapedType::Trait<TensorType> {
98 public:
99  using Type::Type;
100 
101  /// Returns the element type of this tensor type.
102  Type getElementType() const;
103 
104  /// Returns if this type is ranked, i.e. it has a known number of dimensions.
105  bool hasRank() const;
106 
107  /// Returns the shape of this tensor type.
108  ArrayRef<int64_t> getShape() const;
109 
110  /// Clone this type with the given shape and element type. If the
111  /// provided shape is `std::nullopt`, the current shape of the type is used.
112  TensorType cloneWith(std::optional<ArrayRef<int64_t>> shape,
113  Type elementType) const;
114 
115  // Make sure that base class overloads are visible.
117 
118  /// Return a clone of this type with the given new shape and element type.
119  /// The returned type is ranked, even if this type is unranked.
120  RankedTensorType clone(ArrayRef<int64_t> shape, Type elementType) const;
121 
122  /// Return a clone of this type with the given new shape. The returned type
123  /// is ranked, even if this type is unranked.
124  RankedTensorType clone(ArrayRef<int64_t> shape) const;
125 
126  /// Return true if the specified element type is ok in a tensor.
127  static bool isValidElementType(Type type);
128 
129  /// Methods for support type inquiry through isa, cast, and dyn_cast.
130  static bool classof(Type type);
131 
132  /// Allow implicit conversion to ShapedType.
133  operator ShapedType() const { return llvm::cast<ShapedType>(*this); }
134 };
135 
136 //===----------------------------------------------------------------------===//
137 // BaseMemRefType
138 //===----------------------------------------------------------------------===//
139 
140 /// This class provides a shared interface for ranked and unranked memref types.
141 /// Note: This class attaches the ShapedType trait to act as a mixin to
142 /// provide many useful utility functions. This inheritance has no effect
143 /// on derived memref types.
144 class BaseMemRefType : public Type, public ShapedType::Trait<BaseMemRefType> {
145 public:
146  using Type::Type;
147 
148  /// Returns the element type of this memref type.
149  Type getElementType() const;
150 
151  /// Returns if this type is ranked, i.e. it has a known number of dimensions.
152  bool hasRank() const;
153 
154  /// Returns the shape of this memref type.
155  ArrayRef<int64_t> getShape() const;
156 
157  /// Clone this type with the given shape and element type. If the
158  /// provided shape is `std::nullopt`, the current shape of the type is used.
159  BaseMemRefType cloneWith(std::optional<ArrayRef<int64_t>> shape,
160  Type elementType) const;
161 
162  // Make sure that base class overloads are visible.
164 
165  /// Return a clone of this type with the given new shape and element type.
166  /// The returned type is ranked, even if this type is unranked.
167  MemRefType clone(ArrayRef<int64_t> shape, Type elementType) const;
168 
169  /// Return a clone of this type with the given new shape. The returned type
170  /// is ranked, even if this type is unranked.
171  MemRefType clone(ArrayRef<int64_t> shape) const;
172 
173  /// Return true if the specified element type is ok in a memref.
174  static bool isValidElementType(Type type);
175 
176  /// Methods for support type inquiry through isa, cast, and dyn_cast.
177  static bool classof(Type type);
178 
179  /// Returns the memory space in which data referred to by this memref resides.
180  Attribute getMemorySpace() const;
181 
182  /// [deprecated] Returns the memory space in old raw integer representation.
183  /// New `Attribute getMemorySpace()` method should be used instead.
184  unsigned getMemorySpaceAsInt() const;
185 
186  /// Allow implicit conversion to ShapedType.
187  operator ShapedType() const { return llvm::cast<ShapedType>(*this); }
188 };
189 
190 } // namespace mlir
191 
192 //===----------------------------------------------------------------------===//
193 // Tablegen Type Declarations
194 //===----------------------------------------------------------------------===//
195 
196 #define GET_TYPEDEF_CLASSES
197 #include "mlir/IR/BuiltinTypes.h.inc"
198 
199 namespace mlir {
200 
201 //===----------------------------------------------------------------------===//
202 // MemRefType
203 //===----------------------------------------------------------------------===//
204 
205 /// This is a builder type that keeps local references to arguments. Arguments
206 /// that are passed into the builder must outlive the builder.
208 public:
209  // Build from another MemRefType.
210  explicit Builder(MemRefType other)
211  : shape(other.getShape()), elementType(other.getElementType()),
212  layout(other.getLayout()), memorySpace(other.getMemorySpace()) {}
213 
214  // Build from scratch.
215  Builder(ArrayRef<int64_t> shape, Type elementType)
216  : shape(shape), elementType(elementType) {}
217 
219  shape = newShape;
220  return *this;
221  }
222 
223  Builder &setElementType(Type newElementType) {
224  elementType = newElementType;
225  return *this;
226  }
227 
228  Builder &setLayout(MemRefLayoutAttrInterface newLayout) {
229  layout = newLayout;
230  return *this;
231  }
232 
233  Builder &setMemorySpace(Attribute newMemorySpace) {
234  memorySpace = newMemorySpace;
235  return *this;
236  }
237 
238  operator MemRefType() {
239  return MemRefType::get(shape, elementType, layout, memorySpace);
240  }
241 
242 private:
243  ArrayRef<int64_t> shape;
244  Type elementType;
245  MemRefLayoutAttrInterface layout;
246  Attribute memorySpace;
247 };
248 
249 //===----------------------------------------------------------------------===//
250 // RankedTensorType
251 //===----------------------------------------------------------------------===//
252 
253 /// This is a builder type that keeps local references to arguments. Arguments
254 /// that are passed into the builder must outlive the builder.
256 public:
257  /// Build from another RankedTensorType.
258  explicit Builder(RankedTensorType other)
259  : shape(other.getShape()), elementType(other.getElementType()),
260  encoding(other.getEncoding()) {}
261 
262  /// Build from scratch.
263  Builder(ArrayRef<int64_t> shape, Type elementType, Attribute encoding)
264  : shape(shape), elementType(elementType), encoding(encoding) {}
265 
267  shape = newShape;
268  return *this;
269  }
270 
271  Builder &setElementType(Type newElementType) {
272  elementType = newElementType;
273  return *this;
274  }
275 
276  Builder &setEncoding(Attribute newEncoding) {
277  encoding = newEncoding;
278  return *this;
279  }
280 
281  /// Erase a dim from shape @pos.
282  Builder &dropDim(unsigned pos) {
283  assert(pos < shape.size() && "overflow");
284  shape.erase(pos);
285  return *this;
286  }
287 
288  /// Insert a val into shape @pos.
289  Builder &insertDim(int64_t val, unsigned pos) {
290  assert(pos <= shape.size() && "overflow");
291  shape.insert(pos, val);
292  return *this;
293  }
294 
295  operator RankedTensorType() {
296  return RankedTensorType::get(shape, elementType, encoding);
297  }
298 
299 private:
301  Type elementType;
302  Attribute encoding;
303 };
304 
305 //===----------------------------------------------------------------------===//
306 // VectorType
307 //===----------------------------------------------------------------------===//
308 
309 /// This is a builder type that keeps local references to arguments. Arguments
310 /// that are passed into the builder must outlive the builder.
312 public:
313  /// Build from another VectorType.
314  explicit Builder(VectorType other)
315  : elementType(other.getElementType()), shape(other.getShape()),
316  scalableDims(other.getScalableDims()) {}
317 
318  /// Build from scratch.
319  Builder(ArrayRef<int64_t> shape, Type elementType,
320  ArrayRef<bool> scalableDims = {})
321  : elementType(elementType), shape(shape), scalableDims(scalableDims) {}
322 
324  ArrayRef<bool> newIsScalableDim = {}) {
325  shape = newShape;
326  scalableDims = newIsScalableDim;
327  return *this;
328  }
329 
330  Builder &setElementType(Type newElementType) {
331  elementType = newElementType;
332  return *this;
333  }
334 
335  /// Erase a dim from shape @pos.
336  Builder &dropDim(unsigned pos) {
337  assert(pos < shape.size() && "overflow");
338  shape.erase(pos);
339  if (!scalableDims.empty())
340  scalableDims.erase(pos);
341  return *this;
342  }
343 
344  /// Set a dim in shape @pos to val.
345  Builder &setDim(unsigned pos, int64_t val) {
346  assert(pos < shape.size() && "overflow");
347  shape.set(pos, val);
348  return *this;
349  }
350 
351  operator VectorType() {
352  return VectorType::get(shape, elementType, scalableDims);
353  }
354 
355 private:
356  Type elementType;
358  CopyOnWriteArrayRef<bool> scalableDims;
359 };
360 
361 /// Given an `originalShape` and a `reducedShape` assumed to be a subset of
362 /// `originalShape` with some `1` entries erased, return the set of indices
363 /// that specifies which of the entries of `originalShape` are dropped to obtain
364 /// `reducedShape`. The returned mask can be applied as a projection to
365 /// `originalShape` to obtain the `reducedShape`. This mask is useful to track
366 /// which dimensions must be kept when e.g. compute MemRef strides under
367 /// rank-reducing operations. Return std::nullopt if reducedShape cannot be
368 /// obtained by dropping only `1` entries in `originalShape`.
369 /// If `matchDynamic` is true, then dynamic dims in `originalShape` and
370 /// `reducedShape` will be considered matching with non-dynamic dims, unless
371 /// the non-dynamic dim is from `originalShape` and equal to 1. For example,
372 /// in ([1, 3, ?], [?, 5]), the mask would be {1, 0, 0}, since 3 and 5 will
373 /// match with the corresponding dynamic dims.
374 std::optional<llvm::SmallDenseSet<unsigned>>
376  ArrayRef<int64_t> reducedShape,
377  bool matchDynamic = false);
378 
379 /// Enum that captures information related to verifier error conditions on
380 /// slice insert/extract type of ops.
382  Success,
383  RankTooLarge,
384  SizeMismatch,
386  // Error codes to ops with a memory space and a layout annotation.
389 };
390 
391 /// Check if `originalType` can be rank reduced to `candidateReducedType` type
392 /// by dropping some dimensions with static size `1`.
393 /// Return `SliceVerificationResult::Success` on success or an appropriate error
394 /// code.
395 SliceVerificationResult isRankReducedType(ShapedType originalType,
396  ShapedType candidateReducedType);
397 
398 //===----------------------------------------------------------------------===//
399 // Deferred Method Definitions
400 //===----------------------------------------------------------------------===//
401 
402 inline bool BaseMemRefType::classof(Type type) {
403  return llvm::isa<MemRefType, UnrankedMemRefType>(type);
404 }
405 
407  return type.isIntOrIndexOrFloat() ||
408  llvm::isa<ComplexType, MemRefType, VectorType, UnrankedMemRefType>(
409  type) ||
410  llvm::isa<MemRefElementTypeInterface>(type);
411 }
412 
413 inline bool FloatType::classof(Type type) {
414  return llvm::isa<
415  Float8E5M2Type, Float8E4M3Type, Float8E4M3FNType, Float8E5M2FNUZType,
416  Float8E4M3FNUZType, Float8E4M3B11FNUZType, BFloat16Type, Float16Type,
417  FloatTF32Type, Float32Type, Float64Type, Float80Type, Float128Type>(type);
418 }
419 
421  return Float8E5M2Type::get(ctx);
422 }
423 
425  return Float8E4M3Type::get(ctx);
426 }
427 
429  return Float8E4M3FNType::get(ctx);
430 }
431 
433  return Float8E5M2FNUZType::get(ctx);
434 }
435 
437  return Float8E4M3FNUZType::get(ctx);
438 }
439 
441  return Float8E4M3B11FNUZType::get(ctx);
442 }
443 
445  return BFloat16Type::get(ctx);
446 }
447 
449  return Float16Type::get(ctx);
450 }
451 
453  return FloatTF32Type::get(ctx);
454 }
455 
457  return Float32Type::get(ctx);
458 }
459 
461  return Float64Type::get(ctx);
462 }
463 
465  return Float80Type::get(ctx);
466 }
467 
469  return Float128Type::get(ctx);
470 }
471 
472 inline bool TensorType::classof(Type type) {
473  return llvm::isa<RankedTensorType, UnrankedTensorType>(type);
474 }
475 
476 //===----------------------------------------------------------------------===//
477 // Type Utilities
478 //===----------------------------------------------------------------------===//
479 
480 /// Returns the strides of the MemRef if the layout map is in strided form.
481 /// MemRefs with a layout map in strided form include:
482 /// 1. empty or identity layout map, in which case the stride information is
483 /// the canonical form computed from sizes;
484 /// 2. a StridedLayoutAttr layout;
485 /// 3. any other layout that be converted into a single affine map layout of
486 /// the form `K + k0 * d0 + ... kn * dn`, where K and ki's are constants or
487 /// symbols.
488 ///
489 /// A stride specification is a list of integer values that are either static
490 /// or dynamic (encoded with ShapedType::kDynamic). Strides encode
491 /// the distance in the number of elements between successive entries along a
492 /// particular dimension.
493 LogicalResult getStridesAndOffset(MemRefType t,
494  SmallVectorImpl<int64_t> &strides,
495  int64_t &offset);
496 
497 /// Wrapper around getStridesAndOffset(MemRefType, SmallVectorImpl<int64_t>,
498 /// int64_t) that will assert if the logical result is not succeeded.
499 std::pair<SmallVector<int64_t>, int64_t> getStridesAndOffset(MemRefType t);
500 
501 /// Return a version of `t` with identity layout if it can be determined
502 /// statically that the layout is the canonical contiguous strided layout.
503 /// Otherwise pass `t`'s layout into `simplifyAffineMap` and return a copy of
504 /// `t` with simplified layout.
505 MemRefType canonicalizeStridedLayout(MemRefType t);
506 
507 /// Given MemRef `sizes` that are either static or dynamic, returns the
508 /// canonical "contiguous" strides AffineExpr. Strides are multiplicative and
509 /// once a dynamic dimension is encountered, all canonical strides become
510 /// dynamic and need to be encoded with a different symbol.
511 /// For canonical strides expressions, the offset is always 0 and the fastest
512 /// varying stride is always `1`.
513 ///
514 /// Examples:
515 /// - memref<3x4x5xf32> has canonical stride expression
516 /// `20*exprs[0] + 5*exprs[1] + exprs[2]`.
517 /// - memref<3x?x5xf32> has canonical stride expression
518 /// `s0*exprs[0] + 5*exprs[1] + exprs[2]`.
519 /// - memref<3x4x?xf32> has canonical stride expression
520 /// `s1*exprs[0] + s0*exprs[1] + exprs[2]`.
522  ArrayRef<AffineExpr> exprs,
523  MLIRContext *context);
524 
525 /// Return the result of makeCanonicalStrudedLayoutExpr for the common case
526 /// where `exprs` is {d0, d1, .., d_(sizes.size()-1)}
528  MLIRContext *context);
529 
530 /// Return "true" if the layout for `t` is compatible with strided semantics.
531 bool isStrided(MemRefType t);
532 
533 /// Return "true" if the last dimension of the given type has a static unit
534 /// stride. Also return "true" for types with no strides.
535 bool isLastMemrefDimUnitStride(MemRefType type);
536 
537 /// Return "true" if the last N dimensions of the given type are contiguous.
538 ///
539 /// Examples:
540 /// - memref<5x4x3x2xi8, strided<[24, 6, 2, 1]> is contiguous when
541 /// considering both _all_ and _only_ the trailing 3 dims,
542 /// - memref<5x4x3x2xi8, strided<[48, 6, 2, 1]> is _only_ contiguous when
543 /// considering the trailing 3 dims.
544 ///
545 bool trailingNDimsContiguous(MemRefType type, int64_t n);
546 
547 } // namespace mlir
548 
549 #endif // MLIR_IR_BUILTINTYPES_H
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,...
Definition: SPIRVOps.cpp:215
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
Definition: Traits.cpp:118
Base type for affine expression.
Definition: AffineExpr.h:68
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class provides a shared interface for ranked and unranked memref types.
Definition: BuiltinTypes.h:144
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.
Definition: BuiltinTypes.h:406
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.
Definition: BuiltinTypes.h:402
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 erase(size_t index)
Definition: ADTExtras.h:40
size_t size() const
Definition: ADTExtras.h:54
void insert(size_t index, T value)
Definition: ADTExtras.h:35
static FloatType getF64(MLIRContext *ctx)
Definition: BuiltinTypes.h:460
FloatType scaleElementBitwidth(unsigned scale)
Get or create a new FloatType with bitwidth scaled by scale.
static FloatType getFloat8E5M2(MLIRContext *ctx)
Definition: BuiltinTypes.h:420
static FloatType getF80(MLIRContext *ctx)
Definition: BuiltinTypes.h:464
static FloatType getFloat8E4M3FN(MLIRContext *ctx)
Definition: BuiltinTypes.h:428
static FloatType getF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:448
const llvm::fltSemantics & getFloatSemantics()
Return the floating semantics of this float type.
static FloatType getTF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:452
static FloatType getBF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:444
static FloatType getFloat8E4M3FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:436
static FloatType getFloat8E4M3B11FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:440
unsigned getFPMantissaWidth()
Return the width of the mantissa of this type.
static FloatType getFloat8E5M2FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:432
static FloatType getF128(MLIRContext *ctx)
Definition: BuiltinTypes.h:468
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.
Definition: BuiltinTypes.h:413
static FloatType getFloat8E4M3(MLIRContext *ctx)
Definition: BuiltinTypes.h:424
static FloatType getF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:456
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This is a builder type that keeps local references to arguments.
Definition: BuiltinTypes.h:207
Builder(ArrayRef< int64_t > shape, Type elementType)
Definition: BuiltinTypes.h:215
Builder & setLayout(MemRefLayoutAttrInterface newLayout)
Definition: BuiltinTypes.h:228
Builder & setElementType(Type newElementType)
Definition: BuiltinTypes.h:223
Builder(MemRefType other)
Definition: BuiltinTypes.h:210
Builder & setShape(ArrayRef< int64_t > newShape)
Definition: BuiltinTypes.h:218
Builder & setMemorySpace(Attribute newMemorySpace)
Definition: BuiltinTypes.h:233
This is a builder type that keeps local references to arguments.
Definition: BuiltinTypes.h:255
Builder(ArrayRef< int64_t > shape, Type elementType, Attribute encoding)
Build from scratch.
Definition: BuiltinTypes.h:263
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
Definition: BuiltinTypes.h:282
Builder & setShape(ArrayRef< int64_t > newShape)
Definition: BuiltinTypes.h:266
Builder & insertDim(int64_t val, unsigned pos)
Insert a val into shape @pos.
Definition: BuiltinTypes.h:289
Builder(RankedTensorType other)
Build from another RankedTensorType.
Definition: BuiltinTypes.h:258
Builder & setElementType(Type newElementType)
Definition: BuiltinTypes.h:271
Builder & setEncoding(Attribute newEncoding)
Definition: BuiltinTypes.h:276
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
Definition: BuiltinTypes.h:97
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.
Definition: BuiltinTypes.h:472
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...
Definition: Types.h:74
constexpr Type()=default
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
Definition: Types.cpp:124
Type trait indicating that the type has value semantics.
Definition: BuiltinTypes.h:45
This is a builder type that keeps local references to arguments.
Definition: BuiltinTypes.h:311
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
Definition: BuiltinTypes.h:336
Builder & setDim(unsigned pos, int64_t val)
Set a dim in shape @pos to val.
Definition: BuiltinTypes.h:345
Builder & setShape(ArrayRef< int64_t > newShape, ArrayRef< bool > newIsScalableDim={})
Definition: BuiltinTypes.h:323
Builder & setElementType(Type newElementType)
Definition: BuiltinTypes.h:330
Builder(VectorType other)
Build from another VectorType.
Definition: BuiltinTypes.h:314
Builder(ArrayRef< int64_t > shape, Type elementType, ArrayRef< bool > scalableDims={})
Build from scratch.
Definition: BuiltinTypes.h:319
Helper class for implementing traits for storage classes.
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
SliceVerificationResult
Enum that captures information related to verifier error conditions on slice insert/extract type of o...
Definition: BuiltinTypes.h:381
bool isLastMemrefDimUnitStride(MemRefType type)
Return "true" if the last dimension of the given type has a static unit stride.
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 ...
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...
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...
bool trailingNDimsContiguous(MemRefType type, int64_t n)
Return "true" if the last N dimensions of the given type are contiguous.