[llvm] [SPIRV] Change how to detect OpenCL/Vulkan Env and update tests accordingly. (PR #129689)
Alexey Bader via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 12:31:54 PDT 2025
================
@@ -532,7 +532,7 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
Inst.addOperand(MCOperand::createImm(TypeCode));
outputMCInst(Inst);
}
- if (ST->isOpenCLEnv() && !M.getNamedMetadata("spirv.ExecutionMode") &&
+ if (ST->isKernelEnv() && !M.getNamedMetadata("spirv.ExecutionMode") &&
----------------
bader wrote:
> Anyway, I think what we are detecting here is capabilities because most uses of `isKernelEnv()/isShaderEnv()` are used to check if a particular feature is allowed --e.g. `Constant` decoration is only allowed if `Kernel` capability is enabled. Fundamentally, we want to know if we're dealing with graphical shaders or compute kernels.
Please, make the method name clearer. E.g.
```suggestion
if (ST->isKernel() && !M.getNamedMetadata("spirv.ExecutionMode") &&
```
or `requiresKernelCapability()`.
> To be honest, I don't see in the SPIR-V spec anything about environments being OpenCL/Vulkan.
Right, SPIR-V spec only says that there are separate specifications:
> 1.2. Execution Environment and Client API
> SPIR-V is adaptable to multiple execution environments: A SPIR-V module is consumed by an execution environment, as specified by a client API. The full set of rules needed to consume SPIR-V in a particular environment comes from the combination of SPIR-V and that environment’s client API specification. The client API specifies its SPIR-V execution environment as well as extra rules, limitations, capabilities, etc. required by the form of SPIR-V it can validly consume.
OpenCL provides [The OpenCL™ SPIR-V Environment Specification](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Env.html) and Vulkan provides [Vulkan Environment for SPIR-V](https://docs.vulkan.org/spec/latest/appendices/spirvenv.html). There are other execution environments supporting SPIR-V formats (e.g. [Level Zero](https://oneapi-src.github.io/level-zero-spec/level-zero/latest/core/SPIRV.html))
My understanding is that compiler performs additional checks for restrictions in the environment specification, which is specified as OS component of the target triple.
https://github.com/llvm/llvm-project/pull/129689
More information about the llvm-commits
mailing list