@@ -207,10 +207,12 @@ use rustc::mir::interpret::{Scalar, GlobalId, AllocType};
207
207
208
208
use monomorphize:: { self , Instance } ;
209
209
use rustc:: util:: nodemap:: { FxHashSet , FxHashMap , DefIdMap } ;
210
+ use rustc:: util:: common:: time;
210
211
211
212
use monomorphize:: item:: { MonoItemExt , DefPathBasedNames , InstantiationMode } ;
212
213
213
214
use rustc_data_structures:: bitvec:: BitVector ;
215
+ use rustc_data_structures:: sync:: { MTRef , MTLock , ParallelIterator , par_iter} ;
214
216
215
217
#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
216
218
pub enum MonoItemCollectionMode {
@@ -298,22 +300,32 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
298
300
mode : MonoItemCollectionMode )
299
301
-> ( FxHashSet < MonoItem < ' tcx > > ,
300
302
InliningMap < ' tcx > ) {
301
- let roots = collect_roots ( tcx, mode) ;
303
+ let roots = time ( tcx. sess , "collecting roots" , || {
304
+ collect_roots ( tcx, mode)
305
+ } ) ;
302
306
303
307
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
+ } ) ;
314
326
}
315
327
316
- ( visited, inlining_map)
328
+ ( visited. into_inner ( ) , inlining_map. into_inner ( ) )
317
329
}
318
330
319
331
// 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>,
354
366
// Collect all monomorphized items reachable from `starting_point`
355
367
fn collect_items_rec < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
356
368
starting_point : MonoItem < ' tcx > ,
357
- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
369
+ visited : MTRef < ' _ , MTLock < FxHashSet < MonoItem < ' tcx > > > > ,
358
370
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 ( ) ) {
361
373
// We've been here already, no need to search again.
362
374
return ;
363
375
}
@@ -428,7 +440,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
428
440
fn record_accesses < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
429
441
caller : MonoItem < ' tcx > ,
430
442
callees : & [ MonoItem < ' tcx > ] ,
431
- inlining_map : & mut InliningMap < ' tcx > ) {
443
+ inlining_map : MTRef < ' _ , MTLock < InliningMap < ' tcx > > > ) {
432
444
let is_inlining_candidate = |mono_item : & MonoItem < ' tcx > | {
433
445
mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
434
446
} ;
@@ -438,7 +450,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
438
450
( * mono_item, is_inlining_candidate ( mono_item) )
439
451
} ) ;
440
452
441
- inlining_map. record_accesses ( caller, accesses) ;
453
+ inlining_map. lock_mut ( ) . record_accesses ( caller, accesses) ;
442
454
}
443
455
444
456
fn check_recursion_limit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments