22 #include "mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc" 30 #include "mlir/Dialect/SPIRV/IR/TargetAndABI.cpp.inc" 42 using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
46 : descriptorSet(descriptorSet), binding(binding),
47 storageClass(storageClass) {}
50 return std::get<0>(key) == descriptorSet && std::get<1>(key) == binding &&
51 std::get<2>(key) == storageClass;
67 using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
71 : version(version), capabilities(capabilities), extensions(extensions) {}
74 return std::get<0>(key) == version && std::get<1>(key) == capabilities &&
75 std::get<2>(key) == extensions;
91 using KeyTy = std::tuple<Attribute, Vendor, DeviceType, uint32_t, Attribute>;
94 DeviceType deviceType, uint32_t deviceID,
96 : triple(triple), limits(limits), vendorID(vendorID),
97 deviceType(deviceType), deviceID(deviceID) {}
101 std::make_tuple(triple, vendorID, deviceType, deviceID, limits);
108 std::get<2>(key), std::get<3>(key),
133 auto storageClassAttr =
136 return get(descriptorSetAttr, bindingAttr, storageClassAttr);
141 IntegerAttr storageClass) {
142 assert(descriptorSet && binding);
144 return Base::get(context, descriptorSet, binding, storageClass);
148 return "interface_var_abi";
152 return getImpl()->binding.cast<IntegerAttr>().getInt();
156 return getImpl()->descriptorSet.cast<IntegerAttr>().getInt();
160 if (getImpl()->storageClass)
161 return static_cast<spirv::StorageClass
>(
162 getImpl()->storageClass.cast<IntegerAttr>().getValue().getZExtValue());
168 IntegerAttr binding, IntegerAttr storageClass) {
169 if (!descriptorSet.getType().isSignlessInteger(32))
170 return emitError() <<
"expected 32-bit integer for descriptor set";
172 if (!binding.getType().isSignlessInteger(32))
173 return emitError() <<
"expected 32-bit integer for binding";
176 if (
auto storageClassAttr = storageClass.cast<IntegerAttr>()) {
177 auto storageClassValue =
178 spirv::symbolizeStorageClass(storageClassAttr.getInt());
179 if (!storageClassValue)
180 return emitError() <<
"unknown storage class";
182 return emitError() <<
"expected valid storage class";
201 capAttrs.reserve(capabilities.size());
202 for (spirv::Capability cap : capabilities)
206 extAttrs.reserve(extensions.size());
207 for (spirv::Extension ext : extensions)
208 extAttrs.push_back(b.
getStringAttr(spirv::stringifyExtension(ext)));
214 ArrayAttr capabilities,
215 ArrayAttr extensions) {
216 assert(version && capabilities && extensions);
218 return Base::get(context, version, capabilities, extensions);
224 return static_cast<spirv::Version
>(
225 getImpl()->version.cast<IntegerAttr>().getValue().getZExtValue());
229 :
llvm::mapped_iterator<ArrayAttr::iterator,
232 return *symbolizeExtension(attr.cast<StringAttr>().getValue());
241 return getImpl()->extensions.cast<ArrayAttr>();
245 :
llvm::mapped_iterator<ArrayAttr::iterator,
248 return *symbolizeCapability(
249 attr.cast<IntegerAttr>().getValue().getZExtValue());
258 return getImpl()->capabilities.cast<ArrayAttr>();
263 IntegerAttr version, ArrayAttr capabilities,
264 ArrayAttr extensions) {
265 if (!version.getType().isSignlessInteger(32))
266 return emitError() <<
"expected 32-bit integer for version";
268 if (!llvm::all_of(capabilities.getValue(), [](
Attribute attr) {
269 if (
auto intAttr = attr.dyn_cast<IntegerAttr>())
270 if (spirv::symbolizeCapability(intAttr.getValue().getZExtValue()))
274 return emitError() <<
"unknown capability in capability list";
276 if (!llvm::all_of(extensions.getValue(), [](
Attribute attr) {
277 if (
auto strAttr = attr.dyn_cast<StringAttr>())
278 if (spirv::symbolizeExtension(strAttr.getValue()))
282 return emitError() <<
"unknown extension in extension list";
293 DeviceType deviceType,
295 DictionaryAttr limits) {
296 assert(triple && limits &&
"expected valid triple and limits");
298 return Base::get(context, triple, vendorID, deviceType, deviceID, limits);
308 return getTripleAttr().getVersion();
312 return getTripleAttr().getExtensions();
316 return getTripleAttr().getExtensionsAttr();
320 return getTripleAttr().getCapabilities();
324 return getTripleAttr().getCapabilitiesAttr();
340 return getImpl()->limits.cast<spirv::ResourceLimitsAttr>();
348 uint32_t , DictionaryAttr limits) {
349 if (!limits.isa<spirv::ResourceLimitsAttr>())
350 return emitError() <<
"expected spirv::ResourceLimitsAttr for limits";
359 void spirv::SPIRVDialect::registerAttributes() {
360 addAttributes<InterfaceVarABIAttr, TargetEnvAttr, VerCapExtAttr>();
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, IntegerAttr version, ArrayAttr capabilities, ArrayAttr extensions)
ArrayAttr getCapabilitiesAttr()
Returns the capabilities as an integer array attribute.
Include the generated interface declarations.
Explicitly register a set of "builtin" types.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spv.' prefix).
This class represents a diagnostic that is inflight and set to be reported.
An attribute that specifies the information regarding the interface variable: descriptor set...
static TargetEnvAttr get(VerCapExtAttr triple, Vendor vendorID, DeviceType deviceType, uint32_t deviceId, DictionaryAttr limits)
Gets a TargetEnvAttr instance.
This is a utility allocator used to allocate memory for instances of derived types.
ArrayAttr getExtensionsAttr()
Returns the extensions as a string array attribute.
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, IntegerAttr descriptorSet, IntegerAttr binding, IntegerAttr storageClass)
ArrayAttr getExtensionsAttr()
Returns the target extensions as a string array attribute.
static ConcreteT get(MLIRContext *ctx, Args... args)
Get or create a new ConcreteT instance within the ctx.
ext_range getExtensions()
Returns the extensions.
DeviceType getDeviceType() const
Returns the device type.
IntegerAttr getI32IntegerAttr(int32_t value)
T * allocate()
Allocate an instance of the provided type.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.
std::tuple< Attribute, Attribute, Attribute > KeyTy
std::tuple< Attribute, Vendor, DeviceType, uint32_t, Attribute > KeyTy
static TargetEnvAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
cap_iterator(ArrayAttr::iterator it)
Attributes are known-constant values of operations.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spv.' prefix).
uint32_t getDescriptorSet()
Returns descriptor set.
TargetEnvAttributeStorage(Attribute triple, Vendor vendorID, DeviceType deviceType, uint32_t deviceID, Attribute limits)
An attribute that specifies the SPIR-V (version, capabilities, extensions) triple.
Vendor getVendorID() const
Returns the vendor ID.
uint32_t getBinding()
Returns binding.
std::tuple< Attribute, Attribute, Attribute > KeyTy
bool operator==(const KeyTy &key) const
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, VerCapExtAttr triple, Vendor vendorID, DeviceType deviceType, uint32_t deviceID, DictionaryAttr limits)
uint32_t getDeviceID() const
Returns the device ID.
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
InterfaceVarABIAttributeStorage(Attribute descriptorSet, Attribute binding, Attribute storageClass)
cap_range getCapabilities()
Returns the capabilities.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
static InterfaceVarABIAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
This class is a general helper class for creating context-global objects like types, attributes, and affine expressions.
ImplType * getImpl() const
Utility for easy access to the storage instance.
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, Optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
bool operator==(const KeyTy &key) const
ext_iterator(ArrayAttr::iterator it)
MLIRContext is the top-level object for a collection of MLIR operations.
static VerCapExtAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
VerCapExtAttr getTripleAttr() const
Returns the (version, capabilities, extensions) triple attribute.
Base storage class appearing in an attribute.
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spv.' prefix).
bool operator==(const KeyTy &key) const
Version getVersion() const
Returns the target version.
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
ArrayAttr getCapabilitiesAttr()
Returns the target capabilities as an integer array attribute.
StringAttr getStringAttr(const Twine &bytes)
An attribute that specifies the target version, allowed extensions and capabilities, and resource limits.
Optional< StorageClass > getStorageClass()
Returns spirv::StorageClass.
Version getVersion()
Returns the version.
VerCapExtAttr::ext_range getExtensions()
Returns the target extensions.
VerCapExtAttributeStorage(Attribute version, Attribute capabilities, Attribute extensions)