rustc: Don't inline in CGUs at -O0
This commit tweaks the behavior of inlining functions into multiple codegen units when rustc is compiling in debug mode. Today rustc will unconditionally treat `#[inline]` functions by translating them into all codegen units that they're needed within, marking the linkage as `internal`. This commit changes the behavior so that in debug mode (compiling at `-O0`) rustc will instead only translate `#[inline]` functions into *one* codegen unit, forcing all other codegen units to reference this one copy. The goal here is to improve debug compile times by reducing the amount of translation that happens on behalf of multiple codegen units. It was discovered in #44941 that increasing the number of codegen units had the adverse side effect of increasing the overal work done by the compiler, and the suspicion here was that the compiler was inlining, translating, and codegen'ing more functions with more codegen units (for example `String` would be basically inlined into all codegen units if used). The strategy in this commit should reduce the cost of `#[inline]` functions to being equivalent to one codegen unit, which is only translating and codegen'ing inline functions once. Collected [data] shows that this does indeed improve the situation from [before] as the overall cpu-clock time increases at a much slower rate and when pinned to one core rustc does not consume significantly more wall clock time than with one codegen unit. One caveat of this commit is that the symbol names for inlined functions that are only translated once needed some slight tweaking. These inline functions could be translated into multiple crates and we need to make sure the symbols don't collideA so the crate name/disambiguator is mixed in to the symbol name hash in these situations. [data]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334880911 [before]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334583384
This commit is contained in:
parent
ac76206be4
commit
4b2bdf7b54
21 changed files with 200 additions and 81 deletions
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
//~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<drop_in_place_intrinsic::StructWithDtor[0]> @@ drop_in_place_intrinsic0[Internal]
|
||||
struct StructWithDtor(u32);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
// ignore-tidy-linelength
|
||||
// compile-flags:-Zprint-trans-items=eager
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![deny(dead_code)]
|
||||
#![feature(coerce_unsized)]
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/extern-drop-glue
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![crate_type="lib"]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/inlining-from-extern-crate
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![crate_type="lib"]
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-drop-glue
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![crate_type="lib"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-inlining-but-not-all
|
||||
// compile-flags:-Zinline-in-all-cgus=no
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![crate_type="lib"]
|
||||
|
||||
mod inline {
|
||||
|
||||
//~ TRANS_ITEM fn local_inlining_but_not_all::inline[0]::inlined_function[0] @@ local_inlining_but_not_all-inline[External]
|
||||
#[inline(always)]
|
||||
pub fn inlined_function()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mod user1 {
|
||||
use super::inline;
|
||||
|
||||
//~ TRANS_ITEM fn local_inlining_but_not_all::user1[0]::foo[0] @@ local_inlining_but_not_all-user1[Internal]
|
||||
fn foo() {
|
||||
inline::inlined_function();
|
||||
}
|
||||
}
|
||||
|
||||
mod user2 {
|
||||
use super::inline;
|
||||
|
||||
//~ TRANS_ITEM fn local_inlining_but_not_all::user2[0]::bar[0] @@ local_inlining_but_not_all-user2[Internal]
|
||||
fn bar() {
|
||||
inline::inlined_function();
|
||||
}
|
||||
}
|
||||
|
||||
mod non_user {
|
||||
|
||||
//~ TRANS_ITEM fn local_inlining_but_not_all::non_user[0]::baz[0] @@ local_inlining_but_not_all-non_user[Internal]
|
||||
fn baz() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-inlining
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![crate_type="lib"]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-transitive-inlining
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![crate_type="lib"]
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
// We specify -Z incremental here because we want to test the partitioning for
|
||||
// incremental compilation
|
||||
// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/vtable-through-const
|
||||
// compile-flags:-Zinline-in-all-cgus
|
||||
|
||||
// This test case makes sure, that references made through constants are
|
||||
// recorded properly in the InliningMap.
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@
|
|||
|
||||
all:
|
||||
$(RUSTC) cci_lib.rs
|
||||
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
|
||||
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \
|
||||
-Z inline-in-all-cgus
|
||||
[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*cci_fn)" -eq "2" ]
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
# in only one compilation unit.
|
||||
|
||||
all:
|
||||
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
|
||||
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \
|
||||
-Z inline-in-all-cgus
|
||||
[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ i32\ .*inlined)" -eq "0" ]
|
||||
[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ internal\ i32\ .*inlined)" -eq "2" ]
|
||||
[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ hidden\ i32\ .*normal)" -eq "1" ]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue