diff --git a/config.toml.example b/config.toml.example index f12ff76284589..f22f4a5a97579 100644 --- a/config.toml.example +++ b/config.toml.example @@ -406,6 +406,13 @@ # Whether to verify generated LLVM IR #verify-llvm-ir = false +# Compile the compiler with a non-default ThinLTO import limit. This import +# limit controls the maximum size of functions imported by ThinLTO. Decreasing +# will make code compile faster at the expense of lower runtime performance. +# If `incremental` is set to true above, the import limit will default to 10 +# instead of LLVM's default of 100. +#thin-lto-import-instr-limit = 100 + # Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`, # generally only set for releases #remap-debuginfo = false diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a2dca66697d6d..f7d8daa75ecb5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1183,6 +1183,21 @@ impl<'a> Builder<'a> { rustflags.arg("-Cprefer-dynamic"); } + // When building incrementally we default to a lower ThinLTO import limit + // (unless explicitly specified otherwise). This will produce a somewhat + // slower code but give way better compile times. + { + let limit = match self.config.rust_thin_lto_import_instr_limit { + Some(limit) => Some(limit), + None if self.config.incremental => Some(10), + _ => None, + }; + + if let Some(limit) = limit { + rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit)); + } + } + Cargo { command: cargo, rustflags } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 0970a50bee47a..ed65a606ff525 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -108,6 +108,7 @@ pub struct Config { pub rust_dist_src: bool, pub rust_codegen_backends: Vec>, pub rust_verify_llvm_ir: bool, + pub rust_thin_lto_import_instr_limit: Option, pub rust_remap_debuginfo: bool, pub build: Interned, @@ -325,6 +326,7 @@ struct Rust { deny_warnings: Option, backtrace_on_ice: Option, verify_llvm_ir: Option, + thin_lto_import_instr_limit: Option, remap_debuginfo: Option, jemalloc: Option, test_compare_mode: Option, @@ -569,6 +571,7 @@ impl Config { set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir); + config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit; set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); if let Some(ref backends) = rust.codegen_backends {