Skip to content

Conversation

@li-mingbao
Copy link
Contributor

Description

This PR templates the variantToValue function to make the function more generic and to support the creation of IndexType and I1Type constants.

Required for #1396

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Constants can now be created from double, integer, and boolean scalars.
  • Refactor

    • Variant-to-value conversion generalized to support any scalar type.
    • Gate builders now use operation location when resolving variant parameters, improving diagnostic accuracy.
  • Chores

    • CHANGELOG updated to reference the new pull request.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Templatizes variantToValue to accept a Location and std::variant<T, Value>, adds three constantFromScalar overloads (double, int64_t, bool), and updates multiple QC/QCO gate build call sites to pass state.location instead of state.

Changes

Cohort / File(s) Summary
Utility Header
mlir/include/mlir/Dialect/Utils/Utils.h
Add `constantFromScalar(OpBuilder&, Location, double
QC Dialect — Standard Gates
mlir/lib/Dialect/QC/IR/Operations/StandardGates/*Op.cpp
Update gate build call sites to pass state.location to variantToValue instead of state. Files include GPhaseOp.cpp, POp.cpp, ROp.cpp, RXOp.cpp, RXXOp.cpp, RYOp.cpp, RYYOp.cpp, RZOp.cpp, RZXOp.cpp, RZZOp.cpp, U2Op.cpp, UOp.cpp, XXMinusYYOp.cpp, XXPlusYYOp.cpp.
QCO Dialect — Standard Gates
mlir/lib/Dialect/QCO/IR/Operations/StandardGates/*Op.cpp
Mirror the QC changes: replace state with state.location when calling variantToValue in corresponding gate implementations (matching files under QCO).
Changelog
CHANGELOG.md
Append PR reference #1465 to Unreleased Added and PR links sections.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

c++

Suggested reviewers

  • burgholzer
  • denialhaag

Poem

🐰 I nudge the header, hop where templates play,
Scalars tucked in neat rows, locations show the way.
Gates now ask for places, not the whole bustling state,
I twitch my nose and cheer — tidy code, tidy gate.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring: templating variantToValue to support different Value types, which is the core change across all modified files.
Description check ✅ Passed The description clearly states the purpose (template variantToValue for genericity and IndexType/I1Type support) and references issue #1396, but all checklist items remain unchecked despite apparent completion of most tasks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.



📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4fe35b and 13314ee.

📒 Files selected for processing (1)
  • CHANGELOG.md
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp:599-757
Timestamp: 2026-01-12T12:05:56.683Z
Learning: In the QCO builder (mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp), the SCF and func builder methods (scfFor, scfWhile, scfIf, funcCall) assume that all operands passed to them are qubit types (qco.qubit). The current validation through updateQubitTracking is sufficient for this use case. The same assumption applies to the QC builder methods.
📚 Learning: 2025-12-05T17:45:37.602Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1360
File: .github/workflows/reusable-mlir-tests.yml:40-43
Timestamp: 2025-12-05T17:45:37.602Z
Learning: In the munich-quantum-toolkit/core repository, patch releases of LLVM dependencies don't require documentation updates, changelog entries, or additional tests beyond what's validated by passing CI checks.

Applied to files:

  • CHANGELOG.md
📚 Learning: 2026-01-08T22:56:09.502Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1435
File: docs/mlir/QC.md:1-11
Timestamp: 2026-01-08T22:56:09.502Z
Learning: In the munich-quantum-toolkit/core repository, MLIR dialect documentation files (e.g., MLIRQCDialect.md, MLIRQCInterfaces.md) are automatically generated during the documentation build via the ReadTheDocs `pre_build` step and do not need to be committed to the repository.

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-10-14T14:37:38.047Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/yaqs PR: 212
File: CHANGELOG.md:12-15
Timestamp: 2025-10-14T14:37:38.047Z
Learning: In the munich-quantum-toolkit/yaqs project, changelog entries follow the template: "- $TITLE ([#$NUMBER]($URL)) ([**AUTHOR**](https://github.com/$AUTHOR))". Issue references should not be included in changelog entries; the PR number is sufficient for traceability.

Applied to files:

  • CHANGELOG.md
📚 Learning: 2026-01-10T18:49:44.352Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1045-1119
Timestamp: 2026-01-10T18:49:44.352Z
Learning: The QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp) does not need defensive mixed-type checks in its func conversion patterns (ConvertQCOFuncFuncOp, ConvertQCOFuncCallOp, ConvertQCOFuncReturnOp) because the conversion workflow always starts from QC to QCO, and the QCToQCO pass already enforces through its dynamic legality checks that func operations contain only qubit types (no mixed classical/quantum). This upstream guarantee justifies the all-qubit assumptions in QCOToQC patterns.

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-12-01T11:00:40.342Z
Learnt from: flowerthrower
Repo: munich-quantum-toolkit/core-plugins-catalyst PR: 1
File: CHANGELOG.md:18-18
Timestamp: 2025-12-01T11:00:40.342Z
Learning: In the munich-quantum-toolkit/core-plugins-catalyst repository, the CHANGELOG.md intentionally references the parent MQT Core repository's release notes (https://github.com/munich-quantum-toolkit/core/releases) because the plugin repository is based on work performed in the parent repository.

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-11-24T10:19:41.147Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1326
File: python/mqt/core/__init__.py:22-22
Timestamp: 2025-11-24T10:19:41.147Z
Learning: In the munich-quantum-toolkit/core repository, Ruff is configured with 'ALL' rules enabled by default, and only specific rules are selectively disabled. When reviewing changes that enable previously-disabled rules (like PLC0415), noqa directives for those rules become necessary and should be retained.

Applied to files:

  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: 🇨‌ Test 🏁 (windows-2025, msvc, Debug) / 🏁 windows-2025 msvc Debug
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04-arm, gcc, Release) / 🐧 ubuntu-24.04-arm gcc Release
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04, gcc, Release) / 🐧 ubuntu-24.04 gcc Release
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04, gcc, Debug) / 🐧 ubuntu-24.04 gcc Debug
  • GitHub Check: 🇨‌ Test 🏁 (windows-2025, msvc, Release) / 🏁 windows-2025 msvc Release
  • GitHub Check: 🇨‌ Test 🏁 (windows-11-arm, msvc, Release) / 🏁 windows-11-arm msvc Release
  • GitHub Check: 🇨‌ Test 🍎 (macos-15, clang, Release) / 🍎 macos-15 clang Release
  • GitHub Check: 🇨‌ Test 🍎 (macos-15, clang, Debug) / 🍎 macos-15 clang Debug
  • GitHub Check: 🇨‌ Test 🍎 (macos-15-intel, clang, Release) / 🍎 macos-15-intel clang Release
  • GitHub Check: 🇨‌ Lint / 🚨 Lint
  • GitHub Check: 🇨‌ Coverage / 📈 Coverage
  • GitHub Check: Summary
🔇 Additional comments (2)
CHANGELOG.md (2)

14-14: LGTM! Changelog entry correctly placed.

The PR reference is appropriately added to the existing QC and QCO MLIR dialects infrastructure entry under the "Added" section, as this PR introduces new utility helpers and templates existing functionality.


317-317: LGTM! PR link correctly added.

The PR link reference follows the correct format and is properly placed in descending numerical order in the links section.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@mlir/include/mlir/Dialect/Utils/Utils.h`:
- Around line 38-44: The Doxygen comment above the Convert-a-variant helper has
a mismatched parameter tag: change the incorrect "@param state" to "@param loc"
to match the actual function parameter name `loc`, and ensure the brief
description refers to `loc` (the operation location) if necessary so the
docblock parameters align with the function signature (look for the comment
around the function that converts a variant parameter to a Value in Utils.h and
update the `@param` tag).
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98abdda and 384efb9.

📒 Files selected for processing (29)
  • mlir/include/mlir/Dialect/Utils/Utils.h
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp
🧰 Additional context used
🧠 Learnings (20)
📓 Common learnings
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1045-1119
Timestamp: 2026-01-10T18:49:44.352Z
Learning: The QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp) does not need defensive mixed-type checks in its func conversion patterns (ConvertQCOFuncFuncOp, ConvertQCOFuncCallOp, ConvertQCOFuncReturnOp) because the conversion workflow always starts from QC to QCO, and the QCToQCO pass already enforces through its dynamic legality checks that func operations contain only qubit types (no mixed classical/quantum). This upstream guarantee justifies the all-qubit assumptions in QCOToQC patterns.
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp:599-757
Timestamp: 2026-01-12T12:05:56.683Z
Learning: In the QCO builder (mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp), the SCF and func builder methods (scfFor, scfWhile, scfIf, funcCall) assume that all operands passed to them are qubit types (qco.qubit). The current validation through updateQubitTracking is sufficient for this use case. The same assumption applies to the QC builder methods.
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:988-1024
Timestamp: 2026-01-10T16:07:55.896Z
Learning: In the QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp), the SCF operation conversion patterns (ConvertQCOScfYieldOp, ConvertQCOScfConditionOp, ConvertQCOScfIfOp, ConvertQCOScfWhileOp, ConvertQCOScfForOp) assume that all operands are qubit types (qco.qubit or qc.qubit), never mixed qubit/classical types. The conversion is scoped to handle all-qubit SCF operations only.
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCToQCO/QCToQCO.cpp:1729-1763
Timestamp: 2026-01-10T16:28:41.975Z
Learning: In the QCToQCO conversion pass (mlir/lib/Conversion/QCToQCO/QCToQCO.cpp), the dynamic legality checks for func operations (func::CallOp, func::FuncOp, func::ReturnOp) and scf operations assume that operations use either all classical types or all qubit types, never mixed. Therefore, checking for the presence of qc::QubitType in operands or arguments is sufficient to determine if conversion is needed—there is no need to check both operands and results separately.
<!-- </add_learning]
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/include/mlir/Dialect/QCO/IR/QCOOps.td:259-259
Timestamp: 2025-12-17T17:44:31.349Z
Learning: In the QCO dialect (mlir/include/mlir/Dialect/QCO/IR/QCOOps.td), GPhaseOp intentionally uses `MemoryEffects<[MemWrite]>` instead of `Pure` to prevent the remove-dead-values pass from eliminating it. Since GPhaseOp is a zero-target operation with no result values, it would otherwise be removed by DCE, even though it has a meaningful effect on the global quantum state.
Learnt from: DRovara
Repo: munich-quantum-toolkit/core PR: 1108
File: mlir/lib/Dialect/MQTOpt/Transforms/DeadGateEliminationPattern.cpp:42-45
Timestamp: 2025-10-09T13:28:29.237Z
Learning: In the MQTOpt MLIR dialect, linear types enforce single-use semantics where each qubit value can only be consumed once, preventing duplicate deallocations and making RAUW operations safe when replacing output qubits with corresponding input qubits in transformation patterns.
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1070-1085
Timestamp: 2026-01-07T12:29:16.380Z
Learning: In the QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp), the ConvertQCOFuncFuncOp pattern assumes that when a func.func operation is matched for conversion, all of its arguments are qco.qubit types (never mixed qubit/classical). The pattern unconditionally converts all arguments to qc::QubitType based on this assumption.
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Operations/StandardGates/PhaseOp.cpp:0-0
Timestamp: 2025-12-08T23:44:44.157Z
Learning: In MLIR code (mlir/ directories), avoid using const qualifiers on core MLIR data types like Value, Type, Attribute, Operation*, Block*, Region*, etc. in function parameters and signatures. MLIR's design rationale explicitly discourages const for these types. See https://mlir.llvm.org/docs/Rationale/UsageOfConst/ for details.
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1040-1050
Timestamp: 2026-01-07T12:29:02.062Z
Learning: In the QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp), ConvertQCOFuncCallOp assumes that if a func::CallOp has qubit results, then all arguments and results are qubits (no mixed classical/quantum types). The conversion is scoped to handle all-qubit function calls only.
Learnt from: MatthiasReumann
Repo: munich-quantum-toolkit/core PR: 1237
File: mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Layout.h:219-231
Timestamp: 2025-10-07T15:30:42.946Z
Learning: In the Layout class for MLIR quantum routing (mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Layout.h), the swap method intentionally does NOT swap the hw fields in QubitInfo. This is correct because SSA values represent quantum states at fixed hardware locations, and only their program index associations change during a SWAP gate. The hw field indicates where an SSA value physically resides and remains constant.
📚 Learning: 2025-11-01T15:57:31.153Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1283
File: src/qir/runtime/QIR.cpp:196-201
Timestamp: 2025-11-01T15:57:31.153Z
Learning: In the QIR runtime (src/qir/runtime/QIR.cpp), the PRX gate (__quantum__qis__prx__body) is an alias for the R gate (Phased X-Rotation) and should call runtime.apply<qc::R>(theta, phi, qubit), not runtime.apply<qc::RX>() which is a single-parameter rotation gate.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
📚 Learning: 2025-10-09T13:20:11.483Z
Learnt from: DRovara
Repo: munich-quantum-toolkit/core PR: 1108
File: mlir/test/Dialect/MQTOpt/Transforms/lift-measurements.mlir:269-288
Timestamp: 2025-10-09T13:20:11.483Z
Learning: In the MQT MLIR dialect, the `rz` gate should not be included in the `DIAGONAL_GATES` set for the `ReplaceBasisStateControlsWithIfPattern` because its operator matrix does not have the required shape | 1 0 | / | 0 x | for the targets-as-controls optimization. It is only included in `LiftMeasurementsAboveGatesPatterns` where the matrix structure requirement differs.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2025-12-08T23:44:39.930Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Operations/StandardGates/PhaseOp.cpp:0-0
Timestamp: 2025-12-08T23:44:39.930Z
Learning: In MLIR code under any mlir/ directory, avoid using const qualifiers on core MLIR types in function parameters/signatures (e.g., Value, Type, Attribute, Operation*, Block*, Region*, etc.). This aligns with MLIR's design rationale and should be applied to C++ source files (e.g., .cpp) within mlir/; see https://mlir.llvm.org/docs/Rationale/UsageOfConst/ for details.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2025-12-17T11:32:45.843Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/MQTOpt/Transforms/Transpilation/LayeredUnit.cpp:83-86
Timestamp: 2025-12-17T11:32:45.843Z
Learning: In the mlir portion of munich-quantum-toolkit/core, prefer marking free functions as static (static linkage) over placing them in anonymous namespaces, per the clang-tidy rule llvm-prefer-static-over-anonymous-namespace. Do not apply this to type/class definitions; they may continue to use anonymous namespaces. This guideline should be checked across C++ source files under mlir/ (e.g., any free function in LayeredUnit.cpp) to ensure free functions have static linkage, while types/classes can remain in anonymous namespaces.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2026-01-10T18:49:44.352Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1045-1119
Timestamp: 2026-01-10T18:49:44.352Z
Learning: The QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp) does not need defensive mixed-type checks in its func conversion patterns (ConvertQCOFuncFuncOp, ConvertQCOFuncCallOp, ConvertQCOFuncReturnOp) because the conversion workflow always starts from QC to QCO, and the QCToQCO pass already enforces through its dynamic legality checks that func operations contain only qubit types (no mixed classical/quantum). This upstream guarantee justifies the all-qubit assumptions in QCOToQC patterns.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2026-01-10T16:28:41.975Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCToQCO/QCToQCO.cpp:1729-1763
Timestamp: 2026-01-10T16:28:41.975Z
Learning: In the QCToQCO conversion pass (mlir/lib/Conversion/QCToQCO/QCToQCO.cpp), the dynamic legality checks for func operations (func::CallOp, func::FuncOp, func::ReturnOp) and scf operations assume that operations use either all classical types or all qubit types, never mixed. Therefore, checking for the presence of qc::QubitType in operands or arguments is sufficient to determine if conversion is needed—there is no need to check both operands and results separately.
<!-- </add_learning]

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
📚 Learning: 2026-01-07T12:29:16.380Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1070-1085
Timestamp: 2026-01-07T12:29:16.380Z
Learning: In the QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp), the ConvertQCOFuncFuncOp pattern assumes that when a func.func operation is matched for conversion, all of its arguments are qco.qubit types (never mixed qubit/classical). The pattern unconditionally converts all arguments to qc::QubitType based on this assumption.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp
📚 Learning: 2026-01-12T12:05:56.683Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp:599-757
Timestamp: 2026-01-12T12:05:56.683Z
Learning: In the QCO builder (mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp), the SCF and func builder methods (scfFor, scfWhile, scfIf, funcCall) assume that all operands passed to them are qubit types (qco.qubit). The current validation through updateQubitTracking is sufficient for this use case. The same assumption applies to the QC builder methods.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2025-12-02T07:37:46.860Z
Learnt from: MatthiasReumann
Repo: munich-quantum-toolkit/core PR: 1301
File: mlir/lib/Dialect/MQTOpt/Transforms/Transpilation/sc/NaiveRoutingPass.cpp:144-151
Timestamp: 2025-12-02T07:37:46.860Z
Learning: In MLIR transformation code (mlir/lib/Dialect/MQTOpt/Transforms/Transpilation/sc/NaiveRoutingPass.cpp and similar), when inserting operations before a target operation, prefer `rewriter.setInsertionPoint(op)` over `rewriter.setInsertionPointAfter(op->getPrevNode())`. The former is cleaner, avoids null pointer edge cases (when op is first in block), and is semantically clearer.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
📚 Learning: 2025-12-17T17:44:31.349Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/include/mlir/Dialect/QCO/IR/QCOOps.td:259-259
Timestamp: 2025-12-17T17:44:31.349Z
Learning: In the QCO dialect (mlir/include/mlir/Dialect/QCO/IR/QCOOps.td), GPhaseOp intentionally uses `MemoryEffects<[MemWrite]>` instead of `Pure` to prevent the remove-dead-values pass from eliminating it. Since GPhaseOp is a zero-target operation with no result values, it would otherwise be removed by DCE, even though it has a meaningful effect on the global quantum state.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2025-12-08T23:58:09.648Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Modifiers/CtrlOp.cpp:80-100
Timestamp: 2025-12-08T23:58:09.648Z
Learning: In the Quartz dialect (mlir/lib/Dialect/Quartz/IR/Modifiers/CtrlOp.cpp), quartz.ctrl uses reference semantics and does not return values, unlike flux.ctrl which uses value semantics and returns transformed qubits. When inlining a GPhaseOp in the CtrlInlineGPhase pattern, it's correct to create POp operations for positive controls and erase the CtrlOp without collecting or replacing result values.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2025-12-08T14:55:43.899Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Flux/IR/Modifiers/CtrlOp.cpp:78-100
Timestamp: 2025-12-08T14:55:43.899Z
Learning: In the Flux dialect (mlir/lib/Dialect/Flux/IR/Modifiers/CtrlOp.cpp), GPhaseOp is a zero-target operation (global phase). When a CtrlOp wraps a GPhaseOp, it only has control qubits and no targets. The CtrlInlineGPhase canonicalization pattern correctly produces outputs only for the positive controls, not targets.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp
  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp
