Skip to content

Commit fdd2627

Browse files
committed
Merge modules and cached_modules for fat LTO
The modules vec can already contain serialized modules and there is no need to distinguish between cached and non-cached cgus at LTO time.
1 parent 21026ca commit fdd2627

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
175175
pub(crate) fn run_fat(
176176
cgcx: &CodegenContext<GccCodegenBackend>,
177177
modules: Vec<FatLtoInput<GccCodegenBackend>>,
178-
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
179178
) -> Result<ModuleCodegen<GccContext>, FatalError> {
180179
let dcx = cgcx.create_dcx();
181180
let dcx = dcx.handle();
@@ -186,7 +185,6 @@ pub(crate) fn run_fat(
186185
cgcx,
187186
dcx,
188187
modules,
189-
cached_modules,
190188
lto_data.upstream_modules,
191189
lto_data.tmp_path,
192190
//&lto_data.symbols_below_threshold,
@@ -197,7 +195,6 @@ fn fat_lto(
197195
cgcx: &CodegenContext<GccCodegenBackend>,
198196
_dcx: DiagCtxtHandle<'_>,
199197
modules: Vec<FatLtoInput<GccCodegenBackend>>,
200-
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
201198
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
202199
tmp_path: TempDir,
203200
//symbols_below_threshold: &[String],
@@ -211,21 +208,12 @@ fn fat_lto(
211208
// modules that are serialized in-memory.
212209
// * `in_memory` contains modules which are already parsed and in-memory,
213210
// such as from multi-CGU builds.
214-
//
215-
// All of `cached_modules` (cached from previous incremental builds) can
216-
// immediately go onto the `serialized_modules` modules list and then we can
217-
// split the `modules` array into these two lists.
218211
let mut in_memory = Vec::new();
219-
serialized_modules.extend(cached_modules.into_iter().map(|(buffer, wp)| {
220-
info!("pushing cached module {:?}", wp.cgu_name);
221-
(buffer, CString::new(wp.cgu_name).unwrap())
222-
}));
223212
for module in modules {
224213
match module {
225214
FatLtoInput::InMemory(m) => in_memory.push(m),
226215
FatLtoInput::Serialized { name, buffer } => {
227216
info!("pushing serialized module {:?}", name);
228-
let buffer = SerializedModule::Local(buffer);
229217
serialized_modules.push((buffer, CString::new(name).unwrap()));
230218
}
231219
}

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,13 @@ impl WriteBackendMethods for GccCodegenBackend {
360360
fn run_and_optimize_fat_lto(
361361
cgcx: &CodegenContext<Self>,
362362
modules: Vec<FatLtoInput<Self>>,
363-
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
364363
diff_fncs: Vec<AutoDiffItem>,
365364
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
366365
if !diff_fncs.is_empty() {
367366
unimplemented!();
368367
}
369368

370-
back::lto::run_fat(cgcx, modules, cached_modules)
369+
back::lto::run_fat(cgcx, modules)
371370
}
372371

373372
fn run_thin_lto(

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,13 @@ fn get_bitcode_slice_from_object_data<'a>(
200200
pub(crate) fn run_fat(
201201
cgcx: &CodegenContext<LlvmCodegenBackend>,
202202
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
203-
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
204203
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
205204
let dcx = cgcx.create_dcx();
206205
let dcx = dcx.handle();
207206
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, dcx)?;
208207
let symbols_below_threshold =
209208
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
210-
fat_lto(cgcx, dcx, modules, cached_modules, upstream_modules, &symbols_below_threshold)
209+
fat_lto(cgcx, dcx, modules, upstream_modules, &symbols_below_threshold)
211210
}
212211

213212
/// Performs thin LTO by performing necessary global analysis and returning two
@@ -245,7 +244,6 @@ fn fat_lto(
245244
cgcx: &CodegenContext<LlvmCodegenBackend>,
246245
dcx: DiagCtxtHandle<'_>,
247246
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
248-
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
249247
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
250248
symbols_below_threshold: &[*const libc::c_char],
251249
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
@@ -258,21 +256,12 @@ fn fat_lto(
258256
// modules that are serialized in-memory.
259257
// * `in_memory` contains modules which are already parsed and in-memory,
260258
// such as from multi-CGU builds.
261-
//
262-
// All of `cached_modules` (cached from previous incremental builds) can
263-
// immediately go onto the `serialized_modules` modules list and then we can
264-
// split the `modules` array into these two lists.
265259
let mut in_memory = Vec::new();
266-
serialized_modules.extend(cached_modules.into_iter().map(|(buffer, wp)| {
267-
info!("pushing cached module {:?}", wp.cgu_name);
268-
(buffer, CString::new(wp.cgu_name).unwrap())
269-
}));
270260
for module in modules {
271261
match module {
272262
FatLtoInput::InMemory(m) => in_memory.push(m),
273263
FatLtoInput::Serialized { name, buffer } => {
274264
info!("pushing serialized module {:?}", name);
275-
let buffer = SerializedModule::Local(buffer);
276265
serialized_modules.push((buffer, CString::new(name).unwrap()));
277266
}
278267
}

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ impl WriteBackendMethods for LlvmCodegenBackend {
177177
fn run_and_optimize_fat_lto(
178178
cgcx: &CodegenContext<Self>,
179179
modules: Vec<FatLtoInput<Self>>,
180-
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
181180
diff_fncs: Vec<AutoDiffItem>,
182181
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
183-
let mut module = back::lto::run_fat(cgcx, modules, cached_modules)?;
182+
let mut module = back::lto::run_fat(cgcx, modules)?;
184183

185184
if !diff_fncs.is_empty() {
186185
builder::autodiff::differentiate(&module, cgcx, diff_fncs)?;

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ pub(crate) enum WorkItemResult<B: WriteBackendMethods> {
808808
}
809809

810810
pub enum FatLtoInput<B: WriteBackendMethods> {
811-
Serialized { name: String, buffer: B::ModuleBuffer },
811+
Serialized { name: String, buffer: SerializedModule<B::ModuleBuffer> },
812812
InMemory(ModuleCodegen<B::Module>),
813813
}
814814

@@ -897,7 +897,10 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
897897
fs::write(&path, buffer.data()).unwrap_or_else(|e| {
898898
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);
899899
});
900-
Ok(WorkItemResult::NeedsFatLto(FatLtoInput::Serialized { name, buffer }))
900+
Ok(WorkItemResult::NeedsFatLto(FatLtoInput::Serialized {
901+
name,
902+
buffer: SerializedModule::Local(buffer),
903+
}))
901904
}
902905
None => Ok(WorkItemResult::NeedsFatLto(FatLtoInput::InMemory(module))),
903906
},
@@ -990,12 +993,16 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
990993

991994
fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
992995
cgcx: &CodegenContext<B>,
993-
needs_fat_lto: Vec<FatLtoInput<B>>,
996+
mut needs_fat_lto: Vec<FatLtoInput<B>>,
994997
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
995998
autodiff: Vec<AutoDiffItem>,
996999
module_config: &ModuleConfig,
9971000
) -> Result<WorkItemResult<B>, FatalError> {
998-
let module = B::run_and_optimize_fat_lto(cgcx, needs_fat_lto, import_only_modules, autodiff)?;
1001+
for (module, wp) in import_only_modules {
1002+
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
1003+
}
1004+
1005+
let module = B::run_and_optimize_fat_lto(cgcx, needs_fat_lto, autodiff)?;
9991006
let module = B::codegen(cgcx, module, module_config)?;
10001007
Ok(WorkItemResult::Finished(module))
10011008
}

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub trait WriteBackendMethods: Clone + 'static {
2525
fn run_and_optimize_fat_lto(
2626
cgcx: &CodegenContext<Self>,
2727
modules: Vec<FatLtoInput<Self>>,
28-
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
2928
diff_fncs: Vec<AutoDiffItem>,
3029
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
3130
/// Performs thin LTO by performing necessary global analysis and returning two

0 commit comments

Comments
 (0)