Use BOLT in x64 dist CI to optimize LLVM

This commit is contained in:
Jakub Beránek 2022-10-02 09:44:04 +02:00
parent 72f4923979
commit cc475f5ef2
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
8 changed files with 158 additions and 7 deletions

View file

@ -16,6 +16,7 @@ use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
use crate::bolt::{instrument_with_bolt_inplace, optimize_library_with_bolt_inplace};
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::config::TargetSelection;
use crate::util::get_clang_cl_resource_dir;
@ -395,6 +396,12 @@ impl Step for Llvm {
if let Some(path) = builder.config.llvm_profile_use.as_ref() {
cfg.define("LLVM_PROFDATA_FILE", &path);
}
if builder.config.llvm_bolt_profile_generate
|| builder.config.llvm_bolt_profile_use.is_some()
{
// Relocations are required for BOLT to work.
ldflags.push_all("-Wl,-q");
}
// Disable zstd to avoid a dependency on libzstd.so.
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
@ -563,12 +570,34 @@ impl Step for Llvm {
}
}
// After LLVM is built, we modify (instrument or optimize) the libLLVM.so library file
// in place. This is fine, because currently we do not support incrementally rebuilding
// LLVM after a configuration change, so to rebuild it the build files have to be removed,
// which will also remove these modified files.
if builder.config.llvm_bolt_profile_generate {
instrument_with_bolt_inplace(&get_built_llvm_lib_path(&build_llvm_config));
}
if let Some(path) = &builder.config.llvm_bolt_profile_use {
optimize_library_with_bolt_inplace(
&get_built_llvm_lib_path(&build_llvm_config),
&Path::new(path),
);
}
t!(stamp.write());
build_llvm_config
}
}
/// Returns path to a built LLVM library (libLLVM.so).
/// Assumes that we have built LLVM into a single library file.
fn get_built_llvm_lib_path(llvm_config_path: &Path) -> PathBuf {
let mut cmd = Command::new(llvm_config_path);
cmd.arg("--libfiles");
PathBuf::from(output(&mut cmd).trim())
}
fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
if !builder.config.llvm_version_check {
return;