Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't codegen items that are statically unreachable #104858

Closed
jyn514 opened this issue Nov 25, 2022 · 2 comments
Closed

Don't codegen items that are statically unreachable #104858

jyn514 opened this issue Nov 25, 2022 · 2 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-compiletime Issue: Problems and improvements with respect to compile times.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 25, 2022

Currently, all items in a crate are codegened, and only stripped later in a linker pass:

// Next we try to make as many symbols "internal" as possible, so LLVM has
// more freedom to optimize.
if !tcx.sess.link_dead_code() {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
partitioner.internalize_symbols(cx, &mut post_inlining);
// Try to strip as much out of the generated object by removing unused
// sections if possible. See more comments in linker.rs
if !sess.link_dead_code() {
// If PGO is enabled sometimes gc_sections will remove the profile data section
// as it appears to be unused. This can then cause the PGO profile file to lose
// some functions. If we are generating a profile we shouldn't strip those metadata
// sections to ensure we have all the data for PGO.
let keep_metadata =
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
if crate_type != CrateType::Executable || !sess.opts.unstable_opts.export_executable_symbols
{
cmd.gc_sections(keep_metadata);
This unnecessarily bloats the amount of time and memory it takes to compile a crate. We already have a dead_code pass; we should use its results to avoid running codegen on unreachable items.

This is a prerequisite for #103356, but I expect it will be a large boost to compile times even if that never lands.

@jyn514 jyn514 added C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Nov 25, 2022
@scottmcm
Copy link
Member

A potential first step would be to handle if const { monomorphized-predicate }, #85836.

@jyn514
Copy link
Member Author

jyn514 commented Nov 28, 2022

We already do this. #104860 (comment)

@jyn514 jyn514 closed this as completed Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-compiletime Issue: Problems and improvements with respect to compile times.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants