Skip to content

Commit e9901d8

Browse files
authored
[LinkerWrapper] Accept compression arguments for HIP fatbins (#84337)
Summary: The HIP toolchain has support for compressing the final output. We should respect that when we create the executable.
1 parent ee24409 commit e9901d8

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8895,6 +8895,10 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
88958895
for (const char *LinkArg : LinkCommand->getArguments())
88968896
CmdArgs.push_back(LinkArg);
88978897

8898+
if (Args.hasFlag(options::OPT_offload_compress,
8899+
options::OPT_no_offload_compress, false))
8900+
CmdArgs.push_back("--compress");
8901+
88988902
const char *Exec =
88998903
Args.MakeArgString(getToolChain().GetProgramPath("clang-linker-wrapper"));
89008904

clang/test/Driver/linker-wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ __attribute__((visibility("protected"), used)) int x;
114114
// RUN: --image=file=%t.elf.o,kind=hip,triple=amdgcn-amd-amdhsa,arch=gfx908
115115
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o \
116116
// RUN: -fembed-offload-object=%t.out
117-
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
117+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu --compress \
118118
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=HIP
119119

120120
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
121121
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a
122-
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx90a,hipv4-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
122+
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx90a,hipv4-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
123123

124124
// RUN: clang-offload-packager -o %t.out \
125125
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
405405
CmdArgs.push_back("-type=o");
406406
CmdArgs.push_back("-bundle-align=4096");
407407

408+
if (Args.hasArg(OPT_compress))
409+
CmdArgs.push_back("-compress");
410+
408411
SmallVector<StringRef> Targets = {"-targets=host-x86_64-unknown-linux"};
409412
for (const auto &[File, Arch] : InputFiles)
410413
Targets.push_back(Saver.save("hipv4-amdgcn-amd-amdhsa--" + Arch));

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def print_wrapped_module : Flag<["--"], "print-wrapped-module">,
5858
HelpText<"Print the wrapped module's IR for testing">;
5959
def save_temps : Flag<["--"], "save-temps">,
6060
Flags<[WrapperOnlyOption]>, HelpText<"Save intermediate results">;
61+
def compress : Flag<["--"], "compress">,
62+
Flags<[WrapperOnlyOption]>, HelpText<"Compress bundled files">;
6163

6264
def wrapper_time_trace_eq : Joined<["--"], "wrapper-time-trace=">,
6365
Flags<[WrapperOnlyOption]>, MetaVarName<"<file>">,

0 commit comments

Comments
 (0)