Skip to content

Commit

Permalink
[SYCL] Disable inlining kernel lambda operator at -O0 (#7578)
Browse files Browse the repository at this point in the history
PR #6977 enabled always inlining kernel lambda operators.
This PR disables this at -O0 as it was leading to a poor
debugging experience.
  • Loading branch information
premanandrao committed Dec 2, 2022
1 parent 5b021a2 commit 2359d94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5097,8 +5097,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-sycl-std=2020");
}

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

if (!Args.hasFlag(options::OPT_fsycl_unnamed_lambda,
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/sycl.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@
// -fsycl-force-inline-kernel-lambda
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-force-inline-kernel-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-force-inline-kernel-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
// RUN: %clangxx -### -fsycl-device-only -O0 %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
// RUN: %clang_cl -### -fsycl-device-only -Od %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE
// RUN: %clangxx -### -fsycl-device-only -O1 %s 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE
// RUN: %clang_cl -### -fsycl-device-only -O2 %s 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE
// CHECK-NOT-INLINE: "-fno-sycl-force-inline-kernel-lambda"
// CHECK-INLINE-NOT: "-fno-sycl-force-inline-kernel-lambda"

/// -fsycl-device-only triple checks
// RUN: %clang -fsycl-device-only -target x86_64-unknown-linux-gnu -### %s 2>&1 \
Expand Down
3 changes: 2 additions & 1 deletion sycl/doc/UsersManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ and not recommended to use in production environment.
Enables/Disables inlining of the kernel lambda operator into the compiler
generated entry point function. This flag does not apply to ESIMD
kernels.
Enabled by default.
Disabled when optimizations are disabled (-O0 or equivalent). Enabled
otherwise.

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

Expand Down

0 comments on commit 2359d94

Please sign in to comment.