Repository navigation
feat(ir): clone statements and CFGs, and inline calls in linear time - #851
Open
alexcgatea wants to merge 12 commits into
Open
alexcgatea wants to merge 12 commits into
alexcgatea wants to merge 12 commits into
Conversation
clone_statement and clone_cfg make detached deep copies in two passes, mapping ids through an IRMap. create adopts the unowned bodies its definition names; detached CFGs never adopted are tombstoned on drop. Graph bodies are rejected until they can be cloned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copied graph gets fresh ports, copied members in their roles and yields; its topology is built from the copied operands once their uses are recorded. Removes CopyOfGraphBody. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
inline_calls inlines one level of same-stage CallSpecialized calls in a CFG's blocks and returns how many. Single-block callees are copied in place; others are copied between the halves of a split block. Walking each block from last to first keeps a run linear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
List splicing and cloning in the Rewriter module docs, count fifteen MutationEvent kinds, and remove the remaining-IR-operations plan now that it is done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Renames body_encloses_point to body_encloses_insertion_pt, and the InsertionPoint parameter of check_can_adopt_bodies_at to insertion_pt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds regression tests placing a cloned DiGraph member and UnGraph edge statement after the statements that read them, and documents that a copy never placed leaves its readers dangling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mapping a block argument no longer drops it from the copy, which left incoming edges passing values to a block with fewer arguments. The liveness check skips values the copy defines, so a map can be reused after its earlier copy is gone. The inliner enters a multi-block copy with a branch passing the call's arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexcgatea
force-pushed
the
alex/cloning-inlining
branch
from
November 12, 2026 15:30
5cd1b07 to
ce1d44a
Compare
Link copied blocks with the shared list helper in the fill pass, so reserving only allocates; clone each definition once when filling; make lookup_or_original public and use it in the inliner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Adds detached deep copies of statements and CFGs, and a one-level call inliner in
kirin-functionthat runs in linear time.New operations
clone_statement,clone_cfg+IRMapIRMapentries, so a map can be reused, even after an earlier copy is gonekirin_function::inline_callsCallSpecializedcalls in a CFGAPI changes
insertplaces a cloned statement;splice_cfg_afterorcreateplaces a cloned CFG. Detached CFGs never placed, including one a splice left empty, are tombstoned when theRewriterdrops, like detached statements.createadopts the unowned bodies its definition names (e.g. a cloned CFG), with the same checks asreplace_statement: each body must be live, owned by nothing (BodyOwnedElsewhere), named once (BodyListedTwice), and must not enclose the insertion point (BodyEnclosesOwner).CFGInfo::parent()accessor.Inlining
kirin-python's
Walk(Inline(...))scales as O(n²) (#554): each multi-block inline splits the call's block, and the split walks every statement after the call. In heavily inlined kernels most of the program ends up in one block, so every split costs close to the whole program. Calls are also visited first to last, so the same tail is moved again for every later call.inline_callsis built to stay linear:retbecomes a branch to the second half.inline_callsis public, so no single run can inline in a quadratic order.splice_cfg_afterrelinks them, with no list removal from the front.FunctionOps<T>(as_call/as_return) to tell the inliner which of its statements are calls and returns; a closure builds its branch op.Not included