[lld] [lld][COFF]Expose UnifiedLTO and PassPipeline Options (PR #69904)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 19:26:55 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 79d318ca0deb68d8392b94ebe9fa2df90348f41b Mon Sep 17 00:00:00 2001
From: Zhang <admin at mayuyu.io>
Date: Wed, 25 Oct 2023 10:25:45 +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    | 32 ++++++++++++++++----------------
 3 files changed, 19 insertions(+), 16 deletions(-)

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..20942e6e55d3d6a 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -47,6 +47,19 @@ std::string BitcodeCompiler::getThinLTOOutputFile(StringRef path) {
   return lto::getThinLTOOutputFile(path, ctx.config.thinLTOPrefixReplaceOld,
                                    ctx.config.thinLTOPrefixReplaceNew);
 }
+static lto::LTO::LTOKind toLTOKind(LTOKind kind) {
+  switch (kind) {
+  case LTOKind::Default: {
+    return lto::LTO::LTOK_Default;
+  }
+  case LTOKind::UnifiedRegular: {
+    return lto::LTO::LTOK_UnifiedRegular;
+  }
+  case LTOKind::UnifiedThin: {
+    return lto::LTO::LTOK_UnifiedThin;
+  }
+  }
+}
 
 lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
@@ -88,6 +101,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) {
@@ -126,23 +140,9 @@ 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;
-  }
-  }
+  lto::LTO::LTOKind kind = toLTOKind(ctx.config.ltoKind);
   ltoObj = std::make_unique<lto::LTO>(createConfig(), backend,
-                                      ctx.config.ltoPartitions, Kind);
+                                      ctx.config.ltoPartitions, kind);
 }
 
 BitcodeCompiler::~BitcodeCompiler() = default;



More information about the llvm-commits mailing list