MLIR  22.0.0git
SPIRVTypes.h
Go to the documentation of this file.
1 //===- SPIRVTypes.h - MLIR SPIR-V Types -------------------------*- 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 // This file declares the types in the SPIR-V dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SPIRV_IR_SPIRVTYPES_H_
14 #define MLIR_DIALECT_SPIRV_IR_SPIRVTYPES_H_
15 
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/Diagnostics.h"
19 #include "mlir/IR/Location.h"
20 #include "mlir/IR/TypeSupport.h"
21 #include "mlir/IR/Types.h"
22 
23 #include <cstdint>
24 #include <tuple>
25 
26 namespace mlir {
27 namespace spirv {
28 
29 namespace detail {
30 struct ArrayTypeStorage;
31 struct CooperativeMatrixTypeStorage;
32 struct TensorArmTypeStorage;
33 struct ImageTypeStorage;
34 struct MatrixTypeStorage;
35 struct PointerTypeStorage;
36 struct RuntimeArrayTypeStorage;
37 struct SampledImageTypeStorage;
38 struct StructTypeStorage;
39 
40 } // namespace detail
41 
42 // Base SPIR-V type for providing availability queries.
43 class SPIRVType : public Type {
44 public:
45  using Type::Type;
46 
47  static bool classof(Type type);
48 
49  bool isScalarOrVector();
50 
51  /// The extension requirements for each type are following the
52  /// ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D))
53  /// convention.
55 
56  /// Appends to `extensions` the extensions needed for this type to appear in
57  /// the given `storage` class. This method does not guarantee the uniqueness
58  /// of extensions; the same extension may be appended multiple times.
59  void getExtensions(ExtensionArrayRefVector &extensions,
60  std::optional<StorageClass> storage = std::nullopt);
61 
62  /// The capability requirements for each type are following the
63  /// ((Capability::A OR Extension::B) AND (Capability::C OR Capability::D))
64  /// convention.
66 
67  /// Appends to `capabilities` the capabilities needed for this type to appear
68  /// in the given `storage` class. This method does not guarantee the
69  /// uniqueness of capabilities; the same capability may be appended multiple
70  /// times.
71  void getCapabilities(CapabilityArrayRefVector &capabilities,
72  std::optional<StorageClass> storage = std::nullopt);
73 
74  /// Returns the size in bytes for each type. If no size can be calculated,
75  /// returns `std::nullopt`. Note that if the type has explicit layout, it is
76  /// also taken into account in calculation.
77  std::optional<int64_t> getSizeInBytes();
78 };
79 
80 // SPIR-V scalar type: bool type, integer type, floating point type.
81 class ScalarType : public SPIRVType {
82 public:
83  using SPIRVType::SPIRVType;
84 
85  static bool classof(Type type);
86 
87  /// Returns true if the given integer type is valid for the SPIR-V dialect.
88  static bool isValid(FloatType);
89  /// Returns true if the given float type is valid for the SPIR-V dialect.
90  static bool isValid(IntegerType);
91 
93  std::optional<StorageClass> storage = std::nullopt);
95  std::optional<StorageClass> storage = std::nullopt);
96 
97  std::optional<int64_t> getSizeInBytes();
98 };
99 
100 // SPIR-V composite type: VectorType, SPIR-V ArrayType, SPIR-V
101 // StructType, or SPIR-V TensorArmType.
102 class CompositeType : public SPIRVType {
103 public:
104  using SPIRVType::SPIRVType;
105 
106  static bool classof(Type type);
107 
108  /// Returns true if the given vector type is valid for the SPIR-V dialect.
109  static bool isValid(VectorType);
110 
111  /// Return the number of elements of the type. This should only be called if
112  /// hasCompileTimeKnownNumElements is true.
113  unsigned getNumElements() const;
114 
115  Type getElementType(unsigned) const;
116 
117  /// Return true if the number of elements is known at compile time and is not
118  /// implementation dependent.
119  bool hasCompileTimeKnownNumElements() const;
120 
122  std::optional<StorageClass> storage = std::nullopt);
124  std::optional<StorageClass> storage = std::nullopt);
125 
126  std::optional<int64_t> getSizeInBytes();
127 };
128 
129 // SPIR-V array type
130 class ArrayType : public Type::TypeBase<ArrayType, CompositeType,
131  detail::ArrayTypeStorage> {
132 public:
133  using Base::Base;
134 
135  static constexpr StringLiteral name = "spirv.array";
136 
137  static ArrayType get(Type elementType, unsigned elementCount);
138 
139  /// Returns an array type with the given stride in bytes.
140  static ArrayType get(Type elementType, unsigned elementCount,
141  unsigned stride);
142 
143  unsigned getNumElements() const;
144 
145  Type getElementType() const;
146 
147  /// Returns the array stride in bytes. 0 means no stride decorated on this
148  /// type.
149  unsigned getArrayStride() const;
150 
152  std::optional<StorageClass> storage = std::nullopt);
154  std::optional<StorageClass> storage = std::nullopt);
155 
156  /// Returns the array size in bytes. Since array type may have an explicit
157  /// stride declaration (in bytes), we also include it in the calculation.
158  std::optional<int64_t> getSizeInBytes();
159 };
160 
161 // SPIR-V image type
163  : public Type::TypeBase<ImageType, SPIRVType, detail::ImageTypeStorage> {
164 public:
165  using Base::Base;
166 
167  static constexpr StringLiteral name = "spirv.image";
168 
169  static ImageType
170  get(Type elementType, Dim dim,
171  ImageDepthInfo depth = ImageDepthInfo::DepthUnknown,
172  ImageArrayedInfo arrayed = ImageArrayedInfo::NonArrayed,
173  ImageSamplingInfo samplingInfo = ImageSamplingInfo::SingleSampled,
174  ImageSamplerUseInfo samplerUse = ImageSamplerUseInfo::SamplerUnknown,
175  ImageFormat format = ImageFormat::Unknown) {
176  return ImageType::get(
177  std::tuple<Type, Dim, ImageDepthInfo, ImageArrayedInfo,
178  ImageSamplingInfo, ImageSamplerUseInfo, ImageFormat>(
179  elementType, dim, depth, arrayed, samplingInfo, samplerUse,
180  format));
181  }
182 
183  static ImageType
184  get(std::tuple<Type, Dim, ImageDepthInfo, ImageArrayedInfo,
185  ImageSamplingInfo, ImageSamplerUseInfo, ImageFormat>);
186 
187  Type getElementType() const;
188  Dim getDim() const;
189  ImageDepthInfo getDepthInfo() const;
190  ImageArrayedInfo getArrayedInfo() const;
191  ImageSamplingInfo getSamplingInfo() const;
192  ImageSamplerUseInfo getSamplerUseInfo() const;
193  ImageFormat getImageFormat() const;
194  // TODO: Add support for Access qualifier
195 
197  std::optional<StorageClass> storage = std::nullopt);
199  std::optional<StorageClass> storage = std::nullopt);
200 };
201 
202 // SPIR-V pointer type
203 class PointerType : public Type::TypeBase<PointerType, SPIRVType,
204  detail::PointerTypeStorage> {
205 public:
206  using Base::Base;
207 
208  static constexpr StringLiteral name = "spirv.pointer";
209 
210  static PointerType get(Type pointeeType, StorageClass storageClass);
211 
212  Type getPointeeType() const;
213 
214  StorageClass getStorageClass() const;
215 
217  std::optional<StorageClass> storage = std::nullopt);
219  std::optional<StorageClass> storage = std::nullopt);
220 };
221 
222 // SPIR-V run-time array type
224  : public Type::TypeBase<RuntimeArrayType, SPIRVType,
225  detail::RuntimeArrayTypeStorage> {
226 public:
227  using Base::Base;
228 
229  static constexpr StringLiteral name = "spirv.rtarray";
230 
231  static RuntimeArrayType get(Type elementType);
232 
233  /// Returns a runtime array type with the given stride in bytes.
234  static RuntimeArrayType get(Type elementType, unsigned stride);
235 
236  Type getElementType() const;
237 
238  /// Returns the array stride in bytes. 0 means no stride decorated on this
239  /// type.
240  unsigned getArrayStride() const;
241 
243  std::optional<StorageClass> storage = std::nullopt);
245  std::optional<StorageClass> storage = std::nullopt);
246 };
247 
248 // SPIR-V sampled image type
250  : public Type::TypeBase<SampledImageType, SPIRVType,
251  detail::SampledImageTypeStorage> {
252 public:
253  using Base::Base;
254 
255  static constexpr StringLiteral name = "spirv.sampled_image";
256 
257  static SampledImageType get(Type imageType);
258 
259  static SampledImageType
261 
262  static LogicalResult
264  Type imageType);
265 
266  Type getImageType() const;
267 
269  std::optional<spirv::StorageClass> storage = std::nullopt);
270  void
272  std::optional<spirv::StorageClass> storage = std::nullopt);
273 };
274 
275 /// SPIR-V struct type. Two kinds of struct types are supported:
276 /// - Literal: a literal struct type is uniqued by its fields (types + offset
277 /// info + decoration info).
278 /// - Identified: an indentified struct type is uniqued by its string identifier
279 /// (name). This is useful in representing recursive structs. For example, the
280 /// following C struct:
281 ///
282 /// struct A {
283 /// A* next;
284 /// };
285 ///
286 /// would be represented in MLIR as:
287 ///
288 /// !spirv.struct<A, (!spirv.ptr<!spirv.struct<A>, Generic>)>
289 ///
290 /// In the above, expressing recursive struct types is accomplished by giving a
291 /// recursive struct a unique identified and using that identifier in the struct
292 /// definition for recursive references.
294  : public Type::TypeBase<StructType, CompositeType,
295  detail::StructTypeStorage, TypeTrait::IsMutable> {
296 public:
297  using Base::Base;
298 
299  // Type for specifying the offset of the struct members
300  using OffsetInfo = uint32_t;
301 
302  static constexpr StringLiteral name = "spirv.struct";
303 
304  // Type for specifying the decoration(s) on struct members.
305  // If `decorationValue` is UnitAttr then decoration has no
306  // value.
308  uint32_t memberIndex;
309  Decoration decoration;
311 
312  MemberDecorationInfo(uint32_t index, Decoration decoration,
314  : memberIndex(index), decoration(decoration),
316 
317  friend bool operator==(const MemberDecorationInfo &lhs,
318  const MemberDecorationInfo &rhs) {
319  return lhs.memberIndex == rhs.memberIndex &&
320  lhs.decoration == rhs.decoration &&
321  lhs.decorationValue == rhs.decorationValue;
322  }
323 
324  friend bool operator<(const MemberDecorationInfo &lhs,
325  const MemberDecorationInfo &rhs) {
326  return std::tuple(lhs.memberIndex, llvm::to_underlying(lhs.decoration)) <
327  std::tuple(rhs.memberIndex, llvm::to_underlying(rhs.decoration));
328  }
329 
330  bool hasValue() const { return !isa<UnitAttr>(decorationValue); }
331  };
332 
333  // Type for specifying the decoration(s) on the struct itself.
335  Decoration decoration;
337 
340 
341  friend bool operator==(const StructDecorationInfo &lhs,
342  const StructDecorationInfo &rhs) {
343  return lhs.decoration == rhs.decoration &&
344  lhs.decorationValue == rhs.decorationValue;
345  }
346 
347  friend bool operator<(const StructDecorationInfo &lhs,
348  const StructDecorationInfo &rhs) {
349  return llvm::to_underlying(lhs.decoration) <
350  llvm::to_underlying(rhs.decoration);
351  }
352 
353  bool hasValue() const { return !isa<UnitAttr>(decorationValue); }
354  };
355 
356  /// Construct a literal StructType with at least one member.
357  static StructType get(ArrayRef<Type> memberTypes,
358  ArrayRef<OffsetInfo> offsetInfo = {},
359  ArrayRef<MemberDecorationInfo> memberDecorations = {},
360  ArrayRef<StructDecorationInfo> structDecorations = {});
361 
362  /// Construct an identified StructType. This creates a StructType whose body
363  /// (member types, offset info, and decorations) is not set yet. A call to
364  /// StructType::trySetBody(...) must follow when the StructType contents are
365  /// available (e.g. parsed or deserialized).
366  ///
367  /// Note: If another thread creates (or had already created) a struct with the
368  /// same identifier, that struct will be returned as a result.
369  static StructType getIdentified(MLIRContext *context, StringRef identifier);
370 
371  /// Construct a (possibly identified) StructType with no members.
372  ///
373  /// Note: this method might fail in a multi-threaded setup if another thread
374  /// created an identified struct with the same identifier but with different
375  /// contents before returning. In which case, an empty (default-constructed)
376  /// StructType is returned.
377  static StructType getEmpty(MLIRContext *context, StringRef identifier = "");
378 
379  /// For literal structs, return an empty string.
380  /// For identified structs, return the struct's identifier.
381  StringRef getIdentifier() const;
382 
383  /// Returns true if the StructType is identified.
384  bool isIdentified() const;
385 
386  unsigned getNumElements() const;
387 
388  Type getElementType(unsigned) const;
389 
390  TypeRange getElementTypes() const;
391 
392  bool hasOffset() const;
393 
394  /// Returns true if the struct has a specified decoration.
395  bool hasDecoration(spirv::Decoration decoration) const;
396 
397  uint64_t getMemberOffset(unsigned) const;
398 
399  // Returns in `memberDecorations` the Decorations (apart from Offset)
400  // associated with all members of the StructType.
401  void getMemberDecorations(SmallVectorImpl<StructType::MemberDecorationInfo>
402  &memberDecorations) const;
403 
404  // Returns in `decorationsInfo` all the Decorations (apart from Offset)
405  // associated with the `i`-th member of the StructType.
407  unsigned i,
408  SmallVectorImpl<StructType::MemberDecorationInfo> &decorationsInfo) const;
409 
410  // Returns in `structDecorations` the Decorations associated with the
411  // StructType.
412  void getStructDecorations(SmallVectorImpl<StructType::StructDecorationInfo>
413  &structDecorations) const;
414 
415  /// Sets the contents of an incomplete identified StructType. This method must
416  /// be called only for identified StructTypes and it must be called only once
417  /// per instance. Otherwise, failure() is returned.
418  LogicalResult
419  trySetBody(ArrayRef<Type> memberTypes, ArrayRef<OffsetInfo> offsetInfo = {},
420  ArrayRef<MemberDecorationInfo> memberDecorations = {},
421  ArrayRef<StructDecorationInfo> structDecorations = {});
422 
424  std::optional<StorageClass> storage = std::nullopt);
426  std::optional<StorageClass> storage = std::nullopt);
427 };
428 
429 llvm::hash_code
430 hash_value(const StructType::MemberDecorationInfo &memberDecorationInfo);
431 
432 llvm::hash_code
433 hash_value(const StructType::StructDecorationInfo &structDecorationInfo);
434 
435 // SPIR-V KHR cooperative matrix type
437  : public Type::TypeBase<CooperativeMatrixType, CompositeType,
438  detail::CooperativeMatrixTypeStorage,
439  ShapedType::Trait> {
440 public:
441  using Base::Base;
442 
443  static constexpr StringLiteral name = "spirv.coopmatrix";
444 
445  static CooperativeMatrixType get(Type elementType, uint32_t rows,
446  uint32_t columns, Scope scope,
447  CooperativeMatrixUseKHR use);
448  Type getElementType() const;
449 
450  /// Returns the scope of the matrix.
451  Scope getScope() const;
452  /// Returns the number of rows of the matrix.
453  uint32_t getRows() const;
454  /// Returns the number of columns of the matrix.
455  uint32_t getColumns() const;
456  /// Returns the use parameter of the cooperative matrix.
457  CooperativeMatrixUseKHR getUse() const;
458 
460  std::optional<StorageClass> storage = std::nullopt);
462  std::optional<StorageClass> storage = std::nullopt);
463 
464  operator ShapedType() const { return llvm::cast<ShapedType>(*this); }
465 
466  ArrayRef<int64_t> getShape() const;
467 
468  bool hasRank() const { return true; }
469 
471  Type elementType) const {
472  if (!shape)
473  return get(elementType, getRows(), getColumns(), getScope(), getUse());
474 
475  assert(shape.value().size() == 2);
476  return get(elementType, shape.value()[0], shape.value()[1], getScope(),
477  getUse());
478  }
479 };
480 
481 // SPIR-V matrix type
482 class MatrixType : public Type::TypeBase<MatrixType, CompositeType,
483  detail::MatrixTypeStorage> {
484 public:
485  using Base::Base;
486 
487  static constexpr StringLiteral name = "spirv.matrix";
488 
489  static MatrixType get(Type columnType, uint32_t columnCount);
490 
492  Type columnType, uint32_t columnCount);
493 
494  static LogicalResult
496  Type columnType, uint32_t columnCount);
497 
498  /// Returns true if the matrix elements are vectors of float elements.
499  static bool isValidColumnType(Type columnType);
500 
501  Type getColumnType() const;
502 
503  /// Returns the number of rows.
504  unsigned getNumRows() const;
505 
506  /// Returns the number of columns.
507  unsigned getNumColumns() const;
508 
509  /// Returns total number of elements (rows*columns).
510  unsigned getNumElements() const;
511 
512  /// Returns the elements' type (i.e, single element type).
513  Type getElementType() const;
514 
516  std::optional<StorageClass> storage = std::nullopt);
518  std::optional<StorageClass> storage = std::nullopt);
519 };
520 
521 /// SPIR-V TensorARM Type
523  : public Type::TypeBase<TensorArmType, CompositeType,
524  detail::TensorArmTypeStorage, ShapedType::Trait> {
525 public:
526  using Base::Base;
527 
528  using ShapedTypeTraits = ShapedType::Trait<TensorArmType>;
529  using ShapedTypeTraits::getDimSize;
530  using ShapedTypeTraits::getDynamicDimIndex;
531  using ShapedTypeTraits::getElementTypeBitWidth;
532  using ShapedTypeTraits::getNumDynamicDims;
534  using ShapedTypeTraits::getRank;
535  using ShapedTypeTraits::hasStaticShape;
536  using ShapedTypeTraits::isDynamicDim;
537 
538  static constexpr StringLiteral name = "spirv.arm.tensor";
539 
540  // TensorArm supports minimum rank of 1, hence an empty shape here means
541  // unranked.
542  static TensorArmType get(ArrayRef<int64_t> shape, Type elementType);
543  TensorArmType cloneWith(std::optional<ArrayRef<int64_t>> shape,
544  Type elementType) const;
545 
546  static LogicalResult
548  ArrayRef<int64_t> shape, Type elementType);
549 
550  Type getElementType() const;
551  ArrayRef<int64_t> getShape() const;
552  bool hasRank() const { return !getShape().empty(); }
553  operator ShapedType() const { return llvm::cast<ShapedType>(*this); }
554 
556  std::optional<StorageClass> storage = std::nullopt);
558  std::optional<StorageClass> storage = std::nullopt);
559 };
560 
561 } // namespace spirv
562 } // namespace mlir
563 
564 #endif // MLIR_DIALECT_SPIRV_IR_SPIRVTYPES_H_
static int64_t getNumElements(Type t)
Compute the total number of elements in the given type, also taking into account nested types.
int64_t rows
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:314
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
constexpr Type()=default
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
Type getElementType() const
Definition: SPIRVTypes.cpp:64
unsigned getArrayStride() const
Returns the array stride in bytes.
Definition: SPIRVTypes.cpp:66
unsigned getNumElements() const
Definition: SPIRVTypes.cpp:62
static ArrayType get(Type elementType, unsigned elementCount)
Definition: SPIRVTypes.cpp:50
std::optional< int64_t > getSizeInBytes()
Returns the array size in bytes.
Definition: SPIRVTypes.cpp:80
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:68
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:73
static constexpr StringLiteral name
Definition: SPIRVTypes.h:135
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:164
std::optional< int64_t > getSizeInBytes()
Definition: SPIRVTypes.cpp:190
bool hasCompileTimeKnownNumElements() const
Return true if the number of elements is known at compile time and is not implementation dependent.
Definition: SPIRVTypes.cpp:139
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:143
unsigned getNumElements() const
Return the number of elements of the type.
Definition: SPIRVTypes.cpp:117
static bool isValid(VectorType)
Returns true if the given vector type is valid for the SPIR-V dialect.
Definition: SPIRVTypes.cpp:100
Type getElementType(unsigned) const
Definition: SPIRVTypes.cpp:106
static bool classof(Type type)
Definition: SPIRVTypes.cpp:92
static constexpr StringLiteral name
Definition: SPIRVTypes.h:443
Scope getScope() const
Returns the scope of the matrix.
Definition: SPIRVTypes.cpp:281
uint32_t getRows() const
Returns the number of rows of the matrix.
Definition: SPIRVTypes.cpp:267
uint32_t getColumns() const
Returns the number of columns of the matrix.
Definition: SPIRVTypes.cpp:272
static CooperativeMatrixType get(Type elementType, uint32_t rows, uint32_t columns, Scope scope, CooperativeMatrixUseKHR use)
Definition: SPIRVTypes.cpp:255
ArrayRef< int64_t > getShape() const
Definition: SPIRVTypes.cpp:277
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:287
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:295
CooperativeMatrixUseKHR getUse() const
Returns the use parameter of the cooperative matrix.
Definition: SPIRVTypes.cpp:283
CooperativeMatrixType cloneWith(std::optional< ArrayRef< int64_t >> shape, Type elementType) const
Definition: SPIRVTypes.h:470
static constexpr StringLiteral name
Definition: SPIRVTypes.h:167
static ImageType get(Type elementType, Dim dim, ImageDepthInfo depth=ImageDepthInfo::DepthUnknown, ImageArrayedInfo arrayed=ImageArrayedInfo::NonArrayed, ImageSamplingInfo samplingInfo=ImageSamplingInfo::SingleSampled, ImageSamplerUseInfo samplerUse=ImageSamplerUseInfo::SamplerUnknown, ImageFormat format=ImageFormat::Unknown)
Definition: SPIRVTypes.h:170
ImageDepthInfo getDepthInfo() const
Definition: SPIRVTypes.cpp:390
ImageArrayedInfo getArrayedInfo() const
Definition: SPIRVTypes.cpp:392
ImageFormat getImageFormat() const
Definition: SPIRVTypes.cpp:404
ImageSamplerUseInfo getSamplerUseInfo() const
Definition: SPIRVTypes.cpp:400
Type getElementType() const
Definition: SPIRVTypes.cpp:386
ImageSamplingInfo getSamplingInfo() const
Definition: SPIRVTypes.cpp:396
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:411
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:406
static MatrixType getChecked(function_ref< InFlightDiagnostic()> emitError, Type columnType, uint32_t columnCount)
unsigned getNumElements() const
Returns total number of elements (rows*columns).
static MatrixType get(Type columnType, uint32_t columnCount)
Type getColumnType() const
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type columnType, uint32_t columnCount)
unsigned getNumColumns() const
Returns the number of columns.
static bool isValidColumnType(Type columnType)
Returns true if the matrix elements are vectors of float elements.
Type getElementType() const
Returns the elements' type (i.e, single element type).
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
static constexpr StringLiteral name
Definition: SPIRVTypes.h:487
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
unsigned getNumRows() const
Returns the number of rows.
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:457
Type getPointeeType() const
Definition: SPIRVTypes.cpp:451
static constexpr StringLiteral name
Definition: SPIRVTypes.h:208
StorageClass getStorageClass() const
Definition: SPIRVTypes.cpp:453
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:468
static PointerType get(Type pointeeType, StorageClass storageClass)
Definition: SPIRVTypes.cpp:447
static constexpr StringLiteral name
Definition: SPIRVTypes.h:229
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:522
unsigned getArrayStride() const
Returns the array stride in bytes.
Definition: SPIRVTypes.cpp:514
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:516
static RuntimeArrayType get(Type elementType)
Definition: SPIRVTypes.cpp:504
SmallVectorImpl< ArrayRef< Capability > > CapabilityArrayRefVector
The capability requirements for each type are following the ((Capability::A OR Extension::B) AND (Cap...
Definition: SPIRVTypes.h:65
std::optional< int64_t > getSizeInBytes()
Returns the size in bytes for each type.
Definition: SPIRVTypes.cpp:766
static bool classof(Type type)
Definition: SPIRVTypes.cpp:706
void getCapabilities(CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Appends to capabilities the capabilities needed for this type to appear in the given storage class.
Definition: SPIRVTypes.cpp:744
SmallVectorImpl< ArrayRef< Extension > > ExtensionArrayRefVector
The extension requirements for each type are following the ((Extension::A OR Extension::B) AND (Exten...
Definition: SPIRVTypes.h:54
void getExtensions(ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Appends to extensions the extensions needed for this type to appear in the given storage class.
Definition: SPIRVTypes.cpp:723
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type imageType)
Definition: SPIRVTypes.cpp:806
static constexpr StringLiteral name
Definition: SPIRVTypes.h:255
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< spirv::StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:820
static SampledImageType getChecked(function_ref< InFlightDiagnostic()> emitError, Type imageType)
Definition: SPIRVTypes.cpp:798
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< spirv::StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:814
static SampledImageType get(Type imageType)
Definition: SPIRVTypes.cpp:793
static bool classof(Type type)
Definition: SPIRVTypes.cpp:538
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:556
static bool isValid(FloatType)
Returns true if the given integer type is valid for the SPIR-V dialect.
Definition: SPIRVTypes.cpp:548
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
Definition: SPIRVTypes.cpp:592
std::optional< int64_t > getSizeInBytes()
Definition: SPIRVTypes.cpp:689
SPIR-V struct type.
Definition: SPIRVTypes.h:295
void getStructDecorations(SmallVectorImpl< StructType::StructDecorationInfo > &structDecorations) const
void getMemberDecorations(SmallVectorImpl< StructType::MemberDecorationInfo > &memberDecorations) const
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
static StructType getIdentified(MLIRContext *context, StringRef identifier)
Construct an identified StructType.
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
bool isIdentified() const
Returns true if the StructType is identified.
StringRef getIdentifier() const
For literal structs, return an empty string.
static StructType getEmpty(MLIRContext *context, StringRef identifier="")
Construct a (possibly identified) StructType with no members.
bool hasDecoration(spirv::Decoration decoration) const
Returns true if the struct has a specified decoration.
unsigned getNumElements() const
Type getElementType(unsigned) const
static constexpr StringLiteral name
Definition: SPIRVTypes.h:302
LogicalResult trySetBody(ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={}, ArrayRef< StructDecorationInfo > structDecorations={})
Sets the contents of an incomplete identified StructType.
TypeRange getElementTypes() const
static StructType get(ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={}, ArrayRef< StructDecorationInfo > structDecorations={})
Construct a literal StructType with at least one member.
uint64_t getMemberOffset(unsigned) const
SPIR-V TensorARM Type.
Definition: SPIRVTypes.h:524
static constexpr StringLiteral name
Definition: SPIRVTypes.h:538
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, ArrayRef< int64_t > shape, Type elementType)
ShapedType::Trait< TensorArmType > ShapedTypeTraits
Definition: SPIRVTypes.h:528
static TensorArmType get(ArrayRef< int64_t > shape, Type elementType)
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, std::optional< StorageClass > storage=std::nullopt)
ArrayRef< int64_t > getShape() const
TensorArmType cloneWith(std::optional< ArrayRef< int64_t >> shape, Type elementType) const
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, std::optional< StorageClass > storage=std::nullopt)
@ Type
An inlay hint that for a type annotation.
llvm::hash_code hash_value(const StructType::MemberDecorationInfo &memberDecorationInfo)
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
friend bool operator==(const MemberDecorationInfo &lhs, const MemberDecorationInfo &rhs)
Definition: SPIRVTypes.h:317
MemberDecorationInfo(uint32_t index, Decoration decoration, Attribute decorationValue)
Definition: SPIRVTypes.h:312
friend bool operator<(const MemberDecorationInfo &lhs, const MemberDecorationInfo &rhs)
Definition: SPIRVTypes.h:324
StructDecorationInfo(Decoration decoration, Attribute decorationValue)
Definition: SPIRVTypes.h:338
friend bool operator<(const StructDecorationInfo &lhs, const StructDecorationInfo &rhs)
Definition: SPIRVTypes.h:347
friend bool operator==(const StructDecorationInfo &lhs, const StructDecorationInfo &rhs)
Definition: SPIRVTypes.h:341