Skip to content

Commit 5bcbe45

Browse files
committed
[LLD][MachO] Enable plugin support for LTO
1 parent 1bf385f commit 5bcbe45

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
@@ -165,6 +165,7 @@ struct Configuration {
165165

166166
llvm::StringRef installName;
167167
llvm::StringRef mapFile;
168+
llvm::StringRef ltoNewPmPasses;
168169
llvm::StringRef ltoObjPath;
169170
llvm::StringRef thinLTOJobs;
170171
llvm::StringRef umbrella;
@@ -238,6 +239,7 @@ struct Configuration {
238239
SymtabPresence localSymbolsPresence = SymtabPresence::All;
239240
SymbolPatterns localSymbolPatterns;
240241
llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
242+
llvm::SmallVector<llvm::StringRef, 0> passPlugins;
241243

242244
bool zeroModTime = true;
243245
bool generateUuid = true;

lld/MachO/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
17231723
config->umbrella = arg->getValue();
17241724
}
17251725
config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto);
1726+
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
17261727
config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto);
17271728
config->thinLTOCachePolicy = getLTOCachePolicy(args);
17281729
config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
@@ -2083,6 +2084,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
20832084
config->mllvmOpts.emplace_back(arg->getValue());
20842085
}
20852086

2087+
config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
2088+
20862089
createSyntheticSections();
20872090
createSyntheticSymbols();
20882091
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>">,
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)