[clang] [CIR][SYCL][NFC] Add sycl-module-id test (PR #230324)
Konstantinos Parasyris via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 8 16:51:41 PDT 2026
https://github.com/koparasy created https://github.com/llvm/llvm-project/pull/230324
Port clang/test/CodeGenSYCL/sycl-module-id.cpp to ClangIR.
FWIW I will port the SYCL tests from OG to CIR. That will likely make it easier to track what is missing.
>From a0b5be71a8af228e210e448e30ab895305642169 Mon Sep 17 00:00:00 2001
From: Konstantinos Parasyris <konstantinos.parasyris at intel.com>
Date: Thu, 8 Oct 2026 16:47:29 -0700
Subject: [PATCH] [CIR][SYCL][NFC] Add sycl-module-id test
Port clang/test/CodeGenSYCL/sycl-module-id.cpp to ClangIR.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply at anthropic.com>
---
clang/test/CIR/CodeGenSYCL/sycl-module-id.cpp | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 clang/test/CIR/CodeGenSYCL/sycl-module-id.cpp
diff --git a/clang/test/CIR/CodeGenSYCL/sycl-module-id.cpp b/clang/test/CIR/CodeGenSYCL/sycl-module-id.cpp
new file mode 100644
index 00000000000000..6f92d3091ed75a
--- /dev/null
+++ b/clang/test/CIR/CodeGenSYCL/sycl-module-id.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+
+// Verify that the "sycl-module-id" function attribute is emitted for:
+// 1. SYCL kernels
+// 2. sycl_external functions
+
+// Required by sycl_kernel_entry_point semantics.
+template <typename KernelName, typename... Ts>
+void sycl_kernel_launch(const char *, Ts...) {}
+
+template <typename KernelName, typename KernelType>
+[[clang::sycl_kernel_entry_point(KernelName)]]
+void kernel_single_task(KernelType kf) { kf(); }
+
+struct KN;
+struct K { void operator()() const {} };
+void use() { kernel_single_task<KN>(K{}); }
+
+[[clang::sycl_external]] int ext(int x) { return x + 1; }
+
+// Both the kernel and the sycl_external function must carry sycl-module-id
+// with a value equal to the module identifier (the source file path).
+// CIR: module @"[[MODID:.*]]" attributes
+// CIR-DAG: cir.func {{.*}}@_Z3exti({{.*}} attributes {{{.*}}"sycl-module-id" = "[[MODID]]"}
+// CIR-DAG: cir.func {{.*}}@_ZTS2KN({{.*}} attributes {{{.*}}"sycl-module-id" = "[[MODID]]"}
+
+// LLVM: source_filename = "[[MODID:.*]]"
+// LLVM-DAG: define {{.*}}spir_kernel {{.*}}@{{.*}}2KN{{.*}} #[[SATTR:[0-9]+]]
+// LLVM-DAG: define {{.*}}spir_func {{.*}}@_Z3exti{{.*}} #[[SATTR]]
+// LLVM: attributes #[[SATTR]] = { {{.*}}"sycl-module-id"="[[MODID]]"
More information about the cfe-commits
mailing list