From 451abd311c90e0e94c8c364a282c472323528cf5 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 11 Aug 2021 13:17:21 -0400 Subject: PGO for LLVM builds on x86_64-unknown-linux-gnu in CI This shows up to 5% less instruction counts on multiple benchmarks, and up to 19% wins on the -j1 wall times for rustc self-compilation. We can afford to spend the extra cycles building LLVM essentially once more for the x86_64-unknown-linux-gnu CI build today. The builder finishes in around 50 minutes on average, and this adds just 10 more minutes. Given the sizeable improvements in compiler performance, this is definitely worth it. --- src/bootstrap/config.rs | 4 ++++ src/bootstrap/dist.rs | 14 ++++++++++---- src/bootstrap/flags.rs | 20 ++++++++++++++++++-- src/bootstrap/native.rs | 8 ++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index dd536cb7b02..5706b8f9e7c 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -143,6 +143,8 @@ pub struct Config { pub rust_new_symbol_mangling: bool, pub rust_profile_use: Option, pub rust_profile_generate: Option, + pub llvm_profile_use: Option, + pub llvm_profile_generate: bool, pub build: TargetSelection, pub hosts: Vec, @@ -605,6 +607,8 @@ impl Config { if let Some(value) = flags.deny_warnings { config.deny_warnings = value; } + config.llvm_profile_use = flags.llvm_profile_use; + config.llvm_profile_generate = flags.llvm_profile_generate; if config.dry_run { let dir = config.out.join("tmp-dry-run"); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 64075e18366..d7d511c1c92 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2157,10 +2157,16 @@ impl Step for ReproducibleArtifacts { } fn run(self, builder: &Builder<'_>) -> Self::Output { - let path = builder.config.rust_profile_use.as_ref()?; - + let mut added_anything = false; let tarball = Tarball::new(builder, "reproducible-artifacts", &self.target.triple); - tarball.add_file(path, ".", 0o644); - Some(tarball.generate()) + if let Some(path) = builder.config.rust_profile_use.as_ref() { + tarball.add_file(path, ".", 0o644); + added_anything = true; + } + if let Some(path) = builder.config.llvm_profile_use.as_ref() { + tarball.add_file(path, ".", 0o644); + added_anything = true; + } + if added_anything { Some(tarball.generate()) } else { None } } } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 80c33fa4d7c..2fddda74a28 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -71,6 +71,13 @@ pub struct Flags { pub rust_profile_use: Option, pub rust_profile_generate: Option, + + pub llvm_profile_use: Option, + // LLVM doesn't support a custom location for generating profile + // information. + // + // llvm_out/build/profiles/ is the location this writes to. + pub llvm_profile_generate: bool, } pub enum Subcommand { @@ -222,8 +229,15 @@ To learn more about a subcommand, run `./x.py -h`", VALUE overrides the skip-rebuild option in config.toml.", "VALUE", ); - opts.optopt("", "rust-profile-generate", "generate PGO profile with rustc build", "FORMAT"); - opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "FORMAT"); + opts.optopt( + "", + "rust-profile-generate", + "generate PGO profile with rustc build", + "PROFILE", + ); + opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE"); + opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc"); + opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE"); // We can't use getopt to parse the options until we have completed specifying which // options are valid, but under the current implementation, some options are conditional on @@ -687,6 +701,8 @@ Arguments: .expect("`color` should be `always`, `never`, or `auto`"), rust_profile_use: matches.opt_str("rust-profile-use"), rust_profile_generate: matches.opt_str("rust-profile-generate"), + llvm_profile_use: matches.opt_str("llvm-profile-use"), + llvm_profile_generate: matches.opt_present("llvm-profile-generate"), } } } diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index d1397394be7..2172b01706d 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -189,6 +189,14 @@ impl Step for Llvm { .define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap()) .define("LLVM_DEFAULT_TARGET_TRIPLE", target_native); + if builder.config.llvm_profile_generate { + cfg.define("LLVM_BUILD_INSTRUMENTED", "IR"); + cfg.define("LLVM_BUILD_RUNTIME", "No"); + } + if let Some(path) = builder.config.llvm_profile_use.as_ref() { + cfg.define("LLVM_PROFDATA_FILE", &path); + } + if target != "aarch64-apple-darwin" && !target.contains("windows") { cfg.define("LLVM_ENABLE_ZLIB", "ON"); } else { -- cgit 1.4.1-3-g733a5 From 1ea8d93c0ca5168e7f434d87e19af337b83157e4 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 25 Aug 2021 14:33:23 -0400 Subject: Bump download-ci-llvm stamp This will ensure the optimized LLVM is used for local builds after rebasing immediately, rather than needing to wait for a future LLVM bump. --- src/bootstrap/download-ci-llvm-stamp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index fb5b058cb4d..19e5fffcc2d 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/80932 +Last change is for: https://github.com/rust-lang/rust/pull/88069 -- cgit 1.4.1-3-g733a5