Skip to content

[SYCL][Driver][thinLTO] Don't pass -emit-only-kernels-as-entry-points to sycl-post-link in early splitting #14991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10741,6 +10741,32 @@ static void getNonTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
addArgs(PostLinkArgs, TCArgs, {"-support-dynamic-linking"});
}

// On Intel targets we don't need non-kernel functions as entry points,
// because it only increases amount of code for device compiler to handle,
// without any actual benefits.
// TODO: Try to extend this feature for non-Intel GPUs.
static bool shouldEmitOnlyKernelsAsEntryPoints(const ToolChain &TC,
const llvm::opt::ArgList &TCArgs,
llvm::Triple Triple) {
if (TCArgs.hasFlag(options::OPT_fno_sycl_remove_unused_external_funcs,
options::OPT_fsycl_remove_unused_external_funcs, false))
return false;
if (isSYCLNativeCPU(TC))
return false;
// When supporting dynamic linking, non-kernels in a device image can be
// called.
if (supportDynamicLinking(TCArgs))
return false;
if (Triple.isNVPTX() || Triple.isAMDGPU())
return false;
bool IsUsingLTO = TC.getDriver().isUsingLTO(/*IsDeviceOffloadAction=*/true);
auto LTOMode = TC.getDriver().getLTOMode(/*IsDeviceOffloadAction=*/true);
// With thinLTO, final entry point handing is done in clang-linker-wrapper
if (IsUsingLTO && LTOMode == LTOK_Thin)
return false;
return true;
}

// Add any sycl-post-link options that rely on a specific Triple in addition
// to user supplied options. This function is invoked only for the old
// offloading model. For the new offloading model, a slightly modified version
Expand Down Expand Up @@ -10778,17 +10804,7 @@ static void getTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
(Triple.getArchName() != "spir64_fpga"))
addArgs(PostLinkArgs, TCArgs, {"-split=auto"});

// On Intel targets we don't need non-kernel functions as entry points,
// because it only increases amount of code for device compiler to handle,
// without any actual benefits.
// TODO: Try to extend this feature for non-Intel GPUs.
if ((!TCArgs.hasFlag(options::OPT_fno_sycl_remove_unused_external_funcs,
options::OPT_fsycl_remove_unused_external_funcs,
false) &&
!isSYCLNativeCPU(TC)) &&
// When supporting dynamic linking, non-kernels in a device image can be
// called.
!supportDynamicLinking(TCArgs) && !Triple.isNVPTX() && !Triple.isAMDGPU())
if (shouldEmitOnlyKernelsAsEntryPoints(TC, TCArgs, Triple))
addArgs(PostLinkArgs, TCArgs, {"-emit-only-kernels-as-entry-points"});

if (!Triple.isAMDGCN())
Expand Down
5 changes: 3 additions & 2 deletions clang/test/Driver/sycl-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
// CHECK_SPLIT_ERROR: '-fsycl-device-code-split=off' is not supported when '-foffload-lto=thin' is set with '-fsycl'

// Verify there's no error and we see the expected cc1 flags and tool invocations with the new offload driver.
// RUN: %clangxx -fsycl --offload-new-driver -foffload-lto=thin %s -### 2>&1 | FileCheck -check-prefix=CHECK_SUPPORTED %s
// RUN: %clangxx -fsycl --offload-new-driver -foffload-lto=thin %s -### 2>&1 | \
// RUN: FileCheck -check-prefix=CHECK_SUPPORTED -implicit-check-not=-emit-only-kernels-as-entry-points %s
// CHECK_SUPPORTED: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown" {{.*}} "-flto=thin" "-flto-unit"
// CHECK_SUPPORTED: sycl-post-link{{.*}}
// CHECK_SUPPORTED: sycl-post-link
// CHECK_SUPPORTED-NOT: -properties
// CHECK_SUPPORTED-NEXT: file-table-tform{{.*}}
// CHECK_SUPPORTED-NEXT: llvm-foreach{{.*}} "--" {{.*}}clang{{.*}} "-fsycl-is-device"{{.*}} "-flto=thin" "-flto-unit"
Expand Down
Loading