diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index c09727676a..dc4c4263c3 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -20,6 +20,9 @@
* `from_plxpr` now uses the `qml.capture.PlxprInterpreter` class for reduced code duplication.
[(#1398)](https://github.com/PennyLaneAI/catalyst/pull/1398)
+* Replace `ValueRange` with `ResultRange` and `Value` with `OpResult` to better align with the semantics of `**QubitResult()` functions like `getNonCtrlQubitResults()`. This change ensures clearer intent and usage. Improve the `matchAndRewrite` function by using `replaceAllUsesWith` instead of for loop.
+ [(#1426)](https://github.com/PennyLaneAI/catalyst/pull/1426)
+
Documentation 📝
Contributors ✍️
@@ -28,4 +31,4 @@ This release contains contributions from (in alphabetical order):
Christina Lee
Mehrdad Malekmohammadi
-
+Sengthai Heng
diff --git a/mlir/include/Quantum/IR/QuantumInterfaces.td b/mlir/include/Quantum/IR/QuantumInterfaces.td
index dc1390c636..a31058543f 100644
--- a/mlir/include/Quantum/IR/QuantumInterfaces.td
+++ b/mlir/include/Quantum/IR/QuantumInterfaces.td
@@ -73,7 +73,7 @@ def QuantumOperation : OpInterface<"QuantumOperation"> {
>,
InterfaceMethod<
"Return all results which are considered output qubit values (including controls).",
- "std::vector", "getQubitResults"
+ "std::vector", "getQubitResults"
>
];
@@ -109,7 +109,7 @@ def QuantumGate : OpInterface<"QuantumGate", [QuantumOperation]> {
>,
InterfaceMethod<
"Return results which are considered non-controlled output qubit values.",
- "mlir::ValueRange", "getNonCtrlQubitResults"
+ "mlir::ResultRange", "getNonCtrlQubitResults"
>,
InterfaceMethod<
"Return all operands which are considered controlling input qubit values.",
@@ -129,7 +129,7 @@ def QuantumGate : OpInterface<"QuantumGate", [QuantumOperation]> {
>,
InterfaceMethod<
"Return all operands which are considered controlling output qubit values.",
- "mlir::ValueRange", "getCtrlQubitResults"
+ "mlir::ResultRange", "getCtrlQubitResults"
>,
InterfaceMethod<
"Return adjoint flag.",
diff --git a/mlir/include/Quantum/IR/QuantumOps.td b/mlir/include/Quantum/IR/QuantumOps.td
index 7c8fa3d4f2..51a1ef0cd5 100644
--- a/mlir/include/Quantum/IR/QuantumOps.td
+++ b/mlir/include/Quantum/IR/QuantumOps.td
@@ -211,8 +211,8 @@ class Gate_Op traits = []> :
qubits.assign(replacements);
}
- std::vector getQubitResults() {
- std::vector values;
+ std::vector getQubitResults() {
+ std::vector values;
values.insert(values.end(), getOutQubits().begin(), getOutQubits().end());
return values;
}
@@ -242,8 +242,8 @@ class UnitaryGate_Op traits = []> :
ctrls.assign(replacements.take_back(ctrls.size()));
}
- std::vector getQubitResults() {
- std::vector values;
+ std::vector getQubitResults() {
+ std::vector values;
values.insert(values.end(), getOutQubits().begin(), getOutQubits().end());
values.insert(values.end(), getOutCtrlQubits().begin(), getOutCtrlQubits().end());
return values;
@@ -283,10 +283,10 @@ class UnitaryGate_Op traits = []> :
"must provide values for all control qubit values");
ctrls.assign(replacements);
}
- mlir::ValueRange getNonCtrlQubitResults() {
+ mlir::ResultRange getNonCtrlQubitResults() {
return getOutQubits();
}
- mlir::ValueRange getCtrlQubitResults() {
+ mlir::ResultRange getCtrlQubitResults() {
return getOutCtrlQubits();
}
}];
diff --git a/mlir/lib/Quantum/Transforms/ChainedSelfInversePatterns.cpp b/mlir/lib/Quantum/Transforms/ChainedSelfInversePatterns.cpp
index eb9665d828..4c40431312 100644
--- a/mlir/lib/Quantum/Transforms/ChainedSelfInversePatterns.cpp
+++ b/mlir/lib/Quantum/Transforms/ChainedSelfInversePatterns.cpp
@@ -175,12 +175,13 @@ struct ChainedUUadjOpRewritePattern : public mlir::OpRewritePattern {
// Replace uses
ValueRange originalNonCtrlQubits = parentOp.getNonCtrlQubitOperands();
ValueRange originalCtrlQubits = parentOp.getCtrlQubitOperands();
- for (const auto &[idx, nonCtrlQubitResult] : llvm::enumerate(op.getNonCtrlQubitResults())) {
- nonCtrlQubitResult.replaceAllUsesWith(originalNonCtrlQubits[idx]);
- }
- for (const auto &[idx, ctrlQubitResult] : llvm::enumerate(op.getCtrlQubitResults())) {
- ctrlQubitResult.replaceAllUsesWith(originalCtrlQubits[idx]);
- }
+
+ ResultRange nonCtrlQubitResults = op.getNonCtrlQubitResults();
+ nonCtrlQubitResults.replaceAllUsesWith(originalNonCtrlQubits);
+
+ ResultRange ctrlQubitResults = op.getCtrlQubitResults();
+ ctrlQubitResults.replaceAllUsesWith(originalCtrlQubits);
+
return success();
}
};