[lld] [lld][COFF]Expose UnifiedLTO options (PR #69904)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 01:38:28 PDT 2023
https://github.com/Naville updated https://github.com/llvm/llvm-project/pull/69904
>From 861830fe59d0a23ceaaab2c7752086fbe2790b51 Mon Sep 17 00:00:00 2001
From: Zhang <admin at mayuyu.io>
Date: Tue, 24 Oct 2023 16:34:34 +0800
Subject: [PATCH 1/2] [lld][COFF]Expose UnifiedLTO options
---
lld/COFF/Config.h | 7 +++++++
lld/COFF/Driver.cpp | 7 +++++++
lld/COFF/LTO.cpp | 17 ++++++++++++++++-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 1c338cc63fa87d2..c23629a2fdd6e37 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -102,6 +102,12 @@ enum class ICFLevel {
// behavior.
};
+enum class LTOKind{
+ Default, // Any LTO mode without Unified LTO. The default mode.
+ UnifiedRegular, // Regular LTO, with Unified LTO enabled.
+ UnifiedThin // ThinLTO, with Unified LTO enabled.
+};
+
// Global configuration.
struct Configuration {
enum ManifestKind { Default, SideBySide, Embed, No };
@@ -317,6 +323,7 @@ struct Configuration {
bool writeCheckSum = false;
EmitKind emit = EmitKind::Obj;
bool allowDuplicateWeak = false;
+ LTOKind ltoKind;
};
} // namespace lld::coff
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 5613c2e6993a5af..3f2f4768ace4d9e 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1882,6 +1882,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (s.getAsInteger(10, config->ltoPartitions) ||
config->ltoPartitions == 0)
error("/opt:lldltopartitions: invalid partition count: " + s);
+ } else if (s.consume_front("lldltobackend=")) {
+ config->ltoKind = StringSwitch<LTOKind>(s)
+ .Case("default", LTOKind::Default)
+ .Case("unifiedthin", LTOKind::UnifiedThin)
+ .Case("unifiedregular", LTOKind::UnifiedRegular)
+ .Default(LTOKind::Default);
+
} else if (s != "lbr" && s != "nolbr")
error("/opt: unknown option: " + s);
}
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 7df931911213672..73cb810a7fcba8e 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -126,8 +126,23 @@ BitcodeCompiler::BitcodeCompiler(COFFLinkerContext &c) : ctx(c) {
llvm::heavyweight_hardware_concurrency(ctx.config.thinLTOJobs));
}
+ lto::LTO::LTOKind Kind = lto::LTO::LTOK_Default;
+ switch (ctx.config.ltoKind) {
+ case LTOKind::Default: {
+ Kind = lto::LTO::LTOK_Default;
+ break;
+ }
+ case LTOKind::UnifiedRegular: {
+ Kind = lto::LTO::LTOK_UnifiedRegular;
+ break;
+ }
+ case LTOKind::UnifiedThin: {
+ Kind = lto::LTO::LTOK_UnifiedThin;
+ break;
+ }
+ }
ltoObj = std::make_unique<lto::LTO>(createConfig(), backend,
- ctx.config.ltoPartitions);
+ ctx.config.ltoPartitions, Kind);
}
BitcodeCompiler::~BitcodeCompiler() = default;
>From cfbcbde0ccff74bd04a2a5eaf907d7201452fcf0 Mon Sep 17 00:00:00 2001
From: Zhang <admin at mayuyu.io>
Date: Tue, 24 Oct 2023 16:37:51 +0800
Subject: [PATCH 2/2] [lld][COFF]Expose LTO UseDefaultPipeline Option
---
lld/COFF/Config.h | 1 +
lld/COFF/Driver.cpp | 2 ++
lld/COFF/LTO.cpp | 1 +
3 files changed, 4 insertions(+)
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index c23629a2fdd6e37..8e86d5493b3d0dc 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -324,6 +324,7 @@ struct Configuration {
EmitKind emit = EmitKind::Obj;
bool allowDuplicateWeak = false;
LTOKind ltoKind;
+ bool useDefaultPipeline = false;
};
} // namespace lld::coff
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 3f2f4768ace4d9e..44cb85f694b1e83 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1889,6 +1889,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
.Case("unifiedregular", LTOKind::UnifiedRegular)
.Default(LTOKind::Default);
+ } else if (s.equals("ltodefaultpipeline")) {
+ config->useDefaultPipeline = true;
} else if (s != "lbr" && s != "nolbr")
error("/opt: unknown option: " + s);
}
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 73cb810a7fcba8e..5e876dad8b09ba3 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -88,6 +88,7 @@ lto::Config BitcodeCompiler::createConfig() {
c.PGOWarnMismatch = ctx.config.ltoPGOWarnMismatch;
c.TimeTraceEnabled = ctx.config.timeTraceEnabled;
c.TimeTraceGranularity = ctx.config.timeTraceGranularity;
+ c.UseDefaultPipeline = ctx.config.useDefaultPipeline;
if (ctx.config.emit == EmitKind::LLVM) {
c.PostInternalizeModuleHook = [this](size_t task, const Module &m) {
More information about the llvm-commits
mailing list