@@ -29,7 +29,7 @@ use super::ModuleKind;
29
29
use super :: CachedModuleCodegen ;
30
30
31
31
use abi;
32
- use back:: write:: { self , OngoingCodegen } ;
32
+ use back:: write;
33
33
use llvm;
34
34
use metadata;
35
35
use rustc:: dep_graph:: cgu_reuse_tracker:: CguReuse ;
@@ -48,7 +48,6 @@ use rustc::util::profiling::ProfileCategory;
48
48
use rustc:: session:: config:: { self , DebugInfo , EntryFnType , Lto } ;
49
49
use rustc:: session:: Session ;
50
50
use rustc_incremental;
51
- use allocator;
52
51
use mir:: place:: PlaceRef ;
53
52
use builder:: { Builder , MemFlags } ;
54
53
use callee;
@@ -591,9 +590,10 @@ fn maybe_create_entry_wrapper<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll
591
590
}
592
591
}
593
592
594
- fn write_metadata < ' a , ' gcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
595
- llvm_module : & ModuleLlvm )
596
- -> EncodedMetadata {
593
+ pub ( crate ) fn write_metadata < ' a , ' gcx > (
594
+ tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
595
+ llvm_module : & ModuleLlvm
596
+ ) -> EncodedMetadata {
597
597
use std:: io:: Write ;
598
598
use flate2:: Compression ;
599
599
use flate2:: write:: DeflateEncoder ;
@@ -720,21 +720,23 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
720
720
}
721
721
}
722
722
723
- pub fn codegen_crate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
724
- rx : mpsc:: Receiver < Box < dyn Any + Send > > )
725
- -> OngoingCodegen
726
- {
723
+ pub fn codegen_crate < ' a , ' tcx , B : BackendMethods > (
724
+ backend : B ,
725
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
726
+ rx : mpsc:: Receiver < Box < dyn Any + Send > >
727
+ ) -> B :: OngoingCodegen {
728
+
727
729
check_for_rustc_errors_attr ( tcx) ;
728
730
729
731
if let Some ( true ) = tcx. sess . opts . debugging_opts . thinlto {
730
- if unsafe { !llvm :: LLVMRustThinLTOAvailable ( ) } {
732
+ if backend . thin_lto_available ( ) {
731
733
tcx. sess . fatal ( "this compiler's LLVM does not support ThinLTO" ) ;
732
734
}
733
735
}
734
736
735
737
if ( tcx. sess . opts . debugging_opts . pgo_gen . is_some ( ) ||
736
738
!tcx. sess . opts . debugging_opts . pgo_use . is_empty ( ) ) &&
737
- unsafe { !llvm :: LLVMRustPGOAvailable ( ) }
739
+ backend . pgo_available ( )
738
740
{
739
741
tcx. sess . fatal ( "this compiler's LLVM does not support PGO" ) ;
740
742
}
@@ -748,9 +750,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
748
750
& [ "crate" ] ,
749
751
Some ( "metadata" ) ) . as_str ( )
750
752
. to_string ( ) ;
751
- let metadata_llvm_module = ModuleLlvm :: new ( tcx. sess , & metadata_cgu_name) ;
753
+ let metadata_llvm_module = backend . new_metadata ( tcx. sess , & metadata_cgu_name) ;
752
754
let metadata = time ( tcx. sess , "write metadata" , || {
753
- write_metadata ( tcx, & metadata_llvm_module)
755
+ backend . write_metadata ( tcx, & metadata_llvm_module)
754
756
} ) ;
755
757
tcx. sess . profiler ( |p| p. end_activity ( ProfileCategory :: Codegen ) ) ;
756
758
@@ -769,19 +771,19 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
769
771
// Skip crate items and just output metadata in -Z no-codegen mode.
770
772
if tcx. sess . opts . debugging_opts . no_codegen ||
771
773
!tcx. sess . opts . output_types . should_codegen ( ) {
772
- let ongoing_codegen = write :: start_async_codegen (
774
+ let ongoing_codegen = backend . start_async_codegen (
773
775
tcx,
774
776
time_graph. clone ( ) ,
775
777
metadata,
776
778
rx,
777
779
1 ) ;
778
780
779
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
780
- ongoing_codegen . codegen_finished ( tcx) ;
781
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, metadata_module) ;
782
+ backend . codegen_finished ( & ongoing_codegen , tcx) ;
781
783
782
784
assert_and_save_dep_graph ( tcx) ;
783
785
784
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
786
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
785
787
786
788
return ongoing_codegen;
787
789
}
@@ -802,7 +804,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
802
804
}
803
805
}
804
806
805
- let ongoing_codegen = write :: start_async_codegen (
807
+ let ongoing_codegen = backend . start_async_codegen (
806
808
tcx,
807
809
time_graph. clone ( ) ,
808
810
metadata,
@@ -830,11 +832,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
830
832
& [ "crate" ] ,
831
833
Some ( "allocator" ) ) . as_str ( )
832
834
. to_string ( ) ;
833
- let modules = ModuleLlvm :: new ( tcx. sess , & llmod_id) ;
835
+ let modules = backend . new_metadata ( tcx. sess , & llmod_id) ;
834
836
time ( tcx. sess , "write allocator module" , || {
835
- unsafe {
836
- allocator:: codegen ( tcx, & modules, kind)
837
- }
837
+ backend. codegen_allocator ( tcx, & modules, kind)
838
838
} ) ;
839
839
840
840
Some ( ModuleCodegen {
@@ -847,10 +847,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
847
847
} ;
848
848
849
849
if let Some ( allocator_module) = allocator_module {
850
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, allocator_module) ;
850
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, allocator_module) ;
851
851
}
852
852
853
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
853
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, metadata_module) ;
854
854
855
855
// We sort the codegen units by size. This way we can schedule work for LLVM
856
856
// a bit more efficiently.
@@ -864,8 +864,8 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
864
864
let mut all_stats = Stats :: default ( ) ;
865
865
866
866
for cgu in codegen_units. into_iter ( ) {
867
- ongoing_codegen . wait_for_signal_to_codegen_item ( ) ;
868
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
867
+ backend . wait_for_signal_to_codegen_item ( & ongoing_codegen ) ;
868
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
869
869
870
870
let cgu_reuse = determine_cgu_reuse ( tcx, & cgu) ;
871
871
tcx. sess . cgu_reuse_tracker . set_actual_reuse ( & cgu. name ( ) . as_str ( ) , cgu_reuse) ;
@@ -900,7 +900,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
900
900
} ;
901
901
}
902
902
903
- ongoing_codegen . codegen_finished ( tcx) ;
903
+ backend . codegen_finished ( & ongoing_codegen , tcx) ;
904
904
905
905
// Since the main thread is sometimes blocked during codegen, we keep track
906
906
// -Ztime-passes output manually.
@@ -934,7 +934,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
934
934
}
935
935
}
936
936
937
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
937
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
938
938
939
939
assert_and_save_dep_graph ( tcx) ;
940
940
ongoing_codegen
@@ -1192,7 +1192,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1192
1192
fn module_codegen < ' a , ' tcx > (
1193
1193
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1194
1194
cgu_name : InternedString )
1195
- -> ( Stats , ModuleCodegen )
1195
+ -> ( Stats , ModuleCodegen < ModuleLlvm > )
1196
1196
{
1197
1197
let cgu = tcx. codegen_unit ( cgu_name) ;
1198
1198
@@ -1343,9 +1343,9 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
1343
1343
mod temp_stable_hash_impls {
1344
1344
use rustc_data_structures:: stable_hasher:: { StableHasherResult , StableHasher ,
1345
1345
HashStable } ;
1346
- use ModuleCodegen ;
1346
+ use { ModuleCodegen , ModuleLlvm } ;
1347
1347
1348
- impl < HCX > HashStable < HCX > for ModuleCodegen {
1348
+ impl < HCX > HashStable < HCX > for ModuleCodegen < ModuleLlvm > {
1349
1349
fn hash_stable < W : StableHasherResult > ( & self ,
1350
1350
_: & mut HCX ,
1351
1351
_: & mut StableHasher < W > ) {
0 commit comments