async-llvm(19): Already start LLVM while still translating.

This commit is contained in:
Michael Woerister 2017-07-26 16:02:32 +02:00 committed by Michael Woerister
parent 7e09d1e170
commit 81b789fd87
3 changed files with 56 additions and 49 deletions

View File

@ -37,11 +37,22 @@
const MODULE: &'static str = "module";
const CFG: &'static str = "cfg";
#[derive(Debug, PartialEq)]
enum Disposition { Reused, Translated }
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Disposition { Reused, Translated }
impl ModuleTranslation {
pub fn disposition(&self) -> (String, Disposition) {
let disposition = match self.source {
ModuleSource::Preexisting(_) => Disposition::Reused,
ModuleSource::Translated(_) => Disposition::Translated,
};
(self.name.clone(), disposition)
}
}
pub(crate) fn assert_module_sources<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
modules: &[ModuleTranslation]) {
modules: &[(String, Disposition)]) {
let _ignore = tcx.dep_graph.in_ignore();
if tcx.sess.opts.incremental.is_none() {
@ -56,7 +67,7 @@ pub(crate) fn assert_module_sources<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct AssertModuleSource<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
modules: &'a [ModuleTranslation],
modules: &'a [(String, Disposition)],
}
impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
@ -75,15 +86,15 @@ fn check_attr(&self, attr: &ast::Attribute) {
}
let mname = self.field(attr, MODULE);
let mtrans = self.modules.iter().find(|mtrans| *mtrans.name == *mname.as_str());
let mtrans = self.modules.iter().find(|&&(ref name, _)| name == mname.as_str());
let mtrans = match mtrans {
Some(m) => m,
None => {
debug!("module name `{}` not found amongst:", mname);
for mtrans in self.modules {
for &(ref name, ref disposition) in self.modules {
debug!("module named `{}` with disposition {:?}",
mtrans.name,
self.disposition(mtrans));
name,
disposition);
}
self.tcx.sess.span_err(
@ -93,7 +104,7 @@ fn check_attr(&self, attr: &ast::Attribute) {
}
};
let mtrans_disposition = self.disposition(mtrans);
let mtrans_disposition = mtrans.1;
if disposition != mtrans_disposition {
self.tcx.sess.span_err(
attr.span,
@ -104,13 +115,6 @@ fn check_attr(&self, attr: &ast::Attribute) {
}
}
fn disposition(&self, mtrans: &ModuleTranslation) -> Disposition {
match mtrans.source {
ModuleSource::Preexisting(_) => Disposition::Reused,
ModuleSource::Translated(_) => Disposition::Translated,
}
}
fn field(&self, attr: &ast::Attribute, name: &str) -> ast::Name {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(name) {

View File

@ -678,7 +678,6 @@ pub fn run_passes(sess: &Session,
};
// Figure out what we actually need to build.
let mut modules_config = ModuleConfig::new(sess, sess.opts.cg.passes.clone());
let mut metadata_config = ModuleConfig::new(sess, vec![]);
let mut allocator_config = ModuleConfig::new(sess, vec![]);
@ -1615,4 +1614,8 @@ pub fn submit_translated_module_to_llvm(&self,
pub fn signal_translation_done(&self) {
drop(self.coordinator_send.send(Message::TranslationDone));
}
pub fn check_for_errors(&self, sess: &Session) {
self.shared_emitter_main.check(sess, false);
}
}

View File

@ -1024,24 +1024,34 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
linker_info,
no_integrated_as);
ongoing_translation.submit_translated_module_to_llvm(tcx.sess, metadata_module);
let translation_items = Arc::new(translation_items);
let mut all_stats = Stats::default();
let modules: Vec<ModuleTranslation> = codegen_units
.into_iter()
.map(|cgu| {
let dep_node = cgu.work_product_dep_node();
let ((stats, module), _) =
tcx.dep_graph.with_task(dep_node,
AssertDepGraphSafe(&shared_ccx),
AssertDepGraphSafe((cgu,
translation_items.clone(),
exported_symbols.clone())),
module_translation);
all_stats.extend(stats);
module
})
.collect();
let mut module_dispositions = tcx.sess.opts.incremental.as_ref().map(|_| Vec::new());
for cgu in codegen_units.into_iter() {
ongoing_translation.check_for_errors(tcx.sess);
let dep_node = cgu.work_product_dep_node();
let ((stats, module), _) =
tcx.dep_graph.with_task(dep_node,
AssertDepGraphSafe(&shared_ccx),
AssertDepGraphSafe((cgu,
translation_items.clone(),
exported_symbols.clone())),
module_translation);
all_stats.extend(stats);
if let Some(ref mut module_dispositions) = module_dispositions {
module_dispositions.push(module.disposition());
}
ongoing_translation.submit_translated_module_to_llvm(tcx.sess, module);
}
if let Some(module_dispositions) = module_dispositions {
assert_module_sources::assert_module_sources(tcx, &module_dispositions);
}
fn module_translation<'a, 'tcx>(
scx: AssertDepGraphSafe<&SharedCrateContext<'a, 'tcx>>,
@ -1175,8 +1185,6 @@ fn module_translation<'a, 'tcx>(
(lcx.into_stats(), module)
}
assert_module_sources::assert_module_sources(tcx, &modules);
symbol_names_test::report_symbol_names(tcx);
if shared_ccx.sess().trans_stats() {
@ -1207,8 +1215,6 @@ fn module_translation<'a, 'tcx>(
}
}
let sess = shared_ccx.sess();
// Translate an allocator shim, if any
//
// If LTO is enabled and we've got some previous LLVM module we translated
@ -1244,23 +1250,17 @@ fn module_translation<'a, 'tcx>(
None
};
if let Some(allocator_module) = allocator_module {
ongoing_translation.submit_translated_module_to_llvm(tcx.sess, allocator_module);
}
ongoing_translation.check_for_errors(tcx.sess);
ongoing_translation.signal_translation_done();
assert_and_save_dep_graph(tcx,
incremental_hashes_map,
metadata_incr_hashes,
link_meta);
ongoing_translation.submit_translated_module_to_llvm(sess, metadata_module);
for mtrans in modules {
ongoing_translation.submit_translated_module_to_llvm(sess, mtrans);
}
if let Some(allocator_module) = allocator_module {
ongoing_translation.submit_translated_module_to_llvm(sess, allocator_module);
}
ongoing_translation.signal_translation_done();
ongoing_translation
}