@@ -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,12 +720,27 @@ 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
731
+ if let Some ( true ) = tcx. sess . opts . debugging_opts . thinlto {
732
+ if backend. thin_lto_available ( ) {
733
+ tcx. sess . fatal ( "this compiler's LLVM does not support ThinLTO" ) ;
734
+ }
735
+ }
736
+
737
+ if ( tcx. sess . opts . debugging_opts . pgo_gen . is_some ( ) ||
738
+ !tcx. sess . opts . debugging_opts . pgo_use . is_empty ( ) ) &&
739
+ backend. pgo_available ( )
740
+ {
741
+ tcx. sess . fatal ( "this compiler's LLVM does not support PGO" ) ;
742
+ }
743
+
729
744
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
730
745
731
746
// Codegen the metadata.
@@ -735,9 +750,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
735
750
& [ "crate" ] ,
736
751
Some ( "metadata" ) ) . as_str ( )
737
752
. to_string ( ) ;
738
- let metadata_llvm_module = ModuleLlvm :: new ( tcx. sess , & metadata_cgu_name) ;
753
+ let metadata_llvm_module = backend . new_metadata ( tcx. sess , & metadata_cgu_name) ;
739
754
let metadata = time ( tcx. sess , "write metadata" , || {
740
- write_metadata ( tcx, & metadata_llvm_module)
755
+ backend . write_metadata ( tcx, & metadata_llvm_module)
741
756
} ) ;
742
757
tcx. sess . profiler ( |p| p. end_activity ( ProfileCategory :: Codegen ) ) ;
743
758
@@ -756,19 +771,19 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
756
771
// Skip crate items and just output metadata in -Z no-codegen mode.
757
772
if tcx. sess . opts . debugging_opts . no_codegen ||
758
773
!tcx. sess . opts . output_types . should_codegen ( ) {
759
- let ongoing_codegen = write :: start_async_codegen (
774
+ let ongoing_codegen = backend . start_async_codegen (
760
775
tcx,
761
776
time_graph,
762
777
metadata,
763
778
rx,
764
779
1 ) ;
765
780
766
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
767
- 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) ;
768
783
769
784
assert_and_save_dep_graph ( tcx) ;
770
785
771
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
786
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
772
787
773
788
return ongoing_codegen;
774
789
}
@@ -789,7 +804,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
789
804
}
790
805
}
791
806
792
- let ongoing_codegen = write :: start_async_codegen (
807
+ let ongoing_codegen = backend . start_async_codegen (
793
808
tcx,
794
809
time_graph. clone ( ) ,
795
810
metadata,
@@ -818,11 +833,9 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
818
833
& [ "crate" ] ,
819
834
Some ( "allocator" ) ) . as_str ( )
820
835
. to_string ( ) ;
821
- let modules = ModuleLlvm :: new ( tcx. sess , & llmod_id) ;
836
+ let modules = backend . new_metadata ( tcx. sess , & llmod_id) ;
822
837
time ( tcx. sess , "write allocator module" , || {
823
- unsafe {
824
- allocator:: codegen ( tcx, & modules, kind)
825
- }
838
+ backend. codegen_allocator ( tcx, & modules, kind)
826
839
} ) ;
827
840
828
841
Some ( ModuleCodegen {
@@ -835,10 +848,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
835
848
} ;
836
849
837
850
if let Some ( allocator_module) = allocator_module {
838
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, allocator_module) ;
851
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, allocator_module) ;
839
852
}
840
853
841
- ongoing_codegen . submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
854
+ backend . submit_pre_codegened_module_to_llvm ( & ongoing_codegen , tcx, metadata_module) ;
842
855
843
856
// We sort the codegen units by size. This way we can schedule work for LLVM
844
857
// a bit more efficiently.
@@ -852,8 +865,8 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
852
865
let mut all_stats = Stats :: default ( ) ;
853
866
854
867
for cgu in codegen_units. into_iter ( ) {
855
- ongoing_codegen . wait_for_signal_to_codegen_item ( ) ;
856
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
868
+ backend . wait_for_signal_to_codegen_item ( & ongoing_codegen ) ;
869
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
857
870
858
871
let cgu_reuse = determine_cgu_reuse ( tcx, & cgu) ;
859
872
tcx. sess . cgu_reuse_tracker . set_actual_reuse ( & cgu. name ( ) . as_str ( ) , cgu_reuse) ;
@@ -888,7 +901,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
888
901
} ;
889
902
}
890
903
891
- ongoing_codegen . codegen_finished ( tcx) ;
904
+ backend . codegen_finished ( & ongoing_codegen , tcx) ;
892
905
893
906
// Since the main thread is sometimes blocked during codegen, we keep track
894
907
// -Ztime-passes output manually.
@@ -922,7 +935,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
922
935
}
923
936
}
924
937
925
- ongoing_codegen . check_for_errors ( tcx. sess ) ;
938
+ backend . check_for_errors ( & ongoing_codegen , tcx. sess ) ;
926
939
927
940
assert_and_save_dep_graph ( tcx) ;
928
941
ongoing_codegen. into_inner ( )
@@ -1099,7 +1112,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1099
1112
fn module_codegen < ' a , ' tcx > (
1100
1113
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1101
1114
cgu_name : InternedString )
1102
- -> ( Stats , ModuleCodegen )
1115
+ -> ( Stats , ModuleCodegen < ModuleLlvm > )
1103
1116
{
1104
1117
let cgu = tcx. codegen_unit ( cgu_name) ;
1105
1118
@@ -1233,9 +1246,9 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
1233
1246
mod temp_stable_hash_impls {
1234
1247
use rustc_data_structures:: stable_hasher:: { StableHasherResult , StableHasher ,
1235
1248
HashStable } ;
1236
- use ModuleCodegen ;
1249
+ use { ModuleCodegen , ModuleLlvm } ;
1237
1250
1238
- impl < HCX > HashStable < HCX > for ModuleCodegen {
1251
+ impl < HCX > HashStable < HCX > for ModuleCodegen < ModuleLlvm > {
1239
1252
fn hash_stable < W : StableHasherResult > ( & self ,
1240
1253
_: & mut HCX ,
1241
1254
_: & mut StableHasher < W > ) {
0 commit comments