@@ -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:: { MTRef , MTLock , ParallelIterator , par_iter} ;
214216
215217#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
216218pub enum MonoItemCollectionMode {
@@ -298,22 +300,32 @@ 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) ;
308+
309+ let mut visited = MTLock :: new ( FxHashSet ( ) ) ;
310+ let mut inlining_map = MTLock :: new ( InliningMap :: new ( ) ) ;
311+
312+ {
313+ let visited: MTRef < ' _ , _ > = & mut visited;
314+ let inlining_map: MTRef < ' _ , _ > = & mut inlining_map;
315+
316+ time ( tcx. sess , "collecting mono items" , || {
317+ par_iter ( roots) . for_each ( |root| {
318+ let mut recursion_depths = DefIdMap ( ) ;
319+ collect_items_rec ( tcx,
320+ root,
321+ visited,
322+ & mut recursion_depths,
323+ inlining_map) ;
324+ } ) ;
325+ } ) ;
314326 }
315327
316- ( visited, inlining_map)
328+ ( visited. into_inner ( ) , inlining_map. into_inner ( ) )
317329}
318330
319331// Find all non-generic items by walking the HIR. These items serve as roots to
@@ -354,10 +366,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
354366// Collect all monomorphized items reachable from `starting_point`
355367fn collect_items_rec < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
356368 starting_point : MonoItem < ' tcx > ,
357- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
369+ visited : MTRef < ' _ , MTLock < FxHashSet < MonoItem < ' tcx > > > > ,
358370 recursion_depths : & mut DefIdMap < usize > ,
359- inlining_map : & mut InliningMap < ' tcx > ) {
360- if !visited. insert ( starting_point. clone ( ) ) {
371+ inlining_map : MTRef < ' _ , MTLock < InliningMap < ' tcx > > > ) {
372+ if !visited. lock_mut ( ) . insert ( starting_point. clone ( ) ) {
361373 // We've been here already, no need to search again.
362374 return ;
363375 }
@@ -428,7 +440,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
428440fn record_accesses < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
429441 caller : MonoItem < ' tcx > ,
430442 callees : & [ MonoItem < ' tcx > ] ,
431- inlining_map : & mut InliningMap < ' tcx > ) {
443+ inlining_map : MTRef < ' _ , MTLock < InliningMap < ' tcx > > > ) {
432444 let is_inlining_candidate = |mono_item : & MonoItem < ' tcx > | {
433445 mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
434446 } ;
@@ -438,7 +450,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
438450 ( * mono_item, is_inlining_candidate ( mono_item) )
439451 } ) ;
440452
441- inlining_map. record_accesses ( caller, accesses) ;
453+ inlining_map. lock_mut ( ) . record_accesses ( caller, accesses) ;
442454}
443455
444456fn check_recursion_limit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments