Skip to content

Make OpenCL an OSType rather than an EnvironmentType.#170297

Merged
maarquitos14 merged 4 commits intollvm:mainfrom
maarquitos14:maronas/opencl-ostype
Feb 10, 2026
Merged

Make OpenCL an OSType rather than an EnvironmentType.#170297
maarquitos14 merged 4 commits intollvm:mainfrom
maarquitos14:maronas/opencl-ostype

Conversation

@maarquitos14
Copy link
Copy Markdown
Contributor

OpenCL was added as an EnvironmentType in #78655, but there is no explanation as to why it was added as such, even after explicitly asking in the PR (#78655 (comment)). This PR makes it an OSType instead, which feels more natural, and updates tests accordingly.

@maarquitos14
Copy link
Copy Markdown
Contributor Author

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 2, 2025

🐧 Linux x64 Test Results

  • 196808 tests passed
  • 6470 tests skipped

✅ The build succeeded and all tests passed.

@bader bader requested review from svenvh and yxsamliu December 2, 2025 16:24
Copy link
Copy Markdown
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test changes imply that AMD team is using the OpenCL EnvironmentType.
@yxsamliu, are you okay with this change?

@llvmbot llvmbot added backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' backend:SPIR-V labels Dec 2, 2025
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Dec 2, 2025

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-backend-spir-v

Author: Marcos Maronas (maarquitos14)

Changes

OpenCL was added as an EnvironmentType in #78655, but there is no explanation as to why it was added as such, even after explicitly asking in the PR (#78655 (comment)). This PR makes it an OSType instead, which feels more natural, and updates tests accordingly.


Full diff: https://github.com/llvm/llvm-project/pull/170297.diff

