Skip to content

Commit

Permalink
Make codegen not be a query (since it's not a real query anyway).
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Aug 31, 2018
1 parent d97d1e1 commit 72c1993
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
6 changes: 0 additions & 6 deletions src/librustc/ty/query/config.rs
Expand Up @@ -722,12 +722,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::codegen_unit<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::compile_codegen_unit<'tcx> {
fn describe(_tcx: TyCtxt, _: InternedString) -> String {
"compile_codegen_unit".to_string()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::output_filenames<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
"output_filenames".to_string()
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/query/mod.rs
Expand Up @@ -28,7 +28,7 @@ use middle::lib_features::LibFeatures;
use middle::lang_items::{LanguageItems, LangItem};
use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
use mir::interpret::ConstEvalResult;
use mir::mono::{CodegenUnit, Stats};
use mir::mono::CodegenUnit;
use mir;
use mir::interpret::{GlobalId, Allocation};
use session::{CompileResult, CrateDisambiguator};
Expand Down Expand Up @@ -530,7 +530,6 @@ define_queries! { <'tcx>
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
[] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
},

Other {
Expand Down
35 changes: 22 additions & 13 deletions src/librustc_codegen_llvm/base.rs
Expand Up @@ -891,7 +891,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
&format!("codegen {}", cgu.name()))
});
let start_time = Instant::now();
all_stats.extend(tcx.compile_codegen_unit(*cgu.name()));
all_stats.extend(compile_codegen_unit(tcx, *cgu.name()));
total_codegen_time += start_time.elapsed();
ongoing_codegen.check_for_errors(tcx.sess);
}
Expand Down Expand Up @@ -1157,11 +1157,15 @@ fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
}

fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cgu: InternedString) -> Stats {
let cgu = tcx.codegen_unit(cgu);

cgu_name: InternedString)
-> Stats {
let start_time = Instant::now();
let (stats, module) = module_codegen(tcx, cgu);

let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
let ((stats, module), _) = tcx.dep_graph.with_task(dep_node,
tcx,
cgu_name,
module_codegen);
let time_to_codegen = start_time.elapsed();

// We assume that the cost to run LLVM on a CGU is proportional to
Expand All @@ -1170,23 +1174,29 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
time_to_codegen.subsec_nanos() as u64;

write::submit_codegened_module_to_llvm(tcx,
module,
cost);
module,
cost);

if tcx.dep_graph.is_fully_enabled() {
let dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
tcx.dep_graph.mark_loaded_from_cache(dep_node_index, false);
}

return stats;

fn module_codegen<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
cgu: Arc<CodegenUnit<'tcx>>)
cgu_name: InternedString)
-> (Stats, ModuleCodegen)
{
let cgu_name = cgu.name().to_string();
let cgu = tcx.codegen_unit(cgu_name);

// Instantiate monomorphizations without filling out definitions yet...
let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name);
let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name.as_str());
let stats = {
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
let mono_items = cx.codegen_unit
.items_in_deterministic_order(cx.tcx);
.items_in_deterministic_order(cx.tcx);
for &(mono_item, (linkage, visibility)) in &mono_items {
mono_item.predefine(&cx, linkage, visibility);
}
Expand Down Expand Up @@ -1235,7 +1245,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
};

(stats, ModuleCodegen {
name: cgu_name,
name: cgu_name.to_string(),
source: ModuleSource::Codegened(llvm_module),
kind: ModuleKind::Regular,
})
Expand All @@ -1255,7 +1265,6 @@ pub fn provide(providers: &mut Providers) {
.cloned()
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
};
providers.compile_codegen_unit = compile_codegen_unit;

provide_extern(providers);
}
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/monomorphize/partitioning.rs
Expand Up @@ -103,7 +103,7 @@
//! inlining, even when they are not marked #[inline].

use monomorphize::collector::InliningMap;
use rustc::dep_graph::WorkProductId;
use rustc::dep_graph::{WorkProductId, DepNode, DepConstructor};
use rustc::hir::CodegenFnAttrFlags;
use rustc::hir::def_id::{DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
use rustc::hir::map::DefPathData;
Expand Down Expand Up @@ -194,6 +194,10 @@ pub trait CodegenUnitExt<'tcx> {
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
items
}

fn codegen_dep_node(&self, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> DepNode {
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
}
}

impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
Expand Down

0 comments on commit 72c1993

Please sign in to comment.