-
-
Notifications
You must be signed in to change notification settings - Fork 159
perf(codegen): preserve_none calling convention for recursion-participating spec clones (#8175) #8203
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
Merged
Merged
perf(codegen): preserve_none calling convention for recursion-participating spec clones (#8175) #8203
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| ### perf(codegen): recursion-participating specialized clones use LLVM's `preserve_none` calling convention (#8175) | ||
|
|
||
| fib40 spent ~45% of wall time on a frame its ~165M leaf invocations never | ||
| used: a param-derived value live across a call was materialized into a | ||
| callee-saved register in the entry block, which pins the CSR save/restore | ||
| there and defeats LLVM shrink-wrapping. `preserve_nonecc` deletes the cause — | ||
| with no callee-saved registers there is nothing to pin, so the frame sinks | ||
| into the recursive path and the leaf runs frameless (5 instructions on | ||
| arm64, 3 on x86-64). | ||
|
|
||
| Mechanism: one module-level registry (`LlModule` → `RegCounter`) drives the | ||
| define header, the cross-unit declare line, and both call choke points | ||
| (`LlBlock::call`'s plain and invoke arms), so a call site can never disagree | ||
| with its callee's convention — a mismatch is UB, not a verifier error, and | ||
| `spec_preserve_none_tests::assert_preserve_none_consistency` scans rendered | ||
| modules for agreement in both directions. The in-process dialect reader | ||
| parses the token on define/call/invoke lines and sets the real LLVM | ||
| convention (`CallingConv::PreserveNone`) on both the function and each call | ||
| site, so text, native, and unit-split backends emit the same machine code. | ||
|
|
||
| Scope: only specialized clones that participate in direct recursion (Tarjan | ||
| SCC over `FuncRef` call edges, `collect_recursion_participants`) — the | ||
| boundary cost of entering a `preserve_none` callee from a normal-CC caller | ||
| (~20 CSRs saved once per entry) amortizes only under a recursive tree. Spec | ||
| clones are `internal` and direct-call-only by construction | ||
| (`spec_abi_symbol_reachability`), so the convention cannot escape a module. | ||
| Target-gated off watchOS `arm64_32` and ARM64 Windows, the same predicate | ||
| family as the RS4GC target-awareness. `PERRY_SPEC_PRESERVE_NONE=0` is the | ||
| single-binary A/B kill switch, keyed into the build and object caches. | ||
|
|
||
| Liveness gates: the recursive-fixture test counts convention-carrying call | ||
| sites (≥3: init site + both recursive edges), and an asm-level test runs the | ||
| exact in-process pipeline (RS4GC + `-O3` + target machine) and asserts the | ||
| clone's first instruction is not a frame store — a change that silently | ||
| stops applying the convention re-grows the pinned frame and goes red. | ||
|
|
||
| Measured on the quiet M1 mini (best-of-5, `/usr/bin/time -l`, both arms from | ||
| one compiler via the kill switch): per-row instruction + peak-RSS table in | ||
| PR #8203. 16 of 19 corpus rows compile byte-identically (the gate holds); | ||
| fib40/interp/iso_miss differ. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.