Skip to content

Commit 052961b

Browse files
committed
rustc_codegen_llvm: move should_use_new_llvm_pass_manager function to llvm_util
1 parent 75d1208 commit 052961b

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::back::write::{
33
};
44
use crate::llvm::archive_ro::ArchiveRO;
55
use crate::llvm::{self, build_string, False, True};
6-
use crate::{LlvmCodegenBackend, ModuleLlvm};
6+
use crate::{llvm_util, LlvmCodegenBackend, ModuleLlvm};
77
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
88
use rustc_codegen_ssa::back::symbol_export;
99
use rustc_codegen_ssa::back::write::{
@@ -596,7 +596,10 @@ pub(crate) fn run_pass_manager(
596596
// tools/lto/LTOCodeGenerator.cpp
597597
debug!("running the pass manager");
598598
unsafe {
599-
if write::should_use_new_llvm_pass_manager(cgcx, config) {
599+
if llvm_util::should_use_new_llvm_pass_manager(
600+
&config.new_llvm_pass_manager,
601+
&cgcx.target_arch,
602+
) {
600603
let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO };
601604
let opt_level = config.opt_level.unwrap_or(config::OptLevel::No);
602605
write::optimize_with_new_llvm_pass_manager(

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

+4-16
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,6 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
413413
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
414414
}
415415

416-
pub(crate) fn should_use_new_llvm_pass_manager(
417-
cgcx: &CodegenContext<LlvmCodegenBackend>,
418-
config: &ModuleConfig,
419-
) -> bool {
420-
// The new pass manager is enabled by default for LLVM >= 13.
421-
// This matches Clang, which also enables it since Clang 13.
422-
423-
// FIXME: There are some perf issues with the new pass manager
424-
// when targeting s390x, so it is temporarily disabled for that
425-
// arch, see https://github.com/rust-lang/rust/issues/89609
426-
config
427-
.new_llvm_pass_manager
428-
.unwrap_or_else(|| cgcx.target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0))
429-
}
430-
431416
pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
432417
cgcx: &CodegenContext<LlvmCodegenBackend>,
433418
diag_handler: &Handler,
@@ -531,7 +516,10 @@ pub(crate) unsafe fn optimize(
531516
}
532517

533518
if let Some(opt_level) = config.opt_level {
534-
if should_use_new_llvm_pass_manager(cgcx, config) {
519+
if llvm_util::should_use_new_llvm_pass_manager(
520+
&config.new_llvm_pass_manager,
521+
&cgcx.target_arch,
522+
) {
535523
let opt_stage = match cgcx.lto {
536524
Lto::Fat => llvm::OptStage::PreLinkFatLTO,
537525
Lto::Thin | Lto::ThinLocal => llvm::OptStage::PreLinkThinLTO,

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

+10
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,13 @@ pub fn tune_cpu(sess: &Session) -> Option<&str> {
415415
let name = sess.opts.debugging_opts.tune_cpu.as_ref()?;
416416
Some(handle_native(name))
417417
}
418+
419+
pub(crate) fn should_use_new_llvm_pass_manager(user_opt: &Option<bool>, target_arch: &str) -> bool {
420+
// The new pass manager is enabled by default for LLVM >= 13.
421+
// This matches Clang, which also enables it since Clang 13.
422+
423+
// FIXME: There are some perf issues with the new pass manager
424+
// when targeting s390x, so it is temporarily disabled for that
425+
// arch, see https://github.com/rust-lang/rust/issues/89609
426+
user_opt.unwrap_or_else(|| target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0))
427+
}

0 commit comments

Comments
 (0)