@@ -9,7 +9,7 @@ use libc::{c_char, c_int, c_void, size_t};
99use rustc_codegen_ssa:: back:: link:: ensure_removed;
1010use rustc_codegen_ssa:: back:: versioned_llvm_target;
1111use rustc_codegen_ssa:: back:: write:: {
12- BitcodeSection , CodegenContext , EmitObj , InlineAsmError , ModuleConfig ,
12+ BitcodeSection , CodegenContext , EmitObj , InlineAsmError , ModuleConfig , SharedEmitter ,
1313 TargetMachineFactoryConfig , TargetMachineFactoryFn ,
1414} ;
1515use rustc_codegen_ssa:: base:: wants_wasm_eh;
@@ -18,7 +18,7 @@ use rustc_codegen_ssa::traits::*;
1818use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen , ModuleKind } ;
1919use rustc_data_structures:: profiling:: SelfProfilerRef ;
2020use rustc_data_structures:: small_c_str:: SmallCStr ;
21- use rustc_errors:: { DiagCtxtHandle , Level } ;
21+ use rustc_errors:: { DiagCtxt , DiagCtxtHandle , Level } ;
2222use rustc_fs_util:: { link_or_copy, path_to_c_string} ;
2323use rustc_middle:: ty:: TyCtxt ;
2424use rustc_session:: Session ;
@@ -356,15 +356,15 @@ pub(crate) enum CodegenDiagnosticsStage {
356356}
357357
358358pub ( crate ) struct DiagnosticHandlers < ' a > {
359- data : * mut ( & ' a CodegenContext < LlvmCodegenBackend > , DiagCtxtHandle < ' a > ) ,
359+ data : * mut ( & ' a CodegenContext < LlvmCodegenBackend > , & ' a SharedEmitter ) ,
360360 llcx : & ' a llvm:: Context ,
361361 old_handler : Option < & ' a llvm:: DiagnosticHandler > ,
362362}
363363
364364impl < ' a > DiagnosticHandlers < ' a > {
365365 pub ( crate ) fn new (
366366 cgcx : & ' a CodegenContext < LlvmCodegenBackend > ,
367- dcx : DiagCtxtHandle < ' a > ,
367+ shared_emitter : & ' a SharedEmitter ,
368368 llcx : & ' a llvm:: Context ,
369369 module : & ModuleCodegen < ModuleLlvm > ,
370370 stage : CodegenDiagnosticsStage ,
@@ -398,8 +398,8 @@ impl<'a> DiagnosticHandlers<'a> {
398398 } )
399399 . and_then ( |dir| dir. to_str ( ) . and_then ( |p| CString :: new ( p) . ok ( ) ) ) ;
400400
401- let pgo_available = cgcx. opts . cg . profile_use . is_some ( ) ;
402- let data = Box :: into_raw ( Box :: new ( ( cgcx, dcx ) ) ) ;
401+ let pgo_available = cgcx. module_config . pgo_use . is_some ( ) ;
402+ let data = Box :: into_raw ( Box :: new ( ( cgcx, shared_emitter ) ) ) ;
403403 unsafe {
404404 let old_handler = llvm:: LLVMRustContextGetDiagnosticHandler ( llcx) ;
405405 llvm:: LLVMRustContextConfigureDiagnosticHandler (
@@ -461,12 +461,16 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
461461 if user. is_null ( ) {
462462 return ;
463463 }
464- let ( cgcx, dcx) =
465- unsafe { * ( user as * const ( & CodegenContext < LlvmCodegenBackend > , DiagCtxtHandle < ' _ > ) ) } ;
464+ let ( cgcx, shared_emitter) =
465+ unsafe { * ( user as * const ( & CodegenContext < LlvmCodegenBackend > , & SharedEmitter ) ) } ;
466+
467+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
468+ let dcx = dcx. handle ( ) ;
466469
467470 match unsafe { llvm:: diagnostic:: Diagnostic :: unpack ( info) } {
468471 llvm:: diagnostic:: InlineAsm ( inline) => {
469- cgcx. diag_emitter . inline_asm_error ( report_inline_asm (
472+ // FIXME use dcx
473+ shared_emitter. inline_asm_error ( report_inline_asm (
470474 cgcx,
471475 inline. message ,
472476 inline. level ,
@@ -776,7 +780,7 @@ pub(crate) unsafe fn llvm_optimize(
776780 & * module. module_llvm . tm . raw ( ) ,
777781 to_pass_builder_opt_level ( opt_level) ,
778782 opt_stage,
779- cgcx. opts . cg . linker_plugin_lto . enabled ( ) ,
783+ cgcx. use_linker_plugin_lto ,
780784 config. no_prepopulate_passes ,
781785 config. verify_llvm_ir ,
782786 config. lint_llvm_ir ,
@@ -887,14 +891,18 @@ pub(crate) unsafe fn llvm_optimize(
887891// Unsafe due to LLVM calls.
888892pub ( crate ) fn optimize (
889893 cgcx : & CodegenContext < LlvmCodegenBackend > ,
890- dcx : DiagCtxtHandle < ' _ > ,
894+ shared_emitter : & SharedEmitter ,
891895 module : & mut ModuleCodegen < ModuleLlvm > ,
892896 config : & ModuleConfig ,
893897) {
894898 let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
895899
900+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
901+ let dcx = dcx. handle ( ) ;
902+
896903 let llcx = & * module. module_llvm . llcx ;
897- let _handlers = DiagnosticHandlers :: new ( cgcx, dcx, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
904+ let _handlers =
905+ DiagnosticHandlers :: new ( cgcx, shared_emitter, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
898906
899907 if config. emit_no_opt_bc {
900908 let out = cgcx. output_filenames . temp_path_ext_for_cgu (
@@ -911,7 +919,7 @@ pub(crate) fn optimize(
911919 let opt_stage = match cgcx. lto {
912920 Lto :: Fat => llvm:: OptStage :: PreLinkFatLTO ,
913921 Lto :: Thin | Lto :: ThinLocal => llvm:: OptStage :: PreLinkThinLTO ,
914- _ if cgcx. opts . cg . linker_plugin_lto . enabled ( ) => llvm:: OptStage :: PreLinkThinLTO ,
922+ _ if cgcx. use_linker_plugin_lto => llvm:: OptStage :: PreLinkThinLTO ,
915923 _ => llvm:: OptStage :: PreLinkNoLTO ,
916924 } ;
917925
@@ -974,19 +982,26 @@ pub(crate) fn optimize(
974982
975983pub ( crate ) fn codegen (
976984 cgcx : & CodegenContext < LlvmCodegenBackend > ,
985+ shared_emitter : & SharedEmitter ,
977986 module : ModuleCodegen < ModuleLlvm > ,
978987 config : & ModuleConfig ,
979988) -> CompiledModule {
980- let dcx = cgcx. create_dcx ( ) ;
989+ let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen" , & * module. name ) ;
990+
991+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
981992 let dcx = dcx. handle ( ) ;
982993
983- let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen" , & * module. name ) ;
984994 {
985995 let llmod = module. module_llvm . llmod ( ) ;
986996 let llcx = & * module. module_llvm . llcx ;
987997 let tm = & * module. module_llvm . tm ;
988- let _handlers =
989- DiagnosticHandlers :: new ( cgcx, dcx, llcx, & module, CodegenDiagnosticsStage :: Codegen ) ;
998+ let _handlers = DiagnosticHandlers :: new (
999+ cgcx,
1000+ shared_emitter,
1001+ llcx,
1002+ & module,
1003+ CodegenDiagnosticsStage :: Codegen ,
1004+ ) ;
9901005
9911006 if cgcx. msvc_imps_needed {
9921007 create_msvc_imps ( cgcx, llcx, llmod) ;
0 commit comments