bugc: add function inlining pass (L2)#252
Merged
Merged
Conversation
Adds InliningStep at optimization level 2: it replaces calls to eligible internal functions with a copy of the callee's body spliced into the caller, eliminating the runtime JUMP/frame. v1 eligibility (correctness over coverage): - internal, non-recursive, single-return LEAF callees; - applied at all call sites; a fully-inlined callee is deleted; - self-recursive / tail-call-optimized callers are left untouched — inlining a helper into a tail-recursive call's arguments (count(succ(n)) -> count(n + 1)) rewrites the tail call into a form the tail-call optimizer mishandles. Inlining runs first at L2 (after L1 constant folding, before CSE/TCO/jump-opt) so those passes still apply to inlined code. Return values use dest-substitution (not a continuation phi), so they survive L3 block-merging. Inlined instructions keep their callee source mapping. Deferred: non-leaf/nested callees, multi-return, size-threshold inlining.
Contributor
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a function-inlining optimization at level 2.
InliningStepreplaces calls to eligible internal functions with a copy of the
callee's body spliced into the caller, eliminating the runtime
JUMP and frame setup for those calls.
v1 eligibility, favoring correctness over coverage:
is deleted;
Inlining a helper into a tail-recursive call's arguments
(
count(succ(n))→count(n + 1)) would rewrite the tail callinto a computed-argument form the tail-call optimizer mishandles,
so recursive callers are skipped.
Inlining runs first at L2 (after L1 constant folding, before
CSE/TCO/jump-opt) so the later passes still apply to inlined code.
Return values use dest-substitution rather than a continuation phi,
so they survive L3 block-merging. Inlined instructions retain their
callee source mapping.
Deferred to follow-ups: non-leaf/nested callees, multi-return, and
size-threshold (non-leaf) inlining.
Tests: a new
inlining.test.tscovers runtime equivalence at O0–O3,callee deletion / call elimination at L2, and the recursive-caller
guard.
optimizer-contexts.test.tsis updated for the new L2+behavior (leaf helpers no longer produce a real caller JUMP).