Skip to content

Commit 6fd99de

Browse files
authored
Revert "[LinkerWrapper] Clean up options after proper forwarding" (llvm#126495)
Reverts llvm#126297 Broken buildbots https://lab.llvm.org/staging/#/builders/105/builds/15554 https://lab.llvm.org/buildbot/#/builders/30/builds/15490 Error is ``` # .---command stderr------------ # | FileCheck error: '/work/janplehr/git/llvm-project/bot-tester-builds/cmakecachebuild/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/bug51781.c.tmp.custom' is empty. # | FileCheck command line: /home/janplehr/git/llvm-project/bot-tester-builds/cmakecachebuild/./bin/FileCheck /work/janplehr/git/llvm-project/offload/test/offloading/bug51781.c -check-prefix=CUSTOM -input-file=/work/janplehr/git/llvm-project/bot-tester-builds/cmakecachebuild/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/bug51781.c.tmp.custom ``` The file is empty, while the `CUSTOM` check-target expects to find ``` // CUSTOM: Rewriting generic-mode kernel with a customized state machine. ```
1 parent 7090dff commit 6fd99de

File tree

5 files changed

+51
-39
lines changed

5 files changed

+51
-39
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -9252,24 +9252,13 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92529252
for (StringRef Arg : LinkerArgs)
92539253
CmdArgs.push_back(Args.MakeArgString(
92549254
"--device-linker=" + TC->getTripleString() + "=" + Arg));
9255-
9256-
// Forward the LTO mode relying on the Driver's parsing.
9257-
if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
9258-
CmdArgs.push_back(Args.MakeArgString(
9259-
"--device-compiler=" + TC->getTripleString() + "=-flto=full"));
9260-
else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
9261-
CmdArgs.push_back(Args.MakeArgString(
9262-
"--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
92639255
}
92649256
}
92659257

92669258
CmdArgs.push_back(
92679259
Args.MakeArgString("--host-triple=" + getToolChain().getTripleString()));
92689260
if (Args.hasArg(options::OPT_v))
92699261
CmdArgs.push_back("--wrapper-verbose");
9270-
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
9271-
CmdArgs.push_back(
9272-
Args.MakeArgString(Twine("--cuda-path=") + A->getValue()));
92739262

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

clang/test/Driver/linker-wrapper.c

+12-12
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 {{.*}}.o {{.*}}.o
24+
// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.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-compiler=-g \
30+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \
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{{.*}} --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}-g
33+
// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -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 -Wl,--no-undefined {{.*}}.o {{.*}}.o
42+
// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -flto -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 --device-compiler=--save-temps \
48+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --save-temps -O2 \
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{{.*}} --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}-save-temps
51+
// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -O2 -flto -Wl,--no-undefined {{.*}}.o -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 -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 -O2 -flto -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 -Wl,--no-undefined {{.*}}.o
151+
// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -flto -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+ -Wl,--no-undefined {{.*}}.o {{.*}}.o
175-
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -Wl,--no-undefined {{.*}}.o {{.*}}.o
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
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 -Wl,--no-undefined {{.*}}.o {{.*}}.o
191-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -Wl,--no-undefined {{.*}}.o {{.*}}.o
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
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/test/Driver/openmp-offload.c

-10
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,3 @@
208208
// RUN: -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHK-SYNTAX-ONLY-ARGS %s
209209
// CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu"{{.*}}"-fsyntax-only"
210210
// CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-unknown-linux"{{.*}}"-fsyntax-only"
211-
212-
//
213-
// Ensure `-foffload-lto` is forwarded properly.
214-
//
215-
// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \
216-
// RUN: -foffload-lto %s 2>&1 | FileCheck -check-prefix=CHK-DEVICE-LTO-FULL %s
217-
// CHK-DEVICE-LTO-FULL: clang-linker-wrapper{{.*}} "--device-compiler=powerpc64le-ibm-linux-gnu=-flto=full"
218-
// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \
219-
// RUN: -foffload-lto=thin %s 2>&1 | FileCheck -check-prefix=CHK-DEVICE-LTO-THIN %s
220-
// CHK-DEVICE-LTO-THIN: clang-linker-wrapper{{.*}} "--device-compiler=powerpc64le-ibm-linux-gnu=-flto=thin"

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,20 @@ 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");
488489
SmallVector<StringRef, 16> CmdArgs{
489490
*ClangPath,
490491
"--no-default-config",
491492
"-o",
492493
*TempFileOrErr,
493494
Args.MakeArgString("--target=" + Triple.getTriple()),
494495
Triple.isAMDGPU() ? Args.MakeArgString("-mcpu=" + Arch)
495-
: Args.MakeArgString("-march=" + Arch)};
496+
: Args.MakeArgString("-march=" + Arch),
497+
Args.MakeArgString("-" + OptLevel),
498+
};
496499

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

550+
if (Args.hasArg(OPT_debug))
551+
CmdArgs.push_back("-g");
552+
553+
if (SaveTemps)
554+
CmdArgs.push_back("-save-temps");
555+
546556
if (SaveTemps && linkerSupportsLTO(Args))
547557
CmdArgs.push_back("-Wl,--save-temps");
548558

549559
if (Args.hasArg(OPT_embed_bitcode))
550560
CmdArgs.push_back("-Wl,--lto-emit-llvm");
551561

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+
552573
for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
553574
CmdArgs.append({"-Xlinker", Args.MakeArgString(Arg)});
554575
for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ 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]>,
21-
MetaVarName<"<triple>">,
22-
HelpText<"Triple to use for the host compilation">;
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">;
2325
def device_linker_args_EQ : Joined<["--"], "device-linker=">,
2426
Flags<[WrapperOnlyOption]>, MetaVarName<"<value> or <triple>=<value>">,
2527
HelpText<"Arguments to pass to the device linker invocation">;
@@ -32,8 +34,18 @@ def dry_run : Flag<["--"], "dry-run">,
3234
def verbose : Flag<["--"], "wrapper-verbose">,
3335
Flags<[WrapperOnlyOption]>, HelpText<"Verbose output from tools">;
3436
def embed_bitcode : Flag<["--"], "embed-bitcode">,
35-
Flags<[WrapperOnlyOption]>,
36-
HelpText<"Embed linked bitcode in the module">;
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">;
3749
def print_wrapped_module : Flag<["--"], "print-wrapped-module">,
3850
Flags<[WrapperOnlyOption]>,
3951
HelpText<"Print the wrapped module's IR for testing">;

0 commit comments

Comments
 (0)