Skip to content

Commit

Permalink
keep noinline for system llvm < 14
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdesjardins committed Dec 30, 2021
1 parent 2b66221 commit e4463b2
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
self.cx
}

fn mark_callsite_cold(&mut self, _llret: RValue<'gcc>) {
fn apply_attrs_to_cleanup_callsite(&mut self, _llret: RValue<'gcc>) {
unimplemented!();
}

Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
unsafe { llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, UNNAMED) }
}

fn mark_callsite_cold(&mut self, llret: &'ll Value) {
fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) {
// Cleanup is always the cold path.
llvm::Attribute::Cold.apply_callsite(llvm::AttributePlace::Function, llret);

// 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) {
llvm::Attribute::NoInline.apply_callsite(llvm::AttributePlace::Function, llret);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,8 @@ extern "C" {
pub fn LLVMRustVersionMinor() -> u32;
pub fn LLVMRustVersionPatch() -> u32;

pub fn LLVMRustIsRustLLVM() -> bool;

pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);

pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ 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() {
// Can be called without initializing LLVM
unsafe {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
let llret = bx.call(fn_ty, fn_ptr, &llargs, self.funclet(fx));
bx.apply_attrs_callsite(&fn_abi, llret);
if fx.mir[self.bb].is_cleanup {
// Cleanup is always the cold path.
bx.mark_callsite_cold(llret);
bx.apply_attrs_to_cleanup_callsite(llret);
}

if let Some((ret_dest, target)) = destination {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,5 @@ pub trait BuilderMethods<'a, 'tcx>:
) -> Self::Value;
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;

fn mark_callsite_cold(&mut self, llret: Self::Value);
fn apply_attrs_to_cleanup_callsite(&mut self, llret: Self::Value);
}
8 changes: 8 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,14 @@ extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }

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(LLVMModuleRef M, const char *Name,
uint32_t Value) {
unwrap(M)->addModuleFlag(Module::Warning, Name, Value);
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/unwind-landingpad-cold.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// no-system-llvm: needs #92110
// compile-flags: -Cno-prepopulate-passes
#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/unwind-landingpad-inline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// no-system-llvm: needs patch for Rust alloc/dealloc functions
// no-system-llvm: needs #92110 + patch for Rust alloc/dealloc functions
// compile-flags: -Copt-level=3
#![crate_type = "lib"]

Expand Down

0 comments on commit e4463b2

Please sign in to comment.