7 Files Affected:

  • (modified) clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl (+1-1)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl (+1-1)
  • (modified) clang/test/Driver/amdgpu-toolchain-opencl.cl (+15-15)
  • (modified) clang/test/Driver/opencl.cl (+1-1)
  • (modified) llvm/include/llvm/TargetParser/Triple.h (+2-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp (+1-1)
  • (modified) llvm/lib/TargetParser/Triple.cpp (+3-3)
diff --git a/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl b/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
index e6a783fff4bc5..6954d5beda344 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
-// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa-opencl -mcpu=fiji -o - %s | FileCheck %s
+// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
 // CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GLOBAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}})
 // CHECK-DAG: ![[DWARF_ADDRESS_SPACE_LOCAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 3)
diff --git a/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl b/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
index 4d5f1019378af..ee6794b63e1df 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
-// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa-opencl -mcpu=fiji -o - %s | FileCheck %s
+// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
 // CHECK-DAG: ![[FILEVAR0:[0-9]+]] = distinct !DIGlobalVariable(name: "FileVar0", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: false, isDefinition: true)
 // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FILEVAR0]], expr: !DIExpression())
diff --git a/clang/test/Driver/amdgpu-toolchain-opencl.cl b/clang/test/Driver/amdgpu-toolchain-opencl.cl
index fb21301744b91..1d74ba3e74c3c 100644
--- a/clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ b/clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -1,17 +1,17 @@
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O0 %s 2>&1 | FileCheck -check-prefix=CHECK_O0 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O1 %s 2>&1 | FileCheck -check-prefix=CHECK_O1 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O2 %s 2>&1 | FileCheck -check-prefix=CHECK_O2 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O3 %s 2>&1 | FileCheck -check-prefix=CHECK_O3 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O4 %s 2>&1 | FileCheck -check-prefix=CHECK_O4 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O5 %s 2>&1 | FileCheck -check-prefix=CHECK_O5 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O0 %s 2>&1 | FileCheck -check-prefix=CHECK_O0 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O1 %s 2>&1 | FileCheck -check-prefix=CHECK_O1 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O2 %s 2>&1 | FileCheck -check-prefix=CHECK_O2 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O3 %s 2>&1 | FileCheck -check-prefix=CHECK_O3 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O4 %s 2>&1 | FileCheck -check-prefix=CHECK_O4 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O5 %s 2>&1 | FileCheck -check-prefix=CHECK_O5 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
 
 // Check default include file is not included for preprocessor output.
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
 
 // CHECK_O0: "-cc1"{{.*}} "-O0"
 // CHECK_O1: "-cc1"{{.*}} "-O1"
@@ -26,14 +26,14 @@
 // CHK-INC: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cl"
 // CHK-INC-NOT: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
 // CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
 // CHK-LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} "--unresolved-symbols=ignore-all"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
 // CHECK-WARN-ATOMIC: "-cc1"{{.*}} "-Werror=atomic-alignment"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 \
diff --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
index 3b0b191827b4c..5b2a1033de081 100644
--- a/clang/test/Driver/opencl.cl
+++ b/clang/test/Driver/opencl.cl
@@ -22,7 +22,7 @@
 // RUN: not %clang -cl-std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s
 // RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
 // RUN: %clang -S -### --target=spir %s 2>&1 | FileCheck --check-prefix=CHECK-W-SPIR-COMPAT %s
-// RUN: %clang -S -### --target=amdgcn-amd-amdhsa-opencl -nogpuinc -nogpulib %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
+// RUN: %clang -S -### --target=amdgcn-amd-amdhsa -nogpuinc -nogpulib %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
 // RUN: %clang -S -### -cl-ext="+test_ext" %s 2>&1 | FileCheck --check-prefix=CHECK-EXT %s
 
 // CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 11b76cd183108..86c7c8e151070 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -248,7 +248,8 @@ class Triple {
     Serenity,
     Vulkan, // Vulkan SPIR-V
     CheriotRTOS,
-    LastOSType = CheriotRTOS
+    OpenCL,
+    LastOSType = OpenCL
   };
   enum EnvironmentType {
     UnknownEnvironment,
@@ -308,7 +309,6 @@ class Triple {
     Mesh,
     Amplification,
     RootSignature,
-    OpenCL,
     OpenHOS,
     Mlibc,
 
diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
index ad6c9cd421b7c..4e80fd3c37b14 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
@@ -89,7 +89,7 @@ SPIRVSubtarget::SPIRVSubtarget(const Triple &TT, const std::string &CPU,
   // Set the environment based on the target triple.
   if (TargetTriple.getOS() == Triple::Vulkan)
     Env = Shader;
-  else if (TargetTriple.getEnvironment() == Triple::OpenCL ||
+  else if (TargetTriple.getOS() == Triple::OpenCL ||
            TargetTriple.getVendor() == Triple::AMD)
     Env = Kernel;
   else
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 11ba9ee32f66a..2b46065dd6123 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -333,6 +333,8 @@ StringRef Triple::getOSTypeName(OSType Kind) {
   case Vulkan: return "vulkan";
   case CheriotRTOS:
     return "cheriotrtos";
+  case OpenCL:
+    return "opencl";
   }
 
   llvm_unreachable("Invalid OSType");
@@ -395,8 +397,6 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
   case Amplification: return "amplification";
   case RootSignature:
     return "rootsignature";
-  case OpenCL:
-    return "opencl";
   case OpenHOS: return "ohos";
   case PAuthTest:
     return "pauthtest";
@@ -742,6 +742,7 @@ static Triple::OSType parseOS(StringRef OSName) {
       .StartsWith("serenity", Triple::Serenity)
       .StartsWith("vulkan", Triple::Vulkan)
       .StartsWith("cheriotrtos", Triple::CheriotRTOS)
+      .StartsWith("opencl", Triple::OpenCL)
       .Default(Triple::UnknownOS);
 }
 
@@ -795,7 +796,6 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
       .StartsWith("mesh", Triple::Mesh)
       .StartsWith("amplification", Triple::Amplification)
       .StartsWith("rootsignature", Triple::RootSignature)
-      .StartsWith("opencl", Triple::OpenCL)
       .StartsWith("ohos", Triple::OpenHOS)
       .StartsWith("pauthtest", Triple::PAuthTest)
       .StartsWith("llvm", Triple::LLVM)

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Dec 2, 2025

@llvm/pr-subscribers-clang-driver

Author: Marcos Maronas (maarquitos14)

Changes

OpenCL was added as an EnvironmentType in #78655, but there is no explanation as to why it was added as such, even after explicitly asking in the PR (#78655 (comment)). This PR makes it an OSType instead, which feels more natural, and updates tests accordingly.


Full diff: https://github.com/llvm/llvm-project/pull/170297.diff

7 Files Affected:

  • (modified) clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl (+1-1)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl (+1-1)
  • (modified) clang/test/Driver/amdgpu-toolchain-opencl.cl (+15-15)
  • (modified) clang/test/Driver/opencl.cl (+1-1)
  • (modified) llvm/include/llvm/TargetParser/Triple.h (+2-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp (+1-1)
  • (modified) llvm/lib/TargetParser/Triple.cpp (+3-3)
diff --git a/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl b/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
index e6a783fff4bc5..6954d5beda344 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
-// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa-opencl -mcpu=fiji -o - %s | FileCheck %s
+// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
 // CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GLOBAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}})
 // CHECK-DAG: ![[DWARF_ADDRESS_SPACE_LOCAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 3)
diff --git a/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl b/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
index 4d5f1019378af..ee6794b63e1df 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
-// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa-opencl -mcpu=fiji -o - %s | FileCheck %s
+// RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
 // CHECK-DAG: ![[FILEVAR0:[0-9]+]] = distinct !DIGlobalVariable(name: "FileVar0", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: false, isDefinition: true)
 // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FILEVAR0]], expr: !DIExpression())
diff --git a/clang/test/Driver/amdgpu-toolchain-opencl.cl b/clang/test/Driver/amdgpu-toolchain-opencl.cl
index fb21301744b91..1d74ba3e74c3c 100644
--- a/clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ b/clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -1,17 +1,17 @@
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O0 %s 2>&1 | FileCheck -check-prefix=CHECK_O0 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O1 %s 2>&1 | FileCheck -check-prefix=CHECK_O1 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O2 %s 2>&1 | FileCheck -check-prefix=CHECK_O2 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O3 %s 2>&1 | FileCheck -check-prefix=CHECK_O3 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O4 %s 2>&1 | FileCheck -check-prefix=CHECK_O4 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O5 %s 2>&1 | FileCheck -check-prefix=CHECK_O5 %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O0 %s 2>&1 | FileCheck -check-prefix=CHECK_O0 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O1 %s 2>&1 | FileCheck -check-prefix=CHECK_O1 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O2 %s 2>&1 | FileCheck -check-prefix=CHECK_O2 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O3 %s 2>&1 | FileCheck -check-prefix=CHECK_O3 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O4 %s 2>&1 | FileCheck -check-prefix=CHECK_O4 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -O5 %s 2>&1 | FileCheck -check-prefix=CHECK_O5 %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
 
 // Check default include file is not included for preprocessor output.
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
 
 // CHECK_O0: "-cc1"{{.*}} "-O0"
 // CHECK_O1: "-cc1"{{.*}} "-O1"
@@ -26,14 +26,14 @@
 // CHK-INC: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cl"
 // CHK-INC-NOT: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
 // CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
 // CHK-LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} "--unresolved-symbols=ignore-all"
 
-// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
 // CHECK-WARN-ATOMIC: "-cc1"{{.*}} "-Werror=atomic-alignment"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 \
diff --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
index 3b0b191827b4c..5b2a1033de081 100644
--- a/clang/test/Driver/opencl.cl
+++ b/clang/test/Driver/opencl.cl
@@ -22,7 +22,7 @@
 // RUN: not %clang -cl-std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s
 // RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
 // RUN: %clang -S -### --target=spir %s 2>&1 | FileCheck --check-prefix=CHECK-W-SPIR-COMPAT %s
-// RUN: %clang -S -### --target=amdgcn-amd-amdhsa-opencl -nogpuinc -nogpulib %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
+// RUN: %clang -S -### --target=amdgcn-amd-amdhsa -nogpuinc -nogpulib %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
 // RUN: %clang -S -### -cl-ext="+test_ext" %s 2>&1 | FileCheck --check-prefix=CHECK-EXT %s
 
 // CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 11b76cd183108..86c7c8e151070 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -248,7 +248,8 @@ class Triple {
     Serenity,
     Vulkan, // Vulkan SPIR-V
     CheriotRTOS,
-    LastOSType = CheriotRTOS
+    OpenCL,
+    LastOSType = OpenCL
   };
   enum EnvironmentType {
     UnknownEnvironment,
@@ -308,7 +309,6 @@ class Triple {
     Mesh,
     Amplification,
     RootSignature,
-    OpenCL,
     OpenHOS,
     Mlibc,
 
diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
index ad6c9cd421b7c..4e80fd3c37b14 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
@@ -89,7 +89,7 @@ SPIRVSubtarget::SPIRVSubtarget(const Triple &TT, const std::string &CPU,
   // Set the environment based on the target triple.
   if (TargetTriple.getOS() == Triple::Vulkan)
     Env = Shader;
-  else if (TargetTriple.getEnvironment() == Triple::OpenCL ||
+  else if (TargetTriple.getOS() == Triple::OpenCL ||
            TargetTriple.getVendor() == Triple::AMD)
     Env = Kernel;
   else
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 11ba9ee32f66a..2b46065dd6123 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -333,6 +333,8 @@ StringRef Triple::getOSTypeName(OSType Kind) {
   case Vulkan: return "vulkan";
   case CheriotRTOS:
     return "cheriotrtos";
+  case OpenCL:
+    return "opencl";
   }
 
   llvm_unreachable("Invalid OSType");
@@ -395,8 +397,6 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
   case Amplification: return "amplification";
   case RootSignature:
     return "rootsignature";
-  case OpenCL:
-    return "opencl";
   case OpenHOS: return "ohos";
   case PAuthTest:
     return "pauthtest";
@@ -742,6 +742,7 @@ static Triple::OSType parseOS(StringRef OSName) {
       .StartsWith("serenity", Triple::Serenity)
       .StartsWith("vulkan", Triple::Vulkan)
       .StartsWith("cheriotrtos", Triple::CheriotRTOS)
+      .StartsWith("opencl", Triple::OpenCL)
       .Default(Triple::UnknownOS);
 }
 
@@ -795,7 +796,6 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
       .StartsWith("mesh", Triple::Mesh)
       .StartsWith("amplification", Triple::Amplification)
       .StartsWith("rootsignature", Triple::RootSignature)
-      .StartsWith("opencl", Triple::OpenCL)
       .StartsWith("ohos", Triple::OpenHOS)
       .StartsWith("pauthtest", Triple::PAuthTest)
       .StartsWith("llvm", Triple::LLVM)

@maarquitos14
Copy link
Copy Markdown
Contributor Author

Test changes imply that AMD team is using the OpenCL EnvironmentType. @yxsamliu, are you okay with this change?

Yes, thanks for tagging somebody. I was planning to ask if anybody from AMD could have a look at this. I suspect OpenCL was originally added as EnvironmentType because of these tests. Likely, the patch was failing for these tests, and they added it as EnvironmentType to fix errors.

@arsenm
Copy link
Copy Markdown
Contributor

arsenm commented Dec 2, 2025

OpenCL should be neither an operating system or an environment. It's a source language, not a target ABI. I think we used to mishandle HIP and OpenCL differences and I don't think AMD is using this anymore

@bader
Copy link
Copy Markdown
Contributor

bader commented Dec 2, 2025

OpenCL should be neither an operating system or an environment. It's a source language, not a target ABI. I think we used to mishandle HIP and OpenCL differences and I don't think AMD is using this anymore

There must be some feature to separate GPU code execution environments (e.g. OpenCL and Vulkan). @arsenm, do you have a constructive proposal to separate them?

@bader
Copy link
Copy Markdown
Contributor

bader commented Dec 9, 2025

OpenCL should be neither an operating system or an environment. It's a source language, not a target ABI. I think we used to mishandle HIP and OpenCL differences and I don't think AMD is using this anymore

There must be some feature to separate GPU code execution environments (e.g. OpenCL and Vulkan). @arsenm, do you have a constructive proposal to separate them?

Ping.

@arsenm, based on your comment I assume this change won't break OpenCL implementation for AMDGPU.
If you are not happy with the current patch, please, share your ideas on handling SPIR-V differences between OpenCL and Vulkan execution environments.

@arsenm
Copy link
Copy Markdown
Contributor

arsenm commented Dec 9, 2025

SPIR-V differences between OpenCL and Vulkan execution environments.

In what way are these different program-visible execution environments? I would hope vendors would implement a common ABI. If there are, I would expect the name to be something reflecting that implementation ABI, not the language?

e.g., the mistake we made here was having different kernel argument layouts for OpenCL, and later fixed that

@bader
Copy link
Copy Markdown
Contributor

bader commented Dec 10, 2025

SPIR-V differences between OpenCL and Vulkan execution environments.

In what way are these different program-visible execution environments? I would hope vendors would implement a common ABI. If there are, I would expect the name to be something reflecting that implementation ABI, not the language?

e.g., the mistake we made here was having different kernel argument layouts for OpenCL, and later fixed that

These environments put incompatible restrictions on SPIR-V instructions.
Here is an empty OpenCL kernel compiled to SPIR-V format by clpsv (for Vulkan execution environment) and clang (for OpenCL execution environment) - https://godbolt.org/z/9b49srbWb.
Vulkan environment requires SPIR-V module to declare OpCapability Shader whereas OpenCL environment requires SPIR-V to declare OpCapability Kernel. There are a lot of other differences like this described in specifications for SPIR-V format, Vulkan environment and OpenCL environment.

@maarquitos14, @MrSidims and @Keenuts, please, help with clarifying how the difference in SPIR-V validation rules for OpenCL and Vulkan execution environments impacts the SPIR-V backend.

@Keenuts
Copy link
Copy Markdown
Contributor

Keenuts commented Dec 11, 2025

Hi,

As Bader mentions, there are a few restrictions. Some are "details", like a different capability, or different MemoryModel operand, but some others are important changes, like the control flow structure:

  • SPIR-V modules targeting Kernel/OpenCL can have arbitrary control flows, and generic pointers.
  • Shader/VK SPIR-V require structured control flow and considers pointers to be intangible, opaque & strongly typed things a bit like C++ references.

On top of those SPIR-V Shader vs SPIR-V Kernel restrictions, you have the target API additional contraints.
Vulkan for example adds another layer of constraints on top of the Shader flavor of SPIR-V ( https://docs.vulkan.org/spec/latest/appendices/spirvenv.html )

  • some opcodes can only be used with some types.
  • static recursion is forbidden
  • cross-wave/lane/group operations are restricted to workgroup/subgroup. Cannot for ex put a device-wide barrier.

@maarquitos14
Copy link
Copy Markdown
Contributor Author

Discussion seems to be stalled again. @arsenm did @bader and @Keenuts address your concerns?

Copy link
Copy Markdown
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this PR, would align with the Vulkan side of things

@maarquitos14
Copy link
Copy Markdown
Contributor Author

@arsenm friendly ping

@arsenm
Copy link
Copy Markdown
Contributor

arsenm commented Jan 8, 2026

SPIR-V modules targeting Kernel/OpenCL can have arbitrary control flows, and generic pointers.

This sounds more like a top level target difference. As for naming, would kernel be more appropriate than OpenCL?

@Keenuts
Copy link
Copy Markdown
Contributor

Keenuts commented Jan 9, 2026

SPIR-V modules targeting Kernel/OpenCL can have arbitrary control flows, and generic pointers.

This sounds more like a top level target difference. As for naming, would kernel be more appropriate than OpenCL?

  • SPIR-V spec: OpCapability Shader requires structured CFG
  • Vulkan spec: Shader capability is allowed, Kernel is not.

So VK requires Shader, Shader requires Logical & structured CFG

  • BUT: VK forbids static recursion while SPIR-V spec makes no mention of it.

So at least for this part, Vulkan is not strictly equivalent to Shader.

  • SPIR-V spec: Kernel means unstructured CFG, but requires unsigned integers.
  • OpenCL spec: execution must be Kernel

So OpenCL requires Kernel, Kernel allows unstructured CFG and requires unsigned int.

  • SPIR-V spec doesn't tie Kernel to a specific addressing model
  • BUT: OpenCL validation rules require Physical32 or Physical64

So it seems similarly to Vulkan, OpenCL != Kernel.

Given OpenCL implies Kernel, and Vulkan implies Shader, it seems to me we should be exposing OpenCL and Vulkan in the triple, but not necessarily Kernel/Shader as those are incomplete to generate usable SPIR-V module (even if valid in the SPIR-V spec world)

@maarquitos14
Copy link
Copy Markdown
Contributor Author

@arsenm any other concerns with this? Can we get it merged?

@maarquitos14
Copy link
Copy Markdown
Contributor Author

@jmmartinez @AlexVlx friendly ping :)

Copy link
Copy Markdown
Contributor

@jmmartinez jmmartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
The change makes sense to me.

I find the opencl naming a bit odd, but do not have something better to suggest.

I find it odd in the sense that opencl is not really an OS.

I'm also wondering how this could eventually compose with other targets. For example, if I'm compiling for amd, we could use amdgcn-amd-opencl instead of --amdhsa? and would that enable some simplification somewhere? Are other targets communicating some OpenCL specific information in the IR through other means, like metadata, attributes... that we could replace?

I was thinking about -compute but what does that even mean... It obscures the relationship between the target and the associated spec.

@maarquitos14
Copy link
Copy Markdown
Contributor Author

I find the opencl naming a bit odd, but do not have something better to suggest.

I find it odd in the sense that opencl is not really an OS.

I agree, OpenCL is not an OS, but neither is Vulkan, as far as I know. I remember @Keenuts explaining why they did go for making Vulkan an OSType, but can't find the reference now. I think the point was that they needed the environment type for the shading stages (e.g. spirv-unknown-vulkan-pixel, spirv-unknown-vulkan-vertex). Please, @Keenuts, correct me if I'm wrong. This PR just aligns OpenCL with Vulkan.

I'm also wondering how this could eventually compose with other targets. For example, if I'm compiling for amd, we could use amdgcn-amd-opencl instead of --amdhsa? and would that enable some simplification somewhere? Are other targets communicating some OpenCL specific information in the IR through other means, like metadata, attributes... that we could replace?

You could use amdgcn-amd-opencl, but I don't think it would replace --amdhsa at the moment. I don't really know, but that wasn't the intent of this PR, and I guess it would require some more work elsewhere. Like I said before, the main driver for this PR was to align OpenCL with Vulkan, and facilitate how SPIRVSubtarget chooses the environment.

@jmmartinez
Copy link
Copy Markdown
Contributor

I'm also wondering how this could eventually compose with other targets. For example, if I'm compiling for amd, we could use amdgcn-amd-opencl instead of --amdhsa? and would that enable some simplification somewhere? Are other targets communicating some OpenCL specific information in the IR through other means, like metadata, attributes... that we could replace?

You could use amdgcn-amd-opencl, but I don't think it would replace --amdhsa at the moment. I don't really know, but that wasn't the intent of this PR, and I guess it would require some more work elsewhere. Like I said before, the main driver for this PR was to align OpenCL with Vulkan, and facilitate how SPIRVSubtarget chooses the environment.

Ah sure, we shouldn't do that. At least not now. It was hypothetical, just to think if there could be an obvious mismatch.

@maarquitos14
Copy link
Copy Markdown
Contributor Author

Unrelated failures, they can be observed in other PRs as well (e.g. #179114).

Failed Tests (3):
  LLVM :: CodeGen/SPIRV/llvm-intrinsics/constrained-arithmetic.ll
  LLVM :: CodeGen/SPIRV/llvm-intrinsics/constrained-fmuladd.ll
  LLVM :: CodeGen/SPIRV/transcoding/OpenCL/convert_functions.ll

@maarquitos14 maarquitos14 merged commit ce94d63 into llvm:main Feb 10, 2026
10 of 11 checks passed
@Keenuts
Copy link
Copy Markdown
Contributor

Keenuts commented Feb 11, 2026

I agree, OpenCL is not an OS, but neither is Vulkan, as far as I know. I remember @Keenuts explaining why they did go for making Vulkan an OSType, but can't find the reference now. I think the point was that they needed the environment type for the shading stages (e.g. spirv-unknown-vulkan-pixel, spirv-unknown-vulkan-vertex). Please, @Keenuts, correct me if I'm wrong. This PR just aligns OpenCL with Vulkan.

Yes, that's correct. Because the environment part of the triple was reserved for pixel/compute/vertex/lib/etc, it made "sense" (if you squint enough) to consider Vulkan/ShaderModel/OpenCL an OS. At least it allowed us to align to what DXIL+ShaderModel was doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU backend:SPIR-V clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants