Skip to content

Commit 4bea7b3

Browse files
committed
auto merge of #16367 : epdtry/rust/parallel-codegen, r=alexcrichton
This branch adds support for running LLVM optimization and codegen on different parts of a crate in parallel. Instead of translating the crate into a single LLVM compilation unit, `rustc` now distributes items in the crate among several compilation units, and spawns worker threads to optimize and codegen each compilation unit independently. This improves compile times on multicore machines, at the cost of worse performance in the compiled code. The intent is to speed up build times during development without sacrificing too much optimization. On the machine I tested this on, `librustc` build time with `-O` went from 265 seconds (master branch, single-threaded) to 115s (this branch, with 4 threads), a speedup of 2.3x. For comparison, the build time without `-O` was 90s (single-threaded). Bootstrapping `rustc` using 4 threads gets a 1.6x speedup over the default settings (870s vs. 1380s), and building `librustc` with the resulting stage2 compiler takes 1.3x as long as the master branch (44s vs. 55s, single threaded, ignoring time spent in LLVM codegen). The user-visible changes from this branch are two new codegen flags: * `-C codegen-units=N`: Distribute items across `N` compilation units. * `-C codegen-threads=N`: Spawn `N` worker threads for running optimization and codegen. (It is possible to set `codegen-threads` larger than `codegen-units`, but this is not very useful.) Internal changes to the compiler are described in detail on the individual commit messages. Note: The first commit on this branch is copied from #16359, which this branch depends on. r? @nick29581
2 parents da1395b + 6d2d47b commit 4bea7b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2954
-1164
lines changed

src/compiletest/runtest.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1577,10 +1577,6 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
15771577

15781578
// codegen tests (vs. clang)
15791579

1580-
fn make_o_name(config: &Config, testfile: &Path) -> Path {
1581-
output_base_name(config, testfile).with_extension("o")
1582-
}
1583-
15841580
fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
15851581
if suffix.len() == 0 {
15861582
(*p).clone()
@@ -1596,14 +1592,13 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
15961592
// FIXME (#9639): This needs to handle non-utf8 paths
15971593
let link_args = vec!("-L".to_string(),
15981594
aux_dir.as_str().unwrap().to_string());
1599-
let llvm_args = vec!("--emit=obj".to_string(),
1600-
"--crate-type=lib".to_string(),
1601-
"-C".to_string(),
1602-
"save-temps".to_string());
1595+
let llvm_args = vec!("--emit=bc,obj".to_string(),
1596+
"--crate-type=lib".to_string());
16031597
let args = make_compile_args(config,
16041598
props,
16051599
link_args.append(llvm_args.as_slice()),
1606-
|a, b| ThisFile(make_o_name(a, b)), testfile);
1600+
|a, b| ThisDirectory(output_base_name(a, b).dir_path()),
1601+
testfile);
16071602
compose_and_run_compiler(config, props, testfile, args, None)
16081603
}
16091604

0 commit comments

Comments
 (0)