📚 Learning: 2026-01-10T17:31:22.110Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:816-862
Timestamp: 2026-01-10T17:31:22.110Z
Learning: In mlir/lib/Conversion/QCOToQC/QCOToQC.cpp, when creating scf::IfOp with `rewriter.create<scf::IfOp>(loc, types, condition, false)`, passing `false` for the withElseRegion parameter creates an else region that exists but contains no blocks. Therefore, inlineRegionBefore can be called on the else region without checking if it exists, and there's no need to erase an auto-created empty block from the else region (unlike the then region, which does get an auto-created empty block that must be erased).

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp
📚 Learning: 2025-10-09T13:13:51.224Z
Learnt from: DRovara
Repo: munich-quantum-toolkit/core PR: 1108
File: mlir/lib/Dialect/MQTOpt/Transforms/ReplaceBasisStateControlsWithIfPattern.cpp:171-180
Timestamp: 2025-10-09T13:13:51.224Z
Learning: In MQT Core MLIR, UnitaryInterface operations guarantee 1-1 correspondence between input and output qubits in the same order. When cloning or modifying unitary operations (e.g., removing controls), this correspondence is maintained by construction, so yielding getAllInQubits() in else-branches matches the result types from the operation's outputs.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp
📚 Learning: 2026-01-07T12:29:02.062Z
Learnt from: li-mingbao
Repo: munich-quantum-toolkit/core PR: 1396
File: mlir/lib/Conversion/QCOToQC/QCOToQC.cpp:1040-1050
Timestamp: 2026-01-07T12:29:02.062Z
Learning: In the QCOToQC conversion pass (mlir/lib/Conversion/QCOToQC/QCOToQC.cpp), ConvertQCOFuncCallOp assumes that if a func::CallOp has qubit results, then all arguments and results are qubits (no mixed classical/quantum types). The conversion is scoped to handle all-qubit function calls only.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
📚 Learning: 2025-12-08T12:44:05.883Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Modifiers/CtrlOp.cpp:60-70
Timestamp: 2025-12-08T12:44:05.883Z
Learning: In the Quartz dialect (mlir/lib/Dialect/Quartz/IR/Modifiers/CtrlOp.cpp), negative controls are not supported at the current stage. The RemoveTrivialCtrl pattern correctly only checks getNumPosControls() when determining if a CtrlOp should be removed.

