Skip to content

✨ Add a pass specializing callees for what is known at their call sites - #2197

Open
DRovara wants to merge 2 commits into
mlir/builder-call-supportfrom
mlir/context-sensitive-specialization
Open

✨ Add a pass specializing callees for what is known at their call sites#2197
DRovara wants to merge 2 commits into
mlir/builder-call-supportfrom
mlir/context-sensitive-specialization

Conversation

@DRovara

@DRovara DRovara commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Fourth of a stack replacing #1970. Builds on #2196. First of the four interprocedural passes; the quantum-ipo pipeline that schedules them arrives in the final slice.

quantum-context-sensitive-specialization redirects a func.call to a specialized copy of its callee whenever the call site pins something down: a qubit argument known to be in |0>, which lets operations that fix |0> be dropped; one known to be in |+>, which lets an x be dropped; or a compile-time constant rotation angle from a small distinguished set, which is folded into the copy.

Copies are shared between call sites with the same context. A callee left without callers is erased, but only when this pass created that situation — unrelated unused functions are left alone, since removing those is the user's decision. Specializations are private, so specializing a public callee neither exports the generated symbol nor leaves it behind once it loses its callers.

IPOUtils.{h,cpp} holds the two helpers the interprocedural passes share; the sibling passes in later slices reuse them.

Testing

19 cases in test_qco_context_sensitive_specialization.cpp, covering the |0>, |+> and constant-angle paths plus specialization reuse across call sites and the negative cases that must not specialize.

They are scheduled on createContextSensitiveSpecialization() alone rather than on a pipeline, per the review comment on the original PR: running each case through the full pipeline made it hard to tell which stage established the result and let one stage mask a regression in another. IPOTestFixture.h carries the fixture the sibling passes will share, and each suite names itself after its pass.

optimizations 140.

AI assistance

Code and this description were produced with Claude Code (Opus 5) and Codex, acting on my instructions and within the scope I authorized.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.64706% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/Optimizations/ContextSensitiveSpecialization.cpp 91.6% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from 11a067f to b4f0800 Compare August 24, 2026 09:33
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from b4f0800 to bcf64f6 Compare August 24, 2026 09:52
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from bcf64f6 to b3697de Compare August 25, 2026 07:50
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from b3697de to 99467de Compare August 25, 2026 08:02
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from 99467de to 47aaea4 Compare August 25, 2026 10:48
@burgholzer
burgholzer force-pushed the mlir/context-sensitive-specialization branch from 47aaea4 to 458d47c Compare August 25, 2026 21:44
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch 2 times, most recently from 08fcbf9 to 857d4fe Compare August 26, 2026 14:11
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from 857d4fe to 3d9f620 Compare August 26, 2026 14:34
@DRovara
DRovara marked this pull request as ready for review August 26, 2026 14:37
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from 3d9f620 to e28d0eb Compare August 27, 2026 11:40
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch 2 times, most recently from 57f1a36 to 40d0f77 Compare August 28, 2026 07:28
@DRovara
DRovara force-pushed the mlir/context-sensitive-specialization branch from 40d0f77 to 301b341 Compare August 28, 2026 08:11
@burgholzer
burgholzer force-pushed the mlir/context-sensitive-specialization branch from 301b341 to eabcd73 Compare August 28, 2026 12:30
@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Aug 28, 2026
Specialize callees from values known at their call sites and cover the interprocedural behavior.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
@burgholzer
burgholzer force-pushed the mlir/context-sensitive-specialization branch from eabcd73 to 6f34e3e Compare August 30, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants