23 : targetAttr(targetAttr) {
25 givenExtensions.insert(ext);
28 for (spirv::Extension ext :
30 givenExtensions.insert(ext);
33 givenCapabilities.insert(cap);
37 givenCapabilities.insert(c);
46 return givenCapabilities.count(capability);
51 const auto *chosen = llvm::find_if(caps, [
this](spirv::Capability cap) {
52 return givenCapabilities.count(cap);
54 if (chosen != caps.end())
60 return givenExtensions.count(extension);
65 const auto *chosen = llvm::find_if(exts, [
this](spirv::Extension ext) {
66 return givenExtensions.count(ext);
68 if (chosen != exts.end())
90 return targetAttr.getContext();
98 return "spv.interface_var_abi";
111 if (cap == spirv::Capability::Kernel)
113 if (cap == spirv::Capability::Shader)
121 spirv::EntryPointABIAttr
123 if (localSize.empty())
124 return spirv::EntryPointABIAttr::get(context,
nullptr);
126 assert(localSize.size() == 3);
127 return spirv::EntryPointABIAttr::get(
128 context, DenseElementsAttr::get<int32_t>(
129 VectorType::get(3, IntegerType::get(context, 32)), localSize)
130 .cast<DenseIntElementsAttr>());
134 while (op && !isa<FunctionOpInterface>(op))
148 return entryPoint.getLocalSize();
153 spirv::ResourceLimitsAttr
158 return spirv::ResourceLimitsAttr::get(
171 {spirv::Capability::Shader},
174 spirv::DeviceType::Unknown,
202 spirv::AddressingModel
207 if (cap == Capability::Kernel)
208 return spirv::AddressingModel::Physical64;
212 if (cap == Capability::PhysicalStorageBufferAddresses)
213 return spirv::AddressingModel::PhysicalStorageBuffer64;
216 return spirv::AddressingModel::Logical;
222 if (cap == spirv::Capability::Kernel)
223 return spirv::ExecutionModel::Kernel;
224 if (cap == spirv::Capability::Shader)
225 return spirv::ExecutionModel::GLCompute;
233 if (cap == spirv::Capability::Addresses)
235 if (cap == spirv::Capability::Shader)
236 return spirv::MemoryModel::GLSL450;
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
DenseIntElementsAttr lookupLocalWorkGroupSize(Operation *op)
Queries the local workgroup size from entry point ABI on the nearest function-like op containing the ...
TargetEnvAttr lookupTargetEnv(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op...
Operation is a basic unit of execution within MLIR.
FailureOr< MemoryModel > getMemoryModel(TargetEnvAttr targetAttr)
Returns memory model selected based on target environment.
An attribute that specifies the information regarding the interface variable: descriptor set...
TargetEnv(TargetEnvAttr targetAttr)
AttrClass getAttrOfType(StringAttr name)
DeviceType getDeviceType() const
Returns the device type.
StringRef getEntryPointABIAttrName()
Returns the attribute name for specifying entry point information.
bool needsInterfaceVarABIAttrs(TargetEnvAttr targetAttr)
Returns whether the given SPIR-V target (described by TargetEnvAttr) needs ABI attributes for interfa...
EntryPointABIAttr getEntryPointABIAttr(ArrayRef< int32_t > localSize, MLIRContext *context)
Gets the EntryPointABIAttr given its fields.
ResourceLimitsAttr getDefaultResourceLimits(MLIRContext *context)
Returns a default resource limits attribute that uses numbers from "Table 46. Required Limits" of the...
EntryPointABIAttr lookupEntryPointABI(Operation *op)
Queries the entry point ABI on the nearest function-like op containing the given op.
StringRef getTargetEnvAttrName()
Returns the attribute name for specifying SPIR-V target environment.
bool allows(Capability) const
Returns true if the given capability is allowed.
MLIRContext * getContext()
Return the context this operation is associated with.
DeviceType getDeviceType() const
Returns the device type.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
SmallVector< Capability, 0 > getRecursiveImpliedCapabilities(Capability cap)
Returns the recursively implied capabilities for the given capability.
This class provides support for representing a failure result, or a valid value of type T...
MLIRContext * getContext() const
Returns the MLIRContext.
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
StringRef getInterfaceVarABIAttrName()
Returns the attribute name for specifying argument ABI information.
ArrayAttr getI32ArrayAttr(ArrayRef< int32_t > values)
InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding, Optional< StorageClass > storageClass, MLIRContext *context)
Gets the InterfaceVarABIAttr given its fields.
Vendor getVendorID() const
Returns the vendor ID.
AddressingModel getAddressingModel(TargetEnvAttr targetAttr)
Returns addressing model selected based on target environment.
static constexpr uint32_t kUnknownDeviceID
ID for unknown devices.
uint32_t getDeviceID() const
Returns the device ID.
FailureOr< ExecutionModel > getExecutionModel(TargetEnvAttr targetAttr)
Returns execution model selected based on target environment.
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
This class is a general helper class for creating context-global objects like types, attributes, and affine expressions.
TargetEnvAttr getDefaultTargetEnv(MLIRContext *context)
Returns the default target environment: SPIR-V 1.0 with Shader capability and no extra extensions...
uint32_t getDeviceID() const
Returns the device ID.
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, Optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
ArrayRef< Extension > getImpliedExtensions(Version version)
Returns the implied extensions for the given version.
MLIRContext is the top-level object for a collection of MLIR operations.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
Version getVersion() const
Returns the target version.
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
Version getVersion() const
static TargetEnvAttr get(VerCapExtAttr triple, Vendor vendorID, DeviceType deviceType, uint32_t deviceId, ResourceLimitsAttr limits)
Gets a TargetEnvAttr instance.
Vendor getVendorID() const
Returns the vendor ID.
An attribute that specifies the target version, allowed extensions and capabilities, and resource limits.
An attribute that represents a reference to a dense integer vector or tensor object.
VerCapExtAttr::ext_range getExtensions()
Returns the target extensions.