Applied to files:

  • mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp
  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp
📚 Learning: 2025-10-07T15:30:42.946Z
Learnt from: MatthiasReumann
Repo: munich-quantum-toolkit/core PR: 1237
File: mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Layout.h:219-231
Timestamp: 2025-10-07T15:30:42.946Z
Learning: In the Layout class for MLIR quantum routing (mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Layout.h), the swap method intentionally does NOT swap the hw fields in QubitInfo. This is correct because SSA values represent quantum states at fixed hardware locations, and only their program index associations change during a SWAP gate. The hw field indicates where an SSA value physically resides and remains constant.

Applied to files:

  • mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp
📚 Learning: 2025-12-08T23:44:44.157Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Operations/StandardGates/PhaseOp.cpp:0-0
Timestamp: 2025-12-08T23:44:44.157Z
Learning: In MLIR code (mlir/ directories), avoid using const qualifiers on core MLIR data types like Value, Type, Attribute, Operation*, Block*, Region*, etc. in function parameters and signatures. MLIR's design rationale explicitly discourages const for these types. See https://mlir.llvm.org/docs/Rationale/UsageOfConst/ for details.

Applied to files:

  • mlir/include/mlir/Dialect/Utils/Utils.h
📚 Learning: 2025-12-14T17:02:02.997Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp:187-210
Timestamp: 2025-12-14T17:02:02.997Z
Learning: In the Flux dialect builder (mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp), the coding style relies on implicit conversion from Value to ValueRange in ctrl() calls (e.g., `ctrl(control, {}, ...)` instead of `ctrl(ValueRange{control}, ValueRange{}, ...)`). This pattern is used consistently throughout all macro-generated methods and should be maintained for consistency.

