Skip to content
Draft
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
10 changes: 5 additions & 5 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const REQUIRED_COMPONENTS: &[&str] =
fn detect_llvm_link() -> (&'static str, &'static str) {
// Force the link mode we want, preferring static by default, but
// possibly overridden by `configure --enable-llvm-link-shared`.
if tracked_env_var_os("LLVM_LINK_SHARED").is_some() {
("dylib", "--link-shared")
} else {
("static", "--link-static")
}
// if tracked_env_var_os("LLVM_LINK_SHARED").is_some() {
// ("dylib", "--link-shared")
// } else {
("static", "--link-static")
// }
}

// Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
Expand Down
21 changes: 11 additions & 10 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,16 +1262,17 @@ pub fn rustc_cargo(
// Since using LTO for optimizing dylibs is currently experimental,
// we need to pass -Zdylib-lto.
cargo.rustflag("-Zdylib-lto");
// Cargo by default passes `-Cembed-bitcode=no` and doesn't pass `-Clto` when
// compiling dylibs (and their dependencies), even when LTO is enabled for the
// crate. Therefore, we need to override `-Clto` and `-Cembed-bitcode` here.
let lto_type = match builder.config.rust_lto {
RustcLto::Thin => "thin",
RustcLto::Fat => "fat",
_ => unreachable!(),
};
cargo.rustflag(&format!("-Clto={lto_type}"));
cargo.rustflag("-Cembed-bitcode=yes");
// // Cargo by default passes `-Cembed-bitcode=no` and doesn't pass `-Clto` when
// // compiling dylibs (and their dependencies), even when LTO is enabled for the
// // crate. Therefore, we need to override `-Clto` and `-Cembed-bitcode` here.
// let lto_type = match builder.config.rust_lto {
// RustcLto::Thin => "thin",
// RustcLto::Fat => "fat",
// _ => unreachable!(),
// };
// cargo.rustflag(&format!("-Clto={lto_type}"));
// cargo.rustflag("-Cembed-bitcode=yes");
cargo.rustflag("-Clinker-plugin-lto");
}
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
RustcLto::Off => {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
// the link step) with each stage.
llvm_link_shared: Cell::new(
llvm_link_shared
.or((!llvm_from_ci && llvm_thin_lto.unwrap_or(false)).then_some(true)),
// .or((!llvm_from_ci && llvm_thin_lto.unwrap_or(false)).then_some(true)),
),
llvm_offload: llvm_offload.unwrap_or(false),
llvm_optimize: llvm_optimize.unwrap_or(true),
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ ENV RUST_CONFIGURE_ARGS="--enable-full-tools \
--set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
--set llvm.thin-lto=true \
--set llvm.link-shared=true \
--set llvm.ninja=false \
--set llvm.libzstd=true \
--set rust.jemalloc \
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eux

python3 ../x.py build --set rust.debug=true opt-dist

./build/$HOSTS/stage1-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \
python3 ../x.py dist \
--host $HOSTS --target $HOSTS \
--include-default-paths \
build-manifest \
Expand Down
6 changes: 3 additions & 3 deletions src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,6 @@ if [ -f /.dockerenv ]; then
docker cp checkout:/checkout/obj $objdir
fi

if isCI; then
cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}"
fi
#if isCI; then
# cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}"
#fi
74 changes: 38 additions & 36 deletions src/tools/opt-dist/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use anyhow::Context;
use camino::{Utf8Path, Utf8PathBuf};
use clap::Parser;
Expand Down Expand Up @@ -313,41 +315,41 @@ fn execute_pipeline(
// therefore the LLVM artifacts on disk are not "tainted" with BOLT instrumentation and they can be reused.
let libdir = env.build_artifacts().join("stage2").join("lib");
timer.section("Stage 3 (BOLT)", |stage| {
let llvm_profile = if env.build_llvm() {
stage.section("Build PGO optimized LLVM", |stage| {
Bootstrap::build(env)
.with_llvm_bolt_ldflags()
.llvm_pgo_optimize(llvm_pgo_profile.as_ref())
.avoid_rustc_rebuild()
.run(stage)
})?;

// The actual name will be something like libLLVM.so.18.1-rust-dev.
let llvm_lib = io::find_file_in_dir(&libdir, "libLLVM.so", "")?;

log::info!("Optimizing {llvm_lib} with BOLT");

// FIXME(kobzol): try gather profiles together, at once for LLVM and rustc
// Instrument the libraries and gather profiles
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)
})
})?;
print_free_disk_space()?;

// Now optimize the library with BOLT. The `libLLVM-XXX.so` library is actually hard-linked
// from several places, and this specific path (`llvm_lib`) will *not* be packaged into
// the final dist build. However, when BOLT optimizes an artifact, it does so *in-place*,
// therefore it will actually optimize all the hard links, which means that the final
// packaged `libLLVM.so` file *will* be BOLT optimized.
bolt_optimize(&llvm_lib, &llvm_profile, env)
.context("Could not optimize LLVM with BOLT")?;

Some(llvm_profile)
} else {
None
};
// let llvm_profile = if env.build_llvm() {
// stage.section("Build PGO optimized LLVM", |stage| {
// Bootstrap::build(env)
// .with_llvm_bolt_ldflags()
// .llvm_pgo_optimize(llvm_pgo_profile.as_ref())
// .avoid_rustc_rebuild()
// .run(stage)
// })?;
//
// // The actual name will be something like libLLVM.so.18.1-rust-dev.
// let llvm_lib = io::find_file_in_dir(&libdir, "libLLVM.so", "")?;
//
// log::info!("Optimizing {llvm_lib} with BOLT");
//
// // FIXME(kobzol): try gather profiles together, at once for LLVM and rustc
// // Instrument the libraries and gather profiles
// 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)
// })
// })?;
// print_free_disk_space()?;
//
// // Now optimize the library with BOLT. The `libLLVM-XXX.so` library is actually hard-linked
// // from several places, and this specific path (`llvm_lib`) will *not* be packaged into
// // the final dist build. However, when BOLT optimizes an artifact, it does so *in-place*,
// // therefore it will actually optimize all the hard links, which means that the final
// // packaged `libLLVM.so` file *will* be BOLT optimized.
// bolt_optimize(&llvm_lib, &llvm_profile, env)
// .context("Could not optimize LLVM with BOLT")?;
//
// Some(llvm_profile)
// } else {
// None
// };

let rustc_lib = io::find_file_in_dir(&libdir, "librustc_driver", ".so")?;

Expand All @@ -367,7 +369,7 @@ fn execute_pipeline(

// LLVM is not being cleared here. Either we built it and we want to use the BOLT-optimized LLVM, or we
// didn't build it, so we don't want to remove it.
Ok(vec![llvm_profile, Some(rustc_profile)])
Ok(vec![None, Some(rustc_profile)])
})?
} else {
vec![]
Expand Down
Loading