rustc: Default 32 codegen units at O0

This commit changes the default of rustc to use 32 codegen units when compiling
in debug mode, typically an opt-level=0 compilation. Since their inception
codegen units have matured quite a bit, gaining features such as:

* Parallel translation and codegen enabling codegen units to get worked on even
  more quickly.
* Deterministic and reliable partitioning through the same infrastructure as
  incremental compilation.
* Global rate limiting through the `jobserver` crate to avoid overloading the
  system.

The largest benefit of codegen units has forever been faster compilation through
parallel processing of modules on the LLVM side of things, using all the cores
available on build machines that typically have many available. Some downsides
have been fixed through the features above, but the major downside remaining is
that using codegen units reduces opportunities for inlining and optimization.
This, however, doesn't matter much during debug builds!

In this commit the default number of codegen units for debug builds has been
raised from 1 to 32. This should enable most `cargo build` compiles that are
bottlenecked on translation and/or code generation to immediately see speedups
through parallelization on available cores.

Work is being done to *always* enable multiple codegen units (and therefore
parallel codegen) but it requires #44841 at least to be landed and stabilized,
but stay tuned if you're interested in that aspect!
This commit is contained in:
Alex Crichton 2017-09-25 12:26:25 -07:00
parent 4b8bf391fd
commit 9e35b797b1
6 changed files with 97 additions and 48 deletions

View file

@ -1,26 +1,28 @@
-include ../tools.mk
LOG = $(TMPDIR)/log.txt
all:
#Option taking a number
$(RUSTC) -C codegen-units dummy.rs 2>&1 | \
grep 'codegen option `codegen-units` requires a number'
$(RUSTC) -C codegen-units= dummy.rs 2>&1 | \
grep 'incorrect value `` for codegen option `codegen-units` - a number was expected'
$(RUSTC) -C codegen-units=foo dummy.rs 2>&1 | \
grep 'incorrect value `foo` for codegen option `codegen-units` - a number was expected'
$(RUSTC) -C codegen-units dummy.rs 2>&1 | tee $(LOG)
grep 'codegen option `codegen-units` requires a number' $(LOG)
$(RUSTC) -C codegen-units= dummy.rs 2>&1 | tee $(LOG)
grep 'incorrect value `` for codegen option `codegen-units` - a number was expected' $(LOG)
$(RUSTC) -C codegen-units=foo dummy.rs 2>&1 | tee $(LOG)
grep 'incorrect value `foo` for codegen option `codegen-units` - a number was expected' $(LOG)
$(RUSTC) -C codegen-units=1 dummy.rs
#Option taking a string
$(RUSTC) -C extra-filename dummy.rs 2>&1 | \
grep 'codegen option `extra-filename` requires a string'
$(RUSTC) -C extra-filename dummy.rs 2>&1 | tee $(LOG)
grep 'codegen option `extra-filename` requires a string' $(LOG)
$(RUSTC) -C extra-filename= dummy.rs 2>&1
$(RUSTC) -C extra-filename=foo dummy.rs 2>&1
#Option taking no argument
$(RUSTC) -C lto= dummy.rs 2>&1 | \
grep 'codegen option `lto` takes no value'
$(RUSTC) -C lto=1 dummy.rs 2>&1 | \
grep 'codegen option `lto` takes no value'
$(RUSTC) -C lto=foo dummy.rs 2>&1 | \
grep 'codegen option `lto` takes no value'
$(RUSTC) -C lto= dummy.rs 2>&1 | tee $(LOG)
grep 'codegen option `lto` takes no value' $(LOG)
$(RUSTC) -C lto=1 dummy.rs 2>&1 | tee $(LOG)
grep 'codegen option `lto` takes no value' $(LOG)
$(RUSTC) -C lto=foo dummy.rs 2>&1 | tee $(LOG)
grep 'codegen option `lto` takes no value' $(LOG)
$(RUSTC) -C lto dummy.rs
# Should not link dead code...

View file

@ -77,6 +77,7 @@ fn main() {
.split(' ').map(|s| s.to_string()).collect();
args.push("--out-dir".to_string());
args.push(env::var("TMPDIR").unwrap());
args.push("-Ccodegen-units=1".to_string());
let (result, _) = rustc_driver::run_compiler(
&args, &mut JitCalls, Some(box JitLoader), None);