Skip to content

Commit 2359d94

Browse files
authored
[SYCL] Disable inlining kernel lambda operator at -O0 (#7578)
PR #6977 enabled always inlining kernel lambda operators. This PR disables this at -O0 as it was leading to a poor debugging experience.
1 parent 5b021a2 commit 2359d94

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -5097,8 +5097,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50975097
CmdArgs.push_back("-sycl-std=2020");
50985098
}
50995099

5100+
bool DisableSYCLForceInlineKernelLambda = false;
5101+
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
5102+
DisableSYCLForceInlineKernelLambda =
5103+
A->getOption().matches(options::OPT_O0);
5104+
// At -O0, disable the inlining for debugging purposes.
51005105
if (!Args.hasFlag(options::OPT_fsycl_force_inline_kernel_lambda,
5101-
options::OPT_fno_sycl_force_inline_kernel_lambda, true))
5106+
options::OPT_fno_sycl_force_inline_kernel_lambda,
5107+
!DisableSYCLForceInlineKernelLambda))
51025108
CmdArgs.push_back("-fno-sycl-force-inline-kernel-lambda");
51035109

51045110
if (!Args.hasFlag(options::OPT_fsycl_unnamed_lambda,

clang/test/Driver/sycl.c

+5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@
7575
// -fsycl-force-inline-kernel-lambda
7676
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-force-inline-kernel-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
7777
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-force-inline-kernel-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
78+
// RUN: %clangxx -### -fsycl-device-only -O0 %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
79+
// RUN: %clang_cl -### -fsycl-device-only -Od %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
80+
// RUN: %clangxx -### -fsycl-device-only -O1 %s 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE
81+
// RUN: %clang_cl -### -fsycl-device-only -O2 %s 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE
7882
// CHECK-NOT-INLINE: "-fno-sycl-force-inline-kernel-lambda"
83+
// CHECK-INLINE-NOT: "-fno-sycl-force-inline-kernel-lambda"
7984

8085
/// -fsycl-device-only triple checks
8186
// RUN: %clang -fsycl-device-only -target x86_64-unknown-linux-gnu -### %s 2>&1 \

sycl/doc/UsersManual.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ and not recommended to use in production environment.
112112
Enables/Disables inlining of the kernel lambda operator into the compiler
113113
generated entry point function. This flag does not apply to ESIMD
114114
kernels.
115-
Enabled by default.
115+
Disabled when optimizations are disabled (-O0 or equivalent). Enabled
116+
otherwise.
116117

117118
**`-fgpu-inline-threshold=<n>`**
118119

0 commit comments

Comments
 (0)