Skip to content

Commit 184949d

Browse files
author
Martin Wehking
authored
[SYCL][HIP] Add --only-needed flag to llvm-link for AMDGCN (#15558)
Add the -only-needed flag for AMDGCN when linking against devicelib. Fixes several test cases that use kernel bundles.
1 parent 19516d0 commit 184949d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
579579
auto isSYCLDeviceLib = [&](const InputInfo &II) {
580580
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
581581
const bool IsNVPTX = this->getToolChain().getTriple().isNVPTX();
582+
const bool IsAMDGCN = this->getToolChain().getTriple().isAMDGCN();
582583
const bool IsFPGA = this->getToolChain().getTriple().isSPIR() &&
583584
this->getToolChain().getTriple().getSubArch() ==
584585
llvm::Triple::SPIRSubArch_fpga;
@@ -598,6 +599,9 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
598599
// NativeCPU links against libclc (libspirv)
599600
if (IsSYCLNativeCPU && InputFilename.contains("libspirv"))
600601
return true;
602+
// AMDGCN links against our libdevice (devicelib)
603+
if (IsAMDGCN && InputFilename.starts_with("devicelib-"))
604+
return true;
601605
// NVPTX links against our libclc (libspirv), our libdevice (devicelib),
602606
// and the CUDA libdevice
603607
if (IsNVPTX && (InputFilename.starts_with("devicelib-") ||

clang/test/Driver/sycl-device-lib-amdgcn.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@
4242
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib--amd.bc", ir, (device-sycl, gfx906)
4343
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, gfx906)
4444

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

clang/test/Driver/sycl-device-lib-nvptx.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@
4242
// CHK-ALL: [[DEVLIB:[0-9]+]]: input, "{{.*}}devicelib--cuda.bc", ir, (device-sycl, sm_50)
4343
// CHK-ALL: {{[0-9]+}}: linker, {{{.*}}[[DEVLIB]]{{.*}}}, ir, (device-sycl, sm_50)
4444

45+
// Check that llvm-link uses the "-only-needed" flag.
46+
// Not using the flag breaks kernel bundles.
47+
// RUN: %clangxx -### --sysroot=%S/Inputs/SYCL -fsycl -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
48+
// RUN: | FileCheck -check-prefix=CHK-ONLY-NEEDED %s
49+
50+
// CHK-ONLY-NEEDED: llvm-link"{{.*}}"-only-needed"{{.*}}"{{.*}}devicelib--cuda.bc"{{.*}}

0 commit comments

Comments
 (0)