2020use std:: ffi:: CString ;
2121use std:: fs:: { self , File } ;
2222use std:: path:: { Path , PathBuf } ;
23+ use std:: sync:: Arc ;
2324
2425use gccjit:: OutputKind ;
2526use object:: read:: archive:: ArchiveFile ;
@@ -29,14 +30,15 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter}
2930use rustc_codegen_ssa:: traits:: * ;
3031use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen , ModuleKind } ;
3132use rustc_data_structures:: memmap:: Mmap ;
32- use rustc_data_structures:: profiling:: SelfProfilerRef ;
3333use rustc_errors:: { DiagCtxt , DiagCtxtHandle } ;
3434use rustc_log:: tracing:: info;
35+ use rustc_session:: Session ;
3536use tempfile:: { TempDir , tempdir} ;
3637
3738use crate :: back:: write:: { codegen, save_temp_bitcode} ;
3839use crate :: errors:: LtoBitcodeFromRlib ;
39- use crate :: { GccCodegenBackend , GccContext , LtoMode , to_gcc_opt_level} ;
40+ use crate :: gcc_util:: new_context;
41+ use crate :: { GccCodegenBackend , GccContext , LtoMode , SyncContext , to_gcc_opt_level} ;
4042
4143struct LtoData {
4244 // FIXME(antoyo): use symbols_below_threshold.
@@ -102,8 +104,8 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
102104/// Performs fat LTO by merging all modules into a single one and returning it
103105/// for further optimization.
104106pub ( crate ) fn run_fat (
107+ sess : & Session ,
105108 cgcx : & CodegenContext ,
106- prof : & SelfProfilerRef ,
107109 shared_emitter : & SharedEmitter ,
108110 each_linked_rlib_for_lto : & [ PathBuf ] ,
109111 modules : Vec < FatLtoInput < GccCodegenBackend > > ,
@@ -114,8 +116,8 @@ pub(crate) fn run_fat(
114116 /*let symbols_below_threshold =
115117 lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
116118 fat_lto (
119+ sess,
117120 cgcx,
118- prof,
119121 dcx,
120122 modules,
121123 lto_data. upstream_modules ,
@@ -125,15 +127,15 @@ pub(crate) fn run_fat(
125127}
126128
127129fn fat_lto (
130+ sess : & Session ,
128131 cgcx : & CodegenContext ,
129- prof : & SelfProfilerRef ,
130132 dcx : DiagCtxtHandle < ' _ > ,
131133 modules : Vec < FatLtoInput < GccCodegenBackend > > ,
132134 mut serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
133135 tmp_path : TempDir ,
134136 //symbols_below_threshold: &[String],
135137) -> CompiledModule {
136- let _timer = prof. generic_activity ( "GCC_fat_lto_build_monolithic_module" ) ;
138+ let _timer = sess . prof . generic_activity ( "GCC_fat_lto_build_monolithic_module" ) ;
137139 info ! ( "going for a fat lto" ) ;
138140
139141 // Sort out all our lists of incoming modules into two lists.
@@ -183,17 +185,16 @@ fn fat_lto(
183185 // module and create a linker with it.
184186 let mut module: ModuleCodegen < GccContext > = match costliest_module {
185187 Some ( ( _cost, i) ) => in_memory. remove ( i) ,
186- None => {
187- unimplemented ! ( "Incremental" ) ;
188- /*assert!(!serialized_modules.is_empty(), "must have at least one serialized module");
189- let (buffer, name) = serialized_modules.remove(0);
190- info!("no in-memory regular modules to choose from, parsing {:?}", name);
191- ModuleCodegen {
192- module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?,
193- name: name.into_string().unwrap(),
194- kind: ModuleKind::Regular,
195- }*/
196- }
188+ None => ModuleCodegen :: new_regular (
189+ "lto_module" . to_string ( ) ,
190+ GccContext {
191+ context : Arc :: new ( SyncContext :: new ( new_context ( sess) ) ) ,
192+ relocation_model : sess. relocation_model ( ) ,
193+ lto_supported : true ,
194+ lto_mode : LtoMode :: None ,
195+ temp_dir : None ,
196+ } ,
197+ ) ,
197198 } ;
198199 {
199200 info ! ( "using {:?} as a base module" , module. name) ;
@@ -220,7 +221,8 @@ fn fat_lto(
220221 // We add the object files and save in should_combine_object_files that we should combine
221222 // them into a single object file when compiling later.
222223 for ( bc_decoded, name) in serialized_modules {
223- let _timer = prof
224+ let _timer = sess
225+ . prof
224226 . generic_activity_with_arg_recorder ( "GCC_fat_lto_link_module" , |recorder| {
225227 recorder. record_arg ( format ! ( "{:?}" , name) )
226228 } ) ;
@@ -258,7 +260,7 @@ fn fat_lto(
258260 // of now.
259261 module. module_llvm . temp_dir = Some ( tmp_path) ;
260262
261- codegen ( cgcx, prof, dcx, module, & cgcx. module_config )
263+ codegen ( cgcx, & sess . prof , dcx, module, & cgcx. module_config )
262264}
263265
264266pub struct ModuleBuffer ( PathBuf ) ;
0 commit comments