Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91b3ef9
feat(mlir): :sparkles: implement dead gate elimination canonicalizati…
DRovara Jun 1, 2026
ba57aa2
fix(mlir): :bug: fix tests
DRovara Jun 1, 2026
b83afab
test(mlir): :white_check_mark: add direct test for dead gate elimination
DRovara Jun 1, 2026
4243ac0
docs(mlir): :memo: update changelog
DRovara Jun 1, 2026
a50032b
style(mlir): :rotating_light: fix linter issues
DRovara Jun 1, 2026
d8c9ad5
fix(mlir): :recycle: guard RegionOp removal for child oeprations with…
DRovara Jun 2, 2026
9717547
fix(mlir): :bug: fix handling for `IfOp` removal and add specialized …
DRovara Jun 2, 2026
2d65418
fix(mlir): :bug: minor bug and code style fixes
DRovara Jun 2, 2026
278a54e
style(mlir): :rotating_light: fix linter issues on includes
DRovara Jun 2, 2026
44eaf7e
fix: :pencil2: fix typo in changelog
DRovara Jun 2, 2026
8b3af43
🎨 Optimize `checkAndRemoveDeadGate` function
burgholzer Jun 2, 2026
6998110
📝 Add to generic changelog entry for mqt-cc
burgholzer Jun 2, 2026
d56ccaf
Update mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp
DRovara Jun 3, 2026
fb9fffb
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 3, 2026
44f295a
test(mlir): :white_check_mark: improve test and add custom return typ…
DRovara Jun 3, 2026
9e8e711
Merge branch 'mlir/dead-gate-elimination' of github.com:munich-quantu…
DRovara Jun 3, 2026
b6cbf8e
style(mlir): :recycle: remove unneeded dumps
DRovara Jun 3, 2026
dee0752
style(mlir): :recycle: move `checkAndRemoveDeadGate` implementation o…
DRovara Jun 3, 2026
244f8bb
style(mlir): :recycle: implement helper function to check if a gate i…
DRovara Jun 3, 2026
6eaac40
style(mlir): :rotating_light: fix includes
DRovara Jun 3, 2026
07a3f4d
docs(mlir): :memo: add comments to document `gphase` operation as mem…
DRovara Jun 5, 2026
cab4155
test(mlir): :white_check_mark: update tests to now use return values
DRovara Jun 5, 2026
6f1c64e
Update mlir/include/mlir/Dialect/QCO/QCOUtils.h
DRovara Jun 8, 2026
7e63992
Update mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp
DRovara Jun 8, 2026
2e9f4e6
Update mlir/unittests/programs/qco_programs.cpp
DRovara Jun 8, 2026
29b0cbe
Update mlir/unittests/programs/qco_programs.h
DRovara Jun 8, 2026
225c88f
style(mlir): :recycle: address some review comments
DRovara Jun 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
- ✨ Add conversions between `jeff` and QCO ([#1479], [#1548], [#1565], [#1637], [#1676], [#1706]) ([**@denialhaag**], [**@burgholzer**])
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1600], [#1664], [#1709], [#1716], [#1748]) ([**@MatthiasReumann**], [**@burgholzer**])
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730], [#1749])
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730], [#1749], [#1755])
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])

### Changed
Expand Down Expand Up @@ -402,6 +402,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool

<!-- PR links -->

