Skip to content

Commit 8e7a49f

Browse files
committed
Fuse codegen into LTO optimize methods
1 parent 3cd6b24 commit 8e7a49f

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/back/lto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ use object::read::archive::ArchiveFile;
2626
use rustc_codegen_ssa::back::lto::SerializedModule;
2727
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter};
2828
use rustc_codegen_ssa::traits::*;
29-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
29+
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind, looks_like_rust_object_file};
3030
use rustc_data_structures::memmap::Mmap;
3131
use rustc_data_structures::profiling::SelfProfilerRef;
3232
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3333
use rustc_log::tracing::info;
3434
use rustc_session::config::Lto;
3535
use tempfile::{TempDir, tempdir};
3636

37-
use crate::back::write::save_temp_bitcode;
37+
use crate::back::write::{codegen, save_temp_bitcode};
3838
use crate::errors::LtoBitcodeFromRlib;
3939
use crate::{GccCodegenBackend, GccContext, LtoMode, to_gcc_opt_level};
4040

@@ -112,7 +112,7 @@ pub(crate) fn run_fat(
112112
shared_emitter: &SharedEmitter,
113113
each_linked_rlib_for_lto: &[PathBuf],
114114
modules: Vec<FatLtoInput<GccCodegenBackend>>,
115-
) -> ModuleCodegen<GccContext> {
115+
) -> CompiledModule {
116116
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
117117
let dcx = dcx.handle();
118118
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
@@ -132,12 +132,12 @@ pub(crate) fn run_fat(
132132
fn fat_lto(
133133
cgcx: &CodegenContext,
134134
prof: &SelfProfilerRef,
135-
_dcx: DiagCtxtHandle<'_>,
135+
dcx: DiagCtxtHandle<'_>,
136136
modules: Vec<FatLtoInput<GccCodegenBackend>>,
137137
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
138138
tmp_path: TempDir,
139139
//symbols_below_threshold: &[String],
140-
) -> ModuleCodegen<GccContext> {
140+
) -> CompiledModule {
141141
let _timer = prof.generic_activity("GCC_fat_lto_build_monolithic_module");
142142
info!("going for a fat lto");
143143

@@ -260,7 +260,7 @@ fn fat_lto(
260260
// of now.
261261
module.module_llvm.temp_dir = Some(tmp_path);
262262

263-
module
263+
codegen(cgcx, prof, dcx, module, &cgcx.module_config)
264264
}
265265

266266
pub struct ModuleBuffer(PathBuf);

src/back/write.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ 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::{
6-
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, SharedEmitter,
7-
};
5+
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
86
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
97
use rustc_data_structures::profiling::SelfProfilerRef;
10-
use rustc_errors::DiagCtxt;
8+
use rustc_errors::DiagCtxtHandle;
119
use rustc_fs_util::link_or_copy;
1210
use rustc_log::tracing::debug;
1311
use rustc_session::config::OutputType;
@@ -20,13 +18,10 @@ use crate::{GccContext, LtoMode};
2018
pub(crate) fn codegen(
2119
cgcx: &CodegenContext,
2220
prof: &SelfProfilerRef,
23-
shared_emitter: &SharedEmitter,
21+
dcx: DiagCtxtHandle<'_>,
2422
module: ModuleCodegen<GccContext>,
2523
config: &ModuleConfig,
2624
) -> CompiledModule {
27-
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
28-
let dcx = dcx.handle();
29-
3025
let _timer = prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
3126
{
3227
let context = &module.module_llvm.context;

src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use rustc_codegen_ssa::{CompiledModule, CompiledModules, CrateInfo, ModuleCodege
9292
use rustc_data_structures::fx::FxIndexMap;
9393
use rustc_data_structures::profiling::SelfProfilerRef;
9494
use rustc_data_structures::sync::IntoDynSyncSend;
95-
use rustc_errors::DiagCtxtHandle;
95+
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
9696
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
9797
use rustc_middle::ty::TyCtxt;
9898
use rustc_middle::util::Providers;
@@ -429,7 +429,7 @@ impl WriteBackendMethods for GccCodegenBackend {
429429
type ModuleBuffer = ModuleBuffer;
430430
type ThinData = ();
431431

432-
fn run_and_optimize_fat_lto(
432+
fn optimize_and_codegen_fat_lto(
433433
cgcx: &CodegenContext,
434434
prof: &SelfProfilerRef,
435435
shared_emitter: &SharedEmitter,
@@ -438,7 +438,7 @@ impl WriteBackendMethods for GccCodegenBackend {
438438
_exported_symbols_for_lto: &[String],
439439
each_linked_rlib_for_lto: &[PathBuf],
440440
modules: Vec<FatLtoInput<Self>>,
441-
) -> ModuleCodegen<Self::Module> {
441+
) -> CompiledModule {
442442
back::lto::run_fat(cgcx, prof, shared_emitter, each_linked_rlib_for_lto, modules)
443443
}
444444

@@ -465,13 +465,13 @@ impl WriteBackendMethods for GccCodegenBackend {
465465
module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level));
466466
}
467467

468-
fn optimize_thin(
468+
fn optimize_and_codegen_thin(
469469
_cgcx: &CodegenContext,
470470
_prof: &SelfProfilerRef,
471471
_shared_emitter: &SharedEmitter,
472472
_tm_factory: TargetMachineFactoryFn<Self>,
473473
_thin: ThinModule<Self>,
474-
) -> ModuleCodegen<Self::Module> {
474+
) -> CompiledModule {
475475
unreachable!()
476476
}
477477

@@ -482,7 +482,9 @@ impl WriteBackendMethods for GccCodegenBackend {
482482
module: ModuleCodegen<Self::Module>,
483483
config: &ModuleConfig,
484484
) -> CompiledModule {
485-
back::write::codegen(cgcx, prof, shared_emitter, module, config)
485+
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
486+
let dcx = dcx.handle();
487+
back::write::codegen(cgcx, prof, dcx, module, config)
486488
}
487489

488490
fn serialize_module(_module: Self::Module, _is_thin: bool) -> Self::ModuleBuffer {

0 commit comments

Comments
 (0)