Translate MIR to clif ir in parallel with parallel rustc
On dev-desktop the advantage of cg_clif over cg_llvm on simple-raytracer is 15% when parallel rustc is disabled. With -Zthreads=16 the advantage goes from 5% to 22% with this change.
This commit is contained in:
parent
50b34279c3
commit
a167142946
@ -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,7 +73,7 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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};
|
||||||
@ -611,13 +612,10 @@ pub(crate) fn run_aot(
|
|||||||
CguReuse::PreLto | CguReuse::PostLto => false,
|
CguReuse::PreLto | CguReuse::PostLto => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, todo_cgus.len());
|
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(tcx.sess, todo_cgus.len()));
|
||||||
|
|
||||||
let modules =
|
let modules = tcx.sess.time("codegen mono items", || {
|
||||||
tcx.sess.time("codegen mono items", || {
|
let mut modules: Vec<_> = par_map(todo_cgus, |(_, cgu)| {
|
||||||
todo_cgus
|
|
||||||
.into_iter()
|
|
||||||
.map(|(_, cgu)| {
|
|
||||||
let dep_node = cgu.codegen_dep_node(tcx);
|
let dep_node = cgu.codegen_dep_node(tcx);
|
||||||
tcx.dep_graph
|
tcx.dep_graph
|
||||||
.with_task(
|
.with_task(
|
||||||
@ -633,11 +631,13 @@ pub(crate) fn run_aot(
|
|||||||
Some(rustc_middle::dep_graph::hash_result),
|
Some(rustc_middle::dep_graph::hash_result),
|
||||||
)
|
)
|
||||||
.0
|
.0
|
||||||
})
|
});
|
||||||
.chain(done_cgus.into_iter().map(|(_, cgu)| {
|
modules.extend(
|
||||||
OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))
|
done_cgus
|
||||||
}))
|
.into_iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|(_, cgu)| OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))),
|
||||||
|
);
|
||||||
|
modules
|
||||||
});
|
});
|
||||||
|
|
||||||
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());
|
||||||
@ -706,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