Auto merge of #94402 - erikdesjardins:revert-coldland, r=nagisa

Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa"

Should fix (untested) #94390

Reopens #46515, #87055

r? `@ehuss`
This commit is contained in:
bors 2022-03-01 08:57:46 +00:00
commit 4a56cbec59
10 changed files with 31 additions and 87 deletions

View File

@ -1403,7 +1403,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
self.cx self.cx
} }
fn apply_attrs_to_cleanup_callsite(&mut self, _llret: RValue<'gcc>) { fn do_not_inline(&mut self, _llret: RValue<'gcc>) {
unimplemented!(); unimplemented!();
} }

View File

@ -23,7 +23,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange}; use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
use rustc_target::spec::{HasTargetSpec, Target}; use rustc_target::spec::{HasTargetSpec, Target};
use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::ffi::CStr; use std::ffi::CStr;
use std::iter; use std::iter;
@ -1179,19 +1178,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
unsafe { llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, UNNAMED) } unsafe { llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, UNNAMED) }
} }
fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) { fn do_not_inline(&mut self, llret: &'ll Value) {
let mut attrs = SmallVec::<[_; 2]>::new(); let noinline = llvm::AttributeKind::NoInline.create_attr(self.llcx);
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[noinline]);
// Cleanup is always the cold path.
attrs.push(llvm::AttributeKind::Cold.create_attr(self.llcx));
// In LLVM versions with deferred inlining (currently, system LLVM < 14),
// inlining drop glue can lead to exponential size blowup, see #41696 and #92110.
if !llvm_util::is_rust_llvm() && llvm_util::get_version() < (14, 0, 0) {
attrs.push(llvm::AttributeKind::NoInline.create_attr(self.llcx));
}
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &attrs);
} }
} }

View File

