18#include "llvm/ADT/DenseSet.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/TypeSwitch.h"
21#include "llvm/Support/ErrorHandling.h"
33 llvm::SmallDenseSet<Type, 8> &visited) {
34 if (!visited.insert(type).second)
36 if (isa<Float4E2M1FNType, Float6E2M3FNType, Float6E3M2FNType>(type) ||
37 (!subByteOnly && isa<Float8E8M0FNUType>(type)))
39 if (
auto composite = dyn_cast<spirv::CompositeType>(type)) {
40 if (
auto structType = dyn_cast<spirv::StructType>(composite))
41 return llvm::any_of(structType.getElementTypes(), [&](
Type element) {
42 return containsMicroscalingTypeImpl(element, subByteOnly, visited);
45 subByteOnly, visited);
47 if (
auto pointer = dyn_cast<spirv::PointerType>(type))
54 llvm::SmallDenseSet<Type, 8> visited;
66class TypeExtensionVisitor {
69 std::optional<StorageClass> storage)
70 : extensions(extensions), storage(storage) {}
81 [
this](
auto concreteType) { addConcrete(concreteType); })
82 .Case<ArrayType, MatrixType, RuntimeArrayType, VectorType>(
83 [
this](
auto concreteType) {
add(concreteType.getElementType()); })
84 .Case([
this](SampledImageType concreteType) {
87 .Case([
this](StructType concreteType) {
91 .Case<SamplerType, NamedBarrierType>([](
auto) { })
92 .DefaultUnreachable(
"Unhandled type");
96 if (
auto functionType = dyn_cast<FunctionType>(type)) {
97 for (Type t : llvm::concat<const Type>(functionType.getInputs(),
98 functionType.getResults()))
102 add(cast<SPIRVType>(type));
107 void addConcrete(CooperativeMatrixType type);
108 void addConcrete(ImageType type);
109 void addConcrete(PointerType type);
110 void addConcrete(ScalarType type);
111 void addConcrete(TensorArmType type);
112 void addConcrete(UntypedPointerType type);
114 template <Extension... Es>
116 static constexpr Extension exts[] = {Es...};
117 extensions.push_back(exts);
121 std::optional<StorageClass> storage;
122 llvm::SmallDenseSet<std::pair<Type, std::optional<StorageClass>>> seen;
132class TypeCapabilityVisitor {
135 std::optional<StorageClass> storage)
136 : capabilities(capabilities), storage(storage) {}
140 void add(SPIRVType type) {
145 .Case<CooperativeMatrixType, ImageType, MatrixType, PointerType,
146 RuntimeArrayType, ScalarType, TensorArmType, UntypedPointerType,
148 [
this](
auto concreteType) { addConcrete(concreteType); })
149 .Case([
this](ArrayType concreteType) {
152 .Case([
this](SampledImageType concreteType) {
155 .Case([
this](StructType concreteType) {
159 .Case([](SamplerType) { })
161 [
this](NamedBarrierType) { pushCaps<Capability::NamedBarrier>(); })
162 .DefaultUnreachable(
"Unhandled type");
165 void add(Type type) {
166 if (
auto functionType = dyn_cast<FunctionType>(type)) {
167 for (Type t : llvm::concat<const Type>(functionType.getInputs(),
168 functionType.getResults()))
172 add(cast<SPIRVType>(type));
177 void addConcrete(CooperativeMatrixType type);
178 void addConcrete(ImageType type);
179 void addConcrete(MatrixType type);
180 void addConcrete(PointerType type);
181 void addConcrete(RuntimeArrayType type);
182 void addConcrete(ScalarType type);
183 void addConcrete(TensorArmType type);
184 void addConcrete(UntypedPointerType type);
185 void addConcrete(VectorType type);
187 template <Capability... Cs>
189 static constexpr Capability caps[] = {Cs...};
190 capabilities.push_back(caps);
194 std::optional<StorageClass> storage;
195 llvm::SmallDenseSet<std::pair<Type, std::optional<StorageClass>>> seen;
205 using KeyTy = std::tuple<Type, unsigned, unsigned>;
226 assert(elementCount &&
"ArrayType needs at least one element");
233 assert(elementCount &&
"ArrayType needs at least one element");
248 if (
auto vectorType = dyn_cast<VectorType>(type))
256 return type.getRank() == 1 &&
257 llvm::is_contained({2, 3, 4, 8, 16}, type.getNumElements()) &&
258 (isa<ScalarType>(type.getElementType()) ||
259 isa<PointerType>(type.getElementType()));
265 TensorArmType>([](
auto type) {
return type.getElementType(); })
268 .DefaultUnreachable(
"Invalid composite type");
274 [](
auto type) {
return type.getNumElements(); })
276 .DefaultUnreachable(
"Invalid type for number of elements query");
280 return !isa<CooperativeMatrixType, RuntimeArrayType>(*
this);
283void TypeCapabilityVisitor::addConcrete(VectorType type) {
284 add(type.getElementType());
286 int64_t vecSize = type.getNumElements();
287 if (vecSize == 8 || vecSize == 16)
288 pushCaps<Capability::Vector16>();
310 std::tuple<Type, int64_t, int64_t, Scope, CooperativeMatrixUseKHR>;
324 shape({std::get<1>(key), std::get<2>(key)}), scope(std::get<3>(key)),
325 use(std::get<4>(key)) {}
331 CooperativeMatrixUseKHR
use;
337 uint32_t rows, uint32_t columns, Scope scope,
338 CooperativeMatrixUseKHR use) {
345 uint32_t rows, uint32_t columns, Scope scope, CooperativeMatrixUseKHR use) {
348 <<
"microscaling types are not supported in cooperative matrices";
354 uint32_t columns, Scope scope,
355 CooperativeMatrixUseKHR use) {
366 return static_cast<uint32_t
>(
getImpl()->shape[0]);
371 return static_cast<uint32_t
>(
getImpl()->shape[1]);
386 pushExts<Extension::SPV_KHR_cooperative_matrix>();
392 pushCaps<Capability::CooperativeMatrixKHR>();
394 pushCaps<Capability::BFloat16CooperativeMatrixKHR>();
396 pushCaps<Capability::Float8CooperativeMatrixEXT>();
409 static_assert((1 << 3) > getMaxEnumValForDim(),
410 "Not enough bits to encode Dim value");
415 static_assert((1 << 2) > getMaxEnumValForImageDepthInfo(),
416 "Not enough bits to encode ImageDepthInfo value");
421 static_assert((1 << 1) > getMaxEnumValForImageArrayedInfo(),
422 "Not enough bits to encode ImageArrayedInfo value");
427 static_assert((1 << 1) > getMaxEnumValForImageSamplingInfo(),
428 "Not enough bits to encode ImageSamplingInfo value");
433 static_assert((1 << 2) > getMaxEnumValForImageSamplerUseInfo(),
434 "Not enough bits to encode ImageSamplerUseInfo value");
439 static_assert((1 << 6) > getMaxEnumValForImageFormat(),
440 "Not enough bits to encode ImageFormat value");
446 using KeyTy = std::tuple<
Type, Dim, ImageDepthInfo, ImageArrayedInfo,
447 ImageSamplingInfo, ImageSamplerUseInfo, ImageFormat>;
476 std::tuple<
Type, Dim, ImageDepthInfo, ImageArrayedInfo, ImageSamplingInfo,
477 ImageSamplerUseInfo, ImageFormat>
484 std::tuple<
Type, Dim, ImageDepthInfo, ImageArrayedInfo, ImageSamplingInfo,
485 ImageSamplerUseInfo, ImageFormat>
488 return emitError() <<
"microscaling types are not supported in images";
494 ImageSamplingInfo, ImageSamplerUseInfo, ImageFormat>
510 return getImpl()->samplingInfo;
514 return getImpl()->samplerUseInfo;
519void TypeExtensionVisitor::addConcrete(
ImageType type) {
523 intTy && intTy.getWidth() == 64)
524 pushExts<Extension::SPV_EXT_shader_image_int64>();
528void TypeCapabilityVisitor::addConcrete(
ImageType type) {
533 bool isMultisampled =
535 bool isArrayed = type.
getArrayedInfo() == ImageArrayedInfo::Arrayed;
537 bool noSampler = sampler == ImageSamplerUseInfo::NoSampler;
538 bool needSampler = sampler == ImageSamplerUseInfo::NeedSampler;
543 pushCaps<Capability::Sampled1D>();
545 pushCaps<Capability::Image1D>();
547 pushCaps<Capability::Image1D, Capability::Sampled1D>();
550 if (isMultisampled && noSampler)
551 pushCaps<Capability::StorageImageMultisample>();
552 if (isMultisampled && isArrayed)
553 pushCaps<Capability::ImageMSArray>();
558 pushCaps<Capability::Shader>();
560 pushCaps<Capability::ImageCubeArray>();
563 pushCaps<Capability::ImageRect, Capability::SampledRect>();
567 pushCaps<Capability::SampledBuffer>();
569 pushCaps<Capability::ImageBuffer>();
571 pushCaps<Capability::ImageBuffer, Capability::SampledBuffer>();
573 case Dim::SubpassData:
574 pushCaps<Capability::InputAttachment>();
579 capabilities.push_back(*fmtCaps);
583 intTy && intTy.getWidth() == 64)
584 pushCaps<Capability::Int64ImageEXT>();
596 using KeyTy = std::pair<Type, StorageClass>;
618 StorageClass storageClass) {
624 Type pointeeType, StorageClass storageClass) {
625 if (storageClass != StorageClass::Function &&
626 storageClass != StorageClass::Private &&
629 <<
"FP4 and FP6 types require Function or Private storage";
640 return getImpl()->storageClass;
643void TypeExtensionVisitor::addConcrete(
PointerType type) {
646 std::optional<StorageClass> oldStorageClass = storage;
649 storage = oldStorageClass;
652 extensions.push_back(*scExts);
655void TypeCapabilityVisitor::addConcrete(
PointerType type) {
658 std::optional<StorageClass> oldStorageClass = storage;
661 storage = oldStorageClass;
664 capabilities.push_back(*scCaps);
688 StorageClass storageClass) {
693 return getImpl()->storageClass;
697 pushExts<Extension::SPV_KHR_untyped_pointers>();
699 extensions.push_back(*scExts);
703 pushCaps<Capability::UntypedPointersKHR>();
705 capabilities.push_back(*scCaps);
713 using KeyTy = std::pair<Type, unsigned>;
746 pushCaps<Capability::Shader>();
754 if (
auto floatType = dyn_cast<FloatType>(type)) {
757 if (
auto intType = dyn_cast<IntegerType>(type)) {
764 if (llvm::is_contained({16u, 32u, 64u}, type.getWidth()))
766 return isa<Float8E4M3FNType, Float8E5M2Type, Float4E2M1FNType,
767 Float6E2M3FNType, Float6E3M2FNType, Float8E8M0FNUType>(type);
771 return llvm::is_contained({1u, 8u, 16u, 32u, 64u}, type.getWidth());
774void TypeExtensionVisitor::addConcrete(
ScalarType type) {
776 pushExts<Extension::SPV_KHR_bfloat16>();
779 pushExts<Extension::SPV_EXT_float8>();
781 if (isa<Float4E2M1FNType, Float6E2M3FNType, Float6E3M2FNType,
782 Float8E8M0FNUType>(type)) {
783 pushExts<Extension::SPV_EXT_ocp_microscaling_types>();
784 pushExts<Extension::SPV_EXT_float8>();
794 case StorageClass::PushConstant:
795 case StorageClass::StorageBuffer:
796 case StorageClass::Uniform:
798 pushExts<Extension::SPV_KHR_8bit_storage>();
800 case StorageClass::Input:
801 case StorageClass::Output:
803 pushExts<Extension::SPV_KHR_16bit_storage>();
810void TypeCapabilityVisitor::addConcrete(
ScalarType type) {
815 if (isa<Float8E8M0FNUType>(type))
816 pushCaps<Capability::Float8UnsignedE8M0EXT>();
822#define STORAGE_CASE(storage, cap8, cap16) \
823 case StorageClass::storage: { \
824 if (bitwidth == 8) { \
825 pushCaps<Capability::cap8>(); \
828 if (bitwidth == 16) { \
829 pushCaps<Capability::cap16>(); \
840 STORAGE_CASE(PushConstant, StoragePushConstant8, StoragePushConstant16);
842 StorageBuffer16BitAccess);
845 case StorageClass::Input:
846 case StorageClass::Output: {
847 if (bitwidth == 16) {
848 pushCaps<Capability::StorageInputOutput16>();
862#define WIDTH_CASE(type, width) \
864 pushCaps<Capability::type##width>(); \
867 if (
auto intType = dyn_cast<IntegerType>(type)) {
876 llvm_unreachable(
"invalid bitwidth to getCapabilities");
879 assert(isa<FloatType>(type));
882 pushCaps<Capability::Float4EXT>();
885 pushCaps<Capability::Float6EXT>();
889 pushCaps<Capability::Float8EXT>();
890 else if (!isa<Float8E8M0FNUType>(type))
891 llvm_unreachable(
"invalid 8-bit float type to getCapabilities");
896 pushCaps<Capability::BFloat16TypeKHR>();
898 pushCaps<Capability::Float16>();
905 llvm_unreachable(
"invalid bitwidth to getCapabilities");
920 if (isa<ScalarType>(type))
922 if (
auto vectorType = dyn_cast<VectorType>(type))
924 if (
auto tensorArmType = dyn_cast<TensorArmType>(type))
925 return isa<ScalarType>(tensorArmType.getElementType());
934 std::optional<StorageClass> storage) {
935 TypeExtensionVisitor{extensions, storage}.add(*
this);
940 std::optional<StorageClass> storage) {
941 TypeCapabilityVisitor{capabilities, storage}.add(*
this);
946 .Case([](
ScalarType type) -> std::optional<int64_t> {
960 if (bitWidth % 8 != 0)
964 .Case([](
ArrayType type) -> std::optional<int64_t> {
967 auto elementType = cast<SPIRVType>(type.getElementType());
968 if (
unsigned stride = type.getArrayStride())
969 return stride * type.getNumElements();
970 if (std::optional<int64_t> size = elementType.getSizeInBytes())
971 return *size * type.getNumElements();
974 .Case<VectorType, TensorArmType>([](
auto type) -> std::optional<int64_t> {
975 if (std::optional<int64_t> elementSize =
976 cast<ScalarType>(type.getElementType()).getSizeInBytes())
977 return *elementSize * type.getNumElements();
980 .Default(std::nullopt);
1017 auto image = dyn_cast<ImageType>(imageType);
1019 return emitError() <<
"expected image type";
1024 if (llvm::is_contained({Dim::SubpassData, Dim::Buffer}, image.getDim()))
1025 return emitError() <<
"Dim must not be SubpassData or Buffer";
1134 StringRef keyIdentifier = std::get<0>(key);
1136 if (!keyIdentifier.empty()) {
1148 const Type *typesList =
nullptr;
1149 if (!keyTypes.empty()) {
1150 typesList = allocator.
copyInto(keyTypes).data();
1154 if (!std::get<2>(key).empty()) {
1156 assert(keyOffsetInfo.size() == keyTypes.size() &&
1157 "size of offset information must be same as the size of number of "
1159 offsetInfoList = allocator.
copyInto(keyOffsetInfo).data();
1164 if (!std::get<3>(key).empty()) {
1165 auto keyMemberDecorations = std::get<3>(key);
1167 memberDecorationList = allocator.
copyInto(keyMemberDecorations).data();
1172 if (!std::get<4>(key).empty()) {
1173 auto keyStructDecorations = std::get<4>(key);
1175 structDecorationList = allocator.
copyInto(keyStructDecorations).data();
1240 if (!structMemberTypes.empty())
1242 allocator.
copyInto(structMemberTypes).data());
1244 if (!structOffsetInfo.empty()) {
1245 assert(structOffsetInfo.size() == structMemberTypes.size() &&
1246 "size of offset information must be same as the size of number of "
1251 if (!structMemberDecorationInfo.empty()) {
1254 allocator.
copyInto(structMemberDecorationInfo).data();
1257 if (!structDecorationInfo.empty()) {
1280 assert(!memberTypes.empty() &&
"Struct needs at least one member type");
1284 llvm::array_pod_sort(sortedMemberDecorations.begin(),
1285 sortedMemberDecorations.end());
1288 llvm::array_pod_sort(sortedStructDecorations.begin(),
1289 sortedStructDecorations.end());
1291 return Base::get(memberTypes.vec().front().getContext(),
1292 StringRef(), memberTypes, offsetInfo,
1293 sortedMemberDecorations, sortedStructDecorations);
1297 StringRef identifier) {
1298 assert(!identifier.empty() &&
1299 "StructType identifier must be non-empty string");
1320 return newStructType;
1331 return getImpl()->memberTypesAndIsBodySet.getPointer()[
index];
1343 getImpl()->getStructDecorationsInfo())
1344 if (info.decoration == decoration)
1358 memberDecorations.clear();
1359 auto implMemberDecorations =
getImpl()->getMemberDecorationsInfo();
1360 memberDecorations.append(implMemberDecorations.begin(),
1361 implMemberDecorations.end());
1368 auto memberDecorations =
getImpl()->getMemberDecorationsInfo();
1369 decorationsInfo.clear();
1370 for (
const auto &memberDecoration : memberDecorations) {
1371 if (memberDecoration.memberIndex ==
index) {
1372 decorationsInfo.push_back(memberDecoration);
1374 if (memberDecoration.memberIndex >
index) {
1384 structDecorations.clear();
1385 auto implDecorations =
getImpl()->getStructDecorationsInfo();
1386 structDecorations.append(implDecorations.begin(), implDecorations.end());
1394 return Base::mutate(memberTypes, offsetInfo, memberDecorations,
1400 return llvm::hash_combine(memberDecorationInfo.
memberIndex,
1406 return llvm::hash_value(structDecorationInfo.
decoration);
1417 using KeyTy = std::tuple<Type, int64_t>;
1421 shape({cast<VectorType>(std::get<0>(key)).getShape()[0],
1422 std::get<1>(key)}) {}
1445 Type columnType, uint32_t columnCount) {
1452 Type columnType, uint32_t columnCount) {
1453 if (columnCount < 2 || columnCount > 4)
1454 return emitError() <<
"matrix can have 2, 3, or 4 columns only";
1457 return emitError() <<
"matrix columns must be vectors of floats";
1460 return emitError() <<
"microscaling types are not supported in matrices";
1464 if (columnShape.size() != 1)
1465 return emitError() <<
"matrix columns must be 1D vectors";
1467 if (columnShape[0] < 2 || columnShape[0] > 4)
1468 return emitError() <<
"matrix columns must be of size 2, 3, or 4";
1475 if (
auto vectorType = dyn_cast<VectorType>(columnType)) {
1476 if (isa<FloatType>(vectorType.getElementType()))
1485 return cast<VectorType>(
getImpl()->columnType).getElementType();
1490 assert(
getImpl()->
shape[1] <= std::numeric_limits<unsigned>::max());
1491 return static_cast<uint32_t
>(
getImpl()->shape[1]);
1496 assert(
getImpl()->
shape[0] <= std::numeric_limits<unsigned>::max());
1497 return static_cast<uint32_t
>(
getImpl()->shape[0]);
1506void TypeCapabilityVisitor::addConcrete(
MatrixType type) {
1508 pushCaps<Capability::Matrix>();
1547 Type elementType)
const {
1556 pushExts<Extension::SPV_ARM_tensors>();
1559void TypeCapabilityVisitor::addConcrete(
TensorArmType type) {
1561 pushCaps<Capability::TensorsARM>();
1567 if (llvm::is_contained(
shape, 0))
1568 return emitError() <<
"arm.tensor do not support dimensions = 0";
1569 if (llvm::any_of(
shape, [](
int64_t dim) {
return dim < 0; }) &&
1570 llvm::any_of(
shape, [](
int64_t dim) {
return dim > 0; }))
1572 <<
"arm.tensor shape dimensions must be either fully dynamic or "
1581void SPIRVDialect::registerTypes() {
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
false
Parses a map_entries map type from a string format back into its numeric value.
constexpr unsigned getNumBits< ImageSamplerUseInfo >()
#define STORAGE_CASE(storage, cap8, cap16)
constexpr unsigned getNumBits< ImageFormat >()
static constexpr unsigned getNumBits()
#define WIDTH_CASE(type, width)
constexpr unsigned getNumBits< ImageArrayedInfo >()
constexpr unsigned getNumBits< ImageSamplingInfo >()
static bool containsMicroscalingTypeImpl(Type type, bool subByteOnly, llvm::SmallDenseSet< Type, 8 > &visited)
Find microscaling elements in composite types, including recursive structs.
constexpr unsigned getNumBits< Dim >()
constexpr unsigned getNumBits< ImageDepthInfo >()
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.
ArrayRef< T > copyInto(ArrayRef< T > elements)
Copy the specified array of elements into memory managed by our bump pointer allocator.
T * allocate()
Allocate an instance of the provided type.
This class provides an abstraction over the various different ranges of value types.
TypeStorage()
This constructor is used by derived classes as part of the TypeUniquer.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Dialect & getDialect() const
Get the dialect this type is registered to.
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
static ConcreteType get(MLIRContext *ctx, Args &&...args)
LogicalResult mutate(Args &&...args)
static ConcreteType getChecked(const Location &loc, Args &&...args)
ImplType * getImpl() const
Type getElementType() const
unsigned getArrayStride() const
Returns the array stride in bytes.
unsigned getNumElements() const
static ArrayType get(Type elementType, unsigned elementCount)
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)
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type elementType, uint32_t rows, uint32_t columns, Scope scope, CooperativeMatrixUseKHR use)
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)
Type getElementType() const
CooperativeMatrixUseKHR getUse() const
Returns the use parameter of the cooperative matrix.
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)
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)
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).
ArrayRef< int64_t > getShape() const
unsigned getNumRows() const
Returns the number of rows.
static NamedBarrierType get(MLIRContext *context)
Type getPointeeType() const
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)
Type getElementType() const
unsigned getArrayStride() const
Returns the array stride in bytes.
static RuntimeArrayType get(Type elementType)
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...
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...
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type imageType)
static SampledImageType getChecked(function_ref< InFlightDiagnostic()> emitError, Type imageType)
Type getImageType() const
static SampledImageType get(Type imageType)
static SamplerType get(MLIRContext *context)
static bool classof(Type type)
static bool isValid(FloatType)
Returns true if the given float type is valid for the SPIR-V dialect.
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
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
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, ArrayRef< int64_t > shape, Type elementType)
Type getElementType() const
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
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.
StorageUniquer::StorageAllocator TypeStorageAllocator
This is a utility allocator used to allocate memory for instances of derived Types.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::TypeSwitch< T, ResultT > TypeSwitch
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
llvm::function_ref< Fn > function_ref
ArrayTypeStorage(const KeyTy &key)
static ArrayTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
std::tuple< Type, unsigned, unsigned > KeyTy
bool operator==(const KeyTy &key) const
CooperativeMatrixTypeStorage(const KeyTy &key)
static CooperativeMatrixTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
CooperativeMatrixUseKHR use
std::array< int64_t, 2 > shape
std::tuple< Type, int64_t, int64_t, Scope, CooperativeMatrixUseKHR > KeyTy
bool operator==(const KeyTy &key) const
std::tuple< Type, Dim, ImageDepthInfo, ImageArrayedInfo, ImageSamplingInfo, ImageSamplerUseInfo, ImageFormat > KeyTy
bool operator==(const KeyTy &key) const
ImageSamplerUseInfo samplerUseInfo
static ImageTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
ImageTypeStorage(const KeyTy &key)
ImageSamplingInfo samplingInfo
ImageArrayedInfo arrayedInfo
MatrixTypeStorage(const KeyTy &key)
std::array< int64_t, 2 > shape
std::tuple< Type, int64_t > KeyTy
bool operator==(const KeyTy &key) const
static MatrixTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
StorageClass storageClass
static PointerTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
PointerTypeStorage(const KeyTy &key)
bool operator==(const KeyTy &key) const
std::pair< Type, StorageClass > KeyTy
RuntimeArrayTypeStorage(const KeyTy &key)
static RuntimeArrayTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
std::pair< Type, unsigned > KeyTy
bool operator==(const KeyTy &key) const
bool operator==(const KeyTy &key) const
static SampledImageTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
SampledImageTypeStorage(const KeyTy &key)
Type storage for SPIR-V structure types:
ArrayRef< StructType::MemberDecorationInfo > getMemberDecorationsInfo() const
StructType::OffsetInfo const * offsetInfo
static StructTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
If the given key contains a non-empty identifier, this method constructs an identified struct and lea...
bool operator==(const KeyTy &key) const
For identified structs, return true if the given key contains the same identifier.
std::tuple< StringRef, ArrayRef< Type >, ArrayRef< StructType::OffsetInfo >, ArrayRef< StructType::MemberDecorationInfo >, ArrayRef< StructType::StructDecorationInfo > > KeyTy
A storage key is divided into 2 parts:
ArrayRef< StructType::OffsetInfo > getOffsetInfo() const
StructTypeStorage(StringRef identifier)
Construct a storage object for an identified struct type.
unsigned numStructDecorations
ArrayRef< StructType::StructDecorationInfo > getStructDecorationsInfo() const
StructType::MemberDecorationInfo const * memberDecorationsInfo
StructTypeStorage(unsigned numMembers, Type const *memberTypes, StructType::OffsetInfo const *layoutInfo, unsigned numMemberDecorations, StructType::MemberDecorationInfo const *memberDecorationsInfo, unsigned numStructDecorations, StructType::StructDecorationInfo const *structDecorationsInfo)
Construct a storage object for a literal struct type.
StructType::StructDecorationInfo const * structDecorationsInfo
llvm::PointerIntPair< Type const *, 1, bool > memberTypesAndIsBodySet
StringRef getIdentifier() const
ArrayRef< Type > getMemberTypes() const
unsigned numMemberDecorations
bool isIdentified() const
LogicalResult mutate(TypeStorageAllocator &allocator, ArrayRef< Type > structMemberTypes, ArrayRef< StructType::OffsetInfo > structOffsetInfo, ArrayRef< StructType::MemberDecorationInfo > structMemberDecorationInfo, ArrayRef< StructType::StructDecorationInfo > structDecorationInfo)
Sets the struct type content for identified structs.
static TensorArmTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
static llvm::hash_code hashKey(const KeyTy &key)
std::tuple< ArrayRef< int64_t >, Type > KeyTy
TensorArmTypeStorage(ArrayRef< int64_t > shape, Type elementType)
bool operator==(const KeyTy &key) const
ArrayRef< int64_t > shape
static UntypedPointerTypeStorage * construct(TypeStorageAllocator &allocator, const KeyTy &key)
bool operator==(const KeyTy &key) const
StorageClass storageClass
UntypedPointerTypeStorage(const KeyTy &key)