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