@@ -15,7 +15,7 @@ use object::{Object, ObjectSection};
15
15
use crate :: debuginfo:: TypeDebugContext ;
16
16
use crate :: prelude:: * ;
17
17
18
- struct SerializeModule {
18
+ pub ( super ) struct SerializeModule {
19
19
isa : Arc < dyn isa:: TargetIsa > ,
20
20
inner : SerializeModuleInner ,
21
21
}
@@ -33,11 +33,11 @@ impl SerializeModule {
33
33
postcard:: to_stdvec ( & self . inner ) . unwrap ( )
34
34
}
35
35
36
- fn deserialize ( blob : & [ u8 ] , isa : Arc < dyn isa:: TargetIsa > ) -> SerializeModule {
36
+ pub ( super ) fn deserialize ( blob : & [ u8 ] , isa : Arc < dyn isa:: TargetIsa > ) -> SerializeModule {
37
37
SerializeModule { isa, inner : postcard:: from_bytes ( blob) . unwrap ( ) }
38
38
}
39
39
40
- fn apply_to ( self , module : & mut dyn Module ) {
40
+ pub ( super ) fn apply_to ( self , module : & mut dyn Module ) {
41
41
//println!("{:#?}", self.inner);
42
42
43
43
let mut function_map: SecondaryMap < FuncId , Option < FuncId > > = SecondaryMap :: new ( ) ;
@@ -492,34 +492,12 @@ fn module_codegen(
492
492
}
493
493
}
494
494
495
- pub ( crate ) fn run_aot (
495
+ pub ( super ) fn load_lto_modules (
496
496
tcx : TyCtxt < ' _ > ,
497
- backend_config : BackendConfig ,
498
- metadata : EncodedMetadata ,
499
- need_metadata_module : bool ,
500
- ) -> Box < OngoingCodegen > {
501
- // FIXME handle `-Ctarget-cpu=native`
502
- let target_cpu = match tcx. sess . opts . cg . target_cpu {
503
- Some ( ref name) => name,
504
- None => tcx. sess . target . cpu . as_ref ( ) ,
505
- }
506
- . to_owned ( ) ;
507
-
508
- let crate_info = CrateInfo :: new ( tcx, target_cpu) ;
509
-
510
- let cgus = if tcx. sess . opts . output_types . should_codegen ( ) {
511
- tcx. collect_and_partition_mono_items ( ( ) ) . 1
512
- } else {
513
- // If only `--emit metadata` is used, we shouldn't perform any codegen.
514
- // Also `tcx.collect_and_partition_mono_items` may panic in that case.
515
- & [ ]
516
- } ;
517
-
518
- let mut modules = tcx. sess . time ( "codegen mono items" , || {
519
- cgus. iter ( )
520
- . map ( |cgu| module_codegen ( tcx, ( backend_config. clone ( ) , cgu. name ( ) ) ) )
521
- . collect :: < Vec < _ > > ( )
522
- } ) ;
497
+ crate_info : & CrateInfo ,
498
+ backend_config : & BackendConfig ,
499
+ ) -> Vec < ( String , SerializeModule ) > {
500
+ let mut modules = vec ! [ ] ;
523
501
524
502
if !( tcx. crate_types ( ) . len ( ) == 1
525
503
&& tcx. crate_types ( ) [ 0 ] == rustc_session:: config:: CrateType :: Rlib )
@@ -561,14 +539,47 @@ pub(crate) fn run_aot(
561
539
lto_object. section_by_name ( ".rodata.cgclif_lto" ) . unwrap ( ) . data ( ) . unwrap ( ) ,
562
540
crate :: build_isa ( tcx. sess , & backend_config) ,
563
541
) ;
564
- modules. push (
565
- emit_module ( tcx, & backend_config, module, ModuleKind :: Regular , name. to_owned ( ) )
566
- . unwrap ( ) ,
567
- ) ;
542
+ modules. push ( ( name. to_owned ( ) , module) ) ;
568
543
}
569
544
}
570
545
}
571
546
547
+ modules
548
+ }
549
+
550
+ pub ( crate ) fn run_aot (
551
+ tcx : TyCtxt < ' _ > ,
552
+ backend_config : BackendConfig ,
553
+ metadata : EncodedMetadata ,
554
+ need_metadata_module : bool ,
555
+ ) -> Box < OngoingCodegen > {
556
+ // FIXME handle `-Ctarget-cpu=native`
557
+ let target_cpu = match tcx. sess . opts . cg . target_cpu {
558
+ Some ( ref name) => name,
559
+ None => tcx. sess . target . cpu . as_ref ( ) ,
560
+ }
561
+ . to_owned ( ) ;
562
+
563
+ let crate_info = CrateInfo :: new ( tcx, target_cpu) ;
564
+
565
+ let cgus = if tcx. sess . opts . output_types . should_codegen ( ) {
566
+ tcx. collect_and_partition_mono_items ( ( ) ) . 1
567
+ } else {
568
+ // If only `--emit metadata` is used, we shouldn't perform any codegen.
569
+ // Also `tcx.collect_and_partition_mono_items` may panic in that case.
570
+ & [ ]
571
+ } ;
572
+
573
+ let mut modules = tcx. sess . time ( "codegen mono items" , || {
574
+ cgus. iter ( )
575
+ . map ( |cgu| module_codegen ( tcx, ( backend_config. clone ( ) , cgu. name ( ) ) ) )
576
+ . collect :: < Vec < _ > > ( )
577
+ } ) ;
578
+
579
+ for ( name, module) in load_lto_modules ( tcx, & crate_info, & backend_config) {
580
+ modules. push ( emit_module ( tcx, & backend_config, module, ModuleKind :: Regular , name) . unwrap ( ) ) ;
581
+ }
582
+
572
583
let mut allocator_module = make_module ( tcx. sess , & backend_config) ;
573
584
let created_alloc_shim = crate :: allocator:: codegen ( tcx, & mut allocator_module) ;
574
585
0 commit comments