[llvm] [SPIRV] Change how to detect OpenCL/Vulkan Env and update tests accordingly. (PR #129689)

Marcos Maronas via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 03:54:38 PDT 2025


================
@@ -267,14 +267,42 @@ static SPIRVType *getArgSPIRVType(const Function &F, unsigned ArgIdx,
 
 static SPIRV::ExecutionModel::ExecutionModel
 getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
+  // FIXME: At the moment, there's a possibility that both `isOpenCLEnv()` and
+  // `isVulkanEnv()` return true. This is because the Triple is not always
+  // precise enough. For now, we'll rely instead on `isLogicalSPIRV()`, but this
+  // should be changed when `isOpenCLEnv()` and `isVulkanEnv()` cannot be true
+  // at the same time.
   if (STI.isOpenCLEnv())
     return SPIRV::ExecutionModel::Kernel;
 
+  if (STI.isVulkanEnv()) {
+    auto attribute = F.getFnAttribute("hlsl.shader");
+    if (!attribute.isValid()) {
+      report_fatal_error(
+          "This entry point lacks mandatory hlsl.shader attribute.");
+    }
+
+    const auto value = attribute.getValueAsString();
+    if (value == "compute")
+      return SPIRV::ExecutionModel::GLCompute;
+
+    report_fatal_error(
+        "This HLSL entry point is not supported by this backend.");
+  }
+
+  assert(STI.getEnv() == SPIRVSubtarget::Unknown);
+  // Can we rely on "hlsl.shader" attribute? Is it mandatory for Vulkan env? If
+  // so, we can set Env to Vulkan whenever we find it, and to OpenCL otherwise.
----------------
maarquitos14 wrote:

Sure, but we can rely on it? Can we assume that if we find such an attribute we're in Vulkan env?


https://github.com/llvm/llvm-project/pull/129689


More information about the llvm-commits mailing list