24 : targetAttr(targetAttr) {
25 givenExtensions.insert_range(targetAttr.getExtensions());
28 givenExtensions.insert_range(
31 for (spirv::Capability cap : targetAttr.getCapabilities()) {
32 givenCapabilities.insert(cap);
35 givenCapabilities.insert_range(spirv::getRecursiveImpliedCapabilities(cap));
40 return targetAttr.getVersion();
44 return givenCapabilities.count(capability);
47std::optional<spirv::Capability>
49 const auto *chosen = llvm::find_if(caps, [
this](spirv::Capability cap) {
50 return givenCapabilities.count(cap);
52 if (chosen != caps.end())
58 return givenExtensions.count(extension);
61std::optional<spirv::Extension>
63 const auto *chosen = llvm::find_if(exts, [
this](spirv::Extension ext) {
64 return givenExtensions.count(ext);
66 if (chosen != exts.end())
72 return targetAttr.getVendorID();
76 return targetAttr.getDeviceType();
80 return targetAttr.getDeviceID();
84 return targetAttr.getResourceLimits();
88 return targetAttr.getContext();
96 return "spirv.interface_var_abi";
101 std::optional<spirv::StorageClass> storageClass,
109 if (cap == spirv::Capability::Kernel)
111 if (cap == spirv::Capability::Shader)
121 std::optional<int> subgroupSize, std::optional<int> targetWidth) {
123 if (!workgroupSize.empty()) {
124 assert(workgroupSize.size() == 3);
127 return spirv::EntryPointABIAttr::get(context, workgroupSizeAttr, subgroupSize,
132 while (op && !isa<FunctionOpInterface>(op))
146 return entryPoint.getWorkgroupSize();
151spirv::ResourceLimitsAttr
156 return spirv::ResourceLimitsAttr::get(
160 b.getI32ArrayAttr({128, 128, 64}),
174 {spirv::Capability::Shader},
178 spirv::ClientAPI::Unknown, spirv::Vendor::Unknown,
205spirv::AddressingModel
207 bool use64bitAddress) {
209 if (cap == Capability::Kernel)
210 return use64bitAddress ? spirv::AddressingModel::Physical64
211 : spirv::AddressingModel::Physical32;
215 if (cap == Capability::PhysicalStorageBufferAddresses)
216 return spirv::AddressingModel::PhysicalStorageBuffer64;
219 return spirv::AddressingModel::Logical;
222FailureOr<spirv::ExecutionModel>
225 if (cap == spirv::Capability::Kernel)
226 return spirv::ExecutionModel::Kernel;
227 if (cap == spirv::Capability::Shader)
228 return spirv::ExecutionModel::GLCompute;
233FailureOr<spirv::MemoryModel>
236 if (cap == spirv::Capability::Kernel)
237 return spirv::MemoryModel::OpenCL;
238 if (cap == spirv::Capability::Shader)
239 return spirv::MemoryModel::GLSL450;
This class is a general helper class for creating context-global objects like types,...
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)
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MLIRContext * getContext()
Return the context this operation is associated with.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int32_t > content)
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,...
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
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.
ArrayRef< Extension > getImpliedExtensions(Version version)
Returns the implied extensions for the given version.
StringRef getInterfaceVarABIAttrName()
Returns the attribute name for specifying argument ABI information.
bool needsInterfaceVarABIAttrs(TargetEnvAttr targetAttr)
Returns whether the given SPIR-V target (described by TargetEnvAttr) needs ABI attributes for interfa...
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
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.
StringRef getLoopControlAttrName()
Returns the attribute name for specifying loop control.
EntryPointABIAttr getEntryPointABIAttr(MLIRContext *context, ArrayRef< int32_t > workgroupSize={}, std::optional< int > subgroupSize={}, std::optional< int > targetWidth={})
Gets the EntryPointABIAttr given its fields.
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.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr