Skip to content

Various refactors to the LTO handling code (part 2) #144062

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 17, 2025

Continuing from #143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.

bjorn3 added 3 commits July 17, 2025 09:08
The modules vec can already contain serialized modules and there is no
need to distinguish between cached and non-cached cgus at LTO time.
It isn't used anywhere. Also inline free_worker into the only call site.
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the lto_refactors2 branch 2 times, most recently from 0044549 to 7026d08 Compare July 17, 2025 10:04
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the lto_refactors2 branch 2 times, most recently from bab46eb to 217e5de Compare July 17, 2025 11:27
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Jul 17, 2025

looked through all the commits and while they look good to me, I don't feel comfortable actually judging these changes, so

r? compiler

@rustbot rustbot assigned davidtwco and unassigned lcnr Jul 17, 2025
@@ -355,23 +356,28 @@ impl WriteBackendMethods for GccCodegenBackend {

fn run_and_optimize_fat_lto(
cgcx: &CodegenContext<Self>,
// FIXME(bjorn3): Limit LTO exports to these symbols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean exactly?
Does that mean that only those symbols should be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is a superset of the set of symbols that will be exported by the linker (it also includes #[used] symbols to ensure those are kept by LTO). By already marking the rest as non-exported during LTO, LTO can optimize non-exported functions more aggressively. For example by changing their ABI or dropping them entirely if unused.

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 17, 2025

Since lcnr's review I've moved the checks for if LTO is allowed to happen right before LTO is done rather than when the coordinator thread starts. This way it doesn't happen for --emit metadata or for non-linked crate types.

Also give than this makes the symbol filtering always happen:

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jul 17, 2025

⌛ Trying commit 02d63c0 with merge f1a7db9

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 17, 2025
Various refactors to the LTO handling code (part 2)

Continuing from #143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 17, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 17, 2025

☀️ Try build successful (CI)
Build commit: f1a7db9 (f1a7db981fde509fe79c4358b40b84e4ca8d66ce, parent: bf5e6cc7a7a7eb03e3ed9b875d76530eddd47d5f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f1a7db9): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-6.8%, -1.2%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -5.0%, secondary 1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.8% [2.6%, 3.1%] 2
Improvements ✅
(primary)
-5.0% [-6.8%, -3.7%] 3
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) -5.0% [-6.8%, -3.7%] 3

Cycles

Results (secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.1%, 2.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.7% [-5.9%, -3.3%] 3
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 464.659s -> 464.118s (-0.12%)
Artifact size: 374.78 MiB -> 374.77 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants