Skip to content

Commit 32012eb

Browse files
Jakob-KoschelTeemperor
authored andcommitted
[ELF] Enable new passmanager plugin support for LTO
Add cli options for new passmanager plugin support to lld. Currently it is not possible to load dynamic NewPM plugins with lld. This is an incremental update to D76866. While that patch only added cli options for llvm-lto2, this adds them for lld as well. This is especially useful for running dynamic plugins on the linux kernel with LTO. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D120490
1 parent 107ce71 commit 32012eb

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct Configuration {
140140
std::vector<VersionDefinition> versionDefinitions;
141141
std::vector<llvm::StringRef> auxiliaryList;
142142
std::vector<llvm::StringRef> filterList;
143+
std::vector<llvm::StringRef> passPlugins;
143144
std::vector<llvm::StringRef> searchPaths;
144145
std::vector<llvm::StringRef> symbolOrderingFile;
145146
std::vector<llvm::StringRef> thinLTOModulesToCompile;

lld/ELF/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ static void readConfigs(opt::InputArgList &args) {
12871287
error(arg->getSpelling() + ": unknown plugin option '" + arg->getValue() +
12881288
"'");
12891289

1290+
config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
1291+
12901292
// Parse -mllvm options.
12911293
for (auto *arg : args.filtered(OPT_mllvm))
12921294
parseClangOption(arg->getValue(), arg->getSpelling());

lld/ELF/LTO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ static lto::Config createConfig() {
147147

148148
c.SampleProfile = std::string(config->ltoSampleProfile);
149149
c.UseNewPM = config->ltoNewPassManager;
150+
for (StringRef pluginFn : config->passPlugins)
151+
c.PassPlugins.push_back(std::string(pluginFn));
150152
c.DebugPassManager = config->ltoDebugPassManager;
151153
c.DwoDir = std::string(config->dwoDir);
152154

lld/ELF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,5 @@ defm check_dynamic_relocations: BB<"check-dynamic-relocations",
716716
"Perform additional validation of the written dynamic relocations",
717717
"Do not perform additional validation of the written dynamic relocations">,
718718
Flags<[HelpHidden]>;
719+
720+
defm load_pass_plugins: EEq<"load-pass-plugin", "Load passes from plugin library">;

lld/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ llvm_canonicalize_cmake_booleans(
1212
LLVM_ENABLE_LIBXML2
1313
LLD_DEFAULT_LD_LLD_IS_MINGW
1414
LLVM_HAVE_LIBXAR
15+
LLVM_BUILD_EXAMPLES
16+
LLVM_ENABLE_PLUGINS
17+
LLVM_BYE_LINK_INTO_TOOLS
1518
)
1619

1720
configure_lit_site_cfg(
@@ -60,6 +63,11 @@ if (NOT LLD_BUILT_STANDALONE)
6063
split-file
6164
yaml2obj
6265
)
66+
if (NOT WIN32)
67+
list(APPEND LLD_TEST_DEPS
68+
Bye
69+
)
70+
endif()
6371
endif()
6472

6573
add_lit_testsuite(check-lld "Running lld test suite"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; REQUIRES: x86, plugins, examples
2+
; UNSUPPORTED: windows
3+
; RUN: opt -module-summary %s -o %t.o
4+
; RUN: ld.lld -%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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8+
target triple = "x86_64-unknown-linux-gnu"
9+
@junk = global i32 0
10+
11+
define i32* @somefunk() {
12+
ret i32* @junk
13+
}

lld/test/lit.cfg.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@
115115
if config.sizeof_void_p == 8:
116116
config.available_features.add("llvm-64-bits")
117117

118+
if config.has_plugins:
119+
config.available_features.add('plugins')
120+
121+
if config.build_examples:
122+
config.available_features.add('examples')
123+
124+
if config.linked_bye_extension:
125+
config.substitutions.append(('%loadbye', ''))
126+
config.substitutions.append(('%loadnewpmbye', ''))
127+
else:
128+
config.substitutions.append(('%loadbye',
129+
'-load={}/Bye{}'.format(config.llvm_shlib_dir,
130+
config.llvm_shlib_ext)))
131+
config.substitutions.append(('%loadnewpmbye',
132+
'-load-pass-plugin={}/Bye{}'
133+
.format(config.llvm_shlib_dir,
134+
config.llvm_shlib_ext)))
135+
118136
tar_executable = lit.util.which('tar', config.environment['PATH'])
119137
if tar_executable:
120138
env = os.environ

lld/test/lit.site.cfg.py.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ config.llvm_src_root = "@LLVM_SOURCE_DIR@"
77
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
88
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
99
config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
10+
config.llvm_shlib_dir = "@SHLIBDIR@"
11+
config.llvm_shlib_ext = "@SHLIBEXT@"
1012
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
1113
config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@"
1214
config.lld_obj_root = "@LLD_BINARY_DIR@"
@@ -19,6 +21,9 @@ config.have_libxar = @LLVM_HAVE_LIBXAR@
1921
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
2022
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
2123
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
24+
config.build_examples = @LLVM_BUILD_EXAMPLES@
25+
config.has_plugins = @LLVM_ENABLE_PLUGINS@
26+
config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
2227

2328
import lit.llvm
2429
lit.llvm.initialize(lit_config, config)

llvm/examples/Bye/Bye.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ static llvm::RegisterStandardPasses RegisterBye(
5050
[](const llvm::PassManagerBuilder &Builder,
5151
llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); });
5252

53+
static llvm::RegisterStandardPasses RegisterByeLTO(
54+
llvm::PassManagerBuilder::EP_ModuleOptimizerEarly,
55+
[](const llvm::PassManagerBuilder &Builder,
56+
llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); });
57+
5358
/* New PM Registration */
5459
llvm::PassPluginLibraryInfo getByePluginInfo() {
5560
return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING,

0 commit comments

Comments
 (0)