Skip to content

Commit 72c1993

Browse files
Make codegen not be a query (since it's not a real query anyway).
1 parent d97d1e1 commit 72c1993

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

src/librustc/ty/query/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::codegen_unit<'tcx> {
722722
}
723723
}
724724

725-
impl<'tcx> QueryDescription<'tcx> for queries::compile_codegen_unit<'tcx> {
726-
fn describe(_tcx: TyCtxt, _: InternedString) -> String {
727-
"compile_codegen_unit".to_string()
728-
}
729-
}
730-
731725
impl<'tcx> QueryDescription<'tcx> for queries::output_filenames<'tcx> {
732726
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
733727
"output_filenames".to_string()

src/librustc/ty/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use middle::lib_features::LibFeatures;
2828
use middle::lang_items::{LanguageItems, LangItem};
2929
use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
3030
use mir::interpret::ConstEvalResult;
31-
use mir::mono::{CodegenUnit, Stats};
31+
use mir::mono::CodegenUnit;
3232
use mir;
3333
use mir::interpret::{GlobalId, Allocation};
3434
use session::{CompileResult, CrateDisambiguator};
@@ -530,7 +530,6 @@ define_queries! { <'tcx>
530530
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
531531
[] fn is_codegened_item: IsCodegenedItem(DefId) -> bool,
532532
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
533-
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
534533
},
535534

536535
Other {

src/librustc_codegen_llvm/base.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
891891
&format!("codegen {}", cgu.name()))
892892
});
893893
let start_time = Instant::now();
894-
all_stats.extend(tcx.compile_codegen_unit(*cgu.name()));
894+
all_stats.extend(compile_codegen_unit(tcx, *cgu.name()));
895895
total_codegen_time += start_time.elapsed();
896896
ongoing_codegen.check_for_errors(tcx.sess);
897897
}
@@ -1157,11 +1157,15 @@ fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
11571157
}
11581158

11591159
fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1160-
cgu: InternedString) -> Stats {
1161-
let cgu = tcx.codegen_unit(cgu);
1162-
1160+
cgu_name: InternedString)
1161+
-> Stats {
11631162
let start_time = Instant::now();
1164-
let (stats, module) = module_codegen(tcx, cgu);
1163+
1164+
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
1165+
let ((stats, module), _) = tcx.dep_graph.with_task(dep_node,
1166+
tcx,
1167+
cgu_name,
1168+
module_codegen);
11651169
let time_to_codegen = start_time.elapsed();
11661170

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

11721176
write::submit_codegened_module_to_llvm(tcx,
1173-
module,
1174-
cost);
1177+
module,
1178+
cost);
1179+
1180+
if tcx.dep_graph.is_fully_enabled() {
1181+
let dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
1182+
tcx.dep_graph.mark_loaded_from_cache(dep_node_index, false);
1183+
}
1184+
11751185
return stats;
11761186

11771187
fn module_codegen<'a, 'tcx>(
11781188
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1179-
cgu: Arc<CodegenUnit<'tcx>>)
1189+
cgu_name: InternedString)
11801190
-> (Stats, ModuleCodegen)
11811191
{
1182-
let cgu_name = cgu.name().to_string();
1192+
let cgu = tcx.codegen_unit(cgu_name);
11831193

11841194
// Instantiate monomorphizations without filling out definitions yet...
1185-
let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name);
1195+
let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name.as_str());
11861196
let stats = {
11871197
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
11881198
let mono_items = cx.codegen_unit
1189-
.items_in_deterministic_order(cx.tcx);
1199+
.items_in_deterministic_order(cx.tcx);
11901200
for &(mono_item, (linkage, visibility)) in &mono_items {
11911201
mono_item.predefine(&cx, linkage, visibility);
11921202
}
@@ -1235,7 +1245,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12351245
};
12361246

12371247
(stats, ModuleCodegen {
1238-
name: cgu_name,
1248+
name: cgu_name.to_string(),
12391249
source: ModuleSource::Codegened(llvm_module),
12401250
kind: ModuleKind::Regular,
12411251
})
@@ -1255,7 +1265,6 @@ pub fn provide(providers: &mut Providers) {
12551265
.cloned()
12561266
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
12571267
};
1258-
providers.compile_codegen_unit = compile_codegen_unit;
12591268

12601269
provide_extern(providers);
12611270
}

src/librustc_mir/monomorphize/partitioning.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
//! inlining, even when they are not marked #[inline].
104104
105105
use monomorphize::collector::InliningMap;
106-
use rustc::dep_graph::WorkProductId;
106+
use rustc::dep_graph::{WorkProductId, DepNode, DepConstructor};
107107
use rustc::hir::CodegenFnAttrFlags;
108108
use rustc::hir::def_id::{DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
109109
use rustc::hir::map::DefPathData;
@@ -194,6 +194,10 @@ pub trait CodegenUnitExt<'tcx> {
194194
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
195195
items
196196
}
197+
198+
fn codegen_dep_node(&self, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> DepNode {
199+
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
200+
}
197201
}
198202

199203
impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {

0 commit comments

Comments
 (0)