@@ -7,14 +7,15 @@ use std::sync::Arc;
7
7
use std:: thread:: JoinHandle ;
8
8
9
9
use cranelift_object:: { ObjectBuilder , ObjectModule } ;
10
+ use rustc_codegen_ssa:: assert_module_sources:: CguReuse ;
10
11
use rustc_codegen_ssa:: back:: metadata:: create_compressed_metadata_file;
12
+ use rustc_codegen_ssa:: base:: determine_cgu_reuse;
11
13
use rustc_codegen_ssa:: { CodegenResults , CompiledModule , CrateInfo , ModuleKind } ;
12
14
use rustc_data_structures:: profiling:: SelfProfilerRef ;
13
15
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
14
16
use rustc_metadata:: EncodedMetadata ;
15
17
use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
16
18
use rustc_middle:: mir:: mono:: { CodegenUnit , MonoItem } ;
17
- use rustc_session:: cgu_reuse_tracker:: CguReuse ;
18
19
use rustc_session:: config:: { DebugInfo , OutputFilenames , OutputType } ;
19
20
use rustc_session:: Session ;
20
21
@@ -374,43 +375,47 @@ pub(crate) fn run_aot(
374
375
}
375
376
}
376
377
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
+
377
390
let global_asm_config = Arc :: new ( crate :: global_asm:: GlobalAsmConfig :: new ( tcx) ) ;
378
391
379
392
let mut concurrency_limiter = ConcurrencyLimiter :: new ( tcx. sess , cgus. len ( ) ) ;
380
393
381
394
let modules = tcx. sess . time ( "codegen mono items" , || {
382
395
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) )
414
419
}
415
420
} )
416
421
. collect :: < Vec < _ > > ( )
@@ -489,32 +494,3 @@ pub(crate) fn run_aot(
489
494
concurrency_limiter,
490
495
} )
491
496
}
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