22 #include "llvm/ADT/SetVector.h" 23 #include "llvm/ADT/SmallSet.h" 24 #include "llvm/ADT/StringExtras.h" 31 class UpdateVCEPass final :
public SPIRVUpdateVCEBase<UpdateVCEPass> {
32 void runOnOperation()
override;
47 for (
const auto &ors : candidates) {
49 deducedExtensions.insert(*chosen);
52 for (spirv::Extension ext : ors)
53 extStrings.push_back(spirv::stringifyExtension(ext));
56 << op->
getName() <<
"' requires at least one extension in [" 57 << llvm::join(extStrings,
", ")
58 <<
"] but none allowed in target environment";
75 for (
const auto &ors : candidates) {
77 deducedCapabilities.insert(*chosen);
80 for (spirv::Capability cap : ors)
81 capStrings.push_back(spirv::stringifyCapability(cap));
84 << op->
getName() <<
"' requires at least one capability in [" 85 << llvm::join(capStrings,
", ")
86 <<
"] but none allowed in target environment";
92 void UpdateVCEPass::runOnOperation() {
93 spirv::ModuleOp module = getOperation();
97 module.emitError(
"missing 'spv.target_env' attribute");
98 return signalPassFailure();
102 spirv::Version allowedVersion = targetAttr.
getVersion();
104 spirv::Version deducedVersion = spirv::Version::V_1_0;
112 if (
auto minVersionIfx = dyn_cast<spirv::QueryMinVersionInterface>(op)) {
115 deducedVersion =
std::max(deducedVersion, *minVersion);
116 if (deducedVersion > allowedVersion) {
118 << op->
getName() <<
"' requires min version " 119 << spirv::stringifyVersion(deducedVersion)
120 <<
" but target environment allows up to " 121 << spirv::stringifyVersion(allowedVersion);
127 if (
auto extensions = dyn_cast<spirv::QueryExtensionInterface>(op))
129 op, targetEnv, extensions.getExtensions(), deducedExtensions)))
133 if (
auto capabilities = dyn_cast<spirv::QueryCapabilityInterface>(op))
135 op, targetEnv, capabilities.getCapabilities(),
136 deducedCapabilities)))
145 if (
auto globalVar = dyn_cast<spirv::GlobalVariableOp>(op))
146 valueTypes.push_back(globalVar.type());
151 for (
Type valueType : valueTypes) {
152 typeExtensions.clear();
155 op, targetEnv, typeExtensions, deducedExtensions)))
158 typeCapabilities.clear();
161 op, targetEnv, typeCapabilities, deducedCapabilities)))
169 return signalPassFailure();
175 deducedVersion, deducedCapabilities.getArrayRef(),
176 deducedExtensions.getArrayRef(), &getContext());
177 module->setAttr(spirv::ModuleOp::getVCETripleAttrName(), triple);
180 std::unique_ptr<OperationPass<spirv::ModuleOp>>
182 return std::make_unique<UpdateVCEPass>();
Include the generated interface declarations.
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.
bool wasInterrupted() const
Returns true if the walk was interrupted.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
bool allows(Capability) const
Returns true if the given capability is allowed.
static LogicalResult checkAndUpdateCapabilityRequirements(Operation *op, const spirv::TargetEnv &targetEnv, const spirv::SPIRVType::CapabilityArrayRefVector &candidates, SetVector< spirv::Capability > &deducedCapabilities)
Checks that candidatescapability requirements are possible to be satisfied with the given targetEnv a...
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.
static WalkResult advance()
static WalkResult interrupt()
result_type_iterator result_type_end()
A utility result that is used to signal how to proceed with an ongoing walk:
operand_type_iterator operand_type_begin()
A wrapper class around a spirv::TargetEnvAttr to provide query methods for allowed version/capabiliti...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
operand_type_iterator operand_type_end()
result_type_iterator result_type_begin()
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
static LogicalResult checkAndUpdateExtensionRequirements(Operation *op, const spirv::TargetEnv &targetEnv, const spirv::SPIRVType::ExtensionArrayRefVector &candidates, SetVector< spirv::Extension > &deducedExtensions)
Checks that candidates extension requirements are possible to be satisfied with the given targetEnv a...
Version getVersion() const
Returns the target version.
OperationName getName()
The name of an operation is the key identifier for it.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
An attribute that specifies the target version, allowed extensions and capabilities, and resource limits.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
std::unique_ptr< OperationPass< spirv::ModuleOp > > createUpdateVersionCapabilityExtensionPass()
Creates an operation pass that deduces and attaches the minimal version/ capabilities/extensions requ...