Skip to content

Commit 948f779

Browse files
committed
Remove support for -Zcombine-cgu
Nobody seems to actually use this, while still adding some extra complexity to the already rather complex codegen coordinator code. It is also not supported by any backend other than the LLVM backend.
1 parent fe2eeab commit 948f779

File tree

7 files changed

+6
-91
lines changed

7 files changed

+6
-91
lines changed

compiler/rustc_codegen_gcc/src/back/write.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use gccjit::{Context, OutputKind};
44
use rustc_codegen_ssa::back::link::ensure_removed;
55
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
66
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
7-
use rustc_errors::DiagCtxtHandle;
87
use rustc_fs_util::link_or_copy;
98
use rustc_session::config::OutputType;
109
use rustc_span::fatal_error::FatalError;
@@ -258,14 +257,6 @@ pub(crate) fn codegen(
258257
))
259258
}
260259

261-
pub(crate) fn link(
262-
_cgcx: &CodegenContext<GccCodegenBackend>,
263-
_dcx: DiagCtxtHandle<'_>,
264-
mut _modules: Vec<ModuleCodegen<GccContext>>,
265-
) -> Result<ModuleCodegen<GccContext>, FatalError> {
266-
unimplemented!();
267-
}
268-
269260
pub(crate) fn save_temp_bitcode(
270261
cgcx: &CodegenContext<GccCodegenBackend>,
271262
_module: &ModuleCodegen<GccContext>,

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,6 @@ impl WriteBackendMethods for GccCodegenBackend {
426426
fn serialize_module(_module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer) {
427427
unimplemented!();
428428
}
429-
430-
fn run_link(
431-
cgcx: &CodegenContext<Self>,
432-
dcx: DiagCtxtHandle<'_>,
433-
modules: Vec<ModuleCodegen<Self::Module>>,
434-
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
435-
back::write::link(cgcx, dcx, modules)
436-
}
437429
}
438430

439431
/// This is the entrypoint for a hot plugged rustc_codegen_gccjit

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -796,29 +796,6 @@ pub(crate) fn optimize(
796796
Ok(())
797797
}
798798

799-
pub(crate) fn link(
800-
cgcx: &CodegenContext<LlvmCodegenBackend>,
801-
dcx: DiagCtxtHandle<'_>,
802-
mut modules: Vec<ModuleCodegen<ModuleLlvm>>,
803-
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
804-
use super::lto::{Linker, ModuleBuffer};
805-
// Sort the modules by name to ensure deterministic behavior.
806-
modules.sort_by(|a, b| a.name.cmp(&b.name));
807-
let (first, elements) =
808-
modules.split_first().expect("Bug! modules must contain at least one module.");
809-
810-
let mut linker = Linker::new(first.module_llvm.llmod());
811-
for module in elements {
812-
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_link_module", &*module.name);
813-
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
814-
linker
815-
.add(buffer.data())
816-
.map_err(|()| llvm_err(dcx, LlvmError::SerializeModule { name: &module.name }))?;
817-
}
818-
drop(linker);
819-
Ok(modules.remove(0))
820-
}
821-
822799
pub(crate) fn codegen(
823800
cgcx: &CodegenContext<LlvmCodegenBackend>,
824801
module: ModuleCodegen<ModuleLlvm>,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ impl WriteBackendMethods for LlvmCodegenBackend {
168168
let stats = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatistics(s) }).unwrap();
169169
print!("{stats}");
170170
}
171-
fn run_link(
172-
cgcx: &CodegenContext<Self>,
173-
dcx: DiagCtxtHandle<'_>,
174-
modules: Vec<ModuleCodegen<Self::Module>>,
175-
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
176-
back::write::link(cgcx, dcx, modules)
177-
}
178171
fn run_and_optimize_fat_lto(
179172
cgcx: &CodegenContext<Self>,
180173
exported_symbols_for_lto: &[String],

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,6 @@ pub(crate) enum WorkItemResult<B: WriteBackendMethods> {
797797
/// The backend has finished compiling a CGU, nothing more required.
798798
Finished(CompiledModule),
799799

800-
/// The backend has finished compiling a CGU, which now needs linking
801-
/// because `-Zcombine-cgu` was specified.
802-
NeedsLink(ModuleCodegen<B::Module>),
803-
804800
/// The backend has finished compiling a CGU, which now needs to go through
805801
/// fat LTO.
806802
NeedsFatLto(FatLtoInput<B>),
@@ -884,7 +880,10 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
884880
};
885881

886882
match lto_type {
887-
ComputedLtoType::No => finish_intra_module_work(cgcx, module, module_config),
883+
ComputedLtoType::No => {
884+
let module = B::codegen(cgcx, module, module_config)?;
885+
Ok(WorkItemResult::Finished(module))
886+
}
888887
ComputedLtoType::Thin => {
889888
let (name, thin_buffer) = B::prepare_thin(module, false);
890889
if let Some(path) = bitcode {
@@ -1024,20 +1023,8 @@ fn execute_thin_lto_work_item<B: ExtraBackendMethods>(
10241023
module_config: &ModuleConfig,
10251024
) -> Result<WorkItemResult<B>, FatalError> {
10261025
let module = B::optimize_thin(cgcx, module)?;
1027-
finish_intra_module_work(cgcx, module, module_config)
1028-
}
1029-
1030-
fn finish_intra_module_work<B: ExtraBackendMethods>(
1031-
cgcx: &CodegenContext<B>,
1032-
module: ModuleCodegen<B::Module>,
1033-
module_config: &ModuleConfig,
1034-
) -> Result<WorkItemResult<B>, FatalError> {
1035-
if !cgcx.opts.unstable_opts.combine_cgu || module.kind == ModuleKind::Allocator {
1036-
let module = B::codegen(cgcx, module, module_config)?;
1037-
Ok(WorkItemResult::Finished(module))
1038-
} else {
1039-
Ok(WorkItemResult::NeedsLink(module))
1040-
}
1026+
let module = B::codegen(cgcx, module, module_config)?;
1027+
Ok(WorkItemResult::Finished(module))
10411028
}
10421029

10431030
/// Messages sent to the coordinator.
@@ -1343,7 +1330,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13431330
// through codegen and LLVM.
13441331
let mut compiled_modules = vec![];
13451332
let mut compiled_allocator_module = None;
1346-
let mut needs_link = Vec::new();
13471333
let mut needs_fat_lto = Vec::new();
13481334
let mut needs_thin_lto = Vec::new();
13491335
let mut lto_import_only_modules = Vec::new();
@@ -1625,7 +1611,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
16251611
Ok(WorkItemResult::Finished(compiled_module)) => {
16261612
match compiled_module.kind {
16271613
ModuleKind::Regular => {
1628-
assert!(needs_link.is_empty());
16291614
compiled_modules.push(compiled_module);
16301615
}
16311616
ModuleKind::Allocator => {
@@ -1634,10 +1619,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
16341619
}
16351620
}
16361621
}
1637-
Ok(WorkItemResult::NeedsLink(module)) => {
1638-
assert!(compiled_modules.is_empty());
1639-
needs_link.push(module);
1640-
}
16411622
Ok(WorkItemResult::NeedsFatLto(fat_lto_input)) => {
16421623
assert!(!started_lto);
16431624
assert!(needs_thin_lto.is_empty());
@@ -1674,17 +1655,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
16741655
return Err(());
16751656
}
16761657

1677-
let needs_link = mem::take(&mut needs_link);
1678-
if !needs_link.is_empty() {
1679-
assert!(compiled_modules.is_empty());
1680-
let dcx = cgcx.create_dcx();
1681-
let dcx = dcx.handle();
1682-
let module = B::run_link(&cgcx, dcx, needs_link).map_err(|_| ())?;
1683-
let module =
1684-
B::codegen(&cgcx, module, cgcx.config(ModuleKind::Regular)).map_err(|_| ())?;
1685-
compiled_modules.push(module);
1686-
}
1687-
16881658
// Drop to print timings
16891659
drop(llvm_start_time);
16901660

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ pub trait WriteBackendMethods: Clone + 'static {
1616
type ThinData: Send + Sync;
1717
type ThinBuffer: ThinBufferMethods;
1818

19-
/// Merge all modules into main_module and returning it
20-
fn run_link(
21-
cgcx: &CodegenContext<Self>,
22-
dcx: DiagCtxtHandle<'_>,
23-
modules: Vec<ModuleCodegen<Self::Module>>,
24-
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
2519
/// Performs fat LTO by merging all modules into a single one, running autodiff
2620
/// if necessary and running any further optimizations
2721
fn run_and_optimize_fat_lto(

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,8 +2168,6 @@ options! {
21682168
"hash algorithm of source files used to check freshness in cargo (`blake3` or `sha256`)"),
21692169
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
21702170
"the backend to use"),
2171-
combine_cgu: bool = (false, parse_bool, [TRACKED],
2172-
"combine CGUs into a single one"),
21732171
contract_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
21742172
"emit runtime checks for contract pre- and post-conditions (default: no)"),
21752173
coverage_options: CoverageOptions = (CoverageOptions::default(), parse_coverage_options, [TRACKED],

0 commit comments

Comments
 (0)