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

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 02:22:15 PDT 2025


================
@@ -78,14 +83,21 @@ class SPIRVSubtarget : public SPIRVGenSubtargetInfo {
   unsigned getPointerSize() const { return PointerSize; }
   unsigned getBound() const { return GR->getBound(); }
   bool canDirectlyComparePointers() const;
-  // TODO: this environment is not implemented in Triple, we need to decide
-  // how to standardize its support. For now, let's assume SPIR-V with physical
-  // addressing is OpenCL, and Logical addressing is Vulkan.
-  bool isOpenCLEnv() const {
-    return TargetTriple.getArch() == Triple::spirv32 ||
-           TargetTriple.getArch() == Triple::spirv64;
+  void setEnv(SPIRVEnvType E) {
+    assert(E != Unknown && "Unknown environment is not allowed");
+    assert(Env == Unknown && "Environment is already set");
+
+    Env = E;
   }
-  bool isVulkanEnv() const { return TargetTriple.getArch() == Triple::spirv; }
+  SPIRVEnvType getEnv() const { return Env; }
+  bool isOpenCLEnv() const { return getEnv() == OpenCL; }
+  bool isVulkanEnv() const { return getEnv() == Vulkan; }
+  // FIXME: This should check the triple arch instead, but a lot of places use
+  // this method now instead of `is[OpenCL/Vulkan]Env()`, and this is a
+  // shortcut to make sure `is[OpenCL/Vulkan]Env()` works as expected. When we
+  // change back all uses of `isLogicalSPIRV()` to `is[OpenCL/Vulkan]Env()`, we
+  // can implement this correctly again.
+  bool isLogicalSPIRV() const { return isVulkanEnv(); }
----------------
Keenuts wrote:

I'm fine requiring an explicit `-vulkan` when targeting vulkan.
Question: shall those 2 functions be:

````
bool isKernelEnv() { return Env==Unknown && (arch == spirv64 || arch == spirv32)
bool isShaderEnv() { return OS == vulkan }
bool isLogicalSPIRV() { return arch == spirv }
```

For now we gated many capabilities/things around `isOpenCL`/`isVulkan`, but we might to change that?

The `StorageImageReadWithoutFormat` check would is isShader(), but the Structurizer would rely on `isLogicalSPIRV()`

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


More information about the llvm-commits mailing list