@@ -43,7 +43,7 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
43
43
fn prepare_lto (
44
44
cgcx : & CodegenContext < LlvmCodegenBackend > ,
45
45
diag_handler : & Handler ,
46
- ) -> Result < ( Vec < CString > , Vec < ( SerializedModule < ModuleBuffer > , CString ) > ) , FatalError > {
46
+ ) -> Result < ( Vec < CString > , Vec < ( SerializedModule < ModuleBuffer > , CString ) > ) , FatalError > {
47
47
let export_threshold = match cgcx. lto {
48
48
// We're just doing LTO for our one crate
49
49
Lto :: ThinLocal => SymbolExportLevel :: Rust ,
@@ -169,8 +169,7 @@ pub(crate) fn run_fat(
169
169
cgcx : & CodegenContext < LlvmCodegenBackend > ,
170
170
modules : Vec < FatLTOInput < LlvmCodegenBackend > > ,
171
171
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
172
- ) -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError > {
173
-
172
+ ) -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError > {
174
173
let diag_handler = cgcx. create_diag_handler ( ) ;
175
174
let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & diag_handler) ?;
176
175
let symbols_below_threshold =
@@ -182,7 +181,7 @@ pub(crate) fn run_fat(
182
181
cached_modules,
183
182
upstream_modules,
184
183
& symbols_below_threshold,
185
- )
184
+ )
186
185
}
187
186
188
187
/// Performs thin LTO by performing necessary global analysis and returning two
@@ -192,7 +191,7 @@ pub(crate) fn run_thin(
192
191
cgcx : & CodegenContext < LlvmCodegenBackend > ,
193
192
modules : Vec < ( String , ThinBuffer ) > ,
194
193
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
195
- ) -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
194
+ ) -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
196
195
let diag_handler = cgcx. create_diag_handler ( ) ;
197
196
let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & diag_handler) ?;
198
197
let symbols_below_threshold =
@@ -201,7 +200,7 @@ pub(crate) fn run_thin(
201
200
unreachable ! (
202
201
"We should never reach this case if the LTO step \
203
202
is deferred to the linker"
204
- ) ;
203
+ ) ;
205
204
}
206
205
thin_lto (
207
206
cgcx,
@@ -210,7 +209,7 @@ pub(crate) fn run_thin(
210
209
upstream_modules,
211
210
cached_modules,
212
211
& symbols_below_threshold,
213
- )
212
+ )
214
213
}
215
214
216
215
pub ( crate ) fn prepare_thin ( module : ModuleCodegen < ModuleLlvm > ) -> ( String , ThinBuffer ) {
@@ -226,7 +225,7 @@ fn fat_lto(
226
225
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
227
226
mut serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
228
227
symbols_below_threshold : & [ * const libc:: c_char ] ,
229
- ) -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError > {
228
+ ) -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError > {
230
229
let _timer = cgcx. prof . generic_activity ( "LLVM_fat_lto_build_monolithic_module" ) ;
231
230
info ! ( "going for a fat lto" ) ;
232
231
@@ -273,7 +272,7 @@ fn fat_lto(
273
272
let cost = unsafe { llvm:: LLVMRustModuleCost ( module. module_llvm . llmod ( ) ) } ;
274
273
( cost, i)
275
274
} )
276
- . max ( ) ;
275
+ . max ( ) ;
277
276
278
277
// If we found a costliest module, we're good to go. Otherwise all our
279
278
// inputs were serialized which could happen in the case, for example, that
@@ -347,7 +346,7 @@ fn fat_lto(
347
346
llmod,
348
347
ptr as * const * const libc:: c_char ,
349
348
symbols_below_threshold. len ( ) as libc:: size_t ,
350
- ) ;
349
+ ) ;
351
350
save_temp_bitcode ( cgcx, & module, "lto.after-restriction" ) ;
352
351
}
353
352
}
@@ -368,7 +367,7 @@ impl<'a> Linker<'a> {
368
367
self . 0 ,
369
368
bytecode. as_ptr ( ) as * const libc:: c_char ,
370
369
bytecode. len ( ) ,
371
- ) {
370
+ ) {
372
371
Ok ( ( ) )
373
372
} else {
374
373
Err ( ( ) )
@@ -422,7 +421,7 @@ fn thin_lto(
422
421
serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
423
422
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
424
423
symbols_below_threshold : & [ * const libc:: c_char ] ,
425
- ) -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
424
+ ) -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
426
425
let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_global_analysis" ) ;
427
426
unsafe {
428
427
info ! ( "going for that thin, thin LTO" ) ;
@@ -500,22 +499,22 @@ fn thin_lto(
500
499
501
500
let ( key_map_path, prev_key_map, curr_key_map) = if let Some ( ref incr_comp_session_dir) =
502
501
cgcx. incr_comp_session_dir
503
- {
504
- let path = incr_comp_session_dir. join ( THIN_LTO_KEYS_INCR_COMP_FILE_NAME ) ;
505
- // If the previous file was deleted, or we get an IO error
506
- // reading the file, then we'll just use `None` as the
507
- // prev_key_map, which will force the code to be recompiled.
508
- let prev =
509
- if path. exists ( ) { ThinLTOKeysMap :: load_from_file ( & path) . ok ( ) } else { None } ;
510
- let curr = ThinLTOKeysMap :: from_thin_lto_modules ( & data, & thin_modules, & module_names) ;
511
- ( Some ( path) , prev, curr)
512
- } else {
513
- // If we don't compile incrementally, we don't need to load the
514
- // import data from LLVM.
515
- assert ! ( green_modules. is_empty( ) ) ;
516
- let curr = ThinLTOKeysMap :: default ( ) ;
517
- ( None , None , curr)
518
- } ;
502
+ {
503
+ let path = incr_comp_session_dir. join ( THIN_LTO_KEYS_INCR_COMP_FILE_NAME ) ;
504
+ // If the previous file was deleted, or we get an IO error
505
+ // reading the file, then we'll just use `None` as the
506
+ // prev_key_map, which will force the code to be recompiled.
507
+ let prev =
508
+ if path. exists ( ) { ThinLTOKeysMap :: load_from_file ( & path) . ok ( ) } else { None } ;
509
+ let curr = ThinLTOKeysMap :: from_thin_lto_modules ( & data, & thin_modules, & module_names) ;
510
+ ( Some ( path) , prev, curr)
511
+ } else {
512
+ // If we don't compile incrementally, we don't need to load the
513
+ // import data from LLVM.
514
+ assert ! ( green_modules. is_empty( ) ) ;
515
+ let curr = ThinLTOKeysMap :: default ( ) ;
516
+ ( None , None , curr)
517
+ } ;
519
518
info ! ( "thin LTO cache key map loaded" ) ;
520
519
info ! ( "prev_key_map: {:#?}" , prev_key_map) ;
521
520
info ! ( "curr_key_map: {:#?}" , curr_key_map) ;
@@ -539,20 +538,20 @@ fn thin_lto(
539
538
let module_name = module_name_to_str ( module_name) ;
540
539
if let ( Some ( prev_key_map) , true ) =
541
540
( prev_key_map. as_ref ( ) , green_modules. contains_key ( module_name) )
542
- {
541
+ {
542
+ assert ! ( cgcx. incr_comp_session_dir. is_some( ) ) ;
543
+
544
+ // If a module exists in both the current and the previous session,
545
+ // and has the same LTO cache key in both sessions, then we can re-use it
546
+ if prev_key_map. keys . get ( module_name) == curr_key_map. keys . get ( module_name) {
547
+ let work_product = green_modules[ module_name] . clone ( ) ;
548
+ copy_jobs. push ( work_product) ;
549
+ info ! ( " - {}: re-used" , module_name) ;
543
550
assert ! ( cgcx. incr_comp_session_dir. is_some( ) ) ;
544
-
545
- // If a module exists in both the current and the previous session,
546
- // and has the same LTO cache key in both sessions, then we can re-use it
547
- if prev_key_map. keys . get ( module_name) == curr_key_map. keys . get ( module_name) {
548
- let work_product = green_modules[ module_name] . clone ( ) ;
549
- copy_jobs. push ( work_product) ;
550
- info ! ( " - {}: re-used" , module_name) ;
551
- assert ! ( cgcx. incr_comp_session_dir. is_some( ) ) ;
552
- cgcx. cgu_reuse_tracker . set_actual_reuse ( module_name, CguReuse :: PostLto ) ;
553
- continue ;
554
- }
551
+ cgcx. cgu_reuse_tracker . set_actual_reuse ( module_name, CguReuse :: PostLto ) ;
552
+ continue ;
555
553
}
554
+ }
556
555
557
556
info ! ( " - {}: re-compiled" , module_name) ;
558
557
opt_jobs. push ( LtoModuleCodegen :: Thin ( ThinModule {
@@ -686,7 +685,7 @@ impl Drop for ThinBuffer {
686
685
pub unsafe fn optimize_thin_module (
687
686
thin_module : ThinModule < LlvmCodegenBackend > ,
688
687
cgcx : & CodegenContext < LlvmCodegenBackend > ,
689
- ) -> Result < ModuleCodegen < ModuleLlvm > , FatalError > {
688
+ ) -> Result < ModuleCodegen < ModuleLlvm > , FatalError > {
690
689
let diag_handler = cgcx. create_diag_handler ( ) ;
691
690
692
691
let module_name = & thin_module. shared . module_names [ thin_module. idx ] ;
@@ -855,7 +854,7 @@ impl ThinLTOKeysMap {
855
854
data : & ThinData ,
856
855
modules : & [ llvm:: ThinLTOModule ] ,
857
856
names : & [ CString ] ,
858
- ) -> Self {
857
+ ) -> Self {
859
858
let keys = iter:: zip ( modules, names)
860
859
. map ( |( module, name) | {
861
860
let key = build_string ( |rust_str| unsafe {
@@ -864,7 +863,7 @@ impl ThinLTOKeysMap {
864
863
. expect ( "Invalid ThinLTO module key" ) ;
865
864
( name. clone ( ) . into_string ( ) . unwrap ( ) , key)
866
865
} )
867
- . collect ( ) ;
866
+ . collect ( ) ;
868
867
Self { keys }
869
868
}
870
869
}
@@ -880,7 +879,7 @@ pub fn parse_module<'a>(
880
879
name : & CStr ,
881
880
data : & [ u8 ] ,
882
881
diag_handler : & Handler ,
883
- ) -> Result < & ' a llvm:: Module , FatalError > {
882
+ ) -> Result < & ' a llvm:: Module , FatalError > {
884
883
unsafe {
885
884
llvm:: LLVMRustParseBitcodeForLTO ( cx, data. as_ptr ( ) , data. len ( ) , name. as_ptr ( ) )
886
885
. ok_or_else ( || write:: llvm_err ( diag_handler, LlvmError :: ParseBitcode ) )
0 commit comments