Skip to content

Commit e4463b2

Browse files
keep noinline for system llvm < 14
1 parent 2b66221 commit e4463b2

File tree

9 files changed

+29
-6
lines changed

9 files changed

+29
-6
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
14041404
self.cx
14051405
}
14061406

1407-
fn mark_callsite_cold(&mut self, _llret: RValue<'gcc>) {
1407+
fn apply_attrs_to_cleanup_callsite(&mut self, _llret: RValue<'gcc>) {
14081408
unimplemented!();
14091409
}
14101410

compiler/rustc_codegen_llvm/src/builder.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12011201
unsafe { llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, UNNAMED) }
12021202
}
12031203

1204-
fn mark_callsite_cold(&mut self, llret: &'ll Value) {
1204+
fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) {
1205+
// Cleanup is always the cold path.
12051206
llvm::Attribute::Cold.apply_callsite(llvm::AttributePlace::Function, llret);
1207+
1208+
// In LLVM versions with deferred inlining (currently, system LLVM < 14),
1209+
// inlining drop glue can lead to exponential size blowup, see #41696 and #92110.
1210+
if !llvm_util::is_rust_llvm() && llvm_util::get_version() < (14, 0, 0) {
1211+
llvm::Attribute::NoInline.apply_callsite(llvm::AttributePlace::Function, llret);
1212+
}
12061213
}
12071214
}
12081215

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,8 @@ extern "C" {
19021902
pub fn LLVMRustVersionMinor() -> u32;
19031903
pub fn LLVMRustVersionPatch() -> u32;
19041904

1905+
pub fn LLVMRustIsRustLLVM() -> bool;
1906+
19051907
pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);
19061908

19071909
pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;

compiler/rustc_codegen_llvm/src/llvm_util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ pub fn get_version() -> (u32, u32, u32) {
217217
}
218218
}
219219

220+
/// Returns `true` if this LLVM is Rust's bundled LLVM (and not system LLVM).
221+
pub fn is_rust_llvm() -> bool {
222+
// Can be called without initializing LLVM
223+
unsafe { llvm::LLVMRustIsRustLLVM() }
224+
}
225+
220226
pub fn print_passes() {
221227
// Can be called without initializing LLVM
222228
unsafe {

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
160160
let llret = bx.call(fn_ty, fn_ptr, &llargs, self.funclet(fx));
161161
bx.apply_attrs_callsite(&fn_abi, llret);
162162
if fx.mir[self.bb].is_cleanup {
163-
// Cleanup is always the cold path.
164-
bx.mark_callsite_cold(llret);
163+
bx.apply_attrs_to_cleanup_callsite(llret);
165164
}
166165

167166
if let Some((ret_dest, target)) = destination {

compiler/rustc_codegen_ssa/src/traits/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,5 @@ pub trait BuilderMethods<'a, 'tcx>:
311311
) -> Self::Value;
312312
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
313313

314-
fn mark_callsite_cold(&mut self, llret: Self::Value);
314+
fn apply_attrs_to_cleanup_callsite(&mut self, llret: Self::Value);
315315
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,14 @@ extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }
716716

717717
extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }
718718

719+
extern "C" bool LLVMRustIsRustLLVM() {
720+
#ifdef LLVM_RUSTLLVM
721+
return true;
722+
#else
723+
return false;
724+
#endif
725+
}
726+
719727
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name,
720728
uint32_t Value) {
721729
unwrap(M)->addModuleFlag(Module::Warning, Name, Value);

src/test/codegen/unwind-landingpad-cold.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// no-system-llvm: needs #92110
12
// compile-flags: -Cno-prepopulate-passes
23
#![crate_type = "lib"]
34

src/test/codegen/unwind-landingpad-inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// no-system-llvm: needs patch for Rust alloc/dealloc functions
1+
// no-system-llvm: needs #92110 + patch for Rust alloc/dealloc functions
22
// compile-flags: -Copt-level=3
33
#![crate_type = "lib"]
44

0 commit comments

Comments
 (0)