Skip to content

Commit b4f3025

Browse files
authored
Merge pull request #880 from bjorn3/lto_all_serialized
Handle all modules being serialized during LTO
2 parents b5a73af + da9e1aa commit b4f3025

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/back/lto.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use std::ffi::CString;
2121
use std::fs::{self, File};
2222
use std::path::{Path, PathBuf};
23+
use std::sync::Arc;
2324

2425
use gccjit::OutputKind;
2526
use object::read::archive::ArchiveFile;
@@ -29,14 +30,15 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter}
2930
use rustc_codegen_ssa::traits::*;
3031
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind};
3132
use rustc_data_structures::memmap::Mmap;
32-
use rustc_data_structures::profiling::SelfProfilerRef;
3333
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3434
use rustc_log::tracing::info;
35+
use rustc_session::Session;
3536
use tempfile::{TempDir, tempdir};
3637

3738
use crate::back::write::{codegen, save_temp_bitcode};
3839
use crate::errors::LtoBitcodeFromRlib;
39-
use crate::{GccCodegenBackend, GccContext, LtoMode, to_gcc_opt_level};
40+
use crate::gcc_util::new_context;
41+
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};
4042

4143
struct LtoData {
4244
// FIXME(antoyo): use symbols_below_threshold.
@@ -102,8 +104,8 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
102104
/// Performs fat LTO by merging all modules into a single one and returning it
103105
/// for further optimization.
104106
pub(crate) fn run_fat(
107+
sess: &Session,
105108
cgcx: &CodegenContext,
106-
prof: &SelfProfilerRef,
107109
shared_emitter: &SharedEmitter,
108110
each_linked_rlib_for_lto: &[PathBuf],
109111
modules: Vec<FatLtoInput<GccCodegenBackend>>,
@@ -114,8 +116,8 @@ pub(crate) fn run_fat(
114116
/*let symbols_below_threshold =
115117
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
116118
fat_lto(
119+
sess,
117120
cgcx,
118-
prof,
119121
dcx,
120122
modules,
121123
lto_data.upstream_modules,
@@ -125,15 +127,15 @@ pub(crate) fn run_fat(
125127
}
126128

127129
fn fat_lto(
130+
sess: &Session,
128131
cgcx: &CodegenContext,
129-
prof: &SelfProfilerRef,
130132
dcx: DiagCtxtHandle<'_>,
131133
modules: Vec<FatLtoInput<GccCodegenBackend>>,
132134
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
133135
tmp_path: TempDir,
134136
//symbols_below_threshold: &[String],
135137
) -> CompiledModule {
136-
let _timer = prof.generic_activity("GCC_fat_lto_build_monolithic_module");
138+
let _timer = sess.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
137139
info!("going for a fat lto");
138140

139141
// Sort out all our lists of incoming modules into two lists.
@@ -183,17 +185,16 @@ fn fat_lto(
183185
// module and create a linker with it.
184186
let mut module: ModuleCodegen<GccContext> = match costliest_module {
185187
Some((_cost, i)) => in_memory.remove(i),
186-
None => {
187-
unimplemented!("Incremental");
188-
/*assert!(!serialized_modules.is_empty(), "must have at least one serialized module");
189-
let (buffer, name) = serialized_modules.remove(0);
190-
info!("no in-memory regular modules to choose from, parsing {:?}", name);
191-
ModuleCodegen {
192-
module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?,
193-
name: name.into_string().unwrap(),
194-
kind: ModuleKind::Regular,
195-
}*/
196-
}
188+
None => ModuleCodegen::new_regular(
189+
"lto_module".to_string(),
190+
GccContext {
191+
context: Arc::new(SyncContext::new(new_context(sess))),
192+
relocation_model: sess.relocation_model(),
193+
lto_supported: true,
194+
lto_mode: LtoMode::None,
195+
temp_dir: None,
196+
},
197+
),
197198
};
198199
{
199200
info!("using {:?} as a base module", module.name);
@@ -220,7 +221,8 @@ fn fat_lto(
220221
// We add the object files and save in should_combine_object_files that we should combine
221222
// them into a single object file when compiling later.
222223
for (bc_decoded, name) in serialized_modules {
223-
let _timer = prof
224+
let _timer = sess
225+
.prof
224226
.generic_activity_with_arg_recorder("GCC_fat_lto_link_module", |recorder| {
225227
recorder.record_arg(format!("{:?}", name))
226228
});
@@ -258,7 +260,7 @@ fn fat_lto(
258260
// of now.
259261
module.module_llvm.temp_dir = Some(tmp_path);
260262

261-
codegen(cgcx, prof, dcx, module, &cgcx.module_config)
263+
codegen(cgcx, &sess.prof, dcx, module, &cgcx.module_config)
262264
}
263265

264266
pub struct ModuleBuffer(PathBuf);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl WriteBackendMethods for GccCodegenBackend {
418418
each_linked_rlib_for_lto: &[PathBuf],
419419
modules: Vec<FatLtoInput<Self>>,
420420
) -> CompiledModule {
421-
back::lto::run_fat(cgcx, &sess.prof, shared_emitter, each_linked_rlib_for_lto, modules)
421+
back::lto::run_fat(sess, cgcx, shared_emitter, each_linked_rlib_for_lto, modules)
422422
}
423423

424424
fn run_thin_lto(

0 commit comments

Comments
 (0)