diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 657267f398ca0..d7737c7429291 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -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, diff --git a/clang/test/Driver/sycl.c b/clang/test/Driver/sycl.c index ed63d4de9898d..8f1a36d3820e4 100644 --- a/clang/test/Driver/sycl.c +++ b/clang/test/Driver/sycl.c @@ -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 \ diff --git a/sycl/doc/UsersManual.md b/sycl/doc/UsersManual.md index 608e8a5192102..4185b1538ee8e 100644 --- a/sycl/doc/UsersManual.md +++ b/sycl/doc/UsersManual.md @@ -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=`**