]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #45400 - alexcrichton:bootstrap-thinlto, r=Mark-Simulacrum
authorbors <bors@rust-lang.org>
Sun, 22 Oct 2017 00:35:05 +0000 (00:35 +0000)
committerbors <bors@rust-lang.org>
Sun, 22 Oct 2017 00:35:05 +0000 (00:35 +0000)
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.

src/bootstrap/bin/rustc.rs
src/bootstrap/builder.rs
src/bootstrap/config.rs
src/libstd/collections/hash/map.rs

index aeeda85e924ef1657825aa28993741867561f2c6..16a23eb364a3822b9e7d55d6d1bbd88754e57a70 100644 (file)
@@ -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()) {
index dee4999879ca384e721e7a9bccb58dfaf0a03611..0dca395fa1fdbfe8f48d8ff709a247e8813351fb 100644 (file)
@@ -471,8 +471,6 @@ pub fn cargo(&self,
              .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 @@ pub fn cargo(&self,
              })
              .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 @@ pub fn cargo(&self,
         // 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");
index d6c83e3acfc8ab3d844535644e4310aab3bb950b..66e5efcea4e809e9b8ee025604a37a9d6f00a7fc 100644 (file)
@@ -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 @@ pub fn parse(args: &[String]) -> 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 @@ pub fn parse(args: &[String]) -> 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 => {}
             }
         }
index 3c0fa0860d394125b7b4eefeb8a188f1d3851e91..d96a4f40d3f8ea0475582b7b9a6cca19afbc1926 100644 (file)
@@ -1113,6 +1113,7 @@ pub fn clear(&mut self) {
     /// assert_eq!(map.get(&2), None);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[inline]
     pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
         where K: Borrow<Q>,
               Q: Hash + Eq
@@ -2554,6 +2555,7 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
 {
     type Key = K;
 
+    #[inline]
     fn get(&self, key: &Q) -> Option<&K> {
         self.search(key).into_occupied_bucket().map(|bucket| bucket.into_refs().0)
     }
@@ -2566,6 +2568,7 @@ fn take(&mut self, key: &Q) -> Option<K> {
         self.search_mut(key).into_occupied_bucket().map(|bucket| pop_internal(bucket).0)
     }
 
+    #[inline]
     fn replace(&mut self, key: K) -> Option<K> {
         self.reserve(1);