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

codegen_ssa cleanups #113879

Merged
merged 20 commits into from
Jul 31, 2023
Merged

codegen_ssa cleanups #113879

merged 20 commits into from
Jul 31, 2023

Conversation

nnethercote
Copy link
Contributor

Some clarifications I made when reading this code closely.

r? @tmiasko

@rustbot rustbot added 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 20, 2023
@nnethercote nnethercote force-pushed the codegen_ssa-cleanups branch from d8b1635 to bbc03e2 Compare July 20, 2023 09:00
@rustbot
Copy link
Collaborator

rustbot commented Jul 21, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@nnethercote
Copy link
Contributor Author

I added some more commits. Best reviewed one commit at a time.

@nnethercote nnethercote force-pushed the codegen_ssa-cleanups branch from 8fbd1a9 to f7eb0a4 Compare July 23, 2023 22:33
@nnethercote nnethercote mentioned this pull request Jul 23, 2023
@nnethercote
Copy link
Contributor Author

I added one more small commit. That should be the end of them :)

@bors
Copy link
Contributor

bors commented Jul 30, 2023

☔ The latest upstream changes (presumably #114264) made this pull request unmergeable. Please resolve the merge conflicts.

It has a single callsite, and provides little value.
And rename the `Compiled` variant as `Finished`, because that name makes
it clearer there is nothing left to do, contrasting nicely with the
`Needs*` variants.
- Thin and fat LTO can't happen together.
- `NeedsLink` and (non-allocator) `Compiled` work item results can't
  happen together.
It took me some time to understand how the main thread can lend a
jobserver token to an LLVM thread. This commit renames a couple of
things to make it clearer.

- Rename the `LLVMing` variant as `Lending`, because that is a clearer
  description of what is happening.
- Rename `running` as `running_with_own_token`, which makes it clearer
  that there might be one additional LLVM thread running (with a loaned
  token). Also add a comment to its definition.
The `Worker` is unnecessary, and just makes it longer than necessary.
This is useful when profiling with a profiler like Samply.
It's no longer used, and `spawn_named_thread` is preferable, because
naming threads is helpful when profiling.
Make it match the corresponding comment at the start of the unstable
options.
Because it's usefulness wasn't clear to me, and I initially wondered if
it could be removed. The text is based on the text in rust-lang#50972, the PR
that added the flag.
`CodegenContext` is immutable except for the `worker` field - we clone
`CodegenContext` in multiple places, changing the `worker` field each
time. It's simpler to move the `worker` field out of `CodegenContext`.
The two functions are alway called together. This commit factors out the
repeated code.
This loop condition involves `codegen_state`, `work_items`, and
`running_with_own_token`. But the body of the loop cannot modify
`codegen_state`, so repeatedly checking it is unnecessary.
The main loop has a *very* complex condition, which includes two
mentions of `codegen_state`. The body of the loop then immediately
switches on the `codegen_state`.

I find it easier to understand if it's a `loop` and we check for exit
conditions after switching on `codegen_state`. We end up with a tiny bit
of code duplication, but it's clear that (a) we never exit in the
`Ongoing` case, (b) we exit in the `Completed` state only if several
things are true (and there's interaction with LTO there), and (c) we
exit in the `Aborted` state if a couple of things are true. Also, the
exit conditions are all simple conjunctions.
It makes things a little clearer.
PR rust-lang#112946 tweaked the naming of LLVM threads, but messed things up
slightly, resulting in threads on Windows having names like `optimize
module {} regex.f10ba03eb5ec7975-cgu.0`.

This commit removes the extraneous `{} `.
This function has some shared code for the thin LTO and fat LTO cases,
but those cases have so little in common that it's actually clearer to
treat them fully separately.
@nnethercote nnethercote force-pushed the codegen_ssa-cleanups branch from 797e703 to c17c8dc Compare July 31, 2023 06:37
@nnethercote
Copy link
Contributor Author

I have rebased.

@bjorn3
Copy link
Member

bjorn3 commented Jul 31, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jul 31, 2023

📌 Commit c17c8dc has been approved by bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 31, 2023
@bors
Copy link
Contributor

bors commented Jul 31, 2023

⌛ Testing commit c17c8dc with merge 5082281...

@bors
Copy link
Contributor

bors commented Jul 31, 2023

☀️ Test successful - checks-actions
Approved by: bjorn3
Pushing 5082281 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 31, 2023
@bors bors merged commit 5082281 into rust-lang:master Jul 31, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 31, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5082281): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.7%, 0.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 652.303s -> 652.574s (0.04%)

@nnethercote nnethercote deleted the codegen_ssa-cleanups branch August 1, 2023 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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