@@ -200,18 +200,11 @@ pub(crate) fn run_fat(
200
200
modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
201
201
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
202
202
) -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError > {
203
- let diag_handler = cgcx. create_dcx ( ) ;
204
- let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & diag_handler ) ?;
203
+ let dcx = cgcx. create_dcx ( ) ;
204
+ let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & dcx ) ?;
205
205
let symbols_below_threshold =
206
206
symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
207
- fat_lto (
208
- cgcx,
209
- & diag_handler,
210
- modules,
211
- cached_modules,
212
- upstream_modules,
213
- & symbols_below_threshold,
214
- )
207
+ fat_lto ( cgcx, & dcx, modules, cached_modules, upstream_modules, & symbols_below_threshold)
215
208
}
216
209
217
210
/// Performs thin LTO by performing necessary global analysis and returning two
@@ -222,8 +215,8 @@ pub(crate) fn run_thin(
222
215
modules : Vec < ( String , ThinBuffer ) > ,
223
216
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
224
217
) -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
225
- let diag_handler = cgcx. create_dcx ( ) ;
226
- let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & diag_handler ) ?;
218
+ let dcx = cgcx. create_dcx ( ) ;
219
+ let ( symbols_below_threshold, upstream_modules) = prepare_lto ( cgcx, & dcx ) ?;
227
220
let symbols_below_threshold =
228
221
symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
229
222
if cgcx. opts . cg . linker_plugin_lto . enabled ( ) {
@@ -232,14 +225,7 @@ pub(crate) fn run_thin(
232
225
is deferred to the linker"
233
226
) ;
234
227
}
235
- thin_lto (
236
- cgcx,
237
- & diag_handler,
238
- modules,
239
- upstream_modules,
240
- cached_modules,
241
- & symbols_below_threshold,
242
- )
228
+ thin_lto ( cgcx, & dcx, modules, upstream_modules, cached_modules, & symbols_below_threshold)
243
229
}
244
230
245
231
pub ( crate ) fn prepare_thin ( module : ModuleCodegen < ModuleLlvm > ) -> ( String , ThinBuffer ) {
@@ -714,19 +700,19 @@ pub unsafe fn optimize_thin_module(
714
700
thin_module : ThinModule < LlvmCodegenBackend > ,
715
701
cgcx : & CodegenContext < LlvmCodegenBackend > ,
716
702
) -> Result < ModuleCodegen < ModuleLlvm > , FatalError > {
717
- let diag_handler = cgcx. create_dcx ( ) ;
703
+ let dcx = cgcx. create_dcx ( ) ;
718
704
719
705
let module_name = & thin_module. shared . module_names [ thin_module. idx ] ;
720
706
let tm_factory_config = TargetMachineFactoryConfig :: new ( cgcx, module_name. to_str ( ) . unwrap ( ) ) ;
721
- let tm = ( cgcx. tm_factory ) ( tm_factory_config) . map_err ( |e| write:: llvm_err ( & diag_handler , e) ) ?;
707
+ let tm = ( cgcx. tm_factory ) ( tm_factory_config) . map_err ( |e| write:: llvm_err ( & dcx , e) ) ?;
722
708
723
709
// Right now the implementation we've got only works over serialized
724
710
// modules, so we create a fresh new LLVM context and parse the module
725
711
// into that context. One day, however, we may do this for upstream
726
712
// crates but for locally codegened modules we may be able to reuse
727
713
// that LLVM Context and Module.
728
714
let llcx = llvm:: LLVMRustContextCreate ( cgcx. fewer_names ) ;
729
- let llmod_raw = parse_module ( llcx, module_name, thin_module. data ( ) , & diag_handler ) ? as * const _ ;
715
+ let llmod_raw = parse_module ( llcx, module_name, thin_module. data ( ) , & dcx ) ? as * const _ ;
730
716
let mut module = ModuleCodegen {
731
717
module_llvm : ModuleLlvm { llmod_raw, llcx, tm : ManuallyDrop :: new ( tm) } ,
732
718
name : thin_module. name ( ) . to_string ( ) ,
@@ -749,7 +735,7 @@ pub unsafe fn optimize_thin_module(
749
735
let _timer =
750
736
cgcx. prof . generic_activity_with_arg ( "LLVM_thin_lto_rename" , thin_module. name ( ) ) ;
751
737
if !llvm:: LLVMRustPrepareThinLTORename ( thin_module. shared . data . 0 , llmod, target) {
752
- return Err ( write:: llvm_err ( & diag_handler , LlvmError :: PrepareThinLtoModule ) ) ;
738
+ return Err ( write:: llvm_err ( & dcx , LlvmError :: PrepareThinLtoModule ) ) ;
753
739
}
754
740
save_temp_bitcode ( cgcx, & module, "thin-lto-after-rename" ) ;
755
741
}
@@ -759,7 +745,7 @@ pub unsafe fn optimize_thin_module(
759
745
. prof
760
746
. generic_activity_with_arg ( "LLVM_thin_lto_resolve_weak" , thin_module. name ( ) ) ;
761
747
if !llvm:: LLVMRustPrepareThinLTOResolveWeak ( thin_module. shared . data . 0 , llmod) {
762
- return Err ( write:: llvm_err ( & diag_handler , LlvmError :: PrepareThinLtoModule ) ) ;
748
+ return Err ( write:: llvm_err ( & dcx , LlvmError :: PrepareThinLtoModule ) ) ;
763
749
}
764
750
save_temp_bitcode ( cgcx, & module, "thin-lto-after-resolve" ) ;
765
751
}
@@ -769,7 +755,7 @@ pub unsafe fn optimize_thin_module(
769
755
. prof
770
756
. generic_activity_with_arg ( "LLVM_thin_lto_internalize" , thin_module. name ( ) ) ;
771
757
if !llvm:: LLVMRustPrepareThinLTOInternalize ( thin_module. shared . data . 0 , llmod) {
772
- return Err ( write:: llvm_err ( & diag_handler , LlvmError :: PrepareThinLtoModule ) ) ;
758
+ return Err ( write:: llvm_err ( & dcx , LlvmError :: PrepareThinLtoModule ) ) ;
773
759
}
774
760
save_temp_bitcode ( cgcx, & module, "thin-lto-after-internalize" ) ;
775
761
}
@@ -778,7 +764,7 @@ pub unsafe fn optimize_thin_module(
778
764
let _timer =
779
765
cgcx. prof . generic_activity_with_arg ( "LLVM_thin_lto_import" , thin_module. name ( ) ) ;
780
766
if !llvm:: LLVMRustPrepareThinLTOImport ( thin_module. shared . data . 0 , llmod, target) {
781
- return Err ( write:: llvm_err ( & diag_handler , LlvmError :: PrepareThinLtoModule ) ) ;
767
+ return Err ( write:: llvm_err ( & dcx , LlvmError :: PrepareThinLtoModule ) ) ;
782
768
}
783
769
save_temp_bitcode ( cgcx, & module, "thin-lto-after-import" ) ;
784
770
}
@@ -790,7 +776,7 @@ pub unsafe fn optimize_thin_module(
790
776
// little differently.
791
777
{
792
778
info ! ( "running thin lto passes over {}" , module. name) ;
793
- run_pass_manager ( cgcx, & diag_handler , & mut module, true ) ?;
779
+ run_pass_manager ( cgcx, & dcx , & mut module, true ) ?;
794
780
save_temp_bitcode ( cgcx, & module, "thin-lto-after-pm" ) ;
795
781
}
796
782
}
0 commit comments