@@ -207,10 +207,12 @@ use rustc::mir::interpret::{Scalar, GlobalId, AllocType};
207207
208208use monomorphize:: { self , Instance } ;
209209use rustc:: util:: nodemap:: { FxHashSet , FxHashMap , DefIdMap } ;
210+ use rustc:: util:: common:: time;
210211
211212use monomorphize:: item:: { MonoItemExt , DefPathBasedNames , InstantiationMode } ;
212213
213214use rustc_data_structures:: bitvec:: BitVector ;
215+ use rustc_data_structures:: sync:: { ParallelIterator , par_iter, Lock } ;
214216
215217#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
216218pub enum MonoItemCollectionMode {
@@ -298,22 +300,26 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
298300 mode : MonoItemCollectionMode )
299301 -> ( FxHashSet < MonoItem < ' tcx > > ,
300302 InliningMap < ' tcx > ) {
301- let roots = collect_roots ( tcx, mode) ;
303+ let roots = time ( tcx. sess , "collecting roots" , || {
304+ collect_roots ( tcx, mode)
305+ } ) ;
302306
303307 debug ! ( "Building mono item graph, beginning at roots" ) ;
304- let mut visited = FxHashSet ( ) ;
305- let mut recursion_depths = DefIdMap ( ) ;
306- let mut inlining_map = InliningMap :: new ( ) ;
307-
308- for root in roots {
309- collect_items_rec ( tcx,
310- root,
311- & mut visited,
312- & mut recursion_depths,
313- & mut inlining_map) ;
314- }
308+ let visited = Lock :: new ( FxHashSet ( ) ) ;
309+ let inlining_map = Lock :: new ( InliningMap :: new ( ) ) ;
310+
311+ time ( tcx. sess , "collecting mono items" , || {
312+ par_iter ( roots) . for_each ( |root| {
313+ let mut recursion_depths = DefIdMap ( ) ;
314+ collect_items_rec ( tcx,
315+ root,
316+ & visited,
317+ & mut recursion_depths,
318+ & inlining_map) ;
319+ } ) ;
320+ } ) ;
315321
316- ( visited, inlining_map)
322+ ( visited. into_inner ( ) , inlining_map. into_inner ( ) )
317323}
318324
319325// Find all non-generic items by walking the HIR. These items serve as roots to
@@ -354,10 +360,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
354360// Collect all monomorphized items reachable from `starting_point`
355361fn collect_items_rec < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
356362 starting_point : MonoItem < ' tcx > ,
357- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
363+ visited : & Lock < FxHashSet < MonoItem < ' tcx > > > ,
358364 recursion_depths : & mut DefIdMap < usize > ,
359- inlining_map : & mut InliningMap < ' tcx > ) {
360- if !visited. insert ( starting_point. clone ( ) ) {
365+ inlining_map : & Lock < InliningMap < ' tcx > > ) {
366+ if !visited. lock ( ) . insert ( starting_point. clone ( ) ) {
361367 // We've been here already, no need to search again.
362368 return ;
363369 }
@@ -428,7 +434,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
428434fn record_accesses < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
429435 caller : MonoItem < ' tcx > ,
430436 callees : & [ MonoItem < ' tcx > ] ,
431- inlining_map : & mut InliningMap < ' tcx > ) {
437+ inlining_map : & Lock < InliningMap < ' tcx > > ) {
432438 let is_inlining_candidate = |mono_item : & MonoItem < ' tcx > | {
433439 mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
434440 } ;
@@ -438,7 +444,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
438444 ( * mono_item, is_inlining_candidate ( mono_item) )
439445 } ) ;
440446
441- inlining_map. record_accesses ( caller, accesses) ;
447+ inlining_map. lock ( ) . record_accesses ( caller, accesses) ;
442448}
443449
444450fn check_recursion_limit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments