@@ -13,7 +13,7 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}
13
13
use rustc_attr as attr;
14
14
use rustc_data_structures:: fx:: FxHashMap ;
15
15
use rustc_data_structures:: profiling:: print_time_passes_entry;
16
- use rustc_data_structures:: sync:: { par_iter, Lock , ParallelIterator } ;
16
+ use rustc_data_structures:: sync:: { par_iter, ParallelIterator } ;
17
17
use rustc_hir as hir;
18
18
use rustc_hir:: def_id:: { LocalDefId , LOCAL_CRATE } ;
19
19
use rustc_hir:: lang_items:: LangItem ;
@@ -554,8 +554,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
554
554
codegen_units
555
555
} ;
556
556
557
- let total_codegen_time = Lock :: new ( Duration :: new ( 0 , 0 ) ) ;
558
-
559
557
// The non-parallel compiler can only translate codegen units to LLVM IR
560
558
// on a single thread, leading to a staircase effect where the N LLVM
561
559
// threads have to wait on the single codegen threads to generate work
@@ -578,23 +576,25 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
578
576
. collect ( ) ;
579
577
580
578
// Compile the found CGUs in parallel.
581
- par_iter ( cgus)
579
+ let start_time = Instant :: now ( ) ;
580
+
581
+ let pre_compiled_cgus = par_iter ( cgus)
582
582
. map ( |( i, _) | {
583
- let start_time = Instant :: now ( ) ;
584
583
let module = backend. compile_codegen_unit ( tcx, codegen_units[ i] . name ( ) ) ;
585
- let mut time = total_codegen_time. lock ( ) ;
586
- * time += start_time. elapsed ( ) ;
587
584
( i, module)
588
585
} )
589
- . collect ( )
586
+ . collect ( ) ;
587
+
588
+ ( pre_compiled_cgus, start_time. elapsed ( ) )
590
589
} )
591
590
} else {
592
- FxHashMap :: default ( )
591
+ ( FxHashMap :: default ( ) , Duration :: new ( 0 , 0 ) )
593
592
}
594
593
} ;
595
594
596
595
let mut cgu_reuse = Vec :: new ( ) ;
597
596
let mut pre_compiled_cgus: Option < FxHashMap < usize , _ > > = None ;
597
+ let mut total_codegen_time = Duration :: new ( 0 , 0 ) ;
598
598
599
599
for ( i, cgu) in codegen_units. iter ( ) . enumerate ( ) {
600
600
ongoing_codegen. wait_for_signal_to_codegen_item ( ) ;
@@ -607,7 +607,9 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
607
607
codegen_units. iter ( ) . map ( |cgu| determine_cgu_reuse ( tcx, & cgu) ) . collect ( )
608
608
} ) ;
609
609
// Pre compile some CGUs
610
- pre_compiled_cgus = Some ( pre_compile_cgus ( & cgu_reuse) ) ;
610
+ let ( compiled_cgus, codegen_time) = pre_compile_cgus ( & cgu_reuse) ;
611
+ pre_compiled_cgus = Some ( compiled_cgus) ;
612
+ total_codegen_time += codegen_time;
611
613
}
612
614
613
615
let cgu_reuse = cgu_reuse[ i] ;
@@ -621,8 +623,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
621
623
} else {
622
624
let start_time = Instant :: now ( ) ;
623
625
let module = backend. compile_codegen_unit ( tcx, cgu. name ( ) ) ;
624
- let mut time = total_codegen_time. lock ( ) ;
625
- * time += start_time. elapsed ( ) ;
626
+ total_codegen_time += start_time. elapsed ( ) ;
626
627
module
627
628
} ;
628
629
submit_codegened_module_to_llvm (
@@ -663,11 +664,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
663
664
664
665
// Since the main thread is sometimes blocked during codegen, we keep track
665
666
// -Ztime-passes output manually.
666
- print_time_passes_entry (
667
- tcx. sess . time_passes ( ) ,
668
- "codegen_to_LLVM_IR" ,
669
- total_codegen_time. into_inner ( ) ,
670
- ) ;
667
+ print_time_passes_entry ( tcx. sess . time_passes ( ) , "codegen_to_LLVM_IR" , total_codegen_time) ;
671
668
672
669
ongoing_codegen. check_for_errors ( tcx. sess ) ;
673
670
0 commit comments