1
Fork 0

Use the existing llvm-plugins option for both legacy and new pm registration

This commit is contained in:
Axel Cohen 2021-11-24 11:43:40 +01:00
parent 97cf461b8f
commit c4f29fa0ed
7 changed files with 24 additions and 23 deletions

View file

@ -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"))
}

View file

@ -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,

View file

@ -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);
let use_new_llvm_pm_plugin_register =
sess.opts.debugging_opts.new_llvm_pass_manager.unwrap_or(false);
// 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);
// 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();