@@ -9,7 +9,9 @@ use std::{io, iter, slice};
99use object:: read:: archive:: ArchiveFile ;
1010use object:: { Object , ObjectSection } ;
1111use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule , ThinShared } ;
12- use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput , SharedEmitter } ;
12+ use rustc_codegen_ssa:: back:: write:: {
13+ CodegenContext , FatLtoInput , SharedEmitter , TargetMachineFactoryFn ,
14+ } ;
1315use rustc_codegen_ssa:: traits:: * ;
1416use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
1517use rustc_data_structures:: fx:: FxHashMap ;
@@ -33,7 +35,7 @@ use crate::{LlvmCodegenBackend, ModuleLlvm};
3335const THIN_LTO_KEYS_INCR_COMP_FILE_NAME : & str = "thin-lto-past-keys.bin" ;
3436
3537fn prepare_lto (
36- cgcx : & CodegenContext < LlvmCodegenBackend > ,
38+ cgcx : & CodegenContext ,
3739 exported_symbols_for_lto : & [ String ] ,
3840 each_linked_rlib_for_lto : & [ PathBuf ] ,
3941 dcx : DiagCtxtHandle < ' _ > ,
@@ -123,7 +125,7 @@ fn prepare_lto(
123125
124126fn get_bitcode_slice_from_object_data < ' a > (
125127 obj : & ' a [ u8 ] ,
126- cgcx : & CodegenContext < LlvmCodegenBackend > ,
128+ cgcx : & CodegenContext ,
127129) -> Result < & ' a [ u8 ] , LtoBitcodeFromRlib > {
128130 // We're about to assume the data here is an object file with sections, but if it's raw LLVM IR
129131 // that won't work. Fortunately, if that's what we have we can just return the object directly,
@@ -149,8 +151,9 @@ fn get_bitcode_slice_from_object_data<'a>(
149151/// Performs fat LTO by merging all modules into a single one and returning it
150152/// for further optimization.
151153pub ( crate ) fn run_fat (
152- cgcx : & CodegenContext < LlvmCodegenBackend > ,
154+ cgcx : & CodegenContext ,
153155 shared_emitter : & SharedEmitter ,
156+ tm_factory : TargetMachineFactoryFn < LlvmCodegenBackend > ,
154157 exported_symbols_for_lto : & [ String ] ,
155158 each_linked_rlib_for_lto : & [ PathBuf ] ,
156159 modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
@@ -161,14 +164,22 @@ pub(crate) fn run_fat(
161164 prepare_lto ( cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx) ;
162165 let symbols_below_threshold =
163166 symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
164- fat_lto ( cgcx, dcx, shared_emitter, modules, upstream_modules, & symbols_below_threshold)
167+ fat_lto (
168+ cgcx,
169+ dcx,
170+ shared_emitter,
171+ tm_factory,
172+ modules,
173+ upstream_modules,
174+ & symbols_below_threshold,
175+ )
165176}
166177
167178/// Performs thin LTO by performing necessary global analysis and returning two
168179/// lists, one of the modules that need optimization and another for modules that
169180/// can simply be copied over from the incr. comp. cache.
170181pub ( crate ) fn run_thin (
171- cgcx : & CodegenContext < LlvmCodegenBackend > ,
182+ cgcx : & CodegenContext ,
172183 dcx : DiagCtxtHandle < ' _ > ,
173184 exported_symbols_for_lto : & [ String ] ,
174185 each_linked_rlib_for_lto : & [ PathBuf ] ,
@@ -195,9 +206,10 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBu
195206}
196207
197208fn fat_lto (
198- cgcx : & CodegenContext < LlvmCodegenBackend > ,
209+ cgcx : & CodegenContext ,
199210 dcx : DiagCtxtHandle < ' _ > ,
200211 shared_emitter : & SharedEmitter ,
212+ tm_factory : TargetMachineFactoryFn < LlvmCodegenBackend > ,
201213 modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
202214 mut serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
203215 symbols_below_threshold : & [ * const libc:: c_char ] ,
@@ -252,7 +264,7 @@ fn fat_lto(
252264 assert ! ( !serialized_modules. is_empty( ) , "must have at least one serialized module" ) ;
253265 let ( buffer, name) = serialized_modules. remove ( 0 ) ;
254266 info ! ( "no in-memory regular modules to choose from, parsing {:?}" , name) ;
255- let llvm_module = ModuleLlvm :: parse ( cgcx, & name, buffer. data ( ) , dcx) ;
267+ let llvm_module = ModuleLlvm :: parse ( cgcx, tm_factory , & name, buffer. data ( ) , dcx) ;
256268 ModuleCodegen :: new_regular ( name. into_string ( ) . unwrap ( ) , llvm_module)
257269 }
258270 } ;
@@ -381,7 +393,7 @@ impl Drop for Linker<'_> {
381393/// all of the `LtoModuleCodegen` units returned below and destroyed once
382394/// they all go out of scope.
383395fn thin_lto (
384- cgcx : & CodegenContext < LlvmCodegenBackend > ,
396+ cgcx : & CodegenContext ,
385397 dcx : DiagCtxtHandle < ' _ > ,
386398 modules : Vec < ( String , ThinBuffer ) > ,
387399 serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
@@ -585,7 +597,7 @@ pub(crate) fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
585597}
586598
587599pub ( crate ) fn run_pass_manager (
588- cgcx : & CodegenContext < LlvmCodegenBackend > ,
600+ cgcx : & CodegenContext ,
589601 dcx : DiagCtxtHandle < ' _ > ,
590602 module : & mut ModuleCodegen < ModuleLlvm > ,
591603 thin : bool ,
@@ -726,8 +738,9 @@ impl Drop for ThinBuffer {
726738}
727739
728740pub ( crate ) fn optimize_thin_module (
729- cgcx : & CodegenContext < LlvmCodegenBackend > ,
741+ cgcx : & CodegenContext ,
730742 shared_emitter : & SharedEmitter ,
743+ tm_factory : TargetMachineFactoryFn < LlvmCodegenBackend > ,
731744 thin_module : ThinModule < LlvmCodegenBackend > ,
732745) -> ModuleCodegen < ModuleLlvm > {
733746 let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
@@ -740,7 +753,7 @@ pub(crate) fn optimize_thin_module(
740753 // into that context. One day, however, we may do this for upstream
741754 // crates but for locally codegened modules we may be able to reuse
742755 // that LLVM Context and Module.
743- let module_llvm = ModuleLlvm :: parse ( cgcx, module_name, thin_module. data ( ) , dcx) ;
756+ let module_llvm = ModuleLlvm :: parse ( cgcx, tm_factory , module_name, thin_module. data ( ) , dcx) ;
744757 let mut module = ModuleCodegen :: new_regular ( thin_module. name ( ) , module_llvm) ;
745758 // Given that the newly created module lacks a thinlto buffer for embedding, we need to re-add it here.
746759 if cgcx. module_config . embed_bitcode ( ) {
0 commit comments