[lld] [LLD][MachO] Enable plugin support for LTO (PR #115690)
Tom Lin via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 10 23:08:53 PST 2024
https://github.com/tom91136 created https://github.com/llvm/llvm-project/pull/115690
Add new CLI options for feature parity with ELF w.r.t pass plugins.
Most of the changes are ported directly from https://github.com/llvm/llvm-project/commit/0c86198b279a98c8550fde318b59ed3ca0ca5045.
With this change, it is now possible to load and run external pass plugins during the LTO phase.
>From 5bcbe450d77dcda6044948827da659e3c997a11f Mon Sep 17 00:00:00 2001
From: Tom Lin <tom91136 at gmail.com>
Date: Mon, 11 Nov 2024 07:05:52 +0000
Subject: [PATCH] [LLD][MachO] Enable plugin support for LTO
---
lld/MachO/Config.h | 2 ++
lld/MachO/Driver.cpp | 3 +++
lld/MachO/LTO.cpp | 3 +++
lld/MachO/Options.td | 6 ++++++
lld/test/MachO/ltopasses-extension.ll | 13 +++++++++++++
5 files changed, 27 insertions(+)
create mode 100644 lld/test/MachO/ltopasses-extension.ll
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 8f6da6330d7ad4..2a266462412b26 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -165,6 +165,7 @@ struct Configuration {
llvm::StringRef installName;
llvm::StringRef mapFile;
+ llvm::StringRef ltoNewPmPasses;
llvm::StringRef ltoObjPath;
llvm::StringRef thinLTOJobs;
llvm::StringRef umbrella;
@@ -238,6 +239,7 @@ struct Configuration {
SymtabPresence localSymbolsPresence = SymtabPresence::All;
SymbolPatterns localSymbolPatterns;
llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
+ llvm::SmallVector<llvm::StringRef, 0> passPlugins;
bool zeroModTime = true;
bool generateUuid = true;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index ab4abb1fa97efc..d2a7c46b720f98 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1723,6 +1723,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
config->umbrella = arg->getValue();
}
config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto);
+ config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto);
config->thinLTOCachePolicy = getLTOCachePolicy(args);
config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
@@ -2083,6 +2084,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
config->mllvmOpts.emplace_back(arg->getValue());
}
+ config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
+
createSyntheticSections();
createSyntheticSymbols();
addSynthenticMethnames();
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 28f5290edb58e3..2eeca44ecbb3c4 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -44,6 +44,9 @@ static lto::Config createConfig() {
c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe;
for (StringRef C : config->mllvmOpts)
c.MllvmArgs.emplace_back(C.str());
+ for (StringRef pluginFn : config->passPlugins)
+ c.PassPlugins.push_back(std::string(pluginFn));
+ c.OptPipeline = std::string(config->ltoNewPmPasses);
c.CodeModel = getCodeModelFromCMModel();
c.CPU = getCPUStr();
c.MAttrs = getMAttrs();
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 70eb7c8b9e466b..677f50fa5fe380 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -162,6 +162,12 @@ def no_objc_category_merging : Flag<["-"], "no_objc_category_merging">,
Group<grp_lld>;
def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
HelpText<"Debug new pass manager">, Group<grp_lld>;
+def lto_newpm_passes: Joined<["--"], "lto-newpm-passes=">,
+ HelpText<"Passes to run during LTO">, Group<grp_lld>;
+def load_pass_plugins : Separate<["--"], "load-pass-plugin">, Group<grp_lld>;
+def load_pass_plugins_eq : Joined<["--"], "load-pass-plugin=">,
+ Alias<!cast<Separate>(load_pass_plugins)>,
+ HelpText<"Load passes from plugin library">, Group<grp_lld>;
def codegen_data_generate_path : Separate<["--"], "codegen-data-generate-path">, Group<grp_lld>;
def codegen_data_generate_path_eq : Joined<["--"], "codegen-data-generate-path=">,
Alias<!cast<Separate>(codegen_data_generate_path)>, MetaVarName<"<cgdata>">,
diff --git a/lld/test/MachO/ltopasses-extension.ll b/lld/test/MachO/ltopasses-extension.ll
new file mode 100644
index 00000000000000..300f03d4cfdb6d
--- /dev/null
+++ b/lld/test/MachO/ltopasses-extension.ll
@@ -0,0 +1,13 @@
+; REQUIRES: x86, plugins, examples
+
+; RUN: opt -module-summary %s -o %t.o
+; RUN: %lld -dylib -%loadnewpmbye --lto-newpm-passes="goodbye" -mllvm %loadbye -mllvm -wave-goodbye %t.o -o /dev/null 2>&1 | FileCheck %s
+; CHECK: Bye
+
+target triple = "x86_64-apple-macosx10.15.0"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ at junk = global i32 0
+
+define ptr @somefunk() {
+ ret ptr @junk
+}
More information about the llvm-commits
mailing list