Applied to files:

  • mlir/include/mlir/Dialect/Utils/Utils.h
🧬 Code graph analysis (2)
mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp (1)
src/dd/StateGeneration.cpp (1)
  • state (126-126)
mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp (1)
src/dd/StateGeneration.cpp (1)
  • state (126-126)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (30)
mlir/include/mlir/Dialect/Utils/Utils.h (2)

28-31: Verify: int64_t produces IndexType, not IntegerType.

This overload creates an IndexAttr (yielding an index type), which is intentional per the PR objectives. If a caller expects a standard i64 integer constant, they would need a separate overload. Please confirm this is the desired behavior for all current and anticipated use cases.


23-26: LGTM!

The constantFromScalar overloads for double and bool are correctly implemented, and the templated variantToValue cleanly dispatches based on the variant's scalar type. This provides good extensibility while maintaining compile-time type safety.

Also applies to: 33-36, 46-53

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXOp.cpp (1)

22-26: LGTM!

The update correctly passes state.location to the refactored variantToValue API.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZXOp.cpp (1)

55-59: LGTM!

The update correctly adapts to the new variantToValue signature.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYOp.cpp (1)

22-26: LGTM!

The update correctly adapts to the new variantToValue signature.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/ROp.cpp (1)

73-79: LGTM!

