Use the existing llvm-plugins option for both legacy and new pm registration
This commit is contained in:
parent
97cf461b8f
commit
c4f29fa0ed
7 changed files with 24 additions and 23 deletions
|
@ -470,7 +470,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
|
||||||
|
|
||||||
let extra_passes = config.passes.join(",");
|
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.
|
// 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
|
// 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,
|
selfprofile_after_pass_callback,
|
||||||
extra_passes.as_ptr().cast(),
|
extra_passes.as_ptr().cast(),
|
||||||
extra_passes.len(),
|
extra_passes.len(),
|
||||||
pass_plugins.as_ptr().cast(),
|
llvm_plugins.as_ptr().cast(),
|
||||||
pass_plugins.len(),
|
llvm_plugins.len(),
|
||||||
);
|
);
|
||||||
result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes"))
|
result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2304,8 +2304,8 @@ extern "C" {
|
||||||
end_callback: SelfProfileAfterPassCallback,
|
end_callback: SelfProfileAfterPassCallback,
|
||||||
ExtraPasses: *const c_char,
|
ExtraPasses: *const c_char,
|
||||||
ExtraPassesLen: size_t,
|
ExtraPassesLen: size_t,
|
||||||
PassPlugins: *const c_char,
|
LLVMPlugins: *const c_char,
|
||||||
PassPluginsLen: size_t,
|
LLVMPluginsLen: size_t,
|
||||||
) -> LLVMRustResult;
|
) -> LLVMRustResult;
|
||||||
pub fn LLVMRustPrintModule(
|
pub fn LLVMRustPrintModule(
|
||||||
M: &'a Module,
|
M: &'a Module,
|
||||||
|
|
|
@ -119,6 +119,11 @@ unsafe fn configure_llvm(sess: &Session) {
|
||||||
|
|
||||||
llvm::LLVMInitializePasses();
|
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 {
|
||||||
// Register LLVM plugins by loading them into the compiler process.
|
// Register LLVM plugins by loading them into the compiler process.
|
||||||
for plugin in &sess.opts.debugging_opts.llvm_plugins {
|
for plugin in &sess.opts.debugging_opts.llvm_plugins {
|
||||||
let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
|
let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
|
||||||
|
@ -128,6 +133,7 @@ unsafe fn configure_llvm(sess: &Session) {
|
||||||
// since the library can make things that will live arbitrarily long.
|
// since the library can make things that will live arbitrarily long.
|
||||||
mem::forget(lib);
|
mem::forget(lib);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rustc_llvm::initialize_available_targets();
|
rustc_llvm::initialize_available_targets();
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,6 @@ pub enum BitcodeSection {
|
||||||
pub struct ModuleConfig {
|
pub struct ModuleConfig {
|
||||||
/// Names of additional optimization passes to run.
|
/// Names of additional optimization passes to run.
|
||||||
pub passes: Vec<String>,
|
pub passes: Vec<String>,
|
||||||
/// Paths of LLVM pass plugins to load.
|
|
||||||
pub pass_plugins: Vec<String>,
|
|
||||||
/// Some(level) to optimize at a certain level, or None to run
|
/// Some(level) to optimize at a certain level, or None to run
|
||||||
/// absolutely no optimizations (used for the metadata module).
|
/// absolutely no optimizations (used for the metadata module).
|
||||||
pub opt_level: Option<config::OptLevel>,
|
pub opt_level: Option<config::OptLevel>,
|
||||||
|
@ -115,6 +113,7 @@ pub struct ModuleConfig {
|
||||||
pub inline_threshold: Option<u32>,
|
pub inline_threshold: Option<u32>,
|
||||||
pub new_llvm_pass_manager: Option<bool>,
|
pub new_llvm_pass_manager: Option<bool>,
|
||||||
pub emit_lifetime_markers: bool,
|
pub emit_lifetime_markers: bool,
|
||||||
|
pub llvm_plugins: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleConfig {
|
impl ModuleConfig {
|
||||||
|
@ -172,8 +171,6 @@ impl ModuleConfig {
|
||||||
ModuleConfig {
|
ModuleConfig {
|
||||||
passes: if_regular!(sess.opts.cg.passes.clone(), vec![]),
|
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_level: opt_level_and_size,
|
||||||
opt_size: opt_level_and_size,
|
opt_size: opt_level_and_size,
|
||||||
|
|
||||||
|
@ -264,6 +261,7 @@ impl ModuleConfig {
|
||||||
inline_threshold: sess.opts.cg.inline_threshold,
|
inline_threshold: sess.opts.cg.inline_threshold,
|
||||||
new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager,
|
new_llvm_pass_manager: sess.opts.debugging_opts.new_llvm_pass_manager,
|
||||||
emit_lifetime_markers: sess.emit_lifetime_markers(),
|
emit_lifetime_markers: sess.emit_lifetime_markers(),
|
||||||
|
llvm_plugins: if_regular!(sess.opts.debugging_opts.llvm_plugins.clone(), vec![]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -587,7 +587,6 @@ fn test_codegen_options_tracking_hash() {
|
||||||
tracked!(overflow_checks, Some(true));
|
tracked!(overflow_checks, Some(true));
|
||||||
tracked!(panic, Some(PanicStrategy::Abort));
|
tracked!(panic, Some(PanicStrategy::Abort));
|
||||||
tracked!(passes, vec![String::from("1"), String::from("2")]);
|
tracked!(passes, vec![String::from("1"), String::from("2")]);
|
||||||
tracked!(pass_plugins, vec![String::from("1"), String::from("2")]);
|
|
||||||
tracked!(prefer_dynamic, true);
|
tracked!(prefer_dynamic, true);
|
||||||
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
|
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
|
||||||
tracked!(profile_use, Some(PathBuf::from("abc")));
|
tracked!(profile_use, Some(PathBuf::from("abc")));
|
||||||
|
|
|
@ -755,7 +755,7 @@ LLVMRustOptimizeWithNewPassManager(
|
||||||
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
|
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
|
||||||
LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
|
LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
|
||||||
const char *ExtraPasses, size_t ExtraPassesLen,
|
const char *ExtraPasses, size_t ExtraPassesLen,
|
||||||
const char *PassPlugins, size_t PassPluginsLen) {
|
const char *LLVMPlugins, size_t LLVMPluginsLen) {
|
||||||
Module *TheModule = unwrap(ModuleRef);
|
Module *TheModule = unwrap(ModuleRef);
|
||||||
TargetMachine *TM = unwrap(TMRef);
|
TargetMachine *TM = unwrap(TMRef);
|
||||||
OptimizationLevel OptLevel = fromRust(OptLevelRust);
|
OptimizationLevel OptLevel = fromRust(OptLevelRust);
|
||||||
|
@ -926,10 +926,10 @@ LLVMRustOptimizeWithNewPassManager(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PassPluginsLen) {
|
if (LLVMPluginsLen) {
|
||||||
auto PluginsStr = StringRef(PassPlugins, PassPluginsLen);
|
auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen);
|
||||||
SmallVector<StringRef> Plugins;
|
SmallVector<StringRef> Plugins;
|
||||||
PluginsStr.split(Plugins, ' ', -1, false);
|
PluginsStr.split(Plugins, ',', -1, false);
|
||||||
for (auto PluginPath: Plugins) {
|
for (auto PluginPath: Plugins) {
|
||||||
auto Plugin = PassPlugin::Load(PluginPath.str());
|
auto Plugin = PassPlugin::Load(PluginPath.str());
|
||||||
if (!Plugin) {
|
if (!Plugin) {
|
||||||
|
|
|
@ -1033,8 +1033,6 @@ options! {
|
||||||
"panic strategy to compile crate with"),
|
"panic strategy to compile crate with"),
|
||||||
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
|
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
|
||||||
"a list of extra LLVM passes to run (space separated)"),
|
"a list of extra LLVM passes to run (space separated)"),
|
||||||
pass_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
|
|
||||||
"a list of LLVM pass plugins to load (space separated)"),
|
|
||||||
prefer_dynamic: bool = (false, parse_bool, [TRACKED],
|
prefer_dynamic: bool = (false, parse_bool, [TRACKED],
|
||||||
"prefer dynamic linking to static linking (default: no)"),
|
"prefer dynamic linking to static linking (default: no)"),
|
||||||
profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
|
profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue