Skip to content

Commit 50b3427

Browse files
committed
Split cgus into todo and done before the main module codegen loop
1 parent 9ee010c commit 50b3427

File tree

2 files changed

+35
-47
lines changed

2 files changed

+35
-47
lines changed

src/concurrency_limiter.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ impl ConcurrencyLimiter {
7878
}
7979
}
8080

81-
pub(super) fn job_already_done(&mut self) {
82-
let mut state = self.state.lock().unwrap();
83-
state.job_already_done();
84-
}
85-
8681
pub(crate) fn finished(mut self) {
8782
self.helper_thread.take();
8883

@@ -190,14 +185,6 @@ mod state {
190185
self.assert_invariants();
191186
}
192187

193-
pub(super) fn job_already_done(&mut self) {
194-
self.assert_invariants();
195-
self.pending_jobs -= 1;
196-
self.assert_invariants();
197-
self.drop_excess_capacity();
198-
self.assert_invariants();
199-
}
200-
201188
pub(super) fn poison(&mut self, error: String) {
202189
self.poisoned = true;
203190
self.stored_error = Some(error);

src/driver/aot.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -604,40 +604,41 @@ pub(crate) fn run_aot(
604604

605605
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
606606

607-
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, cgus.len());
608-
609-
let modules = tcx.sess.time("codegen mono items", || {
610-
cgus.iter()
611-
.enumerate()
612-
.map(|(i, cgu)| {
613-
let cgu_reuse =
614-
if backend_config.disable_incr_cache { CguReuse::No } else { cgu_reuse[i] };
615-
match cgu_reuse {
616-
CguReuse::No => {
617-
let dep_node = cgu.codegen_dep_node(tcx);
618-
tcx.dep_graph
619-
.with_task(
620-
dep_node,
621-
tcx,
622-
(
623-
backend_config.clone(),
624-
global_asm_config.clone(),
625-
cgu.name(),
626-
concurrency_limiter.acquire(tcx.dcx()),
627-
),
628-
module_codegen,
629-
Some(rustc_middle::dep_graph::hash_result),
630-
)
631-
.0
632-
}
633-
CguReuse::PreLto | CguReuse::PostLto => {
634-
concurrency_limiter.job_already_done();
635-
OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))
636-
}
637-
}
638-
})
639-
.collect::<Vec<_>>()
640-
});
607+
let (todo_cgus, done_cgus) =
608+
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
609+
_ if backend_config.disable_incr_cache => true,
610+
CguReuse::No => true,
611+
CguReuse::PreLto | CguReuse::PostLto => false,
612+
});
613+
614+
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, todo_cgus.len());
615+
616+
let modules =
617+
tcx.sess.time("codegen mono items", || {
618+
todo_cgus
619+
.into_iter()
620+
.map(|(_, cgu)| {
621+
let dep_node = cgu.codegen_dep_node(tcx);
622+
tcx.dep_graph
623+
.with_task(
624+
dep_node,
625+
tcx,
626+
(
627+
backend_config.clone(),
628+
global_asm_config.clone(),
629+
cgu.name(),
630+
concurrency_limiter.acquire(tcx.dcx()),
631+
),
632+
module_codegen,
633+
Some(rustc_middle::dep_graph::hash_result),
634+
)
635+
.0
636+
})
637+
.chain(done_cgus.into_iter().map(|(_, cgu)| {
638+
OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))
639+
}))
640+
.collect::<Vec<_>>()
641+
});
641642

642643
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
643644
let mut allocator_unwind_context = UnwindContext::new(allocator_module.isa(), true);

0 commit comments

Comments
 (0)