@@ -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;
@@ -584,9 +583,10 @@ fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
584
583
}
585
584
}
586
585
587
- fn write_metadata < ' a , ' gcx > ( tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
588
- llvm_module : & ModuleLlvm )
589
- -> EncodedMetadata {
586
+ pub ( crate ) fn write_metadata < ' a , ' gcx > (
587
+ tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
588
+ llvm_module : & ModuleLlvm
589
+ ) -> EncodedMetadata {
590
590
use std:: io:: Write ;
591
591
use flate2:: Compression ;
592
592
use flate2:: write:: DeflateEncoder ;
@@ -713,10 +713,12 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
713
713
}
714
714
}
715
715
716
- pub fn codegen_crate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
717
- rx : mpsc:: Receiver < Box < dyn Any + Send > > )
718
- -> OngoingCodegen
719
- {
716
+ pub fn codegen_crate < ' a , ' tcx , B : BackendMethods > (
717
+ backend : B ,
718
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
719
+ rx : mpsc:: Receiver < Box < dyn Any + Send > >
720
+ ) -> B :: OngoingCodegen {
721
+
720
722
check_for_rustc_errors_attr ( tcx) ;
721
723
722
724
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
@@ -728,9 +730,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
728
730
& [ "crate" ] ,
729
731
Some ( "metadata" ) ) . as_str ( )
730
732
. to_string ( ) ;
731
- let metadata_llvm_module = ModuleLlvm :: new ( tcx. sess , & metadata_cgu_name) ;
733
+ let metadata_llvm_module = backend . new_metadata ( tcx. sess , & metadata_cgu_name) ;
732
734
let metadata = time ( tcx. sess , "write metadata" , || {
733
- write_metadata ( tcx, & metadata_llvm_module)
735
+ backend . write_metadata ( tcx, & metadata_llvm_module)
734
736
} ) ;
735
737
tcx. sess . profiler ( |p| p. end_activity ( ProfileCategory :: Codegen ) ) ;
736
738
@@ -749,19 +751,19 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
749
751
// Skip crate items and just output metadata in -Z no-codegen mode.
750
752
if tcx. sess . opts . debugging_opts . no_codegen ||
751
753
!tcx. sess . opts . output_types . should_codegen ( ) {
752
- let ongoing_codegen = write :: start_async_codegen (
754
+ let ongoing_codegen = backend . start_async_codegen (
753
755
tcx,
754
756
time_graph,
755
757
metadata,
756
758
rx,
757
759
1 ) ;
758
760
759
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
760
- ongoing_codegen . codegen_finished ( tcx) ;
761
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, metadata_module) ;
762
+ backend . codegen_finished ( & ongoing_codegen , tcx) ;
761
763
762
764
assert_and_save_dep_graph ( tcx) ;
763
765
764
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
766
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
765
767
766
768
return ongoing_codegen;
767
769
}
@@ -782,13 +784,13 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
782
784
}
783
785
}
784
786
785
- let ongoing_codegen = write :: start_async_codegen (
787
+ let ongoing_codegen = backend . start_async_codegen (
786
788
tcx,
787
789
time_graph. clone ( ) ,
788
790
metadata,
789
791
rx,
790
792
codegen_units. len ( ) ) ;
791
- let ongoing_codegen = AbortCodegenOnDrop ( Some ( ongoing_codegen) ) ;
793
+ let ongoing_codegen = AbortCodegenOnDrop :: < B > ( Some ( ongoing_codegen) ) ;
792
794
793
795
// Codegen an allocator shim, if necessary.
794
796
//
@@ -811,11 +813,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
811
813
& [ "crate" ] ,
812
814
Some ( "allocator" ) ) . as_str ( )
813
815
. to_string ( ) ;
814
- let modules = ModuleLlvm :: new ( tcx. sess , & llmod_id) ;
816
+ let modules = backend . new_metadata ( tcx. sess , & llmod_id) ;
815
817
time ( tcx. sess , "write allocator module" , || {
816
- unsafe {
817
- allocator:: codegen ( tcx, & modules, kind)
818
- }
818
+ backend. codegen_allocator ( tcx, & modules, kind)
819
819
} ) ;
820
820
821
821
Some ( ModuleCodegen {
@@ -828,10 +828,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
828
828
} ;
829
829
830
830
if let Some ( allocator_module) = allocator_module {
831
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, allocator_module) ;
831
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, allocator_module) ;
832
832
}
833
833
834
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
834
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, metadata_module) ;
835
835
836
836
// We sort the codegen units by size. This way we can schedule work for LLVM
837
837
// a bit more efficiently.
@@ -845,8 +845,8 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
845
845
let mut all_stats = Stats :: default ( ) ;
846
846
847
847
for cgu in codegen_units. into_iter ( ) {
848
- ongoing_codegen . wait_for_signal_to_codegen_item ( ) ;
849
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
848
+ backend . wait_for_signal_to_codegen_item ( & ongoing_codegen ) ;
849
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
850
850
851
851
let cgu_reuse = determine_cgu_reuse ( tcx, & cgu) ;
852
852
tcx. sess . cgu_reuse_tracker . set_actual_reuse ( & cgu. name ( ) . as_str ( ) , cgu_reuse) ;
@@ -881,7 +881,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
881
881
} ;
882
882
}
883
883
884
- ongoing_codegen . codegen_finished ( tcx) ;
884
+ backend . codegen_finished ( & ongoing_codegen , tcx) ;
885
885
886
886
// Since the main thread is sometimes blocked during codegen, we keep track
887
887
// -Ztime-passes output manually.
@@ -915,7 +915,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
915
915
}
916
916
}
917
917
918
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
918
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
919
919
920
920
assert_and_save_dep_graph ( tcx) ;
921
921
ongoing_codegen. into_inner ( )
@@ -938,32 +938,32 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
938
938
/// If you see this comment in the code, then it means that this workaround
939
939
/// worked! We may yet one day track down the mysterious cause of that
940
940
/// segfault...
941
- struct AbortCodegenOnDrop ( Option < OngoingCodegen > ) ;
941
+ struct AbortCodegenOnDrop < B : BackendMethods > ( Option < B :: OngoingCodegen > ) ;
942
942
943
- impl AbortCodegenOnDrop {
944
- fn into_inner ( mut self ) -> OngoingCodegen {
943
+ impl < B : BackendMethods > AbortCodegenOnDrop < B > {
944
+ fn into_inner ( mut self ) -> B :: OngoingCodegen {
945
945
self . 0 . take ( ) . unwrap ( )
946
946
}
947
947
}
948
948
949
- impl Deref for AbortCodegenOnDrop {
950
- type Target = OngoingCodegen ;
949
+ impl < B : BackendMethods > Deref for AbortCodegenOnDrop < B > {
950
+ type Target = B :: OngoingCodegen ;
951
951
952
- fn deref ( & self ) -> & OngoingCodegen {
952
+ fn deref ( & self ) -> & B :: OngoingCodegen {
953
953
self . 0 . as_ref ( ) . unwrap ( )
954
954
}
955
955
}
956
956
957
- impl DerefMut for AbortCodegenOnDrop {
958
- fn deref_mut ( & mut self ) -> & mut OngoingCodegen {
957
+ impl < B : BackendMethods > DerefMut for AbortCodegenOnDrop < B > {
958
+ fn deref_mut ( & mut self ) -> & mut B :: OngoingCodegen {
959
959
self . 0 . as_mut ( ) . unwrap ( )
960
960
}
961
961
}
962
962
963
- impl Drop for AbortCodegenOnDrop {
963
+ impl < B : BackendMethods > Drop for AbortCodegenOnDrop < B > {
964
964
fn drop ( & mut self ) {
965
965
if let Some ( codegen) = self . 0 . take ( ) {
966
- codegen . codegen_aborted ( ) ;
966
+ B :: codegen_aborted ( codegen ) ;
967
967
}
968
968
}
969
969
}
@@ -1092,7 +1092,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1092
1092
fn module_codegen < ' a , ' tcx > (
1093
1093
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1094
1094
cgu_name : InternedString )
1095
- -> ( Stats , ModuleCodegen )
1095
+ -> ( Stats , ModuleCodegen < ModuleLlvm > )
1096
1096
{
1097
1097
let cgu = tcx. codegen_unit ( cgu_name) ;
1098
1098
@@ -1226,9 +1226,9 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
1226
1226
mod temp_stable_hash_impls {
1227
1227
use rustc_data_structures:: stable_hasher:: { StableHasherResult , StableHasher ,
1228
1228
HashStable } ;
1229
- use ModuleCodegen ;
1229
+ use { ModuleCodegen , ModuleLlvm } ;
1230
1230
1231
- impl < HCX > HashStable < HCX > for ModuleCodegen {
1231
+ impl < HCX > HashStable < HCX > for ModuleCodegen < ModuleLlvm > {
1232
1232
fn hash_stable < W : StableHasherResult > ( & self ,
1233
1233
_: & mut HCX ,
1234
1234
_: & mut StableHasher < W > ) {
0 commit comments