Skip to content

Commit 63cc2bb

Browse files
committed
Auto merge of #88243 - nikic:newpm-2, r=nagisa
Enable new pass manager with LLVM 13 The new pass manager is enabled by default in clang since Clang/LLVM 13. Per the recent discussion on llvm-dev (https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html) the legacy pass manager will be unmaintained in LLVM 14 and removed entirely in LLVM 15. This switches us to use the new pass manager if LLVM >= 13 is used. It's possible to still use the old pass manager using `-Z new-llvm-pass-manager=no`.
2 parents e9f29a8 + 51203dc commit 63cc2bb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
370370
}
371371

372372
pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
373-
// The new pass manager is disabled by default.
374-
config.new_llvm_pass_manager.unwrap_or(false)
373+
// The new pass manager is enabled by default for LLVM >= 13.
374+
// This matches Clang, which also enables it since Clang 13.
375+
config.new_llvm_pass_manager.unwrap_or_else(|| llvm_util::get_version() >= (13, 0, 0))
375376
}
376377

377378
pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,10 @@ LLVMRustOptimizeWithNewPassManager(
10041004
#endif
10051005
bool NeedThinLTOBufferPasses = UseThinLTOBuffers;
10061006
if (!NoPrepopulatePasses) {
1007-
if (OptLevel == OptimizationLevel::O0) {
1007+
// The pre-link pipelines don't support O0 and require using budilO0DefaultPipeline() instead.
1008+
// At the same time, the LTO pipelines do support O0 and using them is required.
1009+
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || OptStage == LLVMRustOptStage::FatLTO;
1010+
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
10081011
#if LLVM_VERSION_GE(12, 0)
10091012
for (const auto &C : PipelineStartEPCallbacks)
10101013
PB.registerPipelineStartEPCallback(C);

src/test/codegen/panic-in-drop-abort.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// compile-flags: -Z panic-in-drop=abort -O
1+
// compile-flags: -Z panic-in-drop=abort -O -Z new-llvm-pass-manager=no
22

33
// Ensure that unwinding code paths are eliminated from the output after
44
// optimization.
55

6+
// This test uses -Z new-llvm-pass-manager=no, because the expected optimization does not happen
7+
// on targets using SEH exceptions (i.e. MSVC) anymore. The core issue is that Rust promises that
8+
// the drop_in_place() function can't unwind, but implements it in a way that *can*, because we
9+
// currently go out of our way to allow longjmps, which also use the unwinding mechanism on MSVC
10+
// targets. We should either forbid longjmps, or not assume nounwind, making this optimization
11+
// incompatible with the current behavior of running cleanuppads on longjmp unwinding.
12+
13+
// CHECK-NOT: {{(call|invoke).*}}should_not_appear_in_output
14+
615
#![crate_type = "lib"]
716
use std::any::Any;
817
use std::mem::forget;
@@ -35,17 +44,13 @@ impl Drop for AssertNeverDrop {
3544
}
3645
}
3746

38-
// CHECK-LABEL: normal_drop
39-
// CHECK-NOT: should_not_appear_in_output
4047
#[no_mangle]
4148
pub fn normal_drop(x: ExternDrop) {
4249
let guard = AssertNeverDrop;
4350
drop(x);
4451
forget(guard);
4552
}
4653

47-
// CHECK-LABEL: indirect_drop
48-
// CHECK-NOT: should_not_appear_in_output
4954
#[no_mangle]
5055
pub fn indirect_drop(x: Box<dyn Any>) {
5156
let guard = AssertNeverDrop;

0 commit comments

Comments
 (0)