@ -1933,8 +1933,6 @@ extern "C" {
pub fn LLVMRustVersionMinor() -> u32; pub fn LLVMRustVersionMinor() -> u32;
pub fn LLVMRustVersionPatch() -> u32; pub fn LLVMRustVersionPatch() -> u32;
pub fn LLVMRustIsRustLLVM() -> bool;
/// Add LLVM module flags. /// Add LLVM module flags.
/// ///
/// In order for Rust-C LTO to work, module flags must be compatible with Clang. What /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What

View File

@ -257,12 +257,6 @@ pub fn get_version() -> (u32, u32, u32) {
} }
} }
/// Returns `true` if this LLVM is Rust's bundled LLVM (and not system LLVM).
pub fn is_rust_llvm() -> bool {
// Can be called without initializing LLVM
unsafe { llvm::LLVMRustIsRustLLVM() }
}
pub fn print_passes() { pub fn print_passes() {
// Can be called without initializing LLVM // Can be called without initializing LLVM
unsafe { unsafe {

View File

@ -166,7 +166,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
bx.invoke(fn_ty, fn_ptr, &llargs, ret_llbb, unwind_block, self.funclet(fx)); bx.invoke(fn_ty, fn_ptr, &llargs, ret_llbb, unwind_block, self.funclet(fx));
bx.apply_attrs_callsite(&fn_abi, invokeret); bx.apply_attrs_callsite(&fn_abi, invokeret);
if fx.mir[self.bb].is_cleanup { if fx.mir[self.bb].is_cleanup {
bx.apply_attrs_to_cleanup_callsite(invokeret); bx.do_not_inline(invokeret);
} }
if let Some((ret_dest, target)) = destination { if let Some((ret_dest, target)) = destination {
@ -178,7 +178,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
let llret = bx.call(fn_ty, fn_ptr, &llargs, self.funclet(fx)); let llret = bx.call(fn_ty, fn_ptr, &llargs, self.funclet(fx));
bx.apply_attrs_callsite(&fn_abi, llret); bx.apply_attrs_callsite(&fn_abi, llret);
if fx.mir[self.bb].is_cleanup { if fx.mir[self.bb].is_cleanup {
bx.apply_attrs_to_cleanup_callsite(llret); // Cleanup is always the cold path. Don't inline
// drop glue. Also, when there is a deeply-nested
// struct, there are "symmetry" issues that cause
// exponential inlining - see issue #41696.
bx.do_not_inline(llret);
} }
if let Some((ret_dest, target)) = destination { if let Some((ret_dest, target)) = destination {
@ -1444,7 +1448,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let llret = bx.call(fn_ty, fn_ptr, &[], None); let llret = bx.call(fn_ty, fn_ptr, &[], None);
bx.apply_attrs_callsite(&fn_abi, llret); bx.apply_attrs_callsite(&fn_abi, llret);
bx.apply_attrs_to_cleanup_callsite(llret); bx.do_not_inline(llret);
bx.unreachable(); bx.unreachable();

View File

@ -479,5 +479,5 @@ pub trait BuilderMethods<'a, 'tcx>:
) -> Self::Value; ) -> Self::Value;
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value; fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
fn apply_attrs_to_cleanup_callsite(&mut self, llret: Self::Value); fn do_not_inline(&mut self, llret: Self::Value);
} }

View File

@ -694,14 +694,6 @@ extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }
extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; } extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }
extern "C" bool LLVMRustIsRustLLVM() {
#ifdef LLVM_RUSTLLVM
return true;
#else
return false;
#endif
}
extern "C" void LLVMRustAddModuleFlag( extern "C" void LLVMRustAddModuleFlag(
LLVMModuleRef M, LLVMModuleRef M,
Module::ModFlagBehavior MergeBehavior, Module::ModFlagBehavior MergeBehavior,

View File

@ -1,15 +0,0 @@
// no-system-llvm: needs #92110
// compile-flags: -Cno-prepopulate-passes
#![crate_type = "lib"]
// This test checks that drop calls in unwind landing pads
// get the `cold` attribute.
// CHECK-LABEL: @check_cold
// CHECK: {{(call|invoke) void .+}}drop_in_place{{.+}} [[ATTRIBUTES:#[0-9]+]]
// CHECK: attributes [[ATTRIBUTES]] = { cold }
#[no_mangle]
pub fn check_cold(f: fn(), x: Box<u32>) {
// this may unwind
f();
}

View File

@ -1,37 +0,0 @@
// no-system-llvm: needs #92110 + patch for Rust alloc/dealloc functions
// compile-flags: -Copt-level=3
#![crate_type = "lib"]
// This test checks that we can inline drop_in_place in
// unwind landing pads.
// Without inlining, the box pointers escape via the call to drop_in_place,
// and LLVM will not optimize out the pointer comparison.
// With inlining, everything should be optimized out.
// See https://github.com/rust-lang/rust/issues/46515
// CHECK-LABEL: @check_no_escape_in_landingpad
// CHECK: start:
// CHECK-NEXT: ret void
#[no_mangle]
pub fn check_no_escape_in_landingpad(f: fn()) {
let x = &*Box::new(0);
let y = &*Box::new(0);
if x as *const _ == y as *const _ {
f();
}
}
// Without inlining, the compiler can't tell that
// dropping an empty string (in a landing pad) does nothing.
// With inlining, the landing pad should be optimized out.
// See https://github.com/rust-lang/rust/issues/87055
// CHECK-LABEL: @check_eliminate_noop_drop
// CHECK: start:
// CHECK-NEXT: call void %g()
// CHECK-NEXT: ret void
#[no_mangle]
pub fn check_eliminate_noop_drop(g: fn()) {
let _var = String::new();
g();
}

View File

@ -16,6 +16,14 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) {
// CHECK-LABEL: @issue71861 // CHECK-LABEL: @issue71861
#[no_mangle] #[no_mangle]
pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> { pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
// CHECK-NOT: panic
// Call to panic_no_unwind in case of double-panic is expected,
// but other panics are not.
// CHECK: cleanup
// CHECK-NEXT: ; call core::panicking::panic_no_unwind
// CHECK-NEXT: panic_no_unwind
// CHECK-NOT: panic // CHECK-NOT: panic
vec.into_boxed_slice() vec.into_boxed_slice()
} }
@ -23,6 +31,17 @@ pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
// CHECK-LABEL: @issue75636 // CHECK-LABEL: @issue75636
#[no_mangle] #[no_mangle]
pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> { pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> {
// CHECK-NOT: panic
// Call to panic_no_unwind in case of double-panic is expected,
// but other panics are not.
// CHECK: cleanup
// CHECK-NEXT: ; call core::panicking::panic_no_unwind
// CHECK-NEXT: panic_no_unwind
// CHECK-NOT: panic // CHECK-NOT: panic
iter.iter().copied().collect() iter.iter().copied().collect()
} }
// CHECK: ; core::panicking::panic_no_unwind
// CHECK: declare void @{{.*}}panic_no_unwind