Both theta and phi operand construction correctly use state.location with the refactored variantToValue API.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZOp.cpp (1)

22-26: LGTM!

The change to pass state.location instead of the full state to variantToValue is correct and aligns with the refactoring to make the utility function more generic by accepting a Location directly.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXMinusYYOp.cpp (1)

74-81: LGTM!

Both thetaOperand and betaOperand conversions consistently use state.location, maintaining the same pattern across all parameter conversions. The build method correctly delegates to the underlying build call with the resolved operands.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXPlusYYOp.cpp (1)

22-29: LGTM!

The variantToValue calls for both theta and beta are consistently updated to use state.location, matching the pattern established across other StandardGates operations in this refactor.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/GPhaseOp.cpp (1)

22-26: LGTM!

The variantToValue call is correctly updated to use state.location. This change is consistent with the broader refactoring pattern applied across all StandardGates operations.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/POp.cpp (1)

55-59: LGTM!

The variantToValue call is correctly updated to pass state.location instead of the full state object, consistent with all other StandardGates operations updated in this PR.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/XXPlusYYOp.cpp (1)

78-80: LGTM!

The refactored variantToValue calls correctly use state.location for both theta and beta operand construction, maintaining consistency with the broader PR pattern across all StandardGates operations.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/U2Op.cpp (1)

