From 9c373e3e5b688160e9be96582fd6877941a6a960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sun, 16 Jul 2023 10:44:32 +0200 Subject: [PATCH] Try to build LLVM without LTO --- src/tools/opt-dist/src/environment/linux.rs | 4 ++++ src/tools/opt-dist/src/environment/mod.rs | 2 ++ src/tools/opt-dist/src/environment/windows.rs | 4 ++++ src/tools/opt-dist/src/exec.rs | 10 ++++++++++ src/tools/opt-dist/src/main.rs | 12 +++++++++++- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/tools/opt-dist/src/environment/linux.rs b/src/tools/opt-dist/src/environment/linux.rs index d4c55c46f7ce8..c2a328b1dbcdb 100644 --- a/src/tools/opt-dist/src/environment/linux.rs +++ b/src/tools/opt-dist/src/environment/linux.rs @@ -41,6 +41,10 @@ impl Environment for LinuxEnvironment { true } + fn supports_shared_llvm(&self) -> bool { + true + } + fn executable_extension(&self) -> &'static str { "" } diff --git a/src/tools/opt-dist/src/environment/mod.rs b/src/tools/opt-dist/src/environment/mod.rs index f66b9ab41ead9..d28983d289c72 100644 --- a/src/tools/opt-dist/src/environment/mod.rs +++ b/src/tools/opt-dist/src/environment/mod.rs @@ -60,6 +60,8 @@ pub trait Environment { fn supports_bolt(&self) -> bool; + fn supports_shared_llvm(&self) -> bool; + /// What is the extension of binary executables in this environment? fn executable_extension(&self) -> &'static str; diff --git a/src/tools/opt-dist/src/environment/windows.rs b/src/tools/opt-dist/src/environment/windows.rs index 36f4c0f29cc4a..12a63cbb03c46 100644 --- a/src/tools/opt-dist/src/environment/windows.rs +++ b/src/tools/opt-dist/src/environment/windows.rs @@ -65,6 +65,10 @@ impl Environment for WindowsEnvironment { false } + fn supports_shared_llvm(&self) -> bool { + false + } + fn executable_extension(&self) -> &'static str { ".exe" } diff --git a/src/tools/opt-dist/src/exec.rs b/src/tools/opt-dist/src/exec.rs index d05ddbd4c0e3b..3777c7c971844 100644 --- a/src/tools/opt-dist/src/exec.rs +++ b/src/tools/opt-dist/src/exec.rs @@ -139,6 +139,16 @@ impl Bootstrap { self } + pub fn without_llvm_lto(mut self) -> Self { + self.cmd = self + .cmd + .arg("--set") + .arg("llvm.thin-lto=false") + .arg("--set") + .arg("llvm.link-shared=true"); + self + } + pub fn rustc_pgo_optimize(mut self, profile: &RustcPGOProfile) -> Self { self.cmd = self.cmd.arg("--rust-profile-use").arg(profile.0.as_str()); self diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 5e82430416b6b..db32cedf731e3 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -38,7 +38,17 @@ fn execute_pipeline( let rustc_profile_dir_root = env.opt_artifacts().join("rustc-pgo"); stage.section("Build PGO instrumented rustc and LLVM", |section| { - Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root).run(section) + let mut builder = Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root); + + if env.supports_shared_llvm() { + // This first LLVM that we build will be thrown away after this stage, and it + // doesn't really need LTO. Without LTO, it builds in ~1 minute thanks to sccache, + // with LTO it takes almost 10 minutes. It makes the followup Rustc PGO + // instrumented/optimized build a bit slower, but it seems to be worth it. + builder = builder.without_llvm_lto(); + } + + builder.run(section) })?; let profile = stage