Skip to content

[SYCL][HIP] Add --only-needed flag to llvm-link for AMDGCN #15558

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 4 commits into from
Oct 1, 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
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
auto isSYCLDeviceLib = [&](const InputInfo &II) {
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
const bool IsNVPTX = this->getToolChain().getTriple().isNVPTX();
const bool IsAMDGCN = this->getToolChain().getTriple().isAMDGCN();
const bool IsFPGA = this->getToolChain().getTriple().isSPIR() &&
this->getToolChain().getTriple().getSubArch() ==
llvm::Triple::SPIRSubArch_fpga;
Expand All @@ -598,6 +599,9 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
// NativeCPU links against libclc (libspirv)
if (IsSYCLNativeCPU && InputFilename.contains("libspirv"))
return true;
// AMDGCN links against our libdevice (devicelib)
if (IsAMDGCN && InputFilename.starts_with("devicelib-"))
return true;
// NVPTX links against our libclc (libspirv), our libdevice (devicelib),
// and the CUDA libdevice
if (IsNVPTX && (InputFilename.starts_with("devicelib-") ||
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/sycl-device-lib-amdgcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib--amd.bc", ir, (device-sycl, gfx906)
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, gfx906)

// Check that llvm-link uses the "-only-needed" flag.
// Not using the flag breaks kernel bundles.
// RUN: %clangxx -### -nogpulib --sysroot=%S/Inputs/SYCL \
// RUN: -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ONLY-NEEDED %s

// CHK-ONLY-NEEDED: llvm-link"{{.*}}"-only-needed"{{.*}}"{{.*}}devicelib--amd.bc"{{.*}}
6 changes: 6 additions & 0 deletions clang/test/Driver/sycl-device-lib-nvptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib--cuda.bc", ir, (device-sycl, sm_50)
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, sm_50)

// Check that llvm-link uses the "-only-needed" flag.
// Not using the flag breaks kernel bundles.
// RUN: %clangxx -### --sysroot=%S/Inputs/SYCL -fsycl -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-ONLY-NEEDED %s

// CHK-ONLY-NEEDED: llvm-link"{{.*}}"-only-needed"{{.*}}"{{.*}}devicelib--cuda.bc"{{.*}}
Loading