[lld] fe08e9c - [lld-macho] Add support for LTO optimization level
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 1 12:05:13 PDT 2021
Author: Leonard Grey
Date: 2021-07-01T15:01:59-04:00
New Revision: fe08e9c4871e8842dc5c8f75a4796a86029c1ebe
URL: https://github.com/llvm/llvm-project/commit/fe08e9c4871e8842dc5c8f75a4796a86029c1ebe
DIFF: https://github.com/llvm/llvm-project/commit/fe08e9c4871e8842dc5c8f75a4796a86029c1ebe.diff
LOG: [lld-macho] Add support for LTO optimization level
Everything (including test) modified from ELF/COFF. Using the same syntax
(--lto-O3, etc) as ELF.
Differential Revision: https://reviews.llvm.org/D105223
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/LTO.cpp
lld/MachO/Options.td
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 722b19f712531..ee4d49bd135a0 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -126,6 +126,7 @@ struct Configuration {
llvm::StringRef outputFile;
llvm::StringRef ltoObjPath;
llvm::StringRef thinLTOJobs;
+ uint32_t ltoo = 2;
bool deadStripDylibs = false;
bool demangle = false;
bool deadStrip = false;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 59f764f8c1d2c..23b505d7b9477 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1082,6 +1082,9 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
config->ltoNewPassManager =
args.hasFlag(OPT_no_lto_legacy_pass_manager, OPT_lto_legacy_pass_manager,
LLVM_ENABLE_NEW_PASS_MANAGER);
+ config->ltoo = args::getInteger(args, OPT_lto_O, 2);
+ if (config->ltoo > 3)
+ error("--lto-O: invalid optimization level: " + Twine(config->ltoo));
config->runtimePaths = args::getStrings(args, OPT_rpath);
config->allLoad = args.hasArg(OPT_all_load);
config->forceLoadObjC = args.hasArg(OPT_ObjC);
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 55e155e1a7dd6..3fa7fe4e32e59 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -13,6 +13,7 @@
#include "Symbols.h"
#include "Target.h"
+#include "lld/Common/Args.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Strings.h"
#include "lld/Common/TargetOptionsCommandFlags.h"
@@ -40,6 +41,8 @@ static lto::Config createConfig() {
};
c.TimeTraceEnabled = config->timeTraceEnabled;
c.TimeTraceGranularity = config->timeTraceGranularity;
+ c.OptLevel = config->ltoo;
+ c.CGOptLevel = args::getCGOptLevel(config->ltoo);
if (config->saveTemps)
checkError(c.addSaveTemps(config->outputFile.str() + ".",
/*UseInputModulePath=*/true));
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index ebff0d5813a02..515053a64cf10 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -64,6 +64,10 @@ def icf_eq: Joined<["--"], "icf=">,
HelpText<"Set level for identical code folding (default: none)">,
MetaVarName<"[none,safe,all]">,
Group<grp_lld>;
+def lto_O: Joined<["--"], "lto-O">,
+ HelpText<"Set optimization level for LTO (default: 2)">,
+ MetaVarName<"<opt-level>">,
+ Group<grp_lld>;
// This is a complete Options.td compiled from Apple's ld(1) manpage
// dated 2018-03-07 and cross checked with ld64 source code in repo
More information about the llvm-commits
mailing list