@@ -7,14 +7,15 @@ use std::sync::Arc;
77use std:: thread:: JoinHandle ;
88
99use cranelift_object:: { ObjectBuilder , ObjectModule } ;
10+ use rustc_codegen_ssa:: assert_module_sources:: CguReuse ;
1011use rustc_codegen_ssa:: back:: metadata:: create_compressed_metadata_file;
12+ use rustc_codegen_ssa:: base:: determine_cgu_reuse;
1113use rustc_codegen_ssa:: { CodegenResults , CompiledModule , CrateInfo , ModuleKind } ;
1214use rustc_data_structures:: profiling:: SelfProfilerRef ;
1315use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1416use rustc_metadata:: EncodedMetadata ;
1517use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
1618use rustc_middle:: mir:: mono:: { CodegenUnit , MonoItem } ;
17- use rustc_session:: cgu_reuse_tracker:: CguReuse ;
1819use rustc_session:: config:: { DebugInfo , OutputFilenames , OutputType } ;
1920use rustc_session:: Session ;
2021
@@ -374,43 +375,47 @@ pub(crate) fn run_aot(
374375 }
375376 }
376377
378+ // Calculate the CGU reuse
379+ let cgu_reuse = tcx. sess . time ( "find_cgu_reuse" , || {
380+ cgus. iter ( ) . map ( |cgu| determine_cgu_reuse ( tcx, & cgu) ) . collect :: < Vec < _ > > ( )
381+ } ) ;
382+
383+ rustc_codegen_ssa:: assert_module_sources:: assert_module_sources ( tcx, & |cgu_reuse_tracker| {
384+ for ( i, cgu) in cgus. iter ( ) . enumerate ( ) {
385+ let cgu_reuse = cgu_reuse[ i] ;
386+ cgu_reuse_tracker. set_actual_reuse ( cgu. name ( ) . as_str ( ) , cgu_reuse) ;
387+ }
388+ } ) ;
389+
377390 let global_asm_config = Arc :: new ( crate :: global_asm:: GlobalAsmConfig :: new ( tcx) ) ;
378391
379392 let mut concurrency_limiter = ConcurrencyLimiter :: new ( tcx. sess , cgus. len ( ) ) ;
380393
381394 let modules = tcx. sess . time ( "codegen mono items" , || {
382395 cgus. iter ( )
383- . map ( |cgu| {
384- let cgu_reuse = if backend_config. disable_incr_cache {
385- CguReuse :: No
386- } else {
387- determine_cgu_reuse ( tcx, cgu)
388- } ;
389- tcx. sess . cgu_reuse_tracker . set_actual_reuse ( cgu. name ( ) . as_str ( ) , cgu_reuse) ;
390-
391- match cgu_reuse {
392- CguReuse :: No => {
393- let dep_node = cgu. codegen_dep_node ( tcx) ;
394- tcx. dep_graph
395- . with_task (
396- dep_node,
397- tcx,
398- (
399- backend_config. clone ( ) ,
400- global_asm_config. clone ( ) ,
401- cgu. name ( ) ,
402- concurrency_limiter. acquire ( tcx. sess . diagnostic ( ) ) ,
403- ) ,
404- module_codegen,
405- Some ( rustc_middle:: dep_graph:: hash_result) ,
406- )
407- . 0
408- }
409- CguReuse :: PreLto => unreachable ! ( ) ,
410- CguReuse :: PostLto => {
411- concurrency_limiter. job_already_done ( ) ;
412- OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) )
413- }
396+ . enumerate ( )
397+ . map ( |( i, cgu) | match cgu_reuse[ i] {
398+ CguReuse :: No => {
399+ let dep_node = cgu. codegen_dep_node ( tcx) ;
400+ tcx. dep_graph
401+ . with_task (
402+ dep_node,
403+ tcx,
404+ (
405+ backend_config. clone ( ) ,
406+ global_asm_config. clone ( ) ,
407+ cgu. name ( ) ,
408+ concurrency_limiter. acquire ( tcx. sess . diagnostic ( ) ) ,
409+ ) ,
410+ module_codegen,
411+ Some ( rustc_middle:: dep_graph:: hash_result) ,
412+ )
413+ . 0
414+ }
415+ CguReuse :: PreLto => unreachable ! ( "LTO not yet supported" ) ,
416+ CguReuse :: PostLto => {
417+ concurrency_limiter. job_already_done ( ) ;
418+ OngoingModuleCodegen :: Sync ( reuse_workproduct_for_cgu ( tcx, cgu) )
414419 }
415420 } )
416421 . collect :: < Vec < _ > > ( )
@@ -489,32 +494,3 @@ pub(crate) fn run_aot(
489494 concurrency_limiter,
490495 } )
491496}
492-
493- // Adapted from https://github.com/rust-lang/rust/blob/303d8aff6092709edd4dbd35b1c88e9aa40bf6d8/src/librustc_codegen_ssa/base.rs#L922-L953
494- fn determine_cgu_reuse < ' tcx > ( tcx : TyCtxt < ' tcx > , cgu : & CodegenUnit < ' tcx > ) -> CguReuse {
495- if !tcx. dep_graph . is_fully_enabled ( ) {
496- return CguReuse :: No ;
497- }
498-
499- let work_product_id = & cgu. work_product_id ( ) ;
500- if tcx. dep_graph . previous_work_product ( work_product_id) . is_none ( ) {
501- // We don't have anything cached for this CGU. This can happen
502- // if the CGU did not exist in the previous session.
503- return CguReuse :: No ;
504- }
505-
506- // Try to mark the CGU as green. If it we can do so, it means that nothing
507- // affecting the LLVM module has changed and we can re-use a cached version.
508- // If we compile with any kind of LTO, this means we can re-use the bitcode
509- // of the Pre-LTO stage (possibly also the Post-LTO version but we'll only
510- // know that later). If we are not doing LTO, there is only one optimized
511- // version of each module, so we re-use that.
512- let dep_node = cgu. codegen_dep_node ( tcx) ;
513- assert ! (
514- !tcx. dep_graph. dep_node_exists( & dep_node) ,
515- "CompileCodegenUnit dep-node for CGU `{}` already exists before marking." ,
516- cgu. name( )
517- ) ;
518-
519- if tcx. try_mark_green ( & dep_node) { CguReuse :: PostLto } else { CguReuse :: No }
520- }
0 commit comments