[lld] [lld][COFF]Expose UnifiedLTO options (PR #69904)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 01:59:33 PDT 2023
https://github.com/Naville updated https://github.com/llvm/llvm-project/pull/69904
>From 44baa0667371a8c187198328201e1df010409bf5 Mon Sep 17 00:00:00 2001
From: Zhang <admin at mayuyu.io>
Date: Mon, 23 Oct 2023 16:52:21 +0800
Subject: [PATCH] [lld][COFF]Expose UnifiedLTO options
---
lld/COFF/Config.h | 3 +++
lld/COFF/Driver.cpp | 14 ++++++++++++++
lld/COFF/LTO.cpp | 4 ++--
lld/COFF/Options.td | 3 +++
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 1c338cc63fa87d2..186fb17745e21e2 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -17,6 +17,7 @@
#include "llvm/Object/COFF.h"
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/LTO/LTO.h"
#include <cstdint>
#include <map>
#include <set>
@@ -27,6 +28,7 @@ namespace lld::coff {
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
using llvm::COFF::WindowsSubsystem;
using llvm::StringRef;
+using llvm::lto::LTO;
class DefinedAbsolute;
class StringChunk;
class Symbol;
@@ -317,6 +319,7 @@ struct Configuration {
bool writeCheckSum = false;
EmitKind emit = EmitKind::Obj;
bool allowDuplicateWeak = false;
+ LTO::LTOKind ltoKind;
};
} // namespace lld::coff
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 5613c2e6993a5af..2b127de80e89531 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -59,6 +59,7 @@ using namespace llvm;
using namespace llvm::object;
using namespace llvm::COFF;
using namespace llvm::sys;
+using namespace llvm::lto;
namespace lld::coff {
@@ -1886,6 +1887,19 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
error("/opt: unknown option: " + s);
}
}
+ // Handle /lto
+ config->ltoKind = LTO::LTOK_Default;
+ if (auto *arg = args.getLastArg(OPT_lto)) {
+ StringRef s = arg->getValue();
+ if (s == "thin")
+ config->ltoKind = LTO::LTOK_UnifiedThin;
+ else if (s == "full")
+ config->ltoKind = LTO::LTOK_UnifiedRegular;
+ else if (s == "default")
+ config->ltoKind = LTO::LTOK_Default;
+ else
+ error("unknown LTO mode: " + s);
+ }
if (!icfLevel)
icfLevel = doGC ? ICFLevel::All : ICFLevel::None;
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 7df931911213672..95c16a02e283cbc 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -126,8 +126,8 @@ BitcodeCompiler::BitcodeCompiler(COFFLinkerContext &c) : ctx(c) {
llvm::heavyweight_hardware_concurrency(ctx.config.thinLTOJobs));
}
- ltoObj = std::make_unique<lto::LTO>(createConfig(), backend,
- ctx.config.ltoPartitions);
+ ltoObj = std::make_unique<lto::LTO>(
+ createConfig(), backend, ctx.config.ltoPartitions, ctx.config.ltoKind);
}
BitcodeCompiler::~BitcodeCompiler() = default;
diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index 977657a433dc581..6eec0cf44bb0c4f 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -309,6 +309,9 @@ def print_search_paths : F<"print-search-paths">;
def show_timing : F<"time">;
def summary : F<"summary">;
+// Flags for LTO
+def lto: P<"lto=","Set LTO backend">,MetaVarName<"[full,thin]">;
+
//==============================================================================
// The flags below do nothing. They are defined only for link.exe compatibility.
//==============================================================================
More information about the llvm-commits
mailing list