Skip to content

Commit a6725ab

Browse files
committed
Move fat LTO out of the main coordinator loop
1 parent b1d5922 commit a6725ab

File tree

1 file changed

+42
-57
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+42
-57
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,6 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
703703
/// Copy the post-LTO artifacts from the incremental cache to the output
704704
/// directory.
705705
CopyPostLtoArtifacts(CachedModuleCodegen),
706-
/// Performs fat LTO on the given module.
707-
FatLto {
708-
exported_symbols_for_lto: Arc<Vec<String>>,
709-
each_linked_rlib_for_lto: Vec<PathBuf>,
710-
needs_fat_lto: Vec<FatLtoInput<B>>,
711-
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
712-
},
713706
/// Performs thin-LTO on the given module.
714707
ThinLto(lto::ThinModule<B>),
715708
}
@@ -759,7 +752,6 @@ impl<B: WriteBackendMethods> WorkItem<B> {
759752
match self {
760753
WorkItem::Optimize(m) => desc("opt", "optimize module", &m.name),
761754
WorkItem::CopyPostLtoArtifacts(m) => desc("cpy", "copy LTO artifacts for", &m.name),
762-
WorkItem::FatLto { .. } => desc("lto", "fat LTO module", "everything"),
763755
WorkItem::ThinLto(m) => desc("lto", "thin-LTO module", m.name()),
764756
}
765757
}
@@ -976,15 +968,17 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
976968
})
977969
}
978970

979-
fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
971+
fn do_fat_lto<B: ExtraBackendMethods>(
980972
cgcx: &CodegenContext<B>,
981973
exported_symbols_for_lto: &[String],
982974
each_linked_rlib_for_lto: &[PathBuf],
983975
mut needs_fat_lto: Vec<FatLtoInput<B>>,
984976
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
985-
) -> WorkItemResult<B> {
977+
) -> CompiledModule {
986978
let _timer = cgcx.prof.generic_activity_with_arg("codegen_module_perform_lto", "everything");
987979

980+
check_lto_allowed(&cgcx);
981+
988982
for (module, wp) in import_only_modules {
989983
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
990984
}
@@ -995,8 +989,7 @@ fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
995989
each_linked_rlib_for_lto,
996990
needs_fat_lto,
997991
);
998-
let module = B::codegen(cgcx, module, &cgcx.module_config);
999-
WorkItemResult::Finished(module)
992+
B::codegen(cgcx, module, &cgcx.module_config)
1000993
}
1001994

1002995
fn execute_thin_lto_work_item<B: ExtraBackendMethods>(
@@ -1421,45 +1414,30 @@ fn start_executing_work<B: ExtraBackendMethods>(
14211414
assert!(!started_lto);
14221415
started_lto = true;
14231416

1424-
let needs_fat_lto = mem::take(&mut needs_fat_lto);
1425-
let needs_thin_lto = mem::take(&mut needs_thin_lto);
1426-
let import_only_modules = mem::take(&mut lto_import_only_modules);
1427-
let each_linked_rlib_file_for_lto =
1428-
mem::take(&mut each_linked_rlib_file_for_lto);
1417+
if !needs_fat_lto.is_empty() {
1418+
// We're doing fat LTO outside of the main loop.
1419+
break;
1420+
}
14291421

14301422
check_lto_allowed(&cgcx);
14311423

1432-
if !needs_fat_lto.is_empty() {
1433-
assert!(needs_thin_lto.is_empty());
1434-
1435-
work_items.push((
1436-
WorkItem::FatLto {
1437-
exported_symbols_for_lto: Arc::clone(&exported_symbols_for_lto),
1438-
each_linked_rlib_for_lto: each_linked_rlib_file_for_lto,
1439-
needs_fat_lto,
1440-
import_only_modules,
1441-
},
1442-
0,
1443-
));
1424+
let needs_thin_lto = mem::take(&mut needs_thin_lto);
1425+
let import_only_modules = mem::take(&mut lto_import_only_modules);
1426+
1427+
for (work, cost) in generate_thin_lto_work(
1428+
&cgcx,
1429+
&exported_symbols_for_lto,
1430+
&each_linked_rlib_file_for_lto,
1431+
needs_thin_lto,
1432+
import_only_modules,
1433+
) {
1434+
let insertion_index = work_items
1435+
.binary_search_by_key(&cost, |&(_, cost)| cost)
1436+
.unwrap_or_else(|e| e);
1437+
work_items.insert(insertion_index, (work, cost));
14441438
if cgcx.parallel {
14451439
helper.request_token();
14461440
}
1447-
} else {
1448-
for (work, cost) in generate_thin_lto_work(
1449-
&cgcx,
1450-
&exported_symbols_for_lto,
1451-
&each_linked_rlib_file_for_lto,
1452-
needs_thin_lto,
1453-
import_only_modules,
1454-
) {
1455-
let insertion_index = work_items
1456-
.binary_search_by_key(&cost, |&(_, cost)| cost)
1457-
.unwrap_or_else(|e| e);
1458-
work_items.insert(insertion_index, (work, cost));
1459-
if cgcx.parallel {
1460-
helper.request_token();
1461-
}
1462-
}
14631441
}
14641442
}
14651443

@@ -1633,6 +1611,25 @@ fn start_executing_work<B: ExtraBackendMethods>(
16331611
return Err(());
16341612
}
16351613

1614+
drop(codegen_state);
1615+
drop(tokens);
1616+
drop(helper);
1617+
1618+
if !needs_fat_lto.is_empty() {
1619+
assert!(compiled_modules.is_empty());
1620+
assert!(needs_thin_lto.is_empty());
1621+
1622+
// This uses the implicit token
1623+
let module = do_fat_lto(
1624+
&cgcx,
1625+
&exported_symbols_for_lto,
1626+
&each_linked_rlib_file_for_lto,
1627+
needs_fat_lto,
1628+
lto_import_only_modules,
1629+
);
1630+
compiled_modules.push(module);
1631+
}
1632+
16361633
// Drop to print timings
16371634
drop(llvm_start_time);
16381635

@@ -1726,18 +1723,6 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17261723
let result = std::panic::catch_unwind(AssertUnwindSafe(|| match work {
17271724
WorkItem::Optimize(m) => execute_optimize_work_item(&cgcx, m),
17281725
WorkItem::CopyPostLtoArtifacts(m) => execute_copy_from_cache_work_item(&cgcx, m),
1729-
WorkItem::FatLto {
1730-
exported_symbols_for_lto,
1731-
each_linked_rlib_for_lto,
1732-
needs_fat_lto,
1733-
import_only_modules,
1734-
} => execute_fat_lto_work_item(
1735-
&cgcx,
1736-
&exported_symbols_for_lto,
1737-
&each_linked_rlib_for_lto,
1738-
needs_fat_lto,
1739-
import_only_modules,
1740-
),
17411726
WorkItem::ThinLto(m) => execute_thin_lto_work_item(&cgcx, m),
17421727
}));
17431728

0 commit comments

Comments
 (0)