aboutsummaryrefslogtreecommitdiff
path: root/lld/MinGW
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2023-08-25 14:24:44 +0300
committerMartin Storsjö <martin@martin.st>2023-08-28 00:28:46 +0300
commit0b51e648307cf6c21c463d3e73e51c03aaa8c9e2 (patch)
treef02528f73aabc05fde040eb852d563a1f007d357 /lld/MinGW
parent69ffd49c434f795af5dd5d39e102c41afeab1d16 (diff)
downloadllvm-0b51e648307cf6c21c463d3e73e51c03aaa8c9e2.zip
llvm-0b51e648307cf6c21c463d3e73e51c03aaa8c9e2.tar.gz
llvm-0b51e648307cf6c21c463d3e73e51c03aaa8c9e2.tar.bz2
[LLD] [MinGW] Hook up more LTO options
Many of these options can be passed to the linker by the Clang driver based on other options passed to Clang, after a23bf1786be7c0738a4cf999c2957155bb32d5af. Before commit 5c92c9f34a7dba804479acef62c576d1a170ef1f, these were ignored by lld, but now we're erroring out on the unrecognized options. The ELF linker has even more LTO options available, but not all of these are currently settable via the lld-link option interface, and some aren't set automatically by Clang but only if the user manually passes them - and thus probably aren't in wide use so far. (Previously LLD/MinGW would have accepted them silently but ignored them though.) Differential Revision: https://reviews.llvm.org/D158887
Diffstat (limited to 'lld/MinGW')
-rw-r--r--lld/MinGW/Driver.cpp14
-rw-r--r--lld/MinGW/Options.td41
2 files changed, 55 insertions, 0 deletions
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 26bd7b3..8fc9ac5 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -282,6 +282,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
add("-align:" + StringRef(a->getValue()));
if (auto *a = args.getLastArg(OPT_heap))
add("-heap:" + StringRef(a->getValue()));
+ if (auto *a = args.getLastArg(OPT_threads))
+ add("-threads:" + StringRef(a->getValue()));
if (auto *a = args.getLastArg(OPT_o))
add("-out:" + StringRef(a->getValue()));
@@ -420,6 +422,18 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
if (auto *arg = args.getLastArg(OPT_plugin_opt_mcpu_eq))
add("-mllvm:-mcpu=" + StringRef(arg->getValue()));
+ if (auto *arg = args.getLastArg(OPT_thinlto_jobs_eq))
+ add("-opt:lldltojobs=" + StringRef(arg->getValue()));
+ if (auto *arg = args.getLastArg(OPT_lto_O))
+ add("-opt:lldlto=" + StringRef(arg->getValue()));
+ if (auto *arg = args.getLastArg(OPT_lto_CGO))
+ add("-opt:lldltocgo=" + StringRef(arg->getValue()));
+ if (auto *arg = args.getLastArg(OPT_plugin_opt_dwo_dir_eq))
+ add("-dwodir:" + StringRef(arg->getValue()));
+ if (args.hasArg(OPT_lto_cs_profile_generate))
+ add("-lto-cs-profile-generate");
+ if (auto *arg = args.getLastArg(OPT_lto_cs_profile_file))
+ add("-lto-cs-profile-file:" + StringRef(arg->getValue()));
for (auto *a : args.filtered(OPT_plugin_opt_eq_minus))
add("-mllvm:-" + StringRef(a->getValue()));
diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index fad950b..e9c4ada 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -4,12 +4,25 @@ class F<string name>: Flag<["--", "-"], name>;
class J<string name>: Joined<["--", "-"], name>;
class S<string name>: Separate<["--", "-"], name>;
+// Convenience classes for long options which only accept two dashes. For lld
+// specific or newer long options, we prefer two dashes to avoid collision with
+// short options. For many others, we have to accept both forms to be compatible
+// with GNU ld.
+class FF<string name> : Flag<["--"], name>;
+class JJ<string name>: Joined<["--"], name>;
+
multiclass Eq<string name, string help> {
def NAME: Separate<["--", "-"], name>;
def NAME # _eq: Joined<["--", "-"], name # "=">, Alias<!cast<Separate>(NAME)>,
HelpText<help>;
}
+multiclass EEq<string name, string help> {
+ def NAME: Separate<["--"], name>;
+ def NAME # _eq: Joined<["--"], name # "=">, Alias<!cast<Separate>(NAME)>,
+ HelpText<help>;
+}
+
multiclass EqLong<string name, string help> {
def NAME: Separate<["--"], name>;
def NAME # _eq: Joined<["--"], name # "=">, Alias<!cast<Separate>(NAME)>,
@@ -119,6 +132,10 @@ defm reproduce: Eq<"reproduce",
"Write a tar file containing input files and command line options to reproduce link">;
defm require_defined: Eq<"require-defined",
"Force symbol to be added to symbol table as an undefined one">;
+defm threads
+ : EEq<"threads",
+ "Number of threads. '1' disables multi-threading. By default all "
+ "available hardware threads are used">;
defm tsaware: B_disable<"tsaware",
"Set the 'Terminal Server aware' flag", "Don't set the 'Terminal Server aware' flag">;
defm undefined: Eq<"undefined", "Include symbol in the link, if available">;
@@ -131,9 +148,33 @@ def version: F<"version">, HelpText<"Display the version number and exit">;
defm wrap: Eq<"wrap", "Use wrapper functions for symbol">,
MetaVarName<"<symbol>">;
+
+def lto_O: JJ<"lto-O">, MetaVarName<"<opt-level>">,
+ HelpText<"Optimization level for LTO">;
+def lto_CGO: JJ<"lto-CGO">, MetaVarName<"<cgopt-level>">,
+ HelpText<"Codegen optimization level for LTO">;
+def lto_cs_profile_generate: FF<"lto-cs-profile-generate">,
+ HelpText<"Perform context sensitive PGO instrumentation">;
+def lto_cs_profile_file: JJ<"lto-cs-profile-file=">,
+ HelpText<"Context sensitive profile file path">;
+
+def thinlto_jobs_eq: JJ<"thinlto-jobs=">,
+ HelpText<"Number of ThinLTO jobs. Default to --threads=">;
+
def plugin_opt_eq_minus: J<"plugin-opt=-">,
HelpText<"Specify an LLVM option for compatibility with LLVMgold.so">;
+def: J<"plugin-opt=thinlto">;
+
+def: J<"plugin-opt=O">, Alias<lto_O>, HelpText<"Alias for --lto-O">;
+def: F<"plugin-opt=cs-profile-generate">,
+ Alias<lto_cs_profile_generate>, HelpText<"Alias for --lto-cs-profile-generate">;
+def: J<"plugin-opt=cs-profile-path=">,
+ Alias<lto_cs_profile_file>, HelpText<"Alias for --lto-cs-profile-file">;
+def plugin_opt_dwo_dir_eq: J<"plugin-opt=dwo_dir=">,
+ HelpText<"Directory to store .dwo files when LTO and debug fission are used">;
+def: J<"plugin-opt=jobs=">, Alias<thinlto_jobs_eq>, HelpText<"Alias for --thinlto-jobs=">;
def plugin_opt_mcpu_eq: J<"plugin-opt=mcpu=">;
+
// This may be either an unhandled LLVMgold.so feature or GCC passed
// -plugin-opt=path/to/{liblto_plugin.so,lto-wrapper}
def plugin_opt_eq : J<"plugin-opt=">;