Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/tools/opt-dist/src/bolt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::utils::io::copy_file;
/// Instruments an artifact at the given `path` (in-place) with BOLT and then calls `func`.
/// After this function finishes, the original file will be restored.
pub fn with_bolt_instrumented<F: FnOnce(&Utf8Path) -> anyhow::Result<R>, R>(
env: &Environment,
path: &Utf8Path,
func: F,
) -> anyhow::Result<R> {
Expand All @@ -26,7 +27,7 @@ pub fn with_bolt_instrumented<F: FnOnce(&Utf8Path) -> anyhow::Result<R>, R>(
let profile_prefix = Utf8Path::from_path(&profile_prefix).unwrap();

// Instrument the original file with BOLT, saving the result into `instrumented_path`
cmd(&["llvm-bolt"])
cmd(&[env.llvm_bolt().as_str()])
.arg("-instrument")
.arg(path)
.arg(&format!("--instrumentation-file={profile_prefix}"))
Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn bolt_optimize(
let split_strategy =
if env.host_tuple().starts_with("aarch64") { "profile2" } else { "cdsplit" };

cmd(&["llvm-bolt"])
cmd(&[env.llvm_bolt().as_str()])
.arg(temp_path.display())
.arg("-data")
.arg(&profile.0)
Expand Down
8 changes: 8 additions & 0 deletions src/tools/opt-dist/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ impl Environment {
pub fn stage0(&self) -> Utf8PathBuf {
self.stage0_root.clone().unwrap_or_else(|| self.build_artifacts().join("stage0"))
}

pub fn llvm_bolt(&self) -> Utf8PathBuf {
self.host_llvm_dir().join(format!("bin/llvm-bolt{}", executable_extension()))
}

pub fn merge_fdata(&self) -> Utf8PathBuf {
self.host_llvm_dir().join(format!("bin/merge-fdata{}", executable_extension()))
}
}

/// What is the extension of binary executables on this platform?
Expand Down
4 changes: 2 additions & 2 deletions src/tools/opt-dist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn execute_pipeline(

// FIXME(kobzol): try gather profiles together, at once for LLVM and rustc
// Instrument the libraries and gather profiles
let llvm_profile = with_bolt_instrumented(&llvm_lib, |llvm_profile_dir| {
let llvm_profile = with_bolt_instrumented(env, &llvm_lib, |llvm_profile_dir| {
stage.section("Gather profiles", |_| {
gather_bolt_profiles(env, "LLVM", llvm_benchmarks(env), llvm_profile_dir)
})
Expand All @@ -354,7 +354,7 @@ fn execute_pipeline(
log::info!("Optimizing {rustc_lib} with BOLT");

// Instrument it and gather profiles
let rustc_profile = with_bolt_instrumented(&rustc_lib, |rustc_profile_dir| {
let rustc_profile = with_bolt_instrumented(env, &rustc_lib, |rustc_profile_dir| {
stage.section("Gather profiles", |_| {
gather_bolt_profiles(env, "rustc", rustc_benchmarks(env), rustc_profile_dir)
})
Expand Down
3 changes: 2 additions & 1 deletion src/tools/opt-dist/src/training.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ pub fn gather_bolt_profiles(
let profiles: Vec<_> =
glob::glob(&format!("{profile_prefix}*"))?.collect::<Result<Vec<_>, _>>()?;

let mut merge_args = vec!["merge-fdata"];
let fdata = env.merge_fdata();
let mut merge_args = vec![fdata.as_str()];
merge_args.extend(profiles.iter().map(|p| p.to_str().unwrap()));

with_log_group("Merging BOLT profiles", || {
Expand Down
Loading