Merge pull request #1489 from rust-lang/parallel_rustc
Translate MIR to clif ir in parallel with parallel rustc
This commit is contained in:
commit
1a2c489a93
@ -6,7 +6,7 @@
|
|||||||
// FIXME don't panic when a worker thread panics
|
// FIXME don't panic when a worker thread panics
|
||||||
|
|
||||||
pub(super) struct ConcurrencyLimiter {
|
pub(super) struct ConcurrencyLimiter {
|
||||||
helper_thread: Option<HelperThread>,
|
helper_thread: Option<Mutex<HelperThread>>,
|
||||||
state: Arc<Mutex<state::ConcurrencyLimiterState>>,
|
state: Arc<Mutex<state::ConcurrencyLimiterState>>,
|
||||||
available_token_condvar: Arc<Condvar>,
|
available_token_condvar: Arc<Condvar>,
|
||||||
finished: bool,
|
finished: bool,
|
||||||
@ -39,14 +39,14 @@ pub(super) fn new(sess: &Session, pending_jobs: usize) -> Self {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ConcurrencyLimiter {
|
ConcurrencyLimiter {
|
||||||
helper_thread: Some(helper_thread),
|
helper_thread: Some(Mutex::new(helper_thread)),
|
||||||
state,
|
state,
|
||||||
available_token_condvar,
|
available_token_condvar,
|
||||||
finished: false,
|
finished: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn acquire(&mut self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
|
pub(super) fn acquire(&self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
loop {
|
loop {
|
||||||
state.assert_invariants();
|
state.assert_invariants();
|
||||||
@ -73,16 +73,11 @@ pub(super) fn acquire(&mut self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.helper_thread.as_mut().unwrap().request_token();
|
self.helper_thread.as_ref().unwrap().lock().unwrap().request_token();
|
||||||
state = self.available_token_condvar.wait(state).unwrap();
|
state = self.available_token_condvar.wait(state).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn job_already_done(&mut self) {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
state.job_already_done();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn finished(mut self) {
|
pub(crate) fn finished(mut self) {
|
||||||
self.helper_thread.take();
|
self.helper_thread.take();
|
||||||
|
|
||||||
@ -190,14 +185,6 @@ pub(super) fn job_finished(&mut self) {
|
|||||||
self.assert_invariants();
|
self.assert_invariants();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn job_already_done(&mut self) {
|
|
||||||
self.assert_invariants();
|
|
||||||
self.pending_jobs -= 1;
|
|
||||||
self.assert_invariants();
|
|
||||||
self.drop_excess_capacity();
|
|
||||||
self.assert_invariants();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn poison(&mut self, error: String) {
|
pub(super) fn poison(&mut self, error: String) {
|
||||||
self.poisoned = true;
|
self.poisoned = true;
|
||||||
self.stored_error = Some(error);
|
self.stored_error = Some(error);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
|
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
|
||||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
|
use rustc_data_structures::sync::{par_map, IntoDynSyncSend};
|
||||||
use rustc_metadata::fs::copy_to_stdout;
|
use rustc_metadata::fs::copy_to_stdout;
|
||||||
use rustc_metadata::EncodedMetadata;
|
use rustc_metadata::EncodedMetadata;
|
||||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||||
@ -604,39 +605,39 @@ pub(crate) fn run_aot(
|
|||||||
|
|
||||||
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
|
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
|
||||||
|
|
||||||
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, cgus.len());
|
let (todo_cgus, done_cgus) =
|
||||||
|
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
|
||||||
|
_ if backend_config.disable_incr_cache => true,
|
||||||
|
CguReuse::No => true,
|
||||||
|
CguReuse::PreLto | CguReuse::PostLto => false,
|
||||||
|
});
|
||||||
|
|
||||||
|
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(tcx.sess, todo_cgus.len()));
|
||||||
|
|
||||||
let modules = tcx.sess.time("codegen mono items", || {
|
let modules = tcx.sess.time("codegen mono items", || {
|
||||||
cgus.iter()
|
let mut modules: Vec<_> = par_map(todo_cgus, |(_, cgu)| {
|
||||||
.enumerate()
|
let dep_node = cgu.codegen_dep_node(tcx);
|
||||||
.map(|(i, cgu)| {
|
tcx.dep_graph
|
||||||
let cgu_reuse =
|
.with_task(
|
||||||
if backend_config.disable_incr_cache { CguReuse::No } else { cgu_reuse[i] };
|
dep_node,
|
||||||
match cgu_reuse {
|
tcx,
|
||||||
CguReuse::No => {
|
(
|
||||||
let dep_node = cgu.codegen_dep_node(tcx);
|
backend_config.clone(),
|
||||||
tcx.dep_graph
|
global_asm_config.clone(),
|
||||||
.with_task(
|
cgu.name(),
|
||||||
dep_node,
|
concurrency_limiter.acquire(tcx.dcx()),
|
||||||
tcx,
|
),
|
||||||
(
|
module_codegen,
|
||||||
backend_config.clone(),
|
Some(rustc_middle::dep_graph::hash_result),
|
||||||
global_asm_config.clone(),
|
)
|
||||||
cgu.name(),
|
.0
|
||||||
concurrency_limiter.acquire(tcx.dcx()),
|
});
|
||||||
),
|
modules.extend(
|
||||||
module_codegen,
|
done_cgus
|
||||||
Some(rustc_middle::dep_graph::hash_result),
|
.into_iter()
|
||||||
)
|
.map(|(_, cgu)| OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))),
|
||||||
.0
|
);
|
||||||
}
|
modules
|
||||||
CguReuse::PreLto | CguReuse::PostLto => {
|
|
||||||
concurrency_limiter.job_already_done();
|
|
||||||
OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
|
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
|
||||||
@ -705,6 +706,6 @@ pub(crate) fn run_aot(
|
|||||||
metadata_module,
|
metadata_module,
|
||||||
metadata,
|
metadata,
|
||||||
crate_info: CrateInfo::new(tcx, target_cpu),
|
crate_info: CrateInfo::new(tcx, target_cpu),
|
||||||
concurrency_limiter,
|
concurrency_limiter: concurrency_limiter.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user