Skip to content

Commit 477ad98

Browse files
committed
Calculate accessor_map in parallel earlier
1 parent c7aabbd commit 477ad98

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ use rustc::ty::print::characteristic_def_id_of_type;
104104
use rustc::ty::query::Providers;
105105
use rustc::ty::{self, DefIdTree, InstanceDef, TyCtxt};
106106
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
107-
use rustc_data_structures::sync;
107+
use rustc_data_structures::sync::{self, join};
108108
use rustc_hir::def::DefKind;
109109
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
110110
use rustc_span::symbol::Symbol;
@@ -132,17 +132,20 @@ pub fn partition<'tcx, I>(
132132
inlining_map: &InliningMap<'tcx>,
133133
) -> Vec<CodegenUnit<'tcx>>
134134
where
135-
I: Iterator<Item = MonoItem<'tcx>>,
135+
I: Iterator<Item = MonoItem<'tcx>> + sync::Send,
136136
{
137137
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");
138138

139139
// In the first step, we place all regular monomorphizations into their
140140
// respective 'home' codegen unit. Regular monomorphizations are all
141141
// functions and statics defined in the local crate.
142-
let mut initial_partitioning = {
143-
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
144-
place_root_mono_items(tcx, mono_items)
145-
};
142+
let (mut initial_partitioning, accessor_map) = join(
143+
|| {
144+
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
145+
place_root_mono_items(tcx, mono_items)
146+
},
147+
|| accessor_map(tcx, inlining_map),
148+
);
146149

147150
initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
148151

@@ -173,7 +176,7 @@ where
173176
// more freedom to optimize.
174177
if !tcx.sess.opts.cg.link_dead_code {
175178
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
176-
internalize_symbols(tcx, &mut post_inlining, inlining_map);
179+
internalize_symbols(tcx, &mut post_inlining, &accessor_map);
177180
}
178181

179182
// Finally, sort by codegen unit name, so that we get deterministic results.
@@ -592,10 +595,27 @@ fn place_inlined_mono_items<'tcx>(
592595
}
593596
}
594597

598+
// Build a map from every monomorphization to all the monomorphizations that
599+
// reference it.
600+
fn accessor_map<'tcx>(
601+
tcx: TyCtxt<'tcx>,
602+
inlining_map: &InliningMap<'tcx>,
603+
) -> FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> {
604+
let _prof_timer = tcx.prof.generic_activity("build_accessor_map");
605+
606+
let mut accessor_map: FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> = Default::default();
607+
inlining_map.iter_accesses(|accessor, accessees| {
608+
for accessee in accessees {
609+
accessor_map.entry(*accessee).or_default().push(accessor);
610+
}
611+
});
612+
accessor_map
613+
}
614+
595615
fn internalize_symbols<'tcx>(
596616
_tcx: TyCtxt<'tcx>,
597617
partitioning: &mut PostInliningPartitioning<'tcx>,
598-
inlining_map: &InliningMap<'tcx>,
618+
accessor_map: &FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>>,
599619
) {
600620
if partitioning.codegen_units.len() == 1 {
601621
// Fast path for when there is only one codegen unit. In this case we
@@ -610,15 +630,6 @@ fn internalize_symbols<'tcx>(
610630
return;
611631
}
612632

613-
// Build a map from every monomorphization to all the monomorphizations that
614-
// reference it.
615-
let mut accessor_map: FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> = Default::default();
616-
inlining_map.iter_accesses(|accessor, accessees| {
617-
for accessee in accessees {
618-
accessor_map.entry(*accessee).or_default().push(accessor);
619-
}
620-
});
621-
622633
let mono_item_placements = &partitioning.mono_item_placements;
623634

624635
// For each internalization candidates in each codegen unit, check if it is

0 commit comments

Comments
 (0)