Skip to content

Commit 1042190

Browse files
committed
Auto merge of #45400 - alexcrichton:bootstrap-thinlto, r=Mark-Simulacrum
rustbuild: Compile rustc with ThinLTO This commit enables ThinLTO for the compiler as well as multiple codegen units. This is intended to get the benefits of parallel codegen while also avoiding any major loss of perf. Finally this commit is also intended as further testing for #45320 and shaking out bugs.
2 parents 9ea3878 + d01427f commit 1042190

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/bootstrap/bin/rustc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ fn main() {
175175
if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
176176
cmd.arg("-C").arg(format!("codegen-units={}", s));
177177
}
178+
if stage != "0" && env::var("RUSTC_THINLTO").is_ok() {
179+
cmd.arg("-Ccodegen-units=16").arg("-Zthinlto");
180+
}
178181

179182
// Emit save-analysis info.
180183
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {

src/bootstrap/builder.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,6 @@ impl<'a> Builder<'a> {
471471
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
472472
.env("RUSTC_REAL", self.rustc(compiler))
473473
.env("RUSTC_STAGE", stage.to_string())
474-
.env("RUSTC_CODEGEN_UNITS",
475-
self.config.rust_codegen_units.to_string())
476474
.env("RUSTC_DEBUG_ASSERTIONS",
477475
self.config.rust_debug_assertions.to_string())
478476
.env("RUSTC_SYSROOT", self.sysroot(compiler))
@@ -486,6 +484,10 @@ impl<'a> Builder<'a> {
486484
})
487485
.env("TEST_MIRI", self.config.test_miri.to_string());
488486

487+
if let Some(n) = self.config.rust_codegen_units {
488+
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
489+
}
490+
489491
if let Some(host_linker) = self.build.linker(compiler.host) {
490492
cargo.env("RUSTC_HOST_LINKER", host_linker);
491493
}
@@ -618,6 +620,14 @@ impl<'a> Builder<'a> {
618620
// FIXME: cargo bench does not accept `--release`
619621
if self.config.rust_optimize && cmd != "bench" {
620622
cargo.arg("--release");
623+
624+
if mode != Mode::Libstd &&
625+
self.config.rust_codegen_units.is_none() &&
626+
self.build.is_rust_llvm(compiler.host)
627+
628+
{
629+
cargo.env("RUSTC_THINLTO", "1");
630+
}
621631
}
622632
if self.config.locked_deps {
623633
cargo.arg("--locked");

src/bootstrap/config.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct Config {
8181

8282
// rust codegen options
8383
pub rust_optimize: bool,
84-
pub rust_codegen_units: u32,
84+
pub rust_codegen_units: Option<u32>,
8585
pub rust_debug_assertions: bool,
8686
pub rust_debuginfo: bool,
8787
pub rust_debuginfo_lines: bool,
@@ -307,7 +307,6 @@ impl Config {
307307
config.submodules = true;
308308
config.docs = true;
309309
config.rust_rpath = true;
310-
config.rust_codegen_units = 1;
311310
config.channel = "dev".to_string();
312311
config.codegen_tests = true;
313312
config.ignore_git = false;
@@ -470,8 +469,8 @@ impl Config {
470469
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
471470

472471
match rust.codegen_units {
473-
Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
474-
Some(n) => config.rust_codegen_units = n,
472+
Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
473+
Some(n) => config.rust_codegen_units = Some(n),
475474
None => {}
476475
}
477476
}

src/libstd/collections/hash/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ impl<K, V, S> HashMap<K, V, S>
11131113
/// assert_eq!(map.get(&2), None);
11141114
/// ```
11151115
#[stable(feature = "rust1", since = "1.0.0")]
1116+
#[inline]
11161117
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
11171118
where K: Borrow<Q>,
11181119
Q: Hash + Eq
@@ -2554,6 +2555,7 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
25542555
{
25552556
type Key = K;
25562557

2558+
#[inline]
25572559
fn get(&self, key: &Q) -> Option<&K> {
25582560
self.search(key).into_occupied_bucket().map(|bucket| bucket.into_refs().0)
25592561
}
@@ -2566,6 +2568,7 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
25662568
self.search_mut(key).into_occupied_bucket().map(|bucket| pop_internal(bucket).0)
25672569
}
25682570

2571+
#[inline]
25692572
fn replace(&mut self, key: K) -> Option<K> {
25702573
self.reserve(1);
25712574

0 commit comments

Comments
 (0)