Skip to content

ir.Method specialization on func.Invoke containing immutable known constants - #735

Open
zhenrongliew wants to merge 5 commits into
mainfrom
dl/method-specialize
Open

zhenrongliew wants to merge 5 commits into
mainfrom
dl/method-specialize

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

Closes #734

Adds a Specialize pass that clones a method with call-site constants baked into its body and rewrites the call to pass only the remaining arguments. The original method is left untouched and still callable.

Design

SpecializeInvoke (rewrite rule) matches func.Invoke, reads one constant fact per operand, and swaps the call. Dropping an operand removes a use; it is DCE's decision to remove it if applicable.

Specialize (pass) owns constant propagation, the key policy, the cache, the budget, the worklist, and backedge cleanup.

Cache, Key & Budget

On argument values, positionally: (method, (key₀ … keyₙ)). So foo(3, x) and foo(x, 3) yield different specializations, while foo(b=x, a=3) normalizes to the same key as foo(3, x) and shares a specialization.

_constant_key admits only: scalars, complex, range, and recursively tuple/frozenset/IList. Mutable values stay parameters.

max_specializations (default 32) per method. At the limit the call falls back to the original method rather creating new specializations.

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://QuEraComputing.github.io/kirin/pr-preview/pr-735/

Built to branch gh-pages at 2026-09-18 18:07 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
12118 10958 90% 0% 🟢

New Files

File Coverage Status
src/kirin/passes/specialize.py 96% 🟢
src/kirin/rewrite/specialize_invoke.py 100% 🟢
TOTAL 98% 🟢

Modified Files

File Coverage Status
src/kirin/passes/_init_.py 100% 🟢
src/kirin/rewrite/_init_.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 17804d9 by action🐍

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/kirin/passes/specialize.py 95.93% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specialization of ir.Method

1 participant