Skip to content

Commit a19b326

Browse files
committed
[LinkerWrapper] Clean up options after proper forwarding
Summary: Recent changes made a lot of this stuff redundant or unused, clean it up a bit. Also snuck in a change to pass the CUDA path since we still use it for `fatbinary` internally.
1 parent 7623d91 commit a19b326

File tree

4 files changed

+29
-51
lines changed

4 files changed

+29
-51
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9220,13 +9220,24 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92209220
for (StringRef Arg : LinkerArgs)
92219221
CmdArgs.push_back(Args.MakeArgString(
92229222
"--device-linker=" + TC->getTripleString() + "=" + Arg));
9223+
9224+
// Forward the LTO mode relying on the Driver's parsing.
9225+
if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
9226+
CmdArgs.push_back(Args.MakeArgString(
9227+
"--device-compiler=" + TC->getTripleString() + "=-flto=full"));
9228+
else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
9229+
CmdArgs.push_back(Args.MakeArgString(
9230+
"--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
92239231
}
92249232
}
92259233

92269234
CmdArgs.push_back(
92279235
Args.MakeArgString("--host-triple=" + getToolChain().getTripleString()));
92289236
if (Args.hasArg(options::OPT_v))
92299237
CmdArgs.push_back("--wrapper-verbose");
9238+
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
9239+
CmdArgs.push_back(
9240+
Args.MakeArgString(Twine("--cuda-path=") + A->getValue()));
92309241

92319242
// Construct the link job so we can wrap around it.
92329243
Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);

clang/test/Driver/linker-wrapper.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ __attribute__((visibility("protected"), used)) int x;
2121
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
2222
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK
2323

24-
// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o
24+
// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
2525

2626
// RUN: clang-offload-packager -o %t.out \
2727
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
2828
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
2929
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out
30-
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \
30+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-compiler=-g \
3131
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK-DEBUG
3232

33-
// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g
33+
// NVPTX-LINK-DEBUG: clang{{.*}} --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}-g
3434

3535
// RUN: clang-offload-packager -o %t.out \
3636
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
@@ -39,16 +39,16 @@ __attribute__((visibility("protected"), used)) int x;
3939
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
4040
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=AMDGPU-LINK
4141

42-
// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
42+
// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -Wl,--no-undefined {{.*}}.o {{.*}}.o
4343

4444
// RUN: clang-offload-packager -o %t.out \
4545
// RUN: --image=file=%t.amdgpu.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \
4646
// RUN: --image=file=%t.amdgpu.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030
4747
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out
48-
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --save-temps -O2 \
48+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-compiler=--save-temps \
4949
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=AMDGPU-LTO-TEMPS
5050

51-
// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -O2 -flto -Wl,--no-undefined {{.*}}.o -save-temps
51+
// AMDGPU-LTO-TEMPS: clang{{.*}} --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}-save-temps
5252

5353
// RUN: clang-offload-packager -o %t.out \
5454
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
@@ -59,7 +59,7 @@ __attribute__((visibility("protected"), used)) int x;
5959
// RUN: --linker-path=/usr/bin/ld.lld --whole-archive %t.a --no-whole-archive \
6060
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
6161

62-
// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
62+
// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
6363

6464
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
6565
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \
@@ -148,7 +148,7 @@ __attribute__((visibility("protected"), used)) int x;
148148
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --clang-backend \
149149
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CLANG-BACKEND
150150

151-
// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o
151+
// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -Wl,--no-undefined {{.*}}.o
152152

153153
// RUN: clang-offload-packager -o %t.out \
154154
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
@@ -171,8 +171,8 @@ __attribute__((visibility("protected"), used)) int x;
171171
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
172172
// RUN: --linker-path=/usr/bin/ld %t-on.o %t-off.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=AMD-TARGET-ID
173173

174-
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack+ -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
175-
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
174+
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack+ -Wl,--no-undefined {{.*}}.o {{.*}}.o
175+
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -Wl,--no-undefined {{.*}}.o {{.*}}.o
176176

177177
// RUN: clang-offload-packager -o %t-lib.out \
178178
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=generic
@@ -187,8 +187,8 @@ __attribute__((visibility("protected"), used)) int x;
187187
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
188188
// RUN: --linker-path=/usr/bin/ld %t1.o %t2.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=ARCH-ALL
189189

190-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
191-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
190+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -Wl,--no-undefined {{.*}}.o {{.*}}.o
191+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -Wl,--no-undefined {{.*}}.o {{.*}}.o
192192

193193
// RUN: clang-offload-packager -o %t.out \
194194
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,16 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
485485
if (!TempFileOrErr)
486486
return TempFileOrErr.takeError();
487487

