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