25-27: LGTM!

Both phi and lambda operand constructions consistently use state.location, aligning with the refactored variantToValue signature.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXXOp.cpp (1)

57-58: LGTM!

The thetaOperand construction correctly uses state.location, consistent with the refactored utility signature.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZOp.cpp (1)

57-58: LGTM!

The thetaOperand construction correctly uses state.location, consistent with the broader refactor.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/POp.cpp (1)

24-25: LGTM!

The thetaOperand construction correctly uses state.location, completing the consistent pattern across all reviewed StandardGates operations.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/U2Op.cpp (1)

102-104: LGTM!

The refactored variantToValue calls correctly use state.location to provide location context for operand materialization. This aligns with the broader PR goal of making the utility function generic while preserving the same behavior.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RXXOp.cpp (1)

24-25: LGTM!

Consistent refactoring to use state.location for theta operand construction.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/ROp.cpp (1)

25-27: LGTM!

Both theta and phi operand constructions correctly updated to use state.location, maintaining consistency with the refactored variantToValue interface.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RXOp.cpp (1)

57-58: LGTM!

Consistent refactoring to use state.location for theta operand construction in the QCO dialect's RXOp.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYYOp.cpp (1)

57-58: LGTM!

Consistent refactoring to use state.location for theta operand construction in the QCO dialect's RYYOp.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RYOp.cpp (1)

57-58: LGTM!

The update to pass state.location directly to variantToValue aligns with the refactored generic API. This is a clean change that correctly provides the location context needed for constant creation.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZZOp.cpp (1)

24-25: LGTM!

Consistent application of the state.location pattern for the two-qubit RZZ gate.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/GPhaseOp.cpp (1)

50-51: LGTM!

Correct update for the zero-target GPhaseOp, maintaining consistency with the location-based variantToValue pattern.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/RZZOp.cpp (1)

57-58: LGTM!

Consistent application of the refactored variantToValue API for the QCO dialect's RZZ gate.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RYYOp.cpp (1)

24-25: LGTM!

Consistent application of the state.location pattern for the two-qubit RYY gate, completing the uniform refactoring across all standard gate operations.

mlir/lib/Dialect/QCO/IR/Operations/StandardGates/UOp.cpp (1)

104-107: LGTM!

The refactoring to use state.location instead of state is applied consistently across all three operands (theta, phi, lambda). This aligns with the PR objective to make variantToValue generic by accepting Location directly.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/RZXOp.cpp (1)

24-25: LGTM!

The change correctly passes state.location to variantToValue, consistent with the refactoring pattern across the codebase.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/XXMinusYYOp.cpp (1)

26-28: LGTM!

Both thetaOperand and betaOperand construction correctly updated to use state.location, maintaining consistency with the broader refactoring effort.

mlir/lib/Dialect/QC/IR/Operations/StandardGates/UOp.cpp (1)

26-29: LGTM!

The refactoring is applied consistently to all three angle operands. This mirrors the corresponding QCO dialect implementation and maintains the uniform approach across the codebase.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

