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