Skip to content

Commit 0be1152

Browse files
committed
Auto merge of #113779 - Kobzol:try-build-no-lto, r=Mark-Simulacrum
Build the first LLVM without LTO in try builds Currently, we perform three LLVM builds in the Linux x64 dist builder, which is used for `try` builds: 1) "Normal" LLVM - takes ~5s to compile thanks to `sccache`, but ~8 minutes to link because of ThinLTO 2) PGO instrumented LLVM - same timings as 1) 3) PGO optimized LLVM - takes about 20 minutes to build When I tried to disable LTO for build 1), it suddenly takes only about a minute to build, because the linking step is much faster. The first LLVM doesn't really need LTO all that much. Without it, it will be a bit slower to build `rustc` in two subsequent steps, but it seems that the ~7 minutes saved on linking it do win that back. Btw, we can't use the host LLVM for build 1), because this LLVM then builds `rustc` in PGO instrumented mode, and we need the same compiler when later PGO optimizing `rustc`. And we want to use our in-house LLVM for that I think.
2 parents 0eb5efc + 9c373e3 commit 0be1152

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/tools/opt-dist/src/environment/linux.rs

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl Environment for LinuxEnvironment {
4141
true
4242
}
4343

44+
fn supports_shared_llvm(&self) -> bool {
45+
true
46+
}
47+
4448
fn executable_extension(&self) -> &'static str {
4549
""
4650
}

src/tools/opt-dist/src/environment/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub trait Environment {
6060

6161
fn supports_bolt(&self) -> bool;
6262

63+
fn supports_shared_llvm(&self) -> bool;
64+
6365
/// What is the extension of binary executables in this environment?
6466
fn executable_extension(&self) -> &'static str;
6567

src/tools/opt-dist/src/environment/windows.rs

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl Environment for WindowsEnvironment {
6565
false
6666
}
6767

68+
fn supports_shared_llvm(&self) -> bool {
69+
false
70+
}
71+
6872
fn executable_extension(&self) -> &'static str {
6973
".exe"
7074
}

src/tools/opt-dist/src/exec.rs

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ impl Bootstrap {
139139
self
140140
}
141141

142+
pub fn without_llvm_lto(mut self) -> Self {
143+
self.cmd = self
144+
.cmd
145+
.arg("--set")
146+
.arg("llvm.thin-lto=false")
147+
.arg("--set")
148+
.arg("llvm.link-shared=true");
149+
self
150+
}
151+
142152
pub fn rustc_pgo_optimize(mut self, profile: &RustcPGOProfile) -> Self {
143153
self.cmd = self.cmd.arg("--rust-profile-use").arg(profile.0.as_str());
144154
self

src/tools/opt-dist/src/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ fn execute_pipeline(
4040
let rustc_profile_dir_root = env.opt_artifacts().join("rustc-pgo");
4141

4242
stage.section("Build PGO instrumented rustc and LLVM", |section| {
43-
Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root).run(section)
43+
let mut builder = Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root);
44+
45+
if env.supports_shared_llvm() {
46+
// This first LLVM that we build will be thrown away after this stage, and it
47+
// doesn't really need LTO. Without LTO, it builds in ~1 minute thanks to sccache,
48+
// with LTO it takes almost 10 minutes. It makes the followup Rustc PGO
49+
// instrumented/optimized build a bit slower, but it seems to be worth it.
50+
builder = builder.without_llvm_lto();
51+
}
52+
53+
builder.run(section)
4454
})?;
4555

4656
let profile = stage

0 commit comments

Comments
 (0)