[clang] 47b0aa5 - [LinkerWrapper] Rework passing args to the LLVM backend
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 18 09:44:34 PDT 2022
Author: Joseph Huber
Date: 2022-07-18T12:44:15-04:00
New Revision: 47b0aa5e4be7ba88bab60b9573407be1f6c387b1
URL: https://github.com/llvm/llvm-project/commit/47b0aa5e4be7ba88bab60b9573407be1f6c387b1
DIFF: https://github.com/llvm/llvm-project/commit/47b0aa5e4be7ba88bab60b9573407be1f6c387b1.diff
LOG: [LinkerWrapper] Rework passing args to the LLVM backend
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/linker-wrapper.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 5ebdda96c8202..881ba3fba44ea 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8472,14 +8472,14 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
// Forward remarks passes to the LLVM backend in the wrapper.
if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
- CmdArgs.push_back(
- Args.MakeArgString(Twine("--pass-remarks=") + A->getValue()));
+ CmdArgs.push_back(Args.MakeArgString(Twine("--offload-opt=-pass-remarks=") +
+ A->getValue()));
if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
- CmdArgs.push_back(
- Args.MakeArgString(Twine("--pass-remarks-missed=") + A->getValue()));
+ CmdArgs.push_back(Args.MakeArgString(
+ Twine("--offload-opt=-pass-remarks-missed=") + A->getValue()));
if (const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
- CmdArgs.push_back(
- Args.MakeArgString(Twine("--pass-remarks-analysis=") + A->getValue()));
+ CmdArgs.push_back(Args.MakeArgString(
+ Twine("--offload-opt=-pass-remarks-analysis=") + A->getValue()));
if (Args.getLastArg(options::OPT_save_temps_EQ))
CmdArgs.push_back("--save-temps");
diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c
index 1c0b8b0293dec..dd0fba763cd46 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -48,7 +48,7 @@
// CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out {{.*}}.o {{.*}}.o
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
-// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -abc \
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \
// RUN: --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=HOST_LINK
// HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index cf1a9d39ee165..8e69cd93efdfe 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -56,15 +56,6 @@ using namespace llvm;
using namespace llvm::opt;
using namespace llvm::object;
-/// We use the command line parser only to forward options like `-pass-remarks`
-/// to the LLVM tools.
-static cl::OptionCategory
- ClangLinkerWrapperCategory("clang-linker-wrapper options");
-static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden,
- cl::cat(ClangLinkerWrapperCategory));
-static cl::list<std::string>
- DummyArguments(cl::Sink, cl::Hidden, cl::cat(ClangLinkerWrapperCategory));
-
/// Path of the current binary.
static const char *LinkerExecutable;
@@ -1513,9 +1504,13 @@ int main(int Argc, char **Argv) {
return EXIT_SUCCESS;
}
- // This forwards '-pass-remarks=' to the LTO backend if present.
- cl::HideUnrelatedOptions(ClangLinkerWrapperCategory);
- cl::ParseCommandLineOptions(Argc, Argv);
+ // This forwards '-mllvm' arguments to LLVM if present.
+ SmallVector<const char *> NewArgv = {Argv[0]};
+ for (const opt::Arg *Arg : Args.filtered(OPT_mllvm))
+ NewArgv.push_back(Arg->getValue());
+ for (const opt::Arg *Arg : Args.filtered(OPT_offload_opt_eq_minus))
+ NewArgv.push_back(Args.MakeArgString(StringRef("-") + Arg->getValue()));
+ cl::ParseCommandLineOptions(NewArgv.size(), &NewArgv[0]);
Verbose = Args.hasArg(OPT_verbose);
DryRun = Args.hasArg(OPT_dry_run);
diff --git a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
index 46fdd5900777b..1ab7fd239f708 100644
--- a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -80,6 +80,8 @@ def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>,
// Arguments for the LLVM backend.
def mllvm : Separate<["-"], "mllvm">, Flags<[WrapperOnlyOption]>,
MetaVarName<"<arg>">, HelpText<"Arguments passed to the LLVM invocation">;
+def offload_opt_eq_minus : Joined<["--", "-"], "offload-opt=-">, Flags<[HelpHidden, WrapperOnlyOption]>,
+ HelpText<"Options passed to LLVM">;
// Standard linker flags also used by the linker wrapper.
def sysroot_EQ : Joined<["--"], "sysroot">, HelpText<"Set the system root">;
More information about the cfe-commits
mailing list