25 : targetAttr(targetAttr) {
27 givenExtensions.insert(ext);
30 for (spirv::Extension ext :
32 givenExtensions.insert(ext);
35 givenCapabilities.insert(cap);
39 givenCapabilities.insert(c);
44 return targetAttr.getVersion();
48 return givenCapabilities.count(capability);
51 std::optional<spirv::Capability>
53 const auto *chosen = llvm::find_if(caps, [
this](spirv::Capability cap) {
54 return givenCapabilities.count(cap);
56 if (chosen != caps.end())
62 return givenExtensions.count(extension);
65 std::optional<spirv::Extension>
67 const auto *chosen = llvm::find_if(exts, [
this](spirv::Extension ext) {
68 return givenExtensions.count(ext);
70 if (chosen != exts.end())
76 return targetAttr.getVendorID();
80 return targetAttr.getDeviceType();
84 return targetAttr.getDeviceID();
88 return targetAttr.getResourceLimits();
92 return targetAttr.getContext();
100 return "spirv.interface_var_abi";
105 std::optional<spirv::StorageClass> storageClass,
113 if (cap == spirv::Capability::Kernel)
115 if (cap == spirv::Capability::Shader)
123 spirv::EntryPointABIAttr
126 std::optional<int> subgroupSize) {
128 if (!workgroupSize.empty()) {
129 assert(workgroupSize.size() == 3);
137 while (op && !isa<FunctionOpInterface>(op))
151 return entryPoint.getWorkgroupSize();
156 spirv::ResourceLimitsAttr
177 {spirv::Capability::Shader},
181 spirv::ClientAPI::Unknown, spirv::Vendor::Unknown,
208 spirv::AddressingModel
210 bool use64bitAddress) {
212 if (cap == Capability::Kernel)
213 return use64bitAddress ? spirv::AddressingModel::Physical64
214 : spirv::AddressingModel::Physical32;
218 if (cap == Capability::PhysicalStorageBufferAddresses)
219 return spirv::AddressingModel::PhysicalStorageBuffer64;
222 return spirv::AddressingModel::Logical;
228 if (cap == spirv::Capability::Kernel)
229 return spirv::ExecutionModel::Kernel;
230 if (cap == spirv::Capability::Shader)
231 return spirv::ExecutionModel::GLCompute;
239 if (cap == spirv::Capability::Kernel)
241 if (cap == spirv::Capability::Shader)
242 return spirv::MemoryModel::GLSL450;
This class is a general helper class for creating context-global objects like types,...
ArrayAttr getI32ArrayAttr(ArrayRef< int32_t > values)
This class provides support for representing a failure result, or a valid value of type T.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
AttrClass getAttrOfType(StringAttr name)
MLIRContext * getContext()
Return the context this operation is associated with.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int32_t > content)
Builder from ArrayRef<T>.
An attribute that specifies the information regarding the interface variable: descriptor set,...
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, std::optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
An attribute that specifies the target version, allowed extensions and capabilities,...
Version getVersion() const
Returns the target version.
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
VerCapExtAttr::ext_range getExtensions()
Returns the target extensions.
static constexpr uint32_t kUnknownDeviceID
ID for unknown devices.
static TargetEnvAttr get(VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI=ClientAPI::Unknown, Vendor vendorID=Vendor::Unknown, DeviceType deviceType=DeviceType::Unknown, uint32_t deviceId=kUnknownDeviceID)
Gets a TargetEnvAttr instance.
DeviceType getDeviceType() const
Returns the device type.
Version getVersion() const
Vendor getVendorID() const
Returns the vendor ID.
bool allows(Capability) const
Returns true if the given capability is allowed.
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
TargetEnv(TargetEnvAttr targetAttr)
MLIRContext * getContext() const
Returns the MLIRContext.
uint32_t getDeviceID() const
Returns the device ID.
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
StringRef getInterfaceVarABIAttrName()
Returns the attribute name for specifying argument ABI information.
SmallVector< Capability, 0 > getRecursiveImpliedCapabilities(Capability cap)
Returns the recursively implied capabilities for the given capability.
bool needsInterfaceVarABIAttrs(TargetEnvAttr targetAttr)
Returns whether the given SPIR-V target (described by TargetEnvAttr) needs ABI attributes for interfa...
EntryPointABIAttr getEntryPointABIAttr(MLIRContext *context, ArrayRef< int32_t > workgroupSize={}, std::optional< int > subgroupSize={})
Gets the EntryPointABIAttr given its fields.
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
ArrayRef< Extension > getImpliedExtensions(Version version)
Returns the implied extensions for the given version.
InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding, std::optional< StorageClass > storageClass, MLIRContext *context)
Gets the InterfaceVarABIAttr given its fields.
EntryPointABIAttr lookupEntryPointABI(Operation *op)
Queries the entry point ABI on the nearest function-like op containing the given op.
TargetEnvAttr lookupTargetEnv(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op.
StringRef getTargetEnvAttrName()
Returns the attribute name for specifying SPIR-V target environment.
DenseI32ArrayAttr lookupLocalWorkGroupSize(Operation *op)
Queries the local workgroup size from entry point ABI on the nearest function-like op containing the ...
AddressingModel getAddressingModel(TargetEnvAttr targetAttr, bool use64bitAddress)
Returns addressing model selected based on target environment.
FailureOr< ExecutionModel > getExecutionModel(TargetEnvAttr targetAttr)
Returns execution model selected based on target environment.
FailureOr< MemoryModel > getMemoryModel(TargetEnvAttr targetAttr)
Returns memory model selected based on target environment.
ResourceLimitsAttr getDefaultResourceLimits(MLIRContext *context)
Returns a default resource limits attribute that uses numbers from "Table 46. Required Limits" of the...
TargetEnvAttr getDefaultTargetEnv(MLIRContext *context)
Returns the default target environment: SPIR-V 1.0 with Shader capability and no extra extensions.
StringRef getEntryPointABIAttrName()
Returns the attribute name for specifying entry point information.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...