about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-10-19 20:02:46 -0700
committerAlex Crichton <alex@alexcrichton.com>2017-10-20 11:49:36 -0700
commit1af1c2de36d39c5e24846d74f1ae549499bab70d (patch)
tree88f6e4b9179dc5e113f7ac80a949d25c699f6e23
parent95272a07f1fe3a82497225a4cd0d67080b8ffebf (diff)
downloadrust-1af1c2de36d39c5e24846d74f1ae549499bab70d.tar.gz
rust-1af1c2de36d39c5e24846d74f1ae549499bab70d.zip
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.
-rw-r--r--src/bootstrap/bin/rustc.rs3
-rw-r--r--src/bootstrap/builder.rs14
-rw-r--r--src/bootstrap/config.rs7
3 files changed, 18 insertions, 6 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index aeeda85e924..16a23eb364a 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -175,6 +175,9 @@ fn main() {
         if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
             cmd.arg("-C").arg(format!("codegen-units={}", s));
         }
+        if stage != "0" && env::var("RUSTC_THINLTO").is_ok() {
+            cmd.arg("-Ccodegen-units=16").arg("-Zthinlto");
+        }
 
         // Emit save-analysis info.
         if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 6480b5a619c..5891925f7f7 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -471,8 +471,6 @@ impl<'a> Builder<'a> {
              .env("RUSTC", self.out.join("bootstrap/debug/rustc"))
              .env("RUSTC_REAL", self.rustc(compiler))
              .env("RUSTC_STAGE", stage.to_string())
-             .env("RUSTC_CODEGEN_UNITS",
-                  self.config.rust_codegen_units.to_string())
              .env("RUSTC_DEBUG_ASSERTIONS",
                   self.config.rust_debug_assertions.to_string())
              .env("RUSTC_SYSROOT", self.sysroot(compiler))
@@ -486,6 +484,10 @@ impl<'a> Builder<'a> {
              })
              .env("TEST_MIRI", self.config.test_miri.to_string());
 
+        if let Some(n) = self.config.rust_codegen_units {
+            cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
+        }
+
         if let Some(host_linker) = self.build.linker(compiler.host) {
             cargo.env("RUSTC_HOST_LINKER", host_linker);
         }
@@ -618,6 +620,14 @@ impl<'a> Builder<'a> {
         // FIXME: cargo bench does not accept `--release`
         if self.config.rust_optimize && cmd != "bench" {
             cargo.arg("--release");
+
+            if mode != Mode::Libstd &&
+               self.config.rust_codegen_units.is_none() &&
+               self.build.is_rust_llvm(compiler.host)
+
+            {
+                cargo.env("RUSTC_THINLTO", "1");
+            }
         }
         if self.config.locked_deps {
             cargo.arg("--locked");
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index d6c83e3acfc..66e5efcea4e 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -81,7 +81,7 @@ pub struct Config {
 
     // rust codegen options
     pub rust_optimize: bool,
-    pub rust_codegen_units: u32,
+    pub rust_codegen_units: Option<u32>,
     pub rust_debug_assertions: bool,
     pub rust_debuginfo: bool,
     pub rust_debuginfo_lines: bool,
@@ -307,7 +307,6 @@ impl Config {
         config.submodules = true;
         config.docs = true;
         config.rust_rpath = true;
-        config.rust_codegen_units = 1;
         config.channel = "dev".to_string();
         config.codegen_tests = true;
         config.ignore_git = false;
@@ -470,8 +469,8 @@ impl Config {
             config.musl_root = rust.musl_root.clone().map(PathBuf::from);
 
             match rust.codegen_units {
-                Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
-                Some(n) => config.rust_codegen_units = n,
+                Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
+                Some(n) => config.rust_codegen_units = Some(n),
                 None => {}
             }
         }