@@ -104,7 +104,7 @@ use rustc::ty::print::characteristic_def_id_of_type;
104
104
use rustc:: ty:: query:: Providers ;
105
105
use rustc:: ty:: { self , DefIdTree , InstanceDef , TyCtxt } ;
106
106
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
107
- use rustc_data_structures:: sync;
107
+ use rustc_data_structures:: sync:: { self , join } ;
108
108
use rustc_hir:: def:: DefKind ;
109
109
use rustc_hir:: def_id:: { CrateNum , DefId , DefIdSet , CRATE_DEF_INDEX , LOCAL_CRATE } ;
110
110
use rustc_span:: symbol:: Symbol ;
@@ -132,17 +132,20 @@ pub fn partition<'tcx, I>(
132
132
inlining_map : & InliningMap < ' tcx > ,
133
133
) -> Vec < CodegenUnit < ' tcx > >
134
134
where
135
- I : Iterator < Item = MonoItem < ' tcx > > ,
135
+ I : Iterator < Item = MonoItem < ' tcx > > + sync :: Send ,
136
136
{
137
137
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning" ) ;
138
138
139
139
// In the first step, we place all regular monomorphizations into their
140
140
// respective 'home' codegen unit. Regular monomorphizations are all
141
141
// 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
+ ) ;
146
149
147
150
initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( tcx) ) ;
148
151
@@ -173,7 +176,7 @@ where
173
176
// more freedom to optimize.
174
177
if !tcx. sess . opts . cg . link_dead_code {
175
178
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 ) ;
177
180
}
178
181
179
182
// Finally, sort by codegen unit name, so that we get deterministic results.
@@ -592,10 +595,27 @@ fn place_inlined_mono_items<'tcx>(
592
595
}
593
596
}
594
597
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
+
595
615
fn internalize_symbols < ' tcx > (
596
616
_tcx : TyCtxt < ' tcx > ,
597
617
partitioning : & mut PostInliningPartitioning < ' tcx > ,
598
- inlining_map : & InliningMap < ' tcx > ,
618
+ accessor_map : & FxHashMap < MonoItem < ' tcx > , Vec < MonoItem < ' tcx > > > ,
599
619
) {
600
620
if partitioning. codegen_units . len ( ) == 1 {
601
621
// Fast path for when there is only one codegen unit. In this case we
@@ -610,15 +630,6 @@ fn internalize_symbols<'tcx>(
610
630
return ;
611
631
}
612
632
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
-
622
633
let mono_item_placements = & partitioning. mono_item_placements ;
623
634
624
635
// For each internalization candidates in each codegen unit, check if it is
0 commit comments