Skip to content

Commit b4e000e

Browse files
authored
[LLD][MachO] Enable plugin support for LTO (llvm#115690)
Add new CLI options for feature parity with ELF w.r.t pass plugins. Most of the changes are ported directly from llvm@0c86198. With this change, it is now possible to load and run external pass plugins during the LTO phase.
1 parent fdb050a commit b4e000e

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

lld/MachO/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct Configuration {
166166
llvm::StringRef installName;
167167
llvm::StringRef clientName;
168168
llvm::StringRef mapFile;
169+
llvm::StringRef ltoNewPmPasses;
169170
llvm::StringRef ltoObjPath;
170171
llvm::StringRef thinLTOJobs;
171172
llvm::StringRef umbrella;
@@ -239,6 +240,7 @@ struct Configuration {
239240
SymtabPresence localSymbolsPresence = SymtabPresence::All;
240241
SymbolPatterns localSymbolPatterns;
241242
llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
243+
llvm::SmallVector<llvm::StringRef, 0> passPlugins;
242244

243245
bool zeroModTime = true;
244246
bool generateUuid = true;

lld/MachO/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
17411741
config->umbrella = arg->getValue();
17421742
}
17431743
config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto);
1744+
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
17441745
config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto);
17451746
config->thinLTOCachePolicy = getLTOCachePolicy(args);
17461747
config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
@@ -2110,6 +2111,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
21102111
config->mllvmOpts.emplace_back(arg->getValue());
21112112
}
21122113

2114+
config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
2115+
21132116
createSyntheticSections();
21142117
createSyntheticSymbols();
21152118
addSynthenticMethnames();

lld/MachO/LTO.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ static lto::Config createConfig() {
4444
c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe;
4545
for (StringRef C : config->mllvmOpts)
4646
c.MllvmArgs.emplace_back(C.str());
47+
for (StringRef pluginFn : config->passPlugins)
48+
c.PassPlugins.push_back(std::string(pluginFn));
49+
c.OptPipeline = std::string(config->ltoNewPmPasses);
4750
c.CodeModel = getCodeModelFromCMModel();
4851
c.CPU = getCPUStr();
4952
c.MAttrs = getMAttrs();

lld/MachO/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ def no_objc_category_merging : Flag<["-"], "no_objc_category_merging">,
162162
Group<grp_lld>;
163163
def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
164164
HelpText<"Debug new pass manager">, Group<grp_lld>;
165+
def lto_newpm_passes: Joined<["--"], "lto-newpm-passes=">,
166+
HelpText<"Passes to run during LTO">, Group<grp_lld>;
167+
def load_pass_plugins : Separate<["--"], "load-pass-plugin">, Group<grp_lld>;
168+
def load_pass_plugins_eq : Joined<["--"], "load-pass-plugin=">,
169+
Alias<!cast<Separate>(load_pass_plugins)>,
170+
HelpText<"Load passes from plugin library">, Group<grp_lld>;
165171
def codegen_data_generate_path : Separate<["--"], "codegen-data-generate-path">, Group<grp_lld>;
166172
def codegen_data_generate_path_eq : Joined<["--"], "codegen-data-generate-path=">,
167173
Alias<!cast<Separate>(codegen_data_generate_path)>, MetaVarName<"<cgdata>">,

lld/test/MachO/ltopasses-extension.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; REQUIRES: x86, plugins, examples
2+
3+
; RUN: opt -module-summary %s -o %t.o
4+
; RUN: %lld -dylib -%loadnewpmbye --lto-newpm-passes="goodbye" -mllvm %loadbye -mllvm -wave-goodbye %t.o -o /dev/null 2>&1 | FileCheck %s
5+
; CHECK: Bye
6+
7+
target triple = "x86_64-apple-macosx10.15.0"
8+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9+
@junk = global i32 0
10+
11+
define ptr @somefunk() {
12+
ret ptr @junk
13+
}

0 commit comments

Comments
 (0)