Skip to content

rustbuild: Compile rustc with ThinLTO #45400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2017
Merged
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
3 changes: 3 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
@@ -175,6 +175,9 @@ fn main() {
if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
cmd.arg("-C").arg(format!("codegen-units={}", s));
}
if stage != "0" && env::var("RUSTC_THINLTO").is_ok() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this skips stage0 as the current stage0 doesn't have ThinLTO (but that should be coming soon) but despite that the ThinLTO implementation on beta is probably too buggy to use.

cmd.arg("-Ccodegen-units=16").arg("-Zthinlto");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we respect the rust.codegen-units settings in config.toml here instead of hard-coding "16"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all intended to be pretty temporary, and for now I'd prefer to just keep this easy to remove later as I don't think anyone's really configuring codegen units anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton Ok, please add a FIXME.

(I did set the CGU to 3 😆)

}

// Emit save-analysis info.
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
14 changes: 12 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
@@ -471,8 +471,6 @@ impl<'a> Builder<'a> {
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
.env("RUSTC_REAL", self.rustc(compiler))
.env("RUSTC_STAGE", stage.to_string())
.env("RUSTC_CODEGEN_UNITS",
self.config.rust_codegen_units.to_string())
.env("RUSTC_DEBUG_ASSERTIONS",
self.config.rust_debug_assertions.to_string())
.env("RUSTC_SYSROOT", self.sysroot(compiler))
@@ -486,6 +484,10 @@ impl<'a> Builder<'a> {
})
.env("TEST_MIRI", self.config.test_miri.to_string());

if let Some(n) = self.config.rust_codegen_units {
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
}

if let Some(host_linker) = self.build.linker(compiler.host) {
cargo.env("RUSTC_HOST_LINKER", host_linker);
}
@@ -618,6 +620,14 @@ impl<'a> Builder<'a> {
// FIXME: cargo bench does not accept `--release`
if self.config.rust_optimize && cmd != "bench" {
cargo.arg("--release");

if mode != Mode::Libstd &&
self.config.rust_codegen_units.is_none() &&
self.build.is_rust_llvm(compiler.host)

{
cargo.env("RUSTC_THINLTO", "1");
}
}
if self.config.locked_deps {
cargo.arg("--locked");
7 changes: 3 additions & 4 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ pub struct Config {

// rust codegen options
pub rust_optimize: bool,
pub rust_codegen_units: u32,
pub rust_codegen_units: Option<u32>,
pub rust_debug_assertions: bool,
pub rust_debuginfo: bool,
pub rust_debuginfo_lines: bool,
@@ -307,7 +307,6 @@ impl Config {
config.submodules = true;
config.docs = true;
config.rust_rpath = true;
config.rust_codegen_units = 1;
config.channel = "dev".to_string();
config.codegen_tests = true;
config.ignore_git = false;
@@ -470,8 +469,8 @@ impl Config {
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

match rust.codegen_units {
Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
Some(n) => config.rust_codegen_units = n,
Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
Some(n) => config.rust_codegen_units = Some(n),
None => {}
}
}
3 changes: 3 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
@@ -1113,6 +1113,7 @@ impl<K, V, S> HashMap<K, V, S>
/// assert_eq!(map.get(&2), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Hash + Eq
@@ -2554,6 +2555,7 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
{
type Key = K;

#[inline]
fn get(&self, key: &Q) -> Option<&K> {
self.search(key).into_occupied_bucket().map(|bucket| bucket.into_refs().0)
}
@@ -2566,6 +2568,7 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
self.search_mut(key).into_occupied_bucket().map(|bucket| pop_internal(bucket).0)
}

#[inline]
fn replace(&mut self, key: K) -> Option<K> {
self.reserve(1);