[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
Wed May 14 07:09:22 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(); }
----------------
maarquitos14 wrote:

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

I'm not sure I understand what you mean. Many capabilities/things are actually Shader/Kernel-specific, so we need to gate them. Are there any specific capabilities/things that are currently gated, but shouldn't be?

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

I have just pushed a new commit where I go back to using `isShaderEnv()` where there were calls to `isVulkanEnv()`, and reinstated the original behavior of `isLogicalSPIRV()`.

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


More information about the llvm-commits mailing list