[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
Mon Apr 7 13:28:10 PDT 2025


================
@@ -78,14 +78,10 @@ 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;
+   return TargetTriple.getEnvironment() == Triple::OpenCL;
   }
-  bool isVulkanEnv() const { return TargetTriple.getArch() == Triple::spirv; }
+  bool isVulkanEnv() const { return !isOpenCLEnv(); }
----------------
bader wrote:

I see that Vulkan is added to the triple as OSType: https://github.com/llvm/llvm-project/blob/7aedebac8cb473555aa8a2928ac3851b0142921e/llvm/include/llvm/TargetParser/Triple.h#L241
SPIR target uses `Vulkan` OSType to detect Vulkan environment: https://github.com/llvm/llvm-project/blob/9fdac840ec4901a6e3c71249a136cbecc4a9921a/clang/lib/Basic/Targets/SPIR.h#L305-L312

OpenCL is a bit messy.
I see one* OpenCL OSType: https://github.com/llvm/llvm-project/blob/7aedebac8cb473555aa8a2928ac3851b0142921e/llvm/include/llvm/TargetParser/Triple.h#L222
Environment component also defines OpenCL: https://github.com/llvm/llvm-project/blob/7aedebac8cb473555aa8a2928ac3851b0142921e/llvm/include/llvm/TargetParser/Triple.h#L300

I don't know the meaning of OpenCL in the environment component, but using OS triple component makes more sense to me. This topic probably forth a separate discussion, but I would add OpenCL component to OSType rather than to environment component. I guess we can alias `NVCL` to the `OpenCL` OSType value.

\* - Maybe `Mesa3D` can be also considered as OpenCL environment.

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


More information about the llvm-commits mailing list