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