summaryrefslogtreecommitdiff
path: root/lld/MachO
diff options
context:
space:
mode:
authorScott Linder <Scott.Linder@amd.com>2023-02-15 17:12:47 +0000
committerScott Linder <Scott.Linder@amd.com>2023-02-15 17:34:35 +0000
commit45ee0a9afc6282000e06fa1edb89fe2159a7b34e (patch)
tree0c234c74eb7897aaa24304a2896623d5905d1ac6 /lld/MachO
parent3cf7f22498254c60067322a28cce2268768bba0b (diff)
downloadllvm-45ee0a9afc6282000e06fa1edb89fe2159a7b34e.tar.gz
[LLD] Add --lto-CGO[0-3] option
Allow controlling the CodeGenOpt::Level independent of the LTO optimization level in LLD via new options for the COFF, ELF, MachO, and wasm frontends to lld. Most are spelled as --lto-CGO[0-3], but COFF is spelled as -opt:lldltocgo=[0-3]. See D57422 for discussion surrounding the issue of how to set the CG opt level. The ultimate goal is to let each function control its CG opt level, but until then the current default means it is impossible to specify a CG opt level lower than 2 while using LTO. This option gives the user a means to control it for as long as it is not handled on a per-function basis. Reviewed By: MaskRay, #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D141970
Diffstat (limited to 'lld/MachO')
-rw-r--r--lld/MachO/Config.h5
-rw-r--r--lld/MachO/Driver.cpp14
-rw-r--r--lld/MachO/LTO.cpp2
-rw-r--r--lld/MachO/Options.td4
4 files changed, 21 insertions, 4 deletions
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 220fb99d2e22..af46303f1ae2 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -26,6 +26,10 @@
#include <vector>
+namespace llvm::CodeGenOpt {
+enum Level : int;
+} // namespace llvm::CodeGenOpt
+
namespace lld {
namespace macho {
@@ -165,6 +169,7 @@ struct Configuration {
llvm::StringRef thinLTOJobs;
llvm::StringRef umbrella;
uint32_t ltoo = 2;
+ llvm::CodeGenOpt::Level ltoCgo;
llvm::CachePruningPolicy thinLTOCachePolicy;
llvm::StringRef thinLTOCacheDir;
llvm::StringRef thinLTOIndexOnlyArg;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 65fea8958946..121fa851041c 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1421,6 +1421,17 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
target = createTargetInfo(args);
depTracker = std::make_unique<DependencyTracker>(
args.getLastArgValue(OPT_dependency_info));
+
+ config->ltoo = args::getInteger(args, OPT_lto_O, 2);
+ if (config->ltoo > 3)
+ error("--lto-O: invalid optimization level: " + Twine(config->ltoo));
+ unsigned ltoCgo =
+ args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo));
+ if (auto level = CodeGenOpt::getLevel(ltoCgo))
+ config->ltoCgo = *level;
+ else
+ error("--lto-CGO: invalid codegen optimization level: " + Twine(ltoCgo));
+
if (errorCount())
return false;
@@ -1558,9 +1569,6 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
config->umbrella = arg->getValue();
}
config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto);
- config->ltoo = args::getInteger(args, OPT_lto_O, 2);
- if (config->ltoo > 3)
- error("--lto-O: invalid optimization level: " + Twine(config->ltoo));
config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto);
config->thinLTOCachePolicy = getLTOCachePolicy(args);
config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 2f5e9d06f396..6e3d4f3c230f 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -70,7 +70,7 @@ static lto::Config createConfig() {
c.TimeTraceEnabled = config->timeTraceEnabled;
c.TimeTraceGranularity = config->timeTraceGranularity;
c.OptLevel = config->ltoo;
- c.CGOptLevel = args::getCGOptLevel(config->ltoo);
+ c.CGOptLevel = config->ltoCgo;
if (config->saveTemps)
checkError(c.addSaveTemps(config->outputFile.str() + ".",
/*UseInputModulePath=*/true));
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index cb66f6277b5b..80a12f256b4b 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -84,6 +84,10 @@ def lto_O: Joined<["--"], "lto-O">,
HelpText<"Set optimization level for LTO (default: 2)">,
MetaVarName<"<opt-level>">,
Group<grp_lld>;
+def lto_CGO: Joined<["--"], "lto-CGO">,
+ HelpText<"Set codegen optimization level for LTO (default: 2)">,
+ MetaVarName<"<cgopt-level>">,
+ Group<grp_lld>;
def thinlto_cache_policy_eq: Joined<["--"], "thinlto-cache-policy=">,
HelpText<"Pruning policy for the ThinLTO cache">,
Group<grp_lld>;