From 97cf461b8f4c0ed0de8fdc1c441b904ddb8b3194 Mon Sep 17 00:00:00 2001 From: Axel Cohen Date: Fri, 19 Nov 2021 17:01:41 +0100 Subject: [PATCH 1/5] Add a codegen option to allow loading LLVM pass plugins --- compiler/rustc_codegen_llvm/src/back/write.rs | 4 ++++ compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 ++ compiler/rustc_codegen_ssa/src/back/write.rs | 4 ++++ compiler/rustc_interface/src/tests.rs | 1 + .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 18 +++++++++++++++++- compiler/rustc_session/src/options.rs | 2 ++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index fa4fad30830d9..a28fca3e700ef 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -470,6 +470,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager( let extra_passes = config.passes.join(","); + let pass_plugins = config.pass_plugins.join(" "); + // FIXME: NewPM doesn't provide a facility to pass custom InlineParams. // We would have to add upstream support for this first, before we can support // config.inline_threshold and our more aggressive default thresholds. @@ -499,6 +501,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager( selfprofile_after_pass_callback, extra_passes.as_ptr().cast(), extra_passes.len(), + pass_plugins.as_ptr().cast(), + pass_plugins.len(), ); result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes")) } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index d9a6723fe27fd..a225d59dd4036 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2304,6 +2304,8 @@ extern "C" { end_callback: SelfProfileAfterPassCallback, ExtraPasses: *const c_char, ExtraPassesLen: size_t, + PassPlugins: *const c_char, + PassPluginsLen: size_t, ) -> LLVMRustResult; pub fn LLVMRustPrintModule( M: &'a Module, diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d6af6104155a1..65a1328222463 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -74,6 +74,8 @@ pub enum BitcodeSection { pub struct ModuleConfig { /// Names of additional optimization passes to run. pub passes: Vec, + /// Paths of LLVM pass plugins to load. + pub pass_plugins: Vec, /// Some(level) to optimize at a certain level, or None to run /// absolutely no optimizations (used for the metadata module). pub opt_level: Option, @@ -170,6 +172,8 @@ impl ModuleConfig { ModuleConfig { passes: if_regular!(sess.opts.cg.passes.clone(), vec![]), + pass_plugins: if_regular!(sess.opts.cg.pass_plugins.clone(), vec![]), + opt_level: opt_level_and_size, opt_size: opt_level_and_size, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index c651feaaa66f6..f63c04138e88f 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -587,6 +587,7 @@ fn test_codegen_options_tracking_hash() { tracked!(overflow_checks, Some(true)); tracked!(panic, Some(PanicStrategy::Abort)); tracked!(passes, vec![String::from("1"), String::from("2")]); + tracked!(pass_plugins, vec![String::from("1"), String::from("2")]); tracked!(prefer_dynamic, true); tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); tracked!(profile_use, Some(PathBuf::from("abc"))); diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 4f77db8a24dc4..32a2ffcef00b5 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -17,6 +17,7 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/Object/IRObjectFile.h" #include "llvm/Passes/PassBuilder.h" +#include "llvm/Passes/PassPlugin.h" #include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/FileSystem.h" @@ -753,7 +754,8 @@ LLVMRustOptimizeWithNewPassManager( void* LlvmSelfProfiler, LLVMRustSelfProfileBeforePassCallback BeforePassCallback, LLVMRustSelfProfileAfterPassCallback AfterPassCallback, - const char *ExtraPasses, size_t ExtraPassesLen) { + const char *ExtraPasses, size_t ExtraPassesLen, + const char *PassPlugins, size_t PassPluginsLen) { Module *TheModule = unwrap(ModuleRef); TargetMachine *TM = unwrap(TMRef); OptimizationLevel OptLevel = fromRust(OptLevelRust); @@ -924,6 +926,20 @@ LLVMRustOptimizeWithNewPassManager( } } + if (PassPluginsLen) { + auto PluginsStr = StringRef(PassPlugins, PassPluginsLen); + SmallVector Plugins; + PluginsStr.split(Plugins, ' ', -1, false); + for (auto PluginPath: Plugins) { + auto Plugin = PassPlugin::Load(PluginPath.str()); + if (!Plugin) { + LLVMRustSetLastError(("Failed to load pass plugin" + PluginPath.str()).c_str()); + continue; + } + Plugin->registerPassBuilderCallbacks(PB); + } + } + #if LLVM_VERSION_GE(13, 0) ModulePassManager MPM; #else diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index bd7b1639613eb..dcff47905357f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1033,6 +1033,8 @@ options! { "panic strategy to compile crate with"), passes: Vec = (Vec::new(), parse_list, [TRACKED], "a list of extra LLVM passes to run (space separated)"), + pass_plugins: Vec = (Vec::new(), parse_list, [TRACKED], + "a list of LLVM pass plugins to load (space separated)"), prefer_dynamic: bool = (false, parse_bool, [TRACKED], "prefer dynamic linking to static linking (default: no)"), profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled, From c4f29fa0ed738b52e7d8ef372c2d09300755dfef Mon Sep 17 00:00:00 2001 From: Axel Cohen Date: Wed, 24 Nov 2021 11:43:40 +0100 Subject: [PATCH 2/5] Use the existing llvm-plugins option for both legacy and new pm registration --- compiler/rustc_codegen_llvm/src/back/write.rs | 6 ++--- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 4 ++-- compiler/rustc_codegen_llvm/src/llvm_util.rs | 22 ++++++++++++------- compiler/rustc_codegen_ssa/src/back/write.rs | 6 ++--- compiler/rustc_interface/src/tests.rs | 1 - .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 8 +++---- compiler/rustc_session/src/options.rs | 2 -- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index a28fca3e700ef..146c0996b8c95 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -470,7 +470,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager( let extra_passes = config.passes.join(","); - let pass_plugins = config.pass_plugins.join(" "); + let llvm_plugins = config.llvm_plugins.join(","); // FIXME: NewPM doesn't provide a facility to pass custom InlineParams. // 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( selfprofile_after_pass_callback, extra_passes.as_ptr().cast(), extra_passes.len(), - pass_plugins.as_ptr().cast(), - pass_plugins.len(), + llvm_plugins.as_ptr().cast(), + llvm_plugins.len(), ); result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes")) } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index a225d59dd4036..c0cc8f9b750c5 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2304,8 +2304,8 @@ extern "C" { end_callback: SelfProfileAfterPassCallback, ExtraPasses: *const c_char, ExtraPassesLen: size_t, - PassPlugins: *const c_char, - PassPluginsLen: size_t, + LLVMPlugins: *const c_char, + LLVMPluginsLen: size_t, ) -> LLVMRustResult; pub fn LLVMRustPrintModule( M: &'a Module, diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 79a261244d3ff..af53b35d815e7 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -119,14 +119,20 @@ unsafe fn configure_llvm(sess: &Session) { llvm::LLVMInitializePasses(); - // Register LLVM plugins by loading them into the compiler process. - for plugin in &sess.opts.debugging_opts.llvm_plugins { - let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e)); - debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin); - - // Intentionally leak the dynamic library. We can't ever unload it - // since the library can make things that will live arbitrarily long. - mem::forget(lib); + let use_new_llvm_pm_plugin_register = + sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false); + + // Use the legacy pm registration if the new_llvm_pass_manager option isn't explicitly enabled + if use_new_llvm_pm_plugin_register { + // Register LLVM plugins by loading them into the compiler process. + for plugin in &sess.opts.debugging_opts.llvm_plugins { + let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e)); + debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin); + + // Intentionally leak the dynamic library. We can't ever unload it + // since the library can make things that will live arbitrarily long. + mem::forget(lib); + } } rustc_llvm::initialize_available_targets(); diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 65a1328222463..0281fd929c5fe 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -74,8 +74,6 @@ pub enum BitcodeSection { pub struct ModuleConfig { /// Names of additional optimization passes to run. pub passes: Vec, - /// Paths of LLVM pass plugins to load. - pub pass_plugins: Vec, /// Some(level) to optimize at a certain level, or None to run /// absolutely no optimizations (used for the metadata module). pub opt_level: Option, @@ -115,6 +113,7 @@ pub struct ModuleConfig { pub inline_threshold: Option, pub new_llvm_pass_manager: Option, pub emit_lifetime_markers: bool, + pub llvm_plugins: Vec, } impl ModuleConfig { @@ -172,8 +171,6 @@ impl ModuleConfig { ModuleConfig { passes: if_regular!(sess.opts.cg.passes.clone(), vec![]), - pass_plugins: if_regular!(sess.opts.cg.pass_plugins.clone(), vec![]), - opt_level: opt_level_and_size, opt_size: opt_level_and_size, @@ -264,6 +261,7 @@ impl ModuleConfig { inline_threshold: sess.opts.cg.inline_threshold, new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager, emit_lifetime_markers: sess.emit_lifetime_markers(), + llvm_plugins: if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]), } } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index f63c04138e88f..c651feaaa66f6 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -587,7 +587,6 @@ fn test_codegen_options_tracking_hash() { tracked!(overflow_checks, Some(true)); tracked!(panic, Some(PanicStrategy::Abort)); tracked!(passes, vec![String::from("1"), String::from("2")]); - tracked!(pass_plugins, vec![String::from("1"), String::from("2")]); tracked!(prefer_dynamic, true); tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); tracked!(profile_use, Some(PathBuf::from("abc"))); diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 32a2ffcef00b5..f06fc3edf5859 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -755,7 +755,7 @@ LLVMRustOptimizeWithNewPassManager( LLVMRustSelfProfileBeforePassCallback BeforePassCallback, LLVMRustSelfProfileAfterPassCallback AfterPassCallback, const char *ExtraPasses, size_t ExtraPassesLen, - const char *PassPlugins, size_t PassPluginsLen) { + const char *LLVMPlugins, size_t LLVMPluginsLen) { Module *TheModule = unwrap(ModuleRef); TargetMachine *TM = unwrap(TMRef); OptimizationLevel OptLevel = fromRust(OptLevelRust); @@ -926,10 +926,10 @@ LLVMRustOptimizeWithNewPassManager( } } - if (PassPluginsLen) { - auto PluginsStr = StringRef(PassPlugins, PassPluginsLen); + if (LLVMPluginsLen) { + auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen); SmallVector Plugins; - PluginsStr.split(Plugins, ' ', -1, false); + PluginsStr.split(Plugins, ',', -1, false); for (auto PluginPath: Plugins) { auto Plugin = PassPlugin::Load(PluginPath.str()); if (!Plugin) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index dcff47905357f..bd7b1639613eb 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1033,8 +1033,6 @@ options! { "panic strategy to compile crate with"), passes: Vec = (Vec::new(), parse_list, [TRACKED], "a list of extra LLVM passes to run (space separated)"), - pass_plugins: Vec = (Vec::new(), parse_list, [TRACKED], - "a list of LLVM pass plugins to load (space separated)"), prefer_dynamic: bool = (false, parse_bool, [TRACKED], "prefer dynamic linking to static linking (default: no)"), profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled, From 75d1208df8f76a39135574231065e4761859b7d8 Mon Sep 17 00:00:00 2001 From: Axel Cohen Date: Wed, 24 Nov 2021 14:23:29 +0100 Subject: [PATCH 3/5] Fix conditions for using legacy or new pm plugins --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_codegen_ssa/src/back/write.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index af53b35d815e7..ace8e0516ed6b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -123,7 +123,7 @@ unsafe fn configure_llvm(sess: &Session) { sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false); // Use the legacy pm registration if the new_llvm_pass_manager option isn't explicitly enabled - if use_new_llvm_pm_plugin_register { + if !use_new_llvm_pm_plugin_register { // Register LLVM plugins by loading them into the compiler process. for plugin in &sess.opts.debugging_opts.llvm_plugins { let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e)); diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 0281fd929c5fe..d23fe621539e8 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -261,7 +261,11 @@ impl ModuleConfig { inline_threshold: sess.opts.cg.inline_threshold, new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager, emit_lifetime_markers: sess.emit_lifetime_markers(), - llvm_plugins: if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]), + llvm_plugins: if sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false) { + if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]) + } else { + vec![] + }, } } From 052961b0138b38a9da26e88e3db6aac19e8c070c Mon Sep 17 00:00:00 2001 From: Axel Cohen Date: Mon, 20 Dec 2021 14:49:04 +0100 Subject: [PATCH 4/5] rustc_codegen_llvm: move should_use_new_llvm_pass_manager function to llvm_util --- compiler/rustc_codegen_llvm/src/back/lto.rs | 7 +++++-- compiler/rustc_codegen_llvm/src/back/write.rs | 20 ++++--------------- compiler/rustc_codegen_llvm/src/llvm_util.rs | 10 ++++++++++ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index f6c40f1689e9e..27c08ba5f3c22 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -3,7 +3,7 @@ use crate::back::write::{ }; use crate::llvm::archive_ro::ArchiveRO; use crate::llvm::{self, build_string, False, True}; -use crate::{LlvmCodegenBackend, ModuleLlvm}; +use crate::{llvm_util, LlvmCodegenBackend, ModuleLlvm}; use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared}; use rustc_codegen_ssa::back::symbol_export; use rustc_codegen_ssa::back::write::{ @@ -596,7 +596,10 @@ pub(crate) fn run_pass_manager( // tools/lto/LTOCodeGenerator.cpp debug!("running the pass manager"); unsafe { - if write::should_use_new_llvm_pass_manager(cgcx, config) { + if llvm_util::should_use_new_llvm_pass_manager( + &config.new_llvm_pass_manager, + &cgcx.target_arch, + ) { let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO }; let opt_level = config.opt_level.unwrap_or(config::OptLevel::No); write::optimize_with_new_llvm_pass_manager( diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 146c0996b8c95..e275ba7d65dc7 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -413,21 +413,6 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option { .map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap()) } -pub(crate) fn should_use_new_llvm_pass_manager( - cgcx: &CodegenContext, - config: &ModuleConfig, -) -> bool { - // The new pass manager is enabled by default for LLVM >= 13. - // This matches Clang, which also enables it since Clang 13. - - // FIXME: There are some perf issues with the new pass manager - // when targeting s390x, so it is temporarily disabled for that - // arch, see https://github.com/rust-lang/rust/issues/89609 - config - .new_llvm_pass_manager - .unwrap_or_else(|| cgcx.target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0)) -} - pub(crate) unsafe fn optimize_with_new_llvm_pass_manager( cgcx: &CodegenContext, diag_handler: &Handler, @@ -531,7 +516,10 @@ pub(crate) unsafe fn optimize( } if let Some(opt_level) = config.opt_level { - if should_use_new_llvm_pass_manager(cgcx, config) { + if llvm_util::should_use_new_llvm_pass_manager( + &config.new_llvm_pass_manager, + &cgcx.target_arch, + ) { let opt_stage = match cgcx.lto { Lto::Fat => llvm::OptStage::PreLinkFatLTO, Lto::Thin | Lto::ThinLocal => llvm::OptStage::PreLinkThinLTO, diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index ace8e0516ed6b..53571e8cb32a1 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -415,3 +415,13 @@ pub fn tune_cpu(sess: &Session) -> Option<&str> { let name = sess.opts.debugging_opts.tune_cpu.as_ref()?; Some(handle_native(name)) } + +pub(crate) fn should_use_new_llvm_pass_manager(user_opt: &Option, target_arch: &str) -> bool { + // The new pass manager is enabled by default for LLVM >= 13. + // This matches Clang, which also enables it since Clang 13. + + // FIXME: There are some perf issues with the new pass manager + // when targeting s390x, so it is temporarily disabled for that + // arch, see https://github.com/rust-lang/rust/issues/89609 + user_opt.unwrap_or_else(|| target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0)) +} From f431df0d7f4f56e5c4c6a73023126e1b02104436 Mon Sep 17 00:00:00 2001 From: Axel Cohen Date: Mon, 20 Dec 2021 14:50:03 +0100 Subject: [PATCH 5/5] Load new pass manager plugins only if the new pm is actually used --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 10 +++++----- compiler/rustc_codegen_ssa/src/back/write.rs | 6 +----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 53571e8cb32a1..863a347e121c2 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -119,11 +119,11 @@ unsafe fn configure_llvm(sess: &Session) { llvm::LLVMInitializePasses(); - let use_new_llvm_pm_plugin_register = - sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false); - - // Use the legacy pm registration if the new_llvm_pass_manager option isn't explicitly enabled - if !use_new_llvm_pm_plugin_register { + // Use the legacy plugin registration if we don't use the new pass manager + if !should_use_new_llvm_pass_manager( + &sess.opts.debugging_opts.new_llvm_pass_manager, + &sess.target.arch, + ) { // Register LLVM plugins by loading them into the compiler process. for plugin in &sess.opts.debugging_opts.llvm_plugins { let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e)); diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d23fe621539e8..0281fd929c5fe 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -261,11 +261,7 @@ impl ModuleConfig { inline_threshold: sess.opts.cg.inline_threshold, new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager, emit_lifetime_markers: sess.emit_lifetime_markers(), - llvm_plugins: if sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false) { - if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]) - } else { - vec![] - }, + llvm_plugins: if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]), } }