Skip to content

👷 Lower reusable functions with standard MLIR passes - #2344

Merged
burgholzer merged 1 commit into
mainfrom
codex/reusable-function-lowering
Sep 6, 2026
Merged

👷 Lower reusable functions with standard MLIR passes#2344
burgholzer merged 1 commit into
mainfrom
codex/reusable-function-lowering

Conversation

@burgholzer

@burgholzer burgholzer commented Sep 3, 2026

Copy link
Copy Markdown
Member

This marks the end of the first stack or PRs to add multiple function support.
Fixes #1659

🤖 AI text below 🤖

Description

Use standard MLIR passes to lower reusable functions for compiler targets. Program entry points are public, defined func.func operations, which gives symbol liveness an explicit root. Target compilation inlines reusable calls before decomposition, mapping, synthesis, and conformance checks. Target-selected QIR compilation avoids redundant early inlining.

QC export and explicit QC/QCO cleanup remove unreachable private functions. The OpenQASM and Qiskit exporters emit only gates reachable from the entry point, so unused gate declarations are dropped. Explicit cleanup also uses MLIR dead-value removal to prune unused unitary parameters and qubits together with the corresponding call operands.

No custom interprocedural framework or WireIterator state is added. qco.call already exposes positional wire correspondence through UnitaryOpInterface; generic func.call remains an intentional wire boundary.

The prerequisite structured-export changes in #2338, #2339, #2340, and #2342 are merged. This branch is rebased onto current main and requires no additional dependency.

Final-head local validation passed: release configuration and build; all 3,918 registered CTest cases with one expected skip; all 294 Qiskit translation tests; C++ lint; and repository lint. Hosted CI for the rebased commit is still running.

Codex implemented and tested the changes with independent MLIR/compiler specialist review.

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.

@burgholzer burgholzer added feature New feature or request Core Anything related to the Core library and IR c++ Anything related to C++ code MLIR Anything related to MLIR labels Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../Dialect/QC/Translation/TranslateQCToOpenQASM3.cpp 81.8% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from afd7d4c to 7fdb302 Compare September 3, 2026 23:12
@burgholzer
burgholzer force-pushed the codex/reusable-function-lowering branch from 4007906 to dd9ae18 Compare September 3, 2026 23:12
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from 7fdb302 to 6328d48 Compare September 4, 2026 21:59
@burgholzer
burgholzer force-pushed the codex/reusable-function-lowering branch 2 times, most recently from d1b21bd to e5b20d2 Compare September 5, 2026 13:09
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from 6328d48 to 26e83a0 Compare September 5, 2026 13:09
@burgholzer
burgholzer force-pushed the codex/reusable-function-lowering branch from e5b20d2 to d3fda6b Compare September 5, 2026 15:00
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch 2 times, most recently from d2688e6 to 1e71124 Compare September 6, 2026 12:06
@mergify mergify Bot added the conflict label Sep 6, 2026
Base automatically changed from codex/qiskit-reusable-gates to main September 6, 2026 20:02
@burgholzer
burgholzer force-pushed the codex/reusable-function-lowering branch from d3fda6b to 05abf45 Compare September 6, 2026 20:12
@burgholzer burgholzer added this to the v4.0.0 - IEEE Quantum Week milestone Sep 6, 2026
@burgholzer burgholzer self-assigned this Sep 6, 2026
@mergify mergify Bot removed the conflict label Sep 6, 2026
Require a public, defined func.func program entry so symbol DCE can
prune unreachable private helpers during QC export and QC/QCO cleanup.
Let structured exporters omit unreachable gate declarations.

Use MLIR dead-value removal in explicit cleanup so unused unitary
parameters and qubits are removed with their matching call operands.

Inline reusable calls once at the target-compilation boundary before
mapping, synthesis, and conformance checks. Avoid redundant inlining in
typed and CLI QIR paths.

Assisted-by: GPT-5.6 via Codex
@burgholzer
burgholzer force-pushed the codex/reusable-function-lowering branch from 05abf45 to 33dbc84 Compare September 6, 2026 21:14

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now also looks decent and like a workable solution for now.
Custom gates will simply be inlined now as part of the target compilation. This is definitely an aspect to improve in the future.

@burgholzer
burgholzer enabled auto-merge (squash) September 6, 2026 21:35
@burgholzer
burgholzer merged commit 818b653 into main Sep 6, 2026
25 of 26 checks passed
@burgholzer
burgholzer deleted the codex/reusable-function-lowering branch September 6, 2026 21:45
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 Core Anything related to the Core library and IR feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Support multiple functions

1 participant