Skip to content

Commit cbf7489

Browse files
committedNov 29, 2018
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 rust-lang#52651.
1 parent 0c1dc62 commit cbf7489

File tree

8 files changed

+21
-6
lines changed

8 files changed

+21
-6
lines changed
 

‎src/librustc_codegen_llvm/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ extern "C" {
13581358
pub fn LLVMRustDebugMetadataVersion() -> u32;
13591359
pub fn LLVMRustVersionMajor() -> u32;
13601360
pub fn LLVMRustVersionMinor() -> u32;
1361+
pub fn LLVMRustIsRustLLVM() -> bool;
13611362

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

‎src/librustc_codegen_llvm/llvm_util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ unsafe fn configure_llvm(sess: &Session) {
7070
if sess.opts.debugging_opts.disable_instrumentation_preinliner {
7171
add("-disable-preinline");
7272
}
73+
if llvm::LLVMRustIsRustLLVM() {
74+
add("-mergefunc-use-aliases");
75+
}
7376

7477
for arg in &sess.opts.cg.llvm_args {
7578
add(&(*arg));

‎src/rustllvm/PassWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
284284
report_fatal_error("Bad RelocModel.");
285285
}
286286

287-
#if LLVM_RUSTLLVM
287+
#ifdef LLVM_RUSTLLVM
288288
/// getLongestEntryLength - Return the length of the longest entry in the table.
289289
///
290290
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {

‎src/rustllvm/RustWrapper.cpp

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

534534
extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }
535535

536+
extern "C" bool LLVMRustIsRustLLVM() {
537+
#ifdef LLVM_RUSTLLVM
538+
return 1;
539+
#else
540+
return 0;
541+
#endif
542+
}
543+
536544
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name,
537545
uint32_t Value) {
538546
unwrap(M)->addModuleFlag(Module::Warning, Name, Value);

‎src/test/codegen/export-no-mangle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -C no-prepopulate-passes
12+
1113
#![crate_type = "lib"]
1214

1315
mod private {

‎src/test/codegen/external-no-mangle-fns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -O
11+
// compile-flags: -C no-prepopulate-passes
1212
// `#[no_mangle]`d functions always have external linkage, i.e. no `internal` in their `define`s
1313

1414
#![crate_type = "lib"]
@@ -43,7 +43,7 @@ const HIDDEN: () = {
4343
};
4444

4545
// The surrounding item should not accidentally become external
46-
// CHECK: define internal {{.*}} void @_ZN22external_no_mangle_fns1x
46+
// CHECK: define internal{{.*}} void @_ZN22external_no_mangle_fns1x
4747
#[inline(never)]
4848
fn x() {
4949
// CHECK: define void @g()

‎src/test/codegen/issue-45222.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ fn foo3r(n: u64) -> u64 {
6969
// CHECK-LABEL: @check_foo3r
7070
#[no_mangle]
7171
pub fn check_foo3r() -> u64 {
72-
// CHECK: ret i64 500005000000000
73-
foo3r(100000)
72+
// CHECK: ret i64 500050000000
73+
foo3r(10000)
7474
}

‎src/test/codegen/match-optimizes-away.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
pub enum Three { A, B, C }
1616

17+
#[repr(u16)]
1718
pub enum Four { A, B, C, D }
1819

1920
#[no_mangle]
@@ -32,7 +33,7 @@ pub fn three_valued(x: Three) -> Three {
3233
pub fn four_valued(x: Four) -> Four {
3334
// CHECK-LABEL: @four_valued
3435
// CHECK-NEXT: {{^.*:$}}
35-
// CHECK-NEXT: ret i8 %0
36+
// CHECK-NEXT: ret i16 %0
3637
match x {
3738
Four::A => Four::A,
3839
Four::B => Four::B,

0 commit comments

Comments
 (0)