Skip to content

Commit

Permalink
[SYCL][HIP] Add --only-needed flag to llvm-link for AMDGCN (#15558)
Browse files Browse the repository at this point in the history
Add the -only-needed flag for AMDGCN when linking against devicelib.

Fixes several test cases that use kernel bundles.
  • Loading branch information
Martin Wehking authored Oct 1, 2024
1 parent 19516d0 commit 184949d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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"{{.*}}

0 comments on commit 184949d

Please sign in to comment.