From 779cb00311dc0bbb942dbdaefa24f98bd2d4cbbe Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:05:38 +0000 Subject: Move run_fat_lto call into execute_fat_lto_work_item This will allow merging all fat LTO steps together. In addition it reduces the amount of work done on the coordinator thread without jobserver token. --- compiler/rustc_codegen_ssa/src/back/write.rs | 68 +++++++++++++++------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index dcee7aec733..c7d2fcef29f 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -397,25 +397,6 @@ impl CodegenContext { } } -fn generate_fat_lto_work( - cgcx: &CodegenContext, - autodiff: Vec, - needs_fat_lto: Vec>, - import_only_modules: Vec<(SerializedModule, WorkProduct)>, -) -> WorkItem { - let _prof_timer = cgcx.prof.generic_activity("codegen_generate_lto_work"); - - let module = - B::run_fat_lto(cgcx, needs_fat_lto, import_only_modules).unwrap_or_else(|e| e.raise()); - if cgcx.lto == Lto::Fat && !autodiff.is_empty() { - let config = cgcx.config(ModuleKind::Regular); - if let Err(err) = B::autodiff(cgcx, &module, autodiff, config) { - err.raise(); - } - } - WorkItem::FatLto(module) -} - fn generate_thin_lto_work( cgcx: &CodegenContext, needs_thin_lto: Vec<(String, B::ThinBuffer)>, @@ -739,7 +720,11 @@ pub(crate) enum WorkItem { /// directory. CopyPostLtoArtifacts(CachedModuleCodegen), /// Performs fat LTO on the given module. - FatLto(ModuleCodegen), + FatLto { + needs_fat_lto: Vec>, + import_only_modules: Vec<(SerializedModule, WorkProduct)>, + autodiff: Vec, + }, /// Performs thin-LTO on the given module. ThinLto(lto::ThinModule), } @@ -748,7 +733,7 @@ impl WorkItem { fn module_kind(&self) -> ModuleKind { match *self { WorkItem::Optimize(ref m) => m.kind, - WorkItem::CopyPostLtoArtifacts(_) | WorkItem::FatLto(_) | WorkItem::ThinLto(_) => { + WorkItem::CopyPostLtoArtifacts(_) | WorkItem::FatLto { .. } | WorkItem::ThinLto(_) => { ModuleKind::Regular } } @@ -798,7 +783,7 @@ impl WorkItem { match self { WorkItem::Optimize(m) => desc("opt", "optimize module", &m.name), WorkItem::CopyPostLtoArtifacts(m) => desc("cpy", "copy LTO artifacts for", &m.name), - WorkItem::FatLto(_) => desc("lto", "fat LTO module", "everything"), + WorkItem::FatLto { .. } => desc("lto", "fat LTO module", "everything"), WorkItem::ThinLto(m) => desc("lto", "thin-LTO module", m.name()), } } @@ -1005,9 +990,21 @@ fn execute_copy_from_cache_work_item( fn execute_fat_lto_work_item( cgcx: &CodegenContext, - mut module: ModuleCodegen, + needs_fat_lto: Vec>, + import_only_modules: Vec<(SerializedModule, WorkProduct)>, + autodiff: Vec, module_config: &ModuleConfig, ) -> Result, FatalError> { + let mut module = + B::run_fat_lto(cgcx, needs_fat_lto, import_only_modules).unwrap_or_else(|e| e.raise()); + + if cgcx.lto == Lto::Fat && !autodiff.is_empty() { + let config = cgcx.config(ModuleKind::Regular); + if let Err(err) = B::autodiff(cgcx, &module, autodiff, config) { + err.raise(); + } + } + B::optimize_fat(cgcx, &mut module)?; let module = B::codegen(cgcx, module, module_config)?; @@ -1490,13 +1487,14 @@ fn start_executing_work( if !needs_fat_lto.is_empty() { assert!(needs_thin_lto.is_empty()); - let work = generate_fat_lto_work( - &cgcx, - autodiff_items.clone(), - needs_fat_lto, - import_only_modules, - ); - work_items.push((work, 0)); + work_items.push(( + WorkItem::FatLto { + needs_fat_lto, + import_only_modules, + autodiff: autodiff_items.clone(), + }, + 0, + )); if cgcx.parallel { helper.request_token(); } @@ -1867,11 +1865,17 @@ fn spawn_work<'a, B: ExtraBackendMethods>( ); Ok(execute_copy_from_cache_work_item(&cgcx, m, module_config)) } - WorkItem::FatLto(m) => { + WorkItem::FatLto { needs_fat_lto, import_only_modules, autodiff } => { let _timer = cgcx .prof .generic_activity_with_arg("codegen_module_perform_lto", "everything"); - execute_fat_lto_work_item(&cgcx, m, module_config) + execute_fat_lto_work_item( + &cgcx, + needs_fat_lto, + import_only_modules, + autodiff, + module_config, + ) } WorkItem::ThinLto(m) => { let _timer = -- cgit 1.4.1-3-g733a5