[clang] [CIR][SYCL] Emit sycl-device module flag for SYCL device Compliation (PR #238117)
Balaji V. Iyer. via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 12:49:32 PST 2026
https://github.com/bviyer updated https://github.com/llvm/llvm-project/pull/238117
>From 1b814bd51d95afecfa9a9fa1719fd09bc0840db0 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Mon, 2 Nov 2026 13:43:10 -0800
Subject: [PATCH 1/4] Added sycl_is_device to CIR's LangOpts.
---
.../include/clang/CIR/Dialect/IR/CIRAttrs.td | 28 ++++++++++---------
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 1 +
.../CIR/CodeGen/lowering-lang-options.cpp | 1 +
clang/test/CIR/IR/lowering-lang-options.cir | 6 ++--
.../abi-lowering/amdgpu-kernel-hip-ptr.cir | 8 +++---
.../test/CIR/Transforms/lowering-prepare.cir | 3 +-
6 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 2fb7102b0ccf2c..db2470c629cb2b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -2683,13 +2683,13 @@ def CIR_LoweringOptionsAttr
The following fields come from `LangOptions`. Each bool field mirrors the
like-named `LangOptions` member: `exceptions`,
- `threadsafe_statics`, `cuda`, `cuda_is_device`, `hip`, `hlsl`, `gpu_rdc`,
- `openmp` (`LangOpts.OpenMP != 0`; only its on/off state matters), and
- `openmp_is_target_device`. `clang_abi_compat` is an `i32` mirroring
- `LangOptions::ClangABI`; it is an `i32` rather than a CIR enum because
- `ClangABI` gains an enumerator every Clang release (see
- `clang/Basic/ABIVersions.def`), and the ordinal round-trips fine within a
- single toolchain. `no_trapping_math` is true when
+ `threadsafe_statics`, `cuda`, `cuda_is_device`, `hip`, `hlsl`,
+ `sycl_is_device`, `gpu_rdc`, `openmp` (`LangOpts.OpenMP != 0`; only its
+ on/off state matters), and `openmp_is_target_device`. `clang_abi_compat`
+ is an `i32` mirroring `LangOptions::ClangABI`; it is an `i32` rather than
+ a CIR enum because `ClangABI` gains an enumerator every Clang release
+ (see `clang/Basic/ABIVersions.def`), and the ordinal round-trips fine
+ within a single toolchain. `no_trapping_math` is true when
`LangOptions::getDefaultExceptionMode()` is `FPE_Ignore`.
The following fields come from `CodeGenOptions`.
@@ -2709,9 +2709,9 @@ def CIR_LoweringOptionsAttr
```
module attributes {cir.lowering_options = #cir.lowering_options<
exceptions = false, threadsafe_statics = true, cuda = false,
- cuda_is_device = false, hip = false, hlsl = false, gpu_rdc = false,
- openmp = false, openmp_is_target_device = false, clang_abi_compat = 17,
- long_double_size = 0, enable_noundef_attrs = false,
+ cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+ gpu_rdc = false, openmp = false, openmp_is_target_device = false,
+ clang_abi_compat = 17, long_double_size = 0, enable_noundef_attrs = false,
no_trapping_math = true, ssp_buffer_size = 8>} { }
```
}];
@@ -2723,6 +2723,7 @@ def CIR_LoweringOptionsAttr
"bool":$cuda_is_device,
"bool":$hip,
"bool":$hlsl,
+ "bool":$sycl_is_device,
"bool":$gpu_rdc,
"bool":$openmp,
"bool":$openmp_is_target_device,
@@ -2735,9 +2736,10 @@ def CIR_LoweringOptionsAttr
let assemblyFormat = [{
`<` struct($exceptions, $threadsafe_statics, $cuda, $cuda_is_device, $hip,
- $hlsl, $gpu_rdc, $openmp, $openmp_is_target_device,
- $clang_abi_compat, $long_double_size, $enable_noundef_attrs,
- $no_trapping_math, $ssp_buffer_size) `>`
+ $hlsl, $sycl_is_device, $gpu_rdc, $openmp,
+ $openmp_is_target_device, $clang_abi_compat, $long_double_size,
+ $enable_noundef_attrs, $no_trapping_math,
+ $ssp_buffer_size) `>`
}];
let canHaveIllegalCXXABIType = 0;
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 7beb3554dbf734..0b9bdb97dde576 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -202,6 +202,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
/*cuda_is_device=*/langOpts.CUDAIsDevice,
/*hip=*/langOpts.HIP,
/*hlsl=*/langOpts.HLSL,
+ /*sycl_is_device=*/langOpts.SYCLIsDevice,
/*gpu_rdc=*/langOpts.GPURelocatableDeviceCode,
/*openmp=*/langOpts.OpenMP != 0,
/*openmp_is_target_device=*/langOpts.OpenMPIsTargetDevice,
diff --git a/clang/test/CIR/CodeGen/lowering-lang-options.cpp b/clang/test/CIR/CodeGen/lowering-lang-options.cpp
index 1f4dac33d82ebc..9a8bce5207a491 100644
--- a/clang/test/CIR/CodeGen/lowering-lang-options.cpp
+++ b/clang/test/CIR/CodeGen/lowering-lang-options.cpp
@@ -27,6 +27,7 @@ int x;
// PLAIN-SAME: cuda_is_device = false
// PLAIN-SAME: hip = false
// PLAIN-SAME: hlsl = false
+// PLAIN-SAME: sycl_is_device = false
// PLAIN-SAME: gpu_rdc = false
// PLAIN-SAME: openmp = false
// PLAIN-SAME: openmp_is_target_device = false
diff --git a/clang/test/CIR/IR/lowering-lang-options.cir b/clang/test/CIR/IR/lowering-lang-options.cir
index eccb09d646289d..f4c6af91cb8f9d 100644
--- a/clang/test/CIR/IR/lowering-lang-options.cir
+++ b/clang/test/CIR/IR/lowering-lang-options.cir
@@ -6,13 +6,15 @@
module attributes {cir.lowering_options = #cir.lowering_options<
exceptions = true, threadsafe_statics = false, cuda = true,
- cuda_is_device = true, hip = true, hlsl = true, gpu_rdc = true, openmp = true,
+ cuda_is_device = true, hip = true, hlsl = true, sycl_is_device = true,
+ gpu_rdc = true, openmp = true,
openmp_is_target_device = true, clang_abi_compat = 9, long_double_size = 80,
enable_noundef_attrs = false, no_trapping_math = true, ssp_buffer_size = 4>} {
}
// CHECK: cir.lowering_options = #cir.lowering_options<
// CHECK-SAME: exceptions = true, threadsafe_statics = false, cuda = true,
-// CHECK-SAME: cuda_is_device = true, hip = true, hlsl = true, gpu_rdc = true, openmp = true,
+// CHECK-SAME: cuda_is_device = true, hip = true, hlsl = true, sycl_is_device = true,
+// CHECK-SAME: gpu_rdc = true, openmp = true,
// CHECK-SAME: openmp_is_target_device = true, clang_abi_compat = 9, long_double_size = 80,
// CHECK-SAME: enable_noundef_attrs = false, no_trapping_math = true, ssp_buffer_size = 4>
diff --git a/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir b/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
index b2427b02afb321..63774f1a658463 100644
--- a/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/amdgpu-kernel-hip-ptr.cir
@@ -12,10 +12,10 @@ module attributes {
#dlti.dl_entry<i64, dense<64>: vector<2xi64>>>,
cir.lowering_options = #cir.lowering_options<
exceptions = false, threadsafe_statics = true, cuda = true,
- cuda_is_device = true, hip = true, hlsl = false, gpu_rdc = false,
- openmp = false, openmp_is_target_device = false, clang_abi_compat = 17,
- long_double_size = 0, enable_noundef_attrs = true, no_trapping_math = true,
- ssp_buffer_size = 8>
+ cuda_is_device = true, hip = true, hlsl = false, sycl_is_device = false,
+ gpu_rdc = false, openmp = false, openmp_is_target_device = false,
+ clang_abi_compat = 17, long_double_size = 0, enable_noundef_attrs = true,
+ no_trapping_math = true, ssp_buffer_size = 8>
} {
// The kernel casts the incoming global pointer back to generic before the
diff --git a/clang/test/CIR/Transforms/lowering-prepare.cir b/clang/test/CIR/Transforms/lowering-prepare.cir
index dad215c0269f5a..bed4ea7ff5d87e 100644
--- a/clang/test/CIR/Transforms/lowering-prepare.cir
+++ b/clang/test/CIR/Transforms/lowering-prepare.cir
@@ -11,7 +11,8 @@ module attributes {
cir.triple = "x86_64-unknown-linux-gnu",
cir.lowering_options = #cir.lowering_options<
exceptions = false, threadsafe_statics = true, cuda = false,
- cuda_is_device = false, hip = false, hlsl = false, gpu_rdc = false, openmp = false,
+ cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+ gpu_rdc = false, openmp = false,
openmp_is_target_device = false, clang_abi_compat = 16, long_double_size = 0,
enable_noundef_attrs = true, no_trapping_math = true,
ssp_buffer_size = 8>
>From db3fdb2420de3280acc455338514970431dde43d Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Thu, 5 Nov 2026 12:19:31 -0800
Subject: [PATCH 2/4] Added a test case as requested by Dinos.
---
.../sycl-lowering-lang-options.cpp | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
diff --git a/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp b/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
new file mode 100644
index 00000000000000..a79dfbd796be27
--- /dev/null
+++ b/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang -fsycl -fsycl-device-only -fclangir -emit-cir %s -o - \
+// RUN: | FileCheck %s --check-prefix=DEVICE
+// RUN: %clang --target=x86_64-unknown-linux-gnu -fsycl -fsycl-host-only \
+// RUN: -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=HOST
+
+// The sycl_is_device field of #cir.lowering_options (see
+// clang/test/CIR/CodeGen/lowering-lang-options.cpp) is serialized by CIRGen
+// from LangOptions::SYCLIsDevice. This drives the full driver with
+// -fsycl-device-only / -fsycl-host-only, rather than passing -fsycl-is-device
+// / -fsycl-is-host to %clang_cc1 directly, so the check also covers the
+// driver's translation of those user-facing flags into the -cc1 invocation
+// that CIRGen runs under.
+
+void foo() {}
+
+// DEVICE: cir.lowering_options = #cir.lowering_options<
+// DEVICE-SAME: sycl_is_device = true
+
+// HOST: cir.lowering_options = #cir.lowering_options<
+// HOST-SAME: sycl_is_device = false
>From 5662ed6134aab57888b60f9d9b85d6d1cb0edc13 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Fri, 6 Nov 2026 12:07:58 -0800
Subject: [PATCH 3/4] Fixed all issues in test as per Dinos
---
.../CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp b/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
index a79dfbd796be27..35874b84102fbd 100644
--- a/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
+++ b/clang/test/CIR/CodeGenSYCL/sycl-lowering-lang-options.cpp
@@ -1,16 +1,8 @@
-// RUN: %clang -fsycl -fsycl-device-only -fclangir -emit-cir %s -o - \
-// RUN: | FileCheck %s --check-prefix=DEVICE
-// RUN: %clang --target=x86_64-unknown-linux-gnu -fsycl -fsycl-host-only \
+// RUN: %clang_cc1 -std=c++17 -triple spirv64-unknown-unknown -fsycl-is-device \
+// RUN: -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=DEVICE
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fsycl-is-host \
// RUN: -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=HOST
-// The sycl_is_device field of #cir.lowering_options (see
-// clang/test/CIR/CodeGen/lowering-lang-options.cpp) is serialized by CIRGen
-// from LangOptions::SYCLIsDevice. This drives the full driver with
-// -fsycl-device-only / -fsycl-host-only, rather than passing -fsycl-is-device
-// / -fsycl-is-host to %clang_cc1 directly, so the check also covers the
-// driver's translation of those user-facing flags into the -cc1 invocation
-// that CIRGen runs under.
-
void foo() {}
// DEVICE: cir.lowering_options = #cir.lowering_options<
>From 13f7fa96699158da6d0e33c700b0b1be9c45033f Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <balaji.iyer at intel.com>
Date: Mon, 9 Nov 2026 12:43:14 -0800
Subject: [PATCH 4/4] Fixed all CI failures.
---
.../CIR/Lowering/no-trapping-math-ssp-buffer-size.cir | 8 ++++----
.../test/CIR/Transforms/abi-lowering/indirect-aliased.cir | 8 ++++----
.../lowering-prepare-cuda-registration-rerun.cir | 2 +-
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir b/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir
index c1474f792f3501..d3508238c6b136 100644
--- a/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir
+++ b/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir
@@ -11,10 +11,10 @@ module attributes {
cir.triple = "x86_64-unknown-linux-gnu",
cir.lowering_options = #cir.lowering_options<
exceptions = false, threadsafe_statics = true, cuda = false,
- cuda_is_device = false, hip = false, hlsl = false, gpu_rdc = false,
- openmp = false, openmp_is_target_device = false, clang_abi_compat = 0,
- long_double_size = 0, enable_noundef_attrs = true, no_trapping_math = true,
- ssp_buffer_size = 16>
+ cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+ gpu_rdc = false, openmp = false, openmp_is_target_device = false,
+ clang_abi_compat = 0, long_double_size = 0, enable_noundef_attrs = true,
+ no_trapping_math = true, ssp_buffer_size = 16>
} {
cir.func @def_fn() {
cir.return
diff --git a/clang/test/CIR/Transforms/abi-lowering/indirect-aliased.cir b/clang/test/CIR/Transforms/abi-lowering/indirect-aliased.cir
index 64d0d393bcd003..626f52cf32bb15 100644
--- a/clang/test/CIR/Transforms/abi-lowering/indirect-aliased.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/indirect-aliased.cir
@@ -219,10 +219,10 @@ module attributes {
#dlti.dl_entry<i64, dense<64>: vector<2xi64>>>,
cir.lowering_options = #cir.lowering_options<
exceptions = false, threadsafe_statics = true, cuda = false,
- cuda_is_device = false, hip = false, hlsl = false, gpu_rdc = false,
- openmp = false, openmp_is_target_device = false, clang_abi_compat = 17,
- long_double_size = 0, enable_noundef_attrs = false, no_trapping_math = true,
- ssp_buffer_size = 8>
+ cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+ gpu_rdc = false, openmp = false, openmp_is_target_device = false,
+ clang_abi_compat = 17, long_double_size = 0, enable_noundef_attrs = false,
+ no_trapping_math = true, ssp_buffer_size = 8>
} {
cir.func private @takes_big_no_noundef(%arg0: !rec_Big) requires_call_conv_lowering
diff --git a/clang/test/CIR/Transforms/lowering-prepare-cuda-registration-rerun.cir b/clang/test/CIR/Transforms/lowering-prepare-cuda-registration-rerun.cir
index 21037004b1df51..729d2f24f52781 100644
--- a/clang/test/CIR/Transforms/lowering-prepare-cuda-registration-rerun.cir
+++ b/clang/test/CIR/Transforms/lowering-prepare-cuda-registration-rerun.cir
@@ -19,7 +19,7 @@
!s32i = !cir.int<s, 32>
!u8i = !cir.int<u, 8>
-module attributes {cir.lowering_options = #cir.lowering_options<exceptions = false, threadsafe_statics = true, cuda = true, cuda_is_device = false, hip = true, hlsl = false, gpu_rdc = false, openmp = false, openmp_is_target_device = false, clang_abi_compat = 16, long_double_size = 0, enable_noundef_attrs = true, no_trapping_math = true, ssp_buffer_size = 8>, cir.triple = "x86_64-unknown-linux-gnu"} {
+module attributes {cir.lowering_options = #cir.lowering_options<exceptions = false, threadsafe_statics = true, cuda = true, cuda_is_device = false, hip = true, hlsl = false, sycl_is_device = false, gpu_rdc = false, openmp = false, openmp_is_target_device = false, clang_abi_compat = 16, long_double_size = 0, enable_noundef_attrs = true, no_trapping_math = true, ssp_buffer_size = 8>, cir.triple = "x86_64-unknown-linux-gnu"} {
cir.global "private" internal dso_local @dv = #cir.undef : !s32i align(4) {cu.var_registration = #cir.cu.var_registration<dv, Variable>}
cir.global constant external @_Z1kv = #cir.global_view<@_Z16__device_stub__kv> : !cir.ptr<!cir.func<()>> align(8)
cir.func @_Z16__device_stub__kv() attributes {cu.kernel_name = #cir.cu.kernel_name<"_Z1kv">} {
More information about the cfe-commits
mailing list