]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Set release mode cgus to 16 by default
authorAlex Crichton <alex@alexcrichton.com>
Thu, 21 Dec 2017 15:03:16 +0000 (07:03 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 24 Dec 2017 00:04:15 +0000 (16:04 -0800)
This commit is the next attempt to enable multiple codegen units by default in
release mode, getting some of those sweet, sweet parallelism wins by running
codegen in parallel. Performance should not be lost due to ThinLTO being on by
default as well.

Closes #45320

src/librustc/session/mod.rs
src/librustc_llvm/ffi.rs
src/librustc_trans/back/lto.rs
src/rustllvm/PassWrapper.cpp

index 60a218500ca78b15761b7a448dc22b602c4e37b0..748a734d1d7accdf0ec14146ec8122ea8fc0879c 100644 (file)
@@ -785,10 +785,7 @@ pub fn codegen_units(&self) -> usize {
         // As a result 16 was chosen here! Mostly because it was a power of 2
         // and most benchmarks agreed it was roughly a local optimum. Not very
         // scientific.
-        match self.opts.optimize {
-            config::OptLevel::No => 16,
-            _ => 1, // FIXME(#46346) this should be 16
-        }
+        16
     }
 
     /// Returns whether ThinLTO is enabled for this compilation
index cb385923067c4a316d39281183ef8b54fb6d0a87..7d653494465169a2bb5631815830278523d78b0d 100644 (file)
@@ -1732,4 +1732,5 @@ pub fn LLVMRustThinLTOGetDICompileUnit(M: ModuleRef,
                                            CU1: *mut *mut c_void,
                                            CU2: *mut *mut c_void);
     pub fn LLVMRustThinLTOPatchDICompileUnit(M: ModuleRef, CU: *mut c_void);
+    pub fn LLVMRustThinLTORemoveAvailableExternally(M: ModuleRef);
 }
index ba8c26bc819be435860edeaaa78b7fe66f16994c..298716840926a49bb2dcc90032cb572686ebed0d 100644 (file)
@@ -726,6 +726,21 @@ unsafe fn optimize(&mut self, cgcx: &CodegenContext, timeline: &mut Timeline)
         run_pass_manager(cgcx, tm, llmod, config, true);
         cgcx.save_temp_bitcode(&mtrans, "thin-lto-after-pm");
         timeline.record("thin-done");
+
+        // FIXME: this is a hack around a bug in LLVM right now. Discovered in
+        // #46910 it was found out that on 32-bit MSVC LLVM will hit a codegen
+        // error if there's an available_externally function in the LLVM module.
+        // Typically we don't actually use these functions but ThinLTO makes
+        // heavy use of them when inlining across modules.
+        //
+        // Tracked upstream at https://bugs.llvm.org/show_bug.cgi?id=35736 this
+        // function call (and its definition on the C++ side of things)
+        // shouldn't be necessary eventually and we can safetly delete these few
+        // lines.
+        llvm::LLVMRustThinLTORemoveAvailableExternally(llmod);
+        cgcx.save_temp_bitcode(&mtrans, "thin-lto-after-rm-ae");
+        timeline.record("no-ae");
+
         Ok(mtrans)
     }
 }
index 776e4a3e65ad55fb2b9baa28ccdeaf49305da9e9..4e326c9e199b1a05cfdaedffd002b4bffc6ca3a9 100644 (file)
@@ -1182,6 +1182,15 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
   MD->addOperand(Unit);
 }
 
+extern "C" void
+LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) {
+  Module *M = unwrap(Mod);
+  for (Function &F : M->functions()) {
+    if (F.hasAvailableExternallyLinkage())
+      F.deleteBody();
+  }
+}
+
 #else
 
 extern "C" bool
@@ -1272,4 +1281,10 @@ extern "C" void
 LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) {
   report_fatal_error("ThinLTO not available");
 }
+
+extern "C" void
+LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) {
+  report_fatal_error("ThinLTO not available");
+}
+
 #endif // LLVM_VERSION_GE(4, 0)