Enable -mergefunc-use-aliases

If the Rust LLVM fork is used, enable the -mergefunc-use-aliases
flag, which will create aliases for merged functions, rather than
inserting a call from one to the other.

A number of codegen tests needed to be adjusted, because functions
that previously fell below the thunk limit are now being merged.
Merging is prevented either using -C no-prepopulate-passes, or by
making the functions non-identical.

I expect that this is going to break something, somewhere, because
it isn't able to deal with aliases properly, but we won't find out
until we try :)

This fixes #52651.
This commit is contained in:
Nikita Popov 2018-11-29 23:05:23 +01:00
parent 0c1dc62c1e
commit cbf748993f
8 changed files with 21 additions and 6 deletions

View File

@ -1358,6 +1358,7 @@ extern "C" {
pub fn LLVMRustDebugMetadataVersion() -> u32;
pub fn LLVMRustVersionMajor() -> u32;
pub fn LLVMRustVersionMinor() -> u32;
pub fn LLVMRustIsRustLLVM() -> bool;
pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);

View File

@ -70,6 +70,9 @@ unsafe fn configure_llvm(sess: &Session) {
if sess.opts.debugging_opts.disable_instrumentation_preinliner {
add("-disable-preinline");
}
if llvm::LLVMRustIsRustLLVM() {
add("-mergefunc-use-aliases");
}
for arg in &sess.opts.cg.llvm_args {
add(&(*arg));

View File

@ -284,7 +284,7 @@ static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
report_fatal_error("Bad RelocModel.");
}
#if LLVM_RUSTLLVM
#ifdef LLVM_RUSTLLVM
/// getLongestEntryLength - Return the length of the longest entry in the table.
///
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {

View File

@ -533,6 +533,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 1;
#else
return 0;
#endif
}
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name,
uint32_t Value) {
unwrap(M)->addModuleFlag(Module::Warning, Name, Value);

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -C no-prepopulate-passes
#![crate_type = "lib"]
mod private {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -O
// compile-flags: -C no-prepopulate-passes
// `#[no_mangle]`d functions always have external linkage, i.e. no `internal` in their `define`s
#![crate_type = "lib"]
@ -43,7 +43,7 @@ const HIDDEN: () = {
};
// The surrounding item should not accidentally become external
// CHECK: define internal {{.*}} void @_ZN22external_no_mangle_fns1x
// CHECK: define internal{{.*}} void @_ZN22external_no_mangle_fns1x
#[inline(never)]
fn x() {
// CHECK: define void @g()

View File

@ -69,6 +69,6 @@ fn foo3r(n: u64) -> u64 {
// CHECK-LABEL: @check_foo3r
#[no_mangle]
pub fn check_foo3r() -> u64 {
// CHECK: ret i64 500005000000000
foo3r(100000)
// CHECK: ret i64 500050000000
foo3r(10000)
}

View File

@ -14,6 +14,7 @@
pub enum Three { A, B, C }
#[repr(u16)]
pub enum Four { A, B, C, D }
#[no_mangle]
@ -32,7 +33,7 @@ pub fn three_valued(x: Three) -> Three {
pub fn four_valued(x: Four) -> Four {
// CHECK-LABEL: @four_valued
// CHECK-NEXT: {{^.*:$}}
// CHECK-NEXT: ret i8 %0
// CHECK-NEXT: ret i16 %0
match x {
Four::A => Four::A,
Four::B => Four::B,