Skip to content

Commit 87ea628

Browse files
committed
Run DCE in per-crate optimize, too (before saving SPIR-V for .rlibs/linking/etc.).
1 parent 28e16b1 commit 87ea628

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

crates/rustc_codegen_spirv/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,17 @@ impl ThinBufferMethods for SpirvModuleBuffer {
309309
impl SpirvCodegenBackend {
310310
fn optimize_common(
311311
_cgcx: &CodegenContext<Self>,
312-
_module: &mut ModuleCodegen<<Self as WriteBackendMethods>::Module>,
312+
module: &mut ModuleCodegen<<Self as WriteBackendMethods>::Module>,
313313
) -> Result<(), FatalError> {
314-
// FIXME(eddyb) actually run as many optimization passes as possible,
315-
// before ever serializing `.spv` files that will later get linked.
314+
// Apply DCE ("dead code elimination") to modules before ever serializing
315+
// them as `.spv` files (technically, `.rcgu.o` files inside `.rlib`s),
316+
// that will later get linked (potentially many times, esp. if this is
317+
// some big upstream library, e.g. `core` itself), and will therefore
318+
// benefit from not having to clean up all sorts of unreachable helpers.
319+
linker::dce::dce(&mut module.module_llvm);
320+
321+
// FIXME(eddyb) run as many optimization passes as possible, not just DCE.
322+
316323
Ok(())
317324
}
318325
}

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(test)]
22
mod test;
33

4-
mod dce;
4+
pub(crate) mod dce;
55
mod destructure_composites;
66
mod duplicates;
77
mod entry_interface;
@@ -277,13 +277,6 @@ pub fn link(
277277
output
278278
};
279279

280-
// FIXME(eddyb) do this before ever saving the original `.spv`s to disk.
281-
{
282-
let _timer = sess.timer("link_dce-post-merge");
283-
dce::dce(&mut output);
284-
}
285-
286-
// HACK(eddyb) this has to be after DCE, to not break SPIR-T w/ dead decorations.
287280
if let Some(dir) = &opts.dump_post_merge {
288281
dump_spv_and_spirt(&output, dir.join(disambiguated_crate_name_for_dumps));
289282
}

0 commit comments

Comments
 (0)