Skip to content

Commit e0efc14

Browse files
committed
[WIP] Turn off PGO and BOLT
1 parent 965f383 commit e0efc14

File tree

3 files changed

+111
-105
lines changed

3 files changed

+111
-105
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ jobs:
529529
try:
530530
name: "try - ${{ matrix.name }}"
531531
env:
532-
DIST_TRY_BUILD: 1
533532
CI_JOB_NAME: "${{ matrix.name }}"
534533
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
535534
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"

src/ci/github-actions/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ jobs:
689689
<<: *base-ci-job
690690
name: try - ${{ matrix.name }}
691691
env:
692-
DIST_TRY_BUILD: 1
692+
# DIST_TRY_BUILD: 1
693693
<<: [*shared-ci-variables, *prod-variables]
694694
if: github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'
695695
strategy:

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

+110-103
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unused)]
12
use crate::bolt::{bolt_optimize, with_bolt_instrumented};
23
use anyhow::Context;
34
use log::LevelFilter;
@@ -7,7 +8,9 @@ use crate::environment::{create_environment, Environment};
78
use crate::exec::Bootstrap;
89
use crate::tests::run_tests;
910
use crate::timer::Timer;
10-
use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles};
11+
use crate::training::{
12+
gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles, LlvmBoltProfile,
13+
};
1114
use crate::utils::io::reset_directory;
1215
use crate::utils::{
1316
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
@@ -39,112 +42,116 @@ fn execute_pipeline(
3942
// Stage 1: Build PGO instrumented rustc
4043
// We use a normal build of LLVM, because gathering PGO profiles for LLVM and `rustc` at the
4144
// same time can cause issues, because the host and in-tree LLVM versions can diverge.
42-
let rustc_pgo_profile = timer.section("Stage 1 (Rustc PGO)", |stage| {
43-
let rustc_profile_dir_root = env.opt_artifacts().join("rustc-pgo");
44-
45-
stage.section("Build PGO instrumented rustc and LLVM", |section| {
46-
let mut builder = Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root);
47-
48-
if env.supports_shared_llvm() {
49-
// This first LLVM that we build will be thrown away after this stage, and it
50-
// doesn't really need LTO. Without LTO, it builds in ~1 minute thanks to sccache,
51-
// with LTO it takes almost 10 minutes. It makes the followup Rustc PGO
52-
// instrumented/optimized build a bit slower, but it seems to be worth it.
53-
builder = builder.without_llvm_lto();
54-
}
55-
56-
builder.run(section)
57-
})?;
58-
59-
let profile = stage
60-
.section("Gather profiles", |_| gather_rustc_profiles(env, &rustc_profile_dir_root))?;
61-
print_free_disk_space()?;
62-
63-
stage.section("Build PGO optimized rustc", |section| {
64-
Bootstrap::build(env).rustc_pgo_optimize(&profile).run(section)
65-
})?;
66-
67-
Ok(profile)
68-
})?;
45+
// let rustc_pgo_profile = timer.section("Stage 1 (Rustc PGO)", |stage| {
46+
// let rustc_profile_dir_root = env.opt_artifacts().join("rustc-pgo");
47+
//
48+
// stage.section("Build PGO instrumented rustc and LLVM", |section| {
49+
// let mut builder = Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root);
50+
//
51+
// if env.supports_shared_llvm() {
52+
// // This first LLVM that we build will be thrown away after this stage, and it
53+
// // doesn't really need LTO. Without LTO, it builds in ~1 minute thanks to sccache,
54+
// // with LTO it takes almost 10 minutes. It makes the followup Rustc PGO
55+
// // instrumented/optimized build a bit slower, but it seems to be worth it.
56+
// builder = builder.without_llvm_lto();
57+
// }
58+
//
59+
// builder.run(section)
60+
// })?;
61+
//
62+
// let profile = stage
63+
// .section("Gather profiles", |_| gather_rustc_profiles(env, &rustc_profile_dir_root))?;
64+
// print_free_disk_space()?;
65+
//
66+
// stage.section("Build PGO optimized rustc", |section| {
67+
// Bootstrap::build(env).rustc_pgo_optimize(&profile).run(section)
68+
// })?;
69+
//
70+
// Ok(profile)
71+
// })?;
6972

7073
// Stage 2: Gather LLVM PGO profiles
7174
// Here we build a PGO instrumented LLVM, reusing the previously PGO optimized rustc.
7275
// Then we use the instrumented LLVM to gather LLVM PGO profiles.
73-
let llvm_pgo_profile = timer.section("Stage 2 (LLVM PGO)", |stage| {
74-
// Remove the previous, uninstrumented build of LLVM.
75-
clear_llvm_files(env)?;
76-
77-
let llvm_profile_dir_root = env.opt_artifacts().join("llvm-pgo");
78-
79-
stage.section("Build PGO instrumented LLVM", |section| {
80-
Bootstrap::build(env)
81-
.llvm_pgo_instrument(&llvm_profile_dir_root)
82-
.avoid_rustc_rebuild()
83-
.run(section)
84-
})?;
85-
86-
let profile = stage
87-
.section("Gather profiles", |_| gather_llvm_profiles(env, &llvm_profile_dir_root))?;
88-
89-
print_free_disk_space()?;
90-
91-
// Proactively delete the instrumented artifacts, to avoid using them by accident in
92-
// follow-up stages.
93-
clear_llvm_files(env)?;
94-
95-
Ok(profile)
96-
})?;
97-
98-
let llvm_bolt_profile = if env.supports_bolt() {
99-
// Stage 3: Build BOLT instrumented LLVM
100-
// We build a PGO optimized LLVM in this step, then instrument it with BOLT and gather BOLT profiles.
101-
// Note that we don't remove LLVM artifacts after this step, so that they are reused in the final dist build.
102-
// BOLT instrumentation is performed "on-the-fly" when the LLVM library is copied to the sysroot of rustc,
103-
// therefore the LLVM artifacts on disk are not "tainted" with BOLT instrumentation and they can be reused.
104-
timer.section("Stage 3 (LLVM BOLT)", |stage| {
105-
stage.section("Build PGO optimized LLVM", |stage| {
106-
Bootstrap::build(env)
107-
.with_llvm_bolt_ldflags()
108-
.llvm_pgo_optimize(&llvm_pgo_profile)
109-
.avoid_rustc_rebuild()
110-
.run(stage)
111-
})?;
112-
113-
// Find the path to the `libLLVM.so` file
114-
let llvm_lib = io::find_file_in_dir(
115-
&env.build_artifacts().join("stage2").join("lib"),
116-
"libLLVM",
117-
".so",
118-
)?;
119-
120-
// Instrument it and gather profiles
121-
let profile = with_bolt_instrumented(&llvm_lib, || {
122-
stage.section("Gather profiles", |_| gather_llvm_bolt_profiles(env))
123-
})?;
124-
print_free_disk_space()?;
125-
126-
// Now optimize the library with BOLT. The `libLLVM-XXX.so` library is actually hard-linked
127-
// from several places, and this specific path (`llvm_lib`) will *not* be packaged into
128-
// the final dist build. However, when BOLT optimizes an artifact, it does so *in-place*,
129-
// therefore it will actually optimize all the hard links, which means that the final
130-
// packaged `libLLVM.so` file *will* be BOLT optimized.
131-
bolt_optimize(&llvm_lib, &profile).context("Could not optimize LLVM with BOLT")?;
132-
133-
// LLVM is not being cleared here, we want to use the BOLT-optimized LLVM
134-
Ok(Some(profile))
135-
})?
136-
} else {
137-
None
138-
};
139-
140-
let mut dist = Bootstrap::dist(env, &dist_args)
141-
.llvm_pgo_optimize(&llvm_pgo_profile)
142-
.rustc_pgo_optimize(&rustc_pgo_profile)
143-
.avoid_rustc_rebuild();
144-
145-
if let Some(llvm_bolt_profile) = llvm_bolt_profile {
146-
dist = dist.with_bolt_profile(llvm_bolt_profile);
147-
}
76+
// let llvm_pgo_profile = timer.section("Stage 2 (LLVM PGO)", |stage| {
77+
// Remove the previous, uninstrumented build of LLVM.
78+
// clear_llvm_files(env)?;
79+
//
80+
// let llvm_profile_dir_root = env.opt_artifacts().join("llvm-pgo");
81+
//
82+
// stage.section("Build PGO instrumented LLVM", |section| {
83+
// Bootstrap::build(env)
84+
// .llvm_pgo_instrument(&llvm_profile_dir_root)
85+
// .avoid_rustc_rebuild()
86+
// .run(section)
87+
// })?;
88+
//
89+
// let profile = stage
90+
// .section("Gather profiles", |_| gather_llvm_profiles(env, &llvm_profile_dir_root))?;
91+
//
92+
// print_free_disk_space()?;
93+
94+
// Proactively delete the instrumented artifacts, to avoid using them by accident in
95+
// follow-up stages.
96+
// clear_llvm_files(env)?;
97+
//
98+
// Ok(profile)
99+
// })?;
100+
101+
// let llvm_bolt_profile = if env.supports_bolt() {
102+
// // Stage 3: Build BOLT instrumented LLVM
103+
// // We build a PGO optimized LLVM in this step, then instrument it with BOLT and gather BOLT profiles.
104+
// // Note that we don't remove LLVM artifacts after this step, so that they are reused in the final dist build.
105+
// // BOLT instrumentation is performed "on-the-fly" when the LLVM library is copied to the sysroot of rustc,
106+
// // therefore the LLVM artifacts on disk are not "tainted" with BOLT instrumentation and they can be reused.
107+
// timer.section("Stage 3 (LLVM BOLT)", |stage| {
108+
// stage.section("Build PGO optimized LLVM", |stage| {
109+
// Bootstrap::build(env)
110+
// .with_llvm_bolt_ldflags()
111+
// .llvm_pgo_optimize(&llvm_pgo_profile)
112+
// .avoid_rustc_rebuild()
113+
// .run(stage)
114+
// })?;
115+
//
116+
// // Find the path to the `libLLVM.so` file
117+
// let llvm_lib = io::find_file_in_dir(
118+
// &env.build_artifacts().join("stage2").join("lib"),
119+
// "libLLVM",
120+
// ".so",
121+
// )?;
122+
//
123+
// // Instrument it and gather profiles
124+
// let profile = with_bolt_instrumented(&llvm_lib, || {
125+
// stage.section("Gather profiles", |_| gather_llvm_bolt_profiles(env))
126+
// })?;
127+
// print_free_disk_space()?;
128+
//
129+
// // Now optimize the library with BOLT. The `libLLVM-XXX.so` library is actually hard-linked
130+
// // from several places, and this specific path (`llvm_lib`) will *not* be packaged into
131+
// // the final dist build. However, when BOLT optimizes an artifact, it does so *in-place*,
132+
// // therefore it will actually optimize all the hard links, which means that the final
133+
// // packaged `libLLVM.so` file *will* be BOLT optimized.
134+
// bolt_optimize(&llvm_lib, &profile).context("Could not optimize LLVM with BOLT")?;
135+
//
136+
// // LLVM is not being cleared here, we want to use the BOLT-optimized LLVM
137+
// Ok(Some(profile))
138+
// })?
139+
// } else {
140+
// None
141+
// };
142+
//
143+
let mut dist = Bootstrap::dist(env, &dist_args);
144+
// .llvm_pgo_optimize(&llvm_pgo_profile)
145+
// .rustc_pgo_optimize(&rustc_pgo_profile)
146+
// .avoid_rustc_rebuild();
147+
148+
// if let Some(llvm_bolt_profile) = llvm_bolt_profile {
149+
// dist = dist.with_bolt_profile(llvm_bolt_profile);
150+
// }
151+
152+
// WIP
153+
std::fs::write("foo.txt", "bar")?;
154+
dist = dist.with_bolt_profile(LlvmBoltProfile("foo.txt".into()));
148155

149156
// Final stage: Assemble the dist artifacts
150157
// The previous PGO optimized rustc build and PGO optimized LLVM builds should be reused.

0 commit comments

Comments
 (0)