[clang] [CIR][SYCL] Fix GPURelocatableDeviceCode NYI blocking all CIR SYCL Codegen tests (PR #236592)
Balaji V. Iyer. via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 30 15:51:40 PDT 2026
https://github.com/bviyer updated https://github.com/llvm/llvm-project/pull/236592
>From a21dd042da8c8766dc8464cc794961b80fc95371 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Wed, 28 Oct 2026 15:28:56 -0700
Subject: [PATCH 1/2] [CIR][SYCL] Fix GPURelocatableDeviceCode NYI blocking all
CIR SYCL Codegen tests
Narrow the GPURelocatableDeviceCode NYI check in `getMangledNameImpl`
to HIP file-scope-static- externalization case, replacing the
blanket SYCL exclusion. Also updated 4 test cases to match.
---
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 8 ++++----
.../CIR/CodeGenSYCL/kernel-caller-address-space.cpp | 2 +-
.../CIR/CodeGenSYCL/kernel-caller-attributes.cpp | 6 +++---
.../CIR/CodeGenSYCL/kernel-caller-entry-point.cpp | 13 +++++++------
4 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 56fb14e5c6baea..465501f61866f0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -2866,10 +2866,10 @@ static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd,
"getMangledName: multi-version functions");
}
}
- // SYCL does not externalize file-scope statics, so RDC does not change the
- // mangled name.
- if (cgm.getLangOpts().GPURelocatableDeviceCode &&
- !cgm.getLangOpts().isSYCL()) {
+ // Make unique name for device side static file-scope variable for HIP.
+ if (cgm.getASTContext().shouldExternalize(nd) &&
+ cgm.getLangOpts().GPURelocatableDeviceCode &&
+ cgm.getLangOpts().CUDAIsDevice) {
cgm.errorNYI(nd->getSourceRange(),
"getMangledName: GPU relocatable device code");
}
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
index cb4a6962644306..e76a66d0533315 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
@@ -48,7 +48,7 @@ void test(int *p) {
// LLVM: store i32 42, ptr addrspace(4)
struct FPKN;
-void callee();
+__attribute__((sycl_device)) void callee();
void test_fp() {
kernel_single_task<FPKN>([]() { void (*fp)() = callee; fp(); });
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
index 9df1b9f98b2b50..ecef7a559c813f 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
@@ -41,7 +41,7 @@ void test(int *p) {
// OGCG: attributes #[[KATTR]] = {{[{].*}}mustprogress{{.*}}norecurse{{.*}}"sycl-module-id"="{{.*}}kernel-caller-attributes.cpp"
// With -fno-finite-loops, checkIfFunctionMustProgress() is false, so the kernel
-// caller must not carry mustprogress; norecurse and sycl-module-id remain. The
-// exact attribute set (which omits mustprogress) is verified here.
+// caller must not carry mustprogress; norecurse and sycl-module-id remain.
// LLVM-NOMP: define spir_kernel void @_ZTS2KN({{.*}}) #[[KATTR:[0-9]+]]
-// LLVM-NOMP: attributes #[[KATTR]] = { convergent noinline norecurse nounwind optnone "sycl-module-id"="{{.*}}kernel-caller-attributes.cpp" }
+// LLVM-NOMP: attributes #[[KATTR]] = {{[{].*}}convergent{{.*}}noinline{{.*}}norecurse{{.*}}"sycl-module-id"="{{.*}}kernel-caller-attributes.cpp"
+// LLVM-NOMP-NOT: mustprogress
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
index cf9a923d466144..0938e158aaac12 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
@@ -5,14 +5,15 @@
// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spirv64-unknown-unknown -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=OGCG,LLVM-OGCG
-// On an ELF target such as spir64, the kernel caller entry point definition is
-// dso_local. dso_local is only attached to a definition, so this also verifies
-// that setDSOLocal() runs after body emission.
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -fclangir -emit-cir %s -o %t-elf.cir
+// On an ELF target such as spir64 using the static relocation model, the
+// kernel caller entry point definition is dso_local. dso_local is only
+// attached to a definition, so this also verifies that setDSOLocal() runs
+// after body emission.
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -fclangir -emit-cir %s -o %t-elf.cir
// RUN: FileCheck --input-file=%t-elf.cir %s -check-prefix=CIR-ELF
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -fclangir -emit-llvm %s -o %t-elf-cir.ll
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -fclangir -emit-llvm %s -o %t-elf-cir.ll
// RUN: FileCheck --input-file=%t-elf-cir.ll %s -check-prefix=LLVM-OGCG-ELF
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o %t-elf.ll
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -emit-llvm %s -o %t-elf.ll
// RUN: FileCheck --input-file=%t-elf.ll %s -check-prefix=LLVM-OGCG-ELF
// On AMDGPU and NVPTX, the kernel caller entry point uses the target's device
>From f1a214f52f2d2eba04d1d4464045778d9b7eecbc Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Fri, 30 Oct 2026 15:51:01 -0700
Subject: [PATCH 2/2] Make all changes requested by Dinos.
---
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 9 ++++-----
.../CIR/CodeGenSYCL/kernel-caller-address-space.cpp | 2 +-
.../CIR/CodeGenSYCL/kernel-caller-attributes.cpp | 6 +++---
.../CIR/CodeGenSYCL/kernel-caller-entry-point.cpp | 13 ++++++-------
4 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 465501f61866f0..f48aa4a8ae4300 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -2868,11 +2868,10 @@ static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd,
}
// Make unique name for device side static file-scope variable for HIP.
if (cgm.getASTContext().shouldExternalize(nd) &&
- cgm.getLangOpts().GPURelocatableDeviceCode &&
- cgm.getLangOpts().CUDAIsDevice) {
- cgm.errorNYI(nd->getSourceRange(),
- "getMangledName: GPU relocatable device code");
- }
+ cgm.getLangOpts().GPURelocatableDeviceCode)
+ if (cgm.getLangOpts().CUDA)
+ cgm.errorNYI(nd->getSourceRange(),
+ "getMangledName: GPU relocatable device code");
return std::string(out.str());
}
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
index e76a66d0533315..cb4a6962644306 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-address-space.cpp
@@ -48,7 +48,7 @@ void test(int *p) {
// LLVM: store i32 42, ptr addrspace(4)
struct FPKN;
-__attribute__((sycl_device)) void callee();
+void callee();
void test_fp() {
kernel_single_task<FPKN>([]() { void (*fp)() = callee; fp(); });
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
index ecef7a559c813f..9df1b9f98b2b50 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-attributes.cpp
@@ -41,7 +41,7 @@ void test(int *p) {
// OGCG: attributes #[[KATTR]] = {{[{].*}}mustprogress{{.*}}norecurse{{.*}}"sycl-module-id"="{{.*}}kernel-caller-attributes.cpp"
// With -fno-finite-loops, checkIfFunctionMustProgress() is false, so the kernel
-// caller must not carry mustprogress; norecurse and sycl-module-id remain.
+// caller must not carry mustprogress; norecurse and sycl-module-id remain. The
+// exact attribute set (which omits mustprogress) is verified here.
// LLVM-NOMP: define spir_kernel void @_ZTS2KN({{.*}}) #[[KATTR:[0-9]+]]
-// LLVM-NOMP: attributes #[[KATTR]] = {{[{].*}}convergent{{.*}}noinline{{.*}}norecurse{{.*}}"sycl-module-id"="{{.*}}kernel-caller-attributes.cpp"
-// LLVM-NOMP-NOT: mustprogress
+// LLVM-NOMP: attributes #[[KATTR]] = { convergent noinline norecurse nounwind optnone "sycl-module-id"="{{.*}}kernel-caller-attributes.cpp" }
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
index 0938e158aaac12..cf9a923d466144 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
@@ -5,15 +5,14 @@
// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spirv64-unknown-unknown -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=OGCG,LLVM-OGCG
-// On an ELF target such as spir64 using the static relocation model, the
-// kernel caller entry point definition is dso_local. dso_local is only
-// attached to a definition, so this also verifies that setDSOLocal() runs
-// after body emission.
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -fclangir -emit-cir %s -o %t-elf.cir
+// On an ELF target such as spir64, the kernel caller entry point definition is
+// dso_local. dso_local is only attached to a definition, so this also verifies
+// that setDSOLocal() runs after body emission.
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -fclangir -emit-cir %s -o %t-elf.cir
// RUN: FileCheck --input-file=%t-elf.cir %s -check-prefix=CIR-ELF
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -fclangir -emit-llvm %s -o %t-elf-cir.ll
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -fclangir -emit-llvm %s -o %t-elf-cir.ll
// RUN: FileCheck --input-file=%t-elf-cir.ll %s -check-prefix=LLVM-OGCG-ELF
-// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -mrelocation-model static -emit-llvm %s -o %t-elf.ll
+// RUN: %clang_cc1 -std=c++20 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o %t-elf.ll
// RUN: FileCheck --input-file=%t-elf.ll %s -check-prefix=LLVM-OGCG-ELF
// On AMDGPU and NVPTX, the kernel caller entry point uses the target's device
More information about the cfe-commits
mailing list