Skip to content

Commit 56d3294

Browse files
authored
Rollup merge of #149209 - lto_refactors8, r=jackh726
Move LTO to OngoingCodegen::join This will make it easier to in the future move all this code to link_binary. Follow up to rust-lang/rust#147810 Part of rust-lang/compiler-team#908
2 parents 012c460 + 385590e commit 56d3294

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/back/lto.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use std::sync::atomic::Ordering;
2626
use gccjit::{Context, OutputKind};
2727
use object::read::archive::ArchiveFile;
2828
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
29-
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
29+
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter};
3030
use rustc_codegen_ssa::traits::*;
3131
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
3232
use rustc_data_structures::memmap::Mmap;
33-
use rustc_errors::DiagCtxtHandle;
33+
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3434
use rustc_log::tracing::info;
3535
use rustc_middle::bug;
3636
use rustc_middle::dep_graph::WorkProduct;
@@ -112,10 +112,11 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
112112
/// for further optimization.
113113
pub(crate) fn run_fat(
114114
cgcx: &CodegenContext<GccCodegenBackend>,
115+
shared_emitter: &SharedEmitter,
115116
each_linked_rlib_for_lto: &[PathBuf],
116117
modules: Vec<FatLtoInput<GccCodegenBackend>>,
117118
) -> ModuleCodegen<GccContext> {
118-
let dcx = cgcx.create_dcx();
119+
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
119120
let dcx = dcx.handle();
120121
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
121122
/*let symbols_below_threshold =
@@ -283,14 +284,13 @@ impl ModuleBufferMethods for ModuleBuffer {
283284
/// can simply be copied over from the incr. comp. cache.
284285
pub(crate) fn run_thin(
285286
cgcx: &CodegenContext<GccCodegenBackend>,
287+
dcx: DiagCtxtHandle<'_>,
286288
each_linked_rlib_for_lto: &[PathBuf],
287289
modules: Vec<(String, ThinBuffer)>,
288290
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
289291
) -> (Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>) {
290-
let dcx = cgcx.create_dcx();
291-
let dcx = dcx.handle();
292292
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
293-
if cgcx.opts.cg.linker_plugin_lto.enabled() {
293+
if cgcx.use_linker_plugin_lto {
294294
unreachable!(
295295
"We should never reach this case if the LTO step \
296296
is deferred to the linker"
@@ -522,8 +522,6 @@ pub fn optimize_thin_module(
522522
thin_module: ThinModule<GccCodegenBackend>,
523523
_cgcx: &CodegenContext<GccCodegenBackend>,
524524
) -> ModuleCodegen<GccContext> {
525-
//let dcx = cgcx.create_dcx();
526-
527525
//let module_name = &thin_module.shared.module_names[thin_module.idx];
528526
/*let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
529527
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&dcx, e))?;*/

src/back/write.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use std::{env, fs};
22

33
use gccjit::{Context, OutputKind};
44
use rustc_codegen_ssa::back::link::ensure_removed;
5-
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
5+
use rustc_codegen_ssa::back::write::{
6+
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, SharedEmitter,
7+
};
68
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
9+
use rustc_errors::DiagCtxt;
710
use rustc_fs_util::link_or_copy;
811
use rustc_log::tracing::debug;
912
use rustc_session::config::OutputType;
@@ -15,10 +18,11 @@ use crate::{GccCodegenBackend, GccContext, LtoMode};
1518

1619
pub(crate) fn codegen(
1720
cgcx: &CodegenContext<GccCodegenBackend>,
21+
shared_emitter: &SharedEmitter,
1822
module: ModuleCodegen<GccContext>,
1923
config: &ModuleConfig,
2024
) -> CompiledModule {
21-
let dcx = cgcx.create_dcx();
25+
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
2226
let dcx = dcx.handle();
2327

2428
let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use gccjit::{TargetInfo, Version};
8484
use rustc_ast::expand::allocator::AllocatorMethod;
8585
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule};
8686
use rustc_codegen_ssa::back::write::{
87-
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn,
87+
CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn,
8888
};
8989
use rustc_codegen_ssa::base::codegen_crate;
9090
use rustc_codegen_ssa::target_features::cfg_target_feature;
@@ -435,23 +435,25 @@ impl WriteBackendMethods for GccCodegenBackend {
435435

436436
fn run_and_optimize_fat_lto(
437437
cgcx: &CodegenContext<Self>,
438+
shared_emitter: &SharedEmitter,
438439
// FIXME(bjorn3): Limit LTO exports to these symbols
439440
_exported_symbols_for_lto: &[String],
440441
each_linked_rlib_for_lto: &[PathBuf],
441442
modules: Vec<FatLtoInput<Self>>,
442443
) -> ModuleCodegen<Self::Module> {
443-
back::lto::run_fat(cgcx, each_linked_rlib_for_lto, modules)
444+
back::lto::run_fat(cgcx, shared_emitter, each_linked_rlib_for_lto, modules)
444445
}
445446

446447
fn run_thin_lto(
447448
cgcx: &CodegenContext<Self>,
449+
dcx: DiagCtxtHandle<'_>,
448450
// FIXME(bjorn3): Limit LTO exports to these symbols
449451
_exported_symbols_for_lto: &[String],
450452
each_linked_rlib_for_lto: &[PathBuf],
451453
modules: Vec<(String, Self::ThinBuffer)>,
452454
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
453455
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>) {
454-
back::lto::run_thin(cgcx, each_linked_rlib_for_lto, modules, cached_modules)
456+
back::lto::run_thin(cgcx, dcx, each_linked_rlib_for_lto, modules, cached_modules)
455457
}
456458

457459
fn print_pass_timings(&self) {
@@ -464,7 +466,7 @@ impl WriteBackendMethods for GccCodegenBackend {
464466

465467
fn optimize(
466468
_cgcx: &CodegenContext<Self>,
467-
_dcx: DiagCtxtHandle<'_>,
469+
_shared_emitter: &SharedEmitter,
468470
module: &mut ModuleCodegen<Self::Module>,
469471
config: &ModuleConfig,
470472
) {
@@ -473,17 +475,19 @@ impl WriteBackendMethods for GccCodegenBackend {
473475

474476
fn optimize_thin(
475477
cgcx: &CodegenContext<Self>,
478+
_shared_emitter: &SharedEmitter,
476479
thin: ThinModule<Self>,
477480
) -> ModuleCodegen<Self::Module> {
478481
back::lto::optimize_thin_module(thin, cgcx)
479482
}
480483

481484
fn codegen(
482485
cgcx: &CodegenContext<Self>,
486+
shared_emitter: &SharedEmitter,
483487
module: ModuleCodegen<Self::Module>,
484488
config: &ModuleConfig,
485489
) -> CompiledModule {
486-
back::write::codegen(cgcx, module, config)
490+
back::write::codegen(cgcx, shared_emitter, module, config)
487491
}
488492

489493
fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {

0 commit comments

Comments
 (0)