Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f79ba85
clean up E0185 explanation
GuillaumeGomez Jan 9, 2020
f45758c
Compile some CGUs in parallel at the start of codegen
Zoxc Jan 5, 2020
69bacd0
Precompile CGUs while the main thread has the implicit job server token
Zoxc Jan 8, 2020
54f8601
Fix ICE #68058
JohnTitor Jan 9, 2020
a59abfa
Revert const_eval call to use const_eval_raw to avoid const validatio…
spastorino Dec 31, 2019
1688719
Promote `Ref`s to constants instead of static
spastorino Nov 22, 2019
2508f17
Promote `Repeat`s to constants instead of statics
spastorino Dec 10, 2019
32fe477
Promote `Argument`s to constants instead of statics
spastorino Dec 11, 2019
6aa4b5a
Add promoted_operand closure to reuse code across different
spastorino Dec 11, 2019
6f2c702
Remove StaticKind::Promoted
spastorino Dec 11, 2019
b63597d
Remove StaticKind
spastorino Dec 11, 2019
fb2f0ec
Use if let instead of match with one meaningful arm
spastorino Dec 11, 2019
9e70c47
Remove unused param_env parameter
spastorino Dec 11, 2019
fd5aa32
Remove Static from PlaceBase
spastorino Dec 11, 2019
5d9b399
Remove PlaceBase enum and make Place base field be local: Local
spastorino Dec 11, 2019
a9de4f1
Fix print const on librustdoc
spastorino Dec 13, 2019
7f3459a
No need to use local.into here
spastorino Dec 13, 2019
a5715a3
Use re_erased instead of re_static
spastorino Dec 19, 2019
8533caa
Make Place Copy
spastorino Dec 19, 2019
1565612
Add span_bug that notes that shuffle indices must be constant
spastorino Dec 19, 2019
36b1756
Do not store lint_root
spastorino Jan 1, 2020
6e1bbff
Promoteds also need param envs.
oli-obk Jan 8, 2020
ecd5852
Errors in promoteds may only cause lints not hard errors
oli-obk Jan 8, 2020
050146f
Add regression tests for promotion mir expansion
oli-obk Jan 9, 2020
43313d5
Remove an outdated comment
oli-obk Jan 9, 2020
a5d8ab7
Rebase fallout
oli-obk Jan 9, 2020
c899f67
Improve E0185 wording
GuillaumeGomez Jan 10, 2020
4fadb50
Update E0185.md
Dylan-DPC Jan 10, 2020
f3ce144
Run codegen unit partitioning and assert_symbols_are_distinct in para…
Zoxc Dec 31, 2019
4beeadd
Fix a deadlock
Zoxc Dec 31, 2019
51a73eb
Avoid a duplicate hash map lookup
Zoxc Dec 31, 2019
4a64716
Add a comment
Zoxc Jan 10, 2020
48cad46
Fix test not to depend on environment
JohnTitor Jan 11, 2020
8f1df30
Only require `allow_internal_unstable` for stable `const fn`
ecstatic-morse Jan 11, 2020
09b5c85
Remove unnecessary `const_fn` feature gates
ecstatic-morse Jan 11, 2020
1d418a1
Test that stable `const fn` requires `allow_internal_unstable`
ecstatic-morse Jan 11, 2020
a5f4239
Rename Result::as_deref_ok to as_deref
tesuji Jan 6, 2020
c2c2d3b
Update test after renaming Result::as_deref
tesuji Jan 7, 2020
fc30825
Expand comment
ecstatic-morse Jan 11, 2020
883932c
Ban `...X` pats, harden tests, and improve diagnostics.
Centril Jan 11, 2020
8e35c4f
feature_gate: Remove `GateStrength`
petrochenkov Jan 8, 2020
020c465
Rollup merge of #67000 - spastorino:remove-promoted-from-place, r=oli…
Centril Jan 11, 2020
f5077d7
Rollup merge of #67756 - Zoxc:collector-tweaks, r=Mark-Simulacrum
Centril Jan 11, 2020
72bf6f4
Rollup merge of #67889 - Zoxc:parallel-cgus, r=michaelwoerister
Centril Jan 11, 2020
1691ee2
Rollup merge of #67930 - lzutao:result-as_deref, r=dtolnay
Centril Jan 11, 2020
71a719c
Rollup merge of #68018 - petrochenkov:nosoft, r=Centril
Centril Jan 11, 2020
b2027df
Rollup merge of #68070 - GuillaumeGomez:clean-up-e0185, r=Dylan-DPC
Centril Jan 11, 2020
544c981
Rollup merge of #68072 - JohnTitor:fix-macro-ice, r=petrochenkov
Centril Jan 11, 2020
b00abbe
Rollup merge of #68114 - ecstatic-morse:fix-feature-gating, r=Centril
Centril Jan 11, 2020
b8f6eb9
Rollup merge of #68120 - Centril:ban-range-to-dotdotdot, r=oli-obk
Centril Jan 11, 2020
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
Prev Previous commit
Next Next commit
Precompile CGUs while the main thread has the implicit job server token
  • Loading branch information
Zoxc committed Jan 9, 2020
commit 69bacd002b432292f5b0fdf76b4fad1432473f36
101 changes: 63 additions & 38 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,54 +609,75 @@ pub fn codegen_crate<B: ExtraBackendMethods>(

let total_codegen_time = Lock::new(Duration::new(0, 0));

let cgu_reuse: Vec<_> = tcx.sess.time("find cgu reuse", || {
codegen_units.iter().map(|cgu| determine_cgu_reuse(tcx, &cgu)).collect()
});

let mut cgus: FxHashMap<usize, _> = if cfg!(parallel_compiler) {
tcx.sess.time("compile first CGUs", || {
// Try to find one CGU to compile per thread.
let cgus: Vec<_> = cgu_reuse
.iter()
.enumerate()
.filter(|&(_, reuse)| reuse == &CguReuse::No)
.take(tcx.sess.threads())
.collect();

// Compile the found CGUs in parallel.
par_iter(cgus)
.map(|(i, _)| {
let start_time = Instant::now();
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
let mut time = total_codegen_time.lock();
*time += start_time.elapsed();
(i, module)
})
.collect()
})
} else {
FxHashMap::default()
// The non-parallel compiler can only translate codegen units to LLVM IR
// on a single thread, leading to a staircase effect where the N LLVM
// threads have to wait on the single codegen threads to generate work
// for them. The parallel compiler does not have this restriction, so
// we can pre-load the LLVM queue in parallel before handing off
// coordination to the OnGoingCodegen scheduler.
//
// This likely is a temporary measure. Once we don't have to support the
// non-parallel compiler anymore, we can compile CGUs end-to-end in
// parallel and get rid of the complicated scheduling logic.
let pre_compile_cgus = |cgu_reuse: &[CguReuse]| {
if cfg!(parallel_compiler) {
tcx.sess.time("compile_first_CGU_batch", || {
// Try to find one CGU to compile per thread.
let cgus: Vec<_> = cgu_reuse
.iter()
.enumerate()
.filter(|&(_, reuse)| reuse == &CguReuse::No)
.take(tcx.sess.threads())
.collect();

// Compile the found CGUs in parallel.
par_iter(cgus)
.map(|(i, _)| {
let start_time = Instant::now();
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
let mut time = total_codegen_time.lock();
*time += start_time.elapsed();
(i, module)
})
.collect()
})
} else {
FxHashMap::default()
}
};

let mut total_codegen_time = total_codegen_time.into_inner();
let mut cgu_reuse = Vec::new();
let mut pre_compiled_cgus: Option<FxHashMap<usize, _>> = None;

for (i, cgu) in codegen_units.into_iter().enumerate() {
for (i, cgu) in codegen_units.iter().enumerate() {
ongoing_codegen.wait_for_signal_to_codegen_item();
ongoing_codegen.check_for_errors(tcx.sess);

// Do some setup work in the first iteration
if pre_compiled_cgus.is_none() {
// Calculate the CGU reuse
cgu_reuse = tcx.sess.time("find_cgu_reuse", || {
codegen_units.iter().map(|cgu| determine_cgu_reuse(tcx, &cgu)).collect()
});
// Pre compile some CGUs
pre_compiled_cgus = Some(pre_compile_cgus(&cgu_reuse));
}

let cgu_reuse = cgu_reuse[i];
tcx.sess.cgu_reuse_tracker.set_actual_reuse(&cgu.name().as_str(), cgu_reuse);

match cgu_reuse {
CguReuse::No => {
let (module, cost) = if let Some(cgu) = cgus.remove(&i) {
cgu
} else {
let start_time = Instant::now();
let module = backend.compile_codegen_unit(tcx, cgu.name());
total_codegen_time += start_time.elapsed();
module
};
let (module, cost) =
if let Some(cgu) = pre_compiled_cgus.as_mut().unwrap().remove(&i) {
cgu
} else {
let start_time = Instant::now();
let module = backend.compile_codegen_unit(tcx, cgu.name());
let mut time = total_codegen_time.lock();
*time += start_time.elapsed();
module
};
submit_codegened_module_to_llvm(
&backend,
&ongoing_codegen.coordinator_send,
Expand Down Expand Up @@ -695,7 +716,11 @@ pub fn codegen_crate<B: ExtraBackendMethods>(

// Since the main thread is sometimes blocked during codegen, we keep track
// -Ztime-passes output manually.
print_time_passes_entry(tcx.sess.time_passes(), "codegen_to_LLVM_IR", total_codegen_time);
print_time_passes_entry(
tcx.sess.time_passes(),
"codegen_to_LLVM_IR",
total_codegen_time.into_inner(),
);

::rustc_incremental::assert_module_sources::assert_module_sources(tcx);

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
mods: &mut Self::Module,
kind: AllocatorKind,
);
/// This generates the codegen unit and returns it along with
/// a `u64` giving an estimate of the unit's processing cost.
fn compile_codegen_unit(
&self,
tcx: TyCtxt<'_>,
Expand Down