488-
StringRef OptLevel = Args.getLastArgValue(OPT_opt_level, "O2");
489488
SmallVector<StringRef, 16> CmdArgs{
490489
*ClangPath,
491490
"--no-default-config",
492491
"-o",
493492
*TempFileOrErr,
494493
Args.MakeArgString("--target=" + Triple.getTriple()),
495494
Triple.isAMDGPU() ? Args.MakeArgString("-mcpu=" + Arch)
496-
: Args.MakeArgString("-march=" + Arch),
497-
Args.MakeArgString("-" + OptLevel),
498-
};
495+
: Args.MakeArgString("-march=" + Arch)};
499496

500497
// Forward all of the `--offload-opt` and similar options to the device.
501-
CmdArgs.push_back("-flto");
502498
for (auto &Arg : Args.filtered(OPT_offload_opt_eq_minus, OPT_mllvm))
503499
CmdArgs.append(
504500
{"-Xlinker",
@@ -547,29 +543,12 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
547543
CmdArgs.append({"-Xlinker", Args.MakeArgString(
548544
"-mllvm=" + StringRef(Arg->getValue()))});
549545

550-
if (Args.hasArg(OPT_debug))
551-
CmdArgs.push_back("-g");
552-
553-
if (SaveTemps)
554-
CmdArgs.push_back("-save-temps");
555-
556546
if (SaveTemps && linkerSupportsLTO(Args))
557547
CmdArgs.push_back("-Wl,--save-temps");
558548

559549
if (Args.hasArg(OPT_embed_bitcode))
560550
CmdArgs.push_back("-Wl,--lto-emit-llvm");
561551

562-
if (Verbose)
563-
CmdArgs.push_back("-v");
564-
565-
if (!CudaBinaryPath.empty())
566-
CmdArgs.push_back(Args.MakeArgString("--cuda-path=" + CudaBinaryPath));
567-
568-
for (StringRef Arg : Args.getAllArgValues(OPT_ptxas_arg))
569-
llvm::copy(
570-
SmallVector<StringRef>({"-Xcuda-ptxas", Args.MakeArgString(Arg)}),
571-
std::back_inserter(CmdArgs));
572-
573552
for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
574553
CmdArgs.append({"-Xlinker", Args.MakeArgString(Arg)});
575554
for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ def cuda_path_EQ : Joined<["--"], "cuda-path=">,
1717
Flags<[WrapperOnlyOption]>, MetaVarName<"<dir>">,
1818
HelpText<"Set the system CUDA path">;
1919
def host_triple_EQ : Joined<["--"], "host-triple=">,
20-
Flags<[WrapperOnlyOption]>, MetaVarName<"<triple>">,
21-
HelpText<"Triple to use for the host compilation">;
22-
def opt_level : Joined<["--"], "opt-level=">,
23-
Flags<[WrapperOnlyOption]>, MetaVarName<"<O0, O1, O2, or O3>">,
24-
HelpText<"Optimization level for LTO">;
20+
Flags<[WrapperOnlyOption]>,
21+
MetaVarName<"<triple>">,
22+
HelpText<"Triple to use for the host compilation">;
2523
def device_linker_args_EQ : Joined<["--"], "device-linker=">,
2624
Flags<[WrapperOnlyOption]>, MetaVarName<"<value> or <triple>=<value>">,
2725
HelpText<"Arguments to pass to the device linker invocation">;
@@ -34,18 +32,8 @@ def dry_run : Flag<["--"], "dry-run">,
3432
def verbose : Flag<["--"], "wrapper-verbose">,
3533
Flags<[WrapperOnlyOption]>, HelpText<"Verbose output from tools">;
3634
def embed_bitcode : Flag<["--"], "embed-bitcode">,
37-
Flags<[WrapperOnlyOption]>, HelpText<"Embed linked bitcode in the module">;
38-
def debug : Flag<["--"], "device-debug">, Flags<[WrapperOnlyOption]>,
39-
HelpText<"Use debugging">;
40-
def ptxas_arg : Joined<["--"], "ptxas-arg=">,
41-
Flags<[WrapperOnlyOption]>,
42-
HelpText<"Argument to pass to the 'ptxas' invocation">;
43-
def pass_remarks_EQ : Joined<["--"], "pass-remarks=">,
44-
Flags<[WrapperOnlyOption]>, HelpText<"Pass remarks for LTO">;
45-
def pass_remarks_missed_EQ : Joined<["--"], "pass-remarks-missed=">,
46-
Flags<[WrapperOnlyOption]>, HelpText<"Pass remarks for LTO">;
47-
def pass_remarks_analysis_EQ : Joined<["--"], "pass-remarks-analysis=">,
48-
Flags<[WrapperOnlyOption]>, HelpText<"Pass remarks for LTO">;
35+
Flags<[WrapperOnlyOption]>,
36+
HelpText<"Embed linked bitcode in the module">;
4937
def print_wrapped_module : Flag<["--"], "print-wrapped-module">,
5038
Flags<[WrapperOnlyOption]>,
5139
HelpText<"Print the wrapped module's IR for testing">;

0 commit comments

Comments
 (0)