❌ Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/include/mlir/Dialect/Utils/Utils.h 83.3% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@mlir/include/mlir/Dialect/Utils/Utils.h`:
- Around line 46-53: The Location parameter must not be const-qualified: change
variantToValue's signature from "const Location& loc" to a non-const Location
parameter (e.g., "Location loc" or "Location &loc" consistent with surrounding
APIs) and update the constantFromScalar overloads called by variantToValue to
accept a non-const Location as well; then adjust any call sites if necessary to
match the new signatures. Ensure you modify the declarations/definitions for
variantToValue and the constantFromScalar overloads (and their forward
declarations) so they all use the same non-const Location type.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 384efb9 and 9e6369c.

📒 Files selected for processing (1)
  • mlir/include/mlir/Dialect/Utils/Utils.h
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Operations/StandardGates/PhaseOp.cpp:0-0
Timestamp: 2025-12-08T23:44:44.157Z
Learning: In MLIR code (mlir/ directories), avoid using const qualifiers on core MLIR data types like Value, Type, Attribute, Operation*, Block*, Region*, etc. in function parameters and signatures. MLIR's design rationale explicitly discourages const for these types. See https://mlir.llvm.org/docs/Rationale/UsageOfConst/ for details.
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp:187-210
Timestamp: 2025-12-14T17:02:02.997Z
Learning: In the Flux dialect builder (mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp), the coding style relies on implicit conversion from Value to ValueRange in ctrl() calls (e.g., `ctrl(control, {}, ...)` instead of `ctrl(ValueRange{control}, ValueRange{}, ...)`). This pattern is used consistently throughout all macro-generated methods and should be maintained for consistency.
📚 Learning: 2025-12-08T23:44:44.157Z
Learnt from: burgholzer
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Quartz/IR/Operations/StandardGates/PhaseOp.cpp:0-0
Timestamp: 2025-12-08T23:44:44.157Z
Learning: In MLIR code (mlir/ directories), avoid using const qualifiers on core MLIR data types like Value, Type, Attribute, Operation*, Block*, Region*, etc. in function parameters and signatures. MLIR's design rationale explicitly discourages const for these types. See https://mlir.llvm.org/docs/Rationale/UsageOfConst/ for details.

Applied to files:

  • mlir/include/mlir/Dialect/Utils/Utils.h
📚 Learning: 2025-12-14T17:02:02.997Z
Learnt from: denialhaag
Repo: munich-quantum-toolkit/core PR: 1264
File: mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp:187-210
Timestamp: 2025-12-14T17:02:02.997Z
Learning: In the Flux dialect builder (mlir/lib/Dialect/Flux/Builder/FluxProgramBuilder.cpp), the coding style relies on implicit conversion from Value to ValueRange in ctrl() calls (e.g., `ctrl(control, {}, ...)` instead of `ctrl(ValueRange{control}, ValueRange{}, ...)`). This pattern is used consistently throughout all macro-generated methods and should be maintained for consistency.

Applied to files:

  • mlir/include/mlir/Dialect/Utils/Utils.h
🧬 Code graph analysis (1)
mlir/include/mlir/Dialect/Utils/Utils.h (1)
mlir/include/mlir/Dialect/QCO/QCOUtils.h (1)
  • mlir (18-201)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: 🇨‌ Test 🍎 (macos-15, clang, Debug) / 🍎 macos-15 clang Debug
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04, gcc, Release) / 🐧 ubuntu-24.04 gcc Release
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04, gcc, Debug) / 🐧 ubuntu-24.04 gcc Debug
  • GitHub Check: 🇨‌ Test 🍎 (macos-15-intel, clang, Release) / 🍎 macos-15-intel clang Release
  • GitHub Check: 🇨‌ Test 🏁 (windows-2025, msvc, Debug) / 🏁 windows-2025 msvc Debug
  • GitHub Check: 🇨‌ Test 🏁 (windows-11-arm, msvc, Release) / 🏁 windows-11-arm msvc Release
  • GitHub Check: 🇨‌ Test 🐧 (ubuntu-24.04-arm, gcc, Release) / 🐧 ubuntu-24.04-arm gcc Release
  • GitHub Check: 🇨‌ Test 🍎 (macos-15, clang, Release) / 🍎 macos-15 clang Release
  • GitHub Check: 🇨‌ Lint / 🚨 Lint
  • GitHub Check: 🇨‌ Coverage / 📈 Coverage
  • GitHub Check: Summary
🔇 Additional comments (2)
mlir/include/mlir/Dialect/Utils/Utils.h (2)

15-15: LGTM!

The Location.h include is correctly added to support the new Location parameter in the function signatures.


38-45: LGTM!

The documentation is correct and the previous @param state vs @param loc mismatch has been fixed.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@li-mingbao
Copy link
Contributor Author

@denialhaag This is just a small change to reduce code duplication in #1396.

Copy link
Member

@denialhaag denialhaag left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the quick turnaround! This looks good from my side, but I'd leave the final approval to @burgholzer! 🙂

Edit: Feel free to add the PR and your name to the changelog entry for the dialect redesign!

@denialhaag denialhaag added refactor Anything related to code refactoring MLIR Anything related to MLIR labels Jan 15, 2026
Signed-off-by: li-mingbao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MLIR Anything related to MLIR refactor Anything related to code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants