@@ -13,7 +13,7 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}
1313use rustc_attr as attr;
1414use rustc_data_structures:: fx:: FxHashMap ;
1515use 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 } ;
1717use rustc_hir as hir;
1818use rustc_hir:: def_id:: { LocalDefId , LOCAL_CRATE } ;
1919use rustc_hir:: lang_items:: LangItem ;
@@ -554,8 +554,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
554554 codegen_units
555555 } ;
556556
557- let total_codegen_time = Lock :: new ( Duration :: new ( 0 , 0 ) ) ;
558-
559557 // The non-parallel compiler can only translate codegen units to LLVM IR
560558 // on a single thread, leading to a staircase effect where the N LLVM
561559 // threads have to wait on the single codegen threads to generate work
@@ -578,23 +576,25 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
578576 . collect ( ) ;
579577
580578 // 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)
582582 . map ( |( i, _) | {
583- let start_time = Instant :: now ( ) ;
584583 let module = backend. compile_codegen_unit ( tcx, codegen_units[ i] . name ( ) ) ;
585- let mut time = total_codegen_time. lock ( ) ;
586- * time += start_time. elapsed ( ) ;
587584 ( i, module)
588585 } )
589- . collect ( )
586+ . collect ( ) ;
587+
588+ ( pre_compiled_cgus, start_time. elapsed ( ) )
590589 } )
591590 } else {
592- FxHashMap :: default ( )
591+ ( FxHashMap :: default ( ) , Duration :: new ( 0 , 0 ) )
593592 }
594593 } ;
595594
596595 let mut cgu_reuse = Vec :: new ( ) ;
597596 let mut pre_compiled_cgus: Option < FxHashMap < usize , _ > > = None ;
597+ let mut total_codegen_time = Duration :: new ( 0 , 0 ) ;
598598
599599 for ( i, cgu) in codegen_units. iter ( ) . enumerate ( ) {
600600 ongoing_codegen. wait_for_signal_to_codegen_item ( ) ;
@@ -607,7 +607,9 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
607607 codegen_units. iter ( ) . map ( |cgu| determine_cgu_reuse ( tcx, & cgu) ) . collect ( )
608608 } ) ;
609609 // 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;
611613 }
612614
613615 let cgu_reuse = cgu_reuse[ i] ;
@@ -621,8 +623,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
621623 } else {
622624 let start_time = Instant :: now ( ) ;
623625 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 ( ) ;
626627 module
627628 } ;
628629 submit_codegened_module_to_llvm (
@@ -663,11 +664,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
663664
664665 // Since the main thread is sometimes blocked during codegen, we keep track
665666 // -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) ;
671668
672669 ongoing_codegen. check_for_errors ( tcx. sess ) ;
673670
0 commit comments