Skip to content

Commit b5361d0

Browse files
committed
rustc: Set release mode cgus to 16 by default
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 rust-lang#45320
1 parent de38f49 commit b5361d0

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/librustc/session/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,7 @@ impl Session {
785785
// As a result 16 was chosen here! Mostly because it was a power of 2
786786
// and most benchmarks agreed it was roughly a local optimum. Not very
787787
// scientific.
788-
match self.opts.optimize {
789-
config::OptLevel::No => 16,
790-
_ => 1, // FIXME(#46346) this should be 16
791-
}
788+
16
792789
}
793790

794791
/// Returns whether ThinLTO is enabled for this compilation

src/librustc_llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1732,4 +1732,5 @@ extern "C" {
17321732
CU1: *mut *mut c_void,
17331733
CU2: *mut *mut c_void);
17341734
pub fn LLVMRustThinLTOPatchDICompileUnit(M: ModuleRef, CU: *mut c_void);
1735+
pub fn LLVMRustThinLTORemoveAvailableExternally(M: ModuleRef);
17351736
}

src/librustc_trans/back/lto.rs

+15
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,21 @@ impl ThinModule {
726726
run_pass_manager(cgcx, tm, llmod, config, true);
727727
cgcx.save_temp_bitcode(&mtrans, "thin-lto-after-pm");
728728
timeline.record("thin-done");
729+
730+
// FIXME: this is a hack around a bug in LLVM right now. Discovered in
731+
// #46910 it was found out that on 32-bit MSVC LLVM will hit a codegen
732+
// error if there's an available_externally function in the LLVM module.
733+
// Typically we don't actually use these functions but ThinLTO makes
734+
// heavy use of them when inlining across modules.
735+
//
736+
// Tracked upstream at https://bugs.llvm.org/show_bug.cgi?id=35736 this
737+
// function call (and its definition on the C++ side of things)
738+
// shouldn't be necessary eventually and we can safetly delete these few
739+
// lines.
740+
llvm::LLVMRustThinLTORemoveAvailableExternally(llmod);
741+
cgcx.save_temp_bitcode(&mtrans, "thin-lto-after-rm-ae");
742+
timeline.record("no-ae");
743+
729744
Ok(mtrans)
730745
}
731746
}

src/rustllvm/PassWrapper.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,15 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
11821182
MD->addOperand(Unit);
11831183
}
11841184

1185+
extern "C" void
1186+
LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) {
1187+
Module *M = unwrap(Mod);
1188+
for (Function &F : M->functions()) {
1189+
if (F.hasAvailableExternallyLinkage())
1190+
F.deleteBody();
1191+
}
1192+
}
1193+
11851194
#else
11861195

11871196
extern "C" bool
@@ -1272,4 +1281,10 @@ extern "C" void
12721281
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) {
12731282
report_fatal_error("ThinLTO not available");
12741283
}
1284+
1285+
extern "C" void
1286+
LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) {
1287+
report_fatal_error("ThinLTO not available");
1288+
}
1289+
12751290
#endif // LLVM_VERSION_GE(4, 0)

0 commit comments

Comments
 (0)