@@ -200,18 +200,11 @@ pub(crate) fn run_fat(
200200 modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
201201 cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
202202) -> 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 ) ?;
205205 let symbols_below_threshold =
206206 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)
215208}
216209
217210/// Performs thin LTO by performing necessary global analysis and returning two
@@ -222,8 +215,8 @@ pub(crate) fn run_thin(
222215 modules : Vec < ( String , ThinBuffer ) > ,
223216 cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
224217) -> 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 ) ?;
227220 let symbols_below_threshold =
228221 symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
229222 if cgcx. opts . cg . linker_plugin_lto . enabled ( ) {
@@ -232,14 +225,7 @@ pub(crate) fn run_thin(
232225 is deferred to the linker"
233226 ) ;
234227 }
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)
243229}
244230
245231pub ( crate ) fn prepare_thin ( module : ModuleCodegen < ModuleLlvm > ) -> ( String , ThinBuffer ) {
@@ -714,19 +700,19 @@ pub unsafe fn optimize_thin_module(
714700 thin_module : ThinModule < LlvmCodegenBackend > ,
715701 cgcx : & CodegenContext < LlvmCodegenBackend > ,
716702) -> Result < ModuleCodegen < ModuleLlvm > , FatalError > {
717- let diag_handler = cgcx. create_dcx ( ) ;
703+ let dcx = cgcx. create_dcx ( ) ;
718704
719705 let module_name = & thin_module. shared . module_names [ thin_module. idx ] ;
720706 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) ) ?;
722708
723709 // Right now the implementation we've got only works over serialized
724710 // modules, so we create a fresh new LLVM context and parse the module
725711 // into that context. One day, however, we may do this for upstream
726712 // crates but for locally codegened modules we may be able to reuse
727713 // that LLVM Context and Module.
728714 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 _ ;
730716 let mut module = ModuleCodegen {
731717 module_llvm : ModuleLlvm { llmod_raw, llcx, tm : ManuallyDrop :: new ( tm) } ,
732718 name : thin_module. name ( ) . to_string ( ) ,
@@ -749,7 +735,7 @@ pub unsafe fn optimize_thin_module(
749735 let _timer =
750736 cgcx. prof . generic_activity_with_arg ( "LLVM_thin_lto_rename" , thin_module. name ( ) ) ;
751737 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 ) ) ;
753739 }
754740 save_temp_bitcode ( cgcx, & module, "thin-lto-after-rename" ) ;
755741 }
@@ -759,7 +745,7 @@ pub unsafe fn optimize_thin_module(
759745 . prof
760746 . generic_activity_with_arg ( "LLVM_thin_lto_resolve_weak" , thin_module. name ( ) ) ;
761747 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 ) ) ;
763749 }
764750 save_temp_bitcode ( cgcx, & module, "thin-lto-after-resolve" ) ;
765751 }
@@ -769,7 +755,7 @@ pub unsafe fn optimize_thin_module(
769755 . prof
770756 . generic_activity_with_arg ( "LLVM_thin_lto_internalize" , thin_module. name ( ) ) ;
771757 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 ) ) ;
773759 }
774760 save_temp_bitcode ( cgcx, & module, "thin-lto-after-internalize" ) ;
775761 }
@@ -778,7 +764,7 @@ pub unsafe fn optimize_thin_module(
778764 let _timer =
779765 cgcx. prof . generic_activity_with_arg ( "LLVM_thin_lto_import" , thin_module. name ( ) ) ;
780766 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 ) ) ;
782768 }
783769 save_temp_bitcode ( cgcx, & module, "thin-lto-after-import" ) ;
784770 }
@@ -790,7 +776,7 @@ pub unsafe fn optimize_thin_module(
790776 // little differently.
791777 {
792778 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 ) ?;
794780 save_temp_bitcode ( cgcx, & module, "thin-lto-after-pm" ) ;
795781 }
796782 }
0 commit comments