[#1755]: https://github.com/munich-quantum-toolkit/core/pull/1755
[#1749]: https://github.com/munich-quantum-toolkit/core/pull/1749
[#1748]: https://github.com/munich-quantum-toolkit/core/pull/1748
[#1737]: https://github.com/munich-quantum-toolkit/core/pull/1737
Expand Down
59 changes: 56 additions & 3 deletions mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,32 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
//===--------------------------------------------------------------------===//

/**
* @brief Initialize the builder and prepare for program construction
* @brief Initialize the builder and prepare for program construction, with
* a default return type of i64.
*
* @details
* Creates a main function with an entry_point attribute. Must be called
* before adding operations.
*/
void initialize();

/**
* @brief Initialize the builder and prepare for program construction
* with specified return types.
* @param returnTypes The return types for the main function
*
* @details
* Creates a main function with an entry_point attribute. Must be called
* before adding operations.
*/
void initialize(TypeRange returnTypes);

/**
* @brief Modify the return types of the main function after initialization.
* @param returnTypes The new return types for the main function
*/
void retype(TypeRange returnTypes);

//===--------------------------------------------------------------------===//
// Constants
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -372,7 +390,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
*
* @param qubit Input qubit (must be valid/unconsumed)
* @param bit The classical bit to record the result
* @return Output qubit value
* @return Pair of (output_qubit, measurement_result)
*
* @par Example:
* ```c++
Expand All @@ -382,7 +400,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
* %q0_out, %r0 = qco.measure("c", 3, 0) %q0 : !qco.qubit
* ```
*/
Value measure(Value qubit, const Bit& bit);
std::pair<Value, Value> measure(Value qubit, const Bit& bit);

/**
* @brief Reset a qubit to |0⟩ state
Expand Down Expand Up @@ -1375,6 +1393,25 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
*/
OwningOpRef<ModuleOp> finalize();

/**
* @brief Finalize the program with a given exit code and return the
* constructed module
* @param returnValues Values representing the exit code to return
*
* @details
* Automatically deallocates all remaining valid qubits and tensors of qubits,
* adds a return statement with a given exit code,
* and transfers ownership of the module to the caller. The builder should not
* be used after calling this method.
*
* The return values must have the types indicated by the function signature
* of the main function, which returns an `i64` by default and can be
* modified by passing different arguments to the `initialize()` method.
*
* @return OwningOpRef containing the constructed quantum program module
*/
OwningOpRef<ModuleOp> finalize(ValueRange returnValues);

/**
* @brief Convenience method for building quantum programs
* @param context The MLIR context to use for building the program
Expand All @@ -1388,6 +1425,22 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
build(MLIRContext* context,
const function_ref<void(QCOProgramBuilder&)>& buildFunc);

/**
* @brief Convenience method for building quantum programs with returns.
* @param context The MLIR context to use for building the program
* @param returnTypes The types of the values to be returned by the program.
* @param buildFunc A function that takes a reference to a QCOProgramBuilder
* and uses it to build the desired quantum program. The builder will be
* properly initialized before calling this function, and the resulting module
* will be finalized using the returned ValueRange after this function
* completes.
* @return The module containing the quantum program built by buildFunc.
*/
static OwningOpRef<ModuleOp> buildWithReturn(
MLIRContext* context,
const function_ref<std::pair<SmallVector<Value>, SmallVector<Type>>(
QCOProgramBuilder&)>& buildFunc);
Comment on lines +1428 to +1442

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Without having thought about it too much right now, is there still a real need for the old build() method, or should any real QCO program return something (other than the exit code)? 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question. I didn't feel confident enough to remove the original build function.

I can imagine scenarios where it would still be useful, the question is just (1) are they valid/important enough? and (2) are they maybe that rare that users could just use buildWithReturn with a function pointer that just returns an empty type range or a single ì64` exit code instead?

Example:
A program that is supposed to be translated down to QIR and should then run the record_outputs (don't remember the exact name) operation. Or, if that's what the new returns will be translated into, then maybe programs with intermediate print operations.

In any case, I have no problem with just removing the original build method, but I feel like that should be your call.

@burgholzer burgholzer Jun 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be fine with dropping the original build method. One can always emulate it with the existing builder by returning an exit code. So the new builder is strictly more expressive.
Edit: the return values of entry point functions will be translated to output recording calls in QIR.


private:
enum class AllocationMode : uint8_t { Unset, Static, Dynamic };

Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Dialect/QCO/IR/QCODialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def QCODialect : Dialect {
let cppNamespace = "::mlir::qco";

let useDefaultTypePrinterParser = 1;

let hasCanonicalizer = 1;
}

#endif // MLIR_DIALECT_QCO_IR_QCODIALECT_TD
Loading