Skip to content

Commit

Permalink
async-llvm(19): Already start LLVM while still translating.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Jul 31, 2017
1 parent 7e09d1e commit 81b789f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
36 changes: 20 additions & 16 deletions src/librustc_trans/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@ use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_TRANSLATED};
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() {
Expand All @@ -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> {
Expand All @@ -75,15 +86,15 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
}

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(
Expand All @@ -93,7 +104,7 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
}
};

let mtrans_disposition = self.disposition(mtrans);
let mtrans_disposition = mtrans.1;
if disposition != mtrans_disposition {
self.tcx.sess.span_err(
attr.span,
Expand All @@ -104,13 +115,6 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
}
}

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) {
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]);
Expand Down Expand Up @@ -1615,4 +1614,8 @@ impl OngoingCrateTranslation {
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);
}
}
62 changes: 31 additions & 31 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down Expand Up @@ -1175,8 +1185,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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() {
Expand Down Expand Up @@ -1207,8 +1215,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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
Expand Down Expand Up @@ -1244,23 +1250,17 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
None
};

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.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
}

Expand Down

0 comments on commit 81b789f

Please sign in to comment.