[lld] b79e990 - [lld][COFF] Add command line options for LTO with new pass manager
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 5 11:45:30 PST 2020
Author: rojamd
Date: 2020-11-05T14:41:35-05:00
New Revision: b79e990f4019c297cbfb62a03b9629d56a37086c
URL: https://github.com/llvm/llvm-project/commit/b79e990f4019c297cbfb62a03b9629d56a37086c
DIFF: https://github.com/llvm/llvm-project/commit/b79e990f4019c297cbfb62a03b9629d56a37086c.diff
LOG: [lld][COFF] Add command line options for LTO with new pass manager
This is more or less a port of rL329598 (D45275) to the COFF linker.
Since there were already LTO-related settings under -opt:, I added
them there instead of new flags.
Differential Revision: https://reviews.llvm.org/D90624
Added:
lld/test/COFF/lto-new-pass-manager.ll
Modified:
lld/COFF/Config.h
lld/COFF/Driver.cpp
lld/COFF/LTO.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 77a08c200da2..65ddc326ba78 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -157,6 +157,11 @@ struct Configuration {
// Used for /opt:lldltocachepolicy=policy
llvm::CachePruningPolicy ltoCachePolicy;
+ // Used for /opt:[no]ltonewpassmanager
+ bool ltoNewPassManager = false;
+ // Used for /opt:[no]ltodebugpassmanager
+ bool ltoDebugPassManager = false;
+
// Used for /merge:from=to (e.g. /merge:.rdata=.text)
std::map<StringRef, StringRef> merge;
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 3c9f675be65e..d52abd100375 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1513,6 +1513,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
unsigned icfLevel =
args.hasArg(OPT_profile) ? 0 : 1; // 0: off, 1: limited, 2: on
unsigned tailMerge = 1;
+ bool ltoNewPM = false;
+ bool ltoDebugPM = false;
for (auto *arg : args.filtered(OPT_opt)) {
std::string str = StringRef(arg->getValue()).lower();
SmallVector<StringRef, 1> vec;
@@ -1530,6 +1532,14 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
tailMerge = 2;
} else if (s == "nolldtailmerge") {
tailMerge = 0;
+ } else if (s == "ltonewpassmanager") {
+ ltoNewPM = true;
+ } else if (s == "noltonewpassmanager") {
+ ltoNewPM = false;
+ } else if (s == "ltodebugpassmanager") {
+ ltoDebugPM = true;
+ } else if (s == "noltodebugpassmanager") {
+ ltoDebugPM = false;
} else if (s.startswith("lldlto=")) {
StringRef optLevel = s.substr(7);
if (optLevel.getAsInteger(10, config->ltoo) || config->ltoo > 3)
@@ -1559,6 +1569,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
config->doGC = doGC;
config->doICF = icfLevel > 0;
config->tailMerge = (tailMerge == 1 && config->doICF) || tailMerge == 2;
+ config->ltoNewPassManager = ltoNewPM;
+ config->ltoDebugPassManager = ltoDebugPM;
// Handle /lldsavetemps
if (args.hasArg(OPT_lldsavetemps))
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 1fa685fb4620..2fa3536db873 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -82,6 +82,8 @@ static lto::Config createConfig() {
c.MAttrs = getMAttrs();
c.CGOptLevel = args::getCGOptLevel(config->ltoo);
c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
+ c.UseNewPM = config->ltoNewPassManager;
+ c.DebugPassManager = config->ltoDebugPassManager;
if (config->saveTemps)
checkError(c.addSaveTemps(std::string(config->outputFile) + ".",
diff --git a/lld/test/COFF/lto-new-pass-manager.ll b/lld/test/COFF/lto-new-pass-manager.ll
new file mode 100644
index 000000000000..b81e00f933b9
--- /dev/null
+++ b/lld/test/COFF/lto-new-pass-manager.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %s.obj
+
+; RUN: lld-link %s.obj -entry:main -opt:ltonewpassmanager -opt:ltodebugpassmanager 2>&1 | FileCheck %s --check-prefix=ENABLED
+; ENABLED: Starting llvm::Module pass manager run.
+; ENABLED: Finished llvm::Module pass manager run.
+
+; Passing -time just to avoid empty FileCheck input
+; RUN: lld-link %s.obj -entry:main -time -opt:ltonewpassmanager -opt:ltodebugpassmanager -opt:noltonewpassmanager 2>&1 | FileCheck %s --check-prefix=DISABLED
+; RUN: lld-link %s.obj -entry:main -time -opt:ltonewpassmanager -opt:ltodebugpassmanager -opt:noltodebugpassmanager 2>&1 | FileCheck %s --check-prefix=DISABLED
+; DISABLED-NOT: Starting llvm::Module pass manager run.
+; DISABLED-NOT: Finished llvm::Module pass manager run.
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.11.0"
+
+define dso_local i32 @main(i32 %argc, i8** nocapture readnone %0) local_unnamed_addr {
+entry:
+ ret i32 %argc
+}
More information about the llvm-commits
mailing list