@@ -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:: { ParallelIterator , par_iter, Lock } ;
214
216
215
217
#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
216
218
pub enum MonoItemCollectionMode {
@@ -298,22 +300,26 @@ 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) ;
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
+ } ) ;
315
321
316
- ( visited, inlining_map)
322
+ ( visited. into_inner ( ) , inlining_map. into_inner ( ) )
317
323
}
318
324
319
325
// 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>,
354
360
// Collect all monomorphized items reachable from `starting_point`
355
361
fn collect_items_rec < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
356
362
starting_point : MonoItem < ' tcx > ,
357
- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
363
+ visited : & Lock < FxHashSet < MonoItem < ' tcx > > > ,
358
364
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 ( ) ) {
361
367
// We've been here already, no need to search again.
362
368
return ;
363
369
}
@@ -428,7 +434,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
428
434
fn record_accesses < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
429
435
caller : MonoItem < ' tcx > ,
430
436
callees : & [ MonoItem < ' tcx > ] ,
431
- inlining_map : & mut InliningMap < ' tcx > ) {
437
+ inlining_map : & Lock < InliningMap < ' tcx > > ) {
432
438
let is_inlining_candidate = |mono_item : & MonoItem < ' tcx > | {
433
439
mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
434
440
} ;
@@ -438,7 +444,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
438
444
( * mono_item, is_inlining_candidate ( mono_item) )
439
445
} ) ;
440
446
441
- inlining_map. record_accesses ( caller, accesses) ;
447
+ inlining_map. lock ( ) . record_accesses ( caller, accesses) ;
442
448
}
443
449
444
450
fn check_recursion_limit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments