Skip to content

Commit c4f29fa

Browse files
committed
Use the existing llvm-plugins option for both legacy and new pm registration
1 parent 97cf461 commit c4f29fa

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
470470

471471
let extra_passes = config.passes.join(",");
472472

473-
let pass_plugins = config.pass_plugins.join(" ");
473+
let llvm_plugins = config.llvm_plugins.join(",");
474474

475475
// FIXME: NewPM doesn't provide a facility to pass custom InlineParams.
476476
// We would have to add upstream support for this first, before we can support
@@ -501,8 +501,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
501501
selfprofile_after_pass_callback,
502502
extra_passes.as_ptr().cast(),
503503
extra_passes.len(),
504-
pass_plugins.as_ptr().cast(),
505-
pass_plugins.len(),
504+
llvm_plugins.as_ptr().cast(),
505+
llvm_plugins.len(),
506506
);
507507
result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes"))
508508
}

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2304,8 +2304,8 @@ extern "C" {
23042304
end_callback: SelfProfileAfterPassCallback,
23052305
ExtraPasses: *const c_char,
23062306
ExtraPassesLen: size_t,
2307-
PassPlugins: *const c_char,
2308-
PassPluginsLen: size_t,
2307+
LLVMPlugins: *const c_char,
2308+
LLVMPluginsLen: size_t,
23092309
) -> LLVMRustResult;
23102310
pub fn LLVMRustPrintModule(
23112311
M: &'a Module,

Diff for: compiler/rustc_codegen_llvm/src/llvm_util.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,20 @@ unsafe fn configure_llvm(sess: &Session) {
119119

120120
llvm::LLVMInitializePasses();
121121

122-
// Register LLVM plugins by loading them into the compiler process.
123-
for plugin in &sess.opts.debugging_opts.llvm_plugins {
124-
let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
125-
debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin);
126-
127-
// Intentionally leak the dynamic library. We can't ever unload it
128-
// since the library can make things that will live arbitrarily long.
129-
mem::forget(lib);
122+
let use_new_llvm_pm_plugin_register =
123+
sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false);
124+
125+
// Use the legacy pm registration if the new_llvm_pass_manager option isn't explicitly enabled
126+
if use_new_llvm_pm_plugin_register {
127+
// Register LLVM plugins by loading them into the compiler process.
128+
for plugin in &sess.opts.debugging_opts.llvm_plugins {
129+
let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
130+
debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin);
131+
132+
// Intentionally leak the dynamic library. We can't ever unload it
133+
// since the library can make things that will live arbitrarily long.
134+
mem::forget(lib);
135+
}
130136
}
131137

132138
rustc_llvm::initialize_available_targets();

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ pub enum BitcodeSection {
7474
pub struct ModuleConfig {
7575
/// Names of additional optimization passes to run.
7676
pub passes: Vec<String>,
77-
/// Paths of LLVM pass plugins to load.
78-
pub pass_plugins: Vec<String>,
7977
/// Some(level) to optimize at a certain level, or None to run
8078
/// absolutely no optimizations (used for the metadata module).
8179
pub opt_level: Option<config::OptLevel>,
@@ -115,6 +113,7 @@ pub struct ModuleConfig {
115113
pub inline_threshold: Option<u32>,
116114
pub new_llvm_pass_manager: Option<bool>,
117115
pub emit_lifetime_markers: bool,
116+
pub llvm_plugins: Vec<String>,
118117
}
119118

120119
impl ModuleConfig {
@@ -172,8 +171,6 @@ impl ModuleConfig {
172171
ModuleConfig {
173172
passes: if_regular!(sess.opts.cg.passes.clone(), vec![]),
174173

175-
pass_plugins: if_regular!(sess.opts.cg.pass_plugins.clone(), vec![]),
176-
177174
opt_level: opt_level_and_size,
178175
opt_size: opt_level_and_size,
179176

@@ -264,6 +261,7 @@ impl ModuleConfig {
264261
inline_threshold: sess.opts.cg.inline_threshold,
265262
new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager,
266263
emit_lifetime_markers: sess.emit_lifetime_markers(),
264+
llvm_plugins: if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]),
267265
}
268266
}
269267

Diff for: compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ fn test_codegen_options_tracking_hash() {
587587
tracked!(overflow_checks, Some(true));
588588
tracked!(panic, Some(PanicStrategy::Abort));
589589
tracked!(passes, vec![String::from("1"), String::from("2")]);
590-
tracked!(pass_plugins, vec![String::from("1"), String::from("2")]);
591590
tracked!(prefer_dynamic, true);
592591
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
593592
tracked!(profile_use, Some(PathBuf::from("abc")));

Diff for: compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ LLVMRustOptimizeWithNewPassManager(
755755
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
756756
LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
757757
const char *ExtraPasses, size_t ExtraPassesLen,
758-
const char *PassPlugins, size_t PassPluginsLen) {
758+
const char *LLVMPlugins, size_t LLVMPluginsLen) {
759759
Module *TheModule = unwrap(ModuleRef);
760760
TargetMachine *TM = unwrap(TMRef);
761761
OptimizationLevel OptLevel = fromRust(OptLevelRust);
@@ -926,10 +926,10 @@ LLVMRustOptimizeWithNewPassManager(
926926
}
927927
}
928928

929-
if (PassPluginsLen) {
930-
auto PluginsStr = StringRef(PassPlugins, PassPluginsLen);
929+
if (LLVMPluginsLen) {
930+
auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen);
931931
SmallVector<StringRef> Plugins;
932-
PluginsStr.split(Plugins, ' ', -1, false);
932+
PluginsStr.split(Plugins, ',', -1, false);
933933
for (auto PluginPath: Plugins) {
934934
auto Plugin = PassPlugin::Load(PluginPath.str());
935935
if (!Plugin) {

Diff for: compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,6 @@ options! {
10331033
"panic strategy to compile crate with"),
10341034
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
10351035
"a list of extra LLVM passes to run (space separated)"),
1036-
pass_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1037-
"a list of LLVM pass plugins to load (space separated)"),
10381036
prefer_dynamic: bool = (false, parse_bool, [TRACKED],
10391037
"prefer dynamic linking to static linking (default: no)"),
10401038
profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,

0 commit comments

Comments
 (0)