Skip to content

Commit c2d414f

Browse files
committed
🔧 Enhance ConvertFuncReturnOp to exclude escaped qubits from the live qubits list.
1 parent b824284 commit c2d414f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎mlir/lib/Conversion/QCToQCO/QCToQCO.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ struct ConvertFuncReturnOp final : StatefulOpConversionPattern<func::ReturnOp> {
135135
llvm::SmallVector<Value> liveQubits;
136136
liveQubits.reserve(state.qubitMap.size());
137137

138+
llvm::DenseSet<Value> escapedQubits;
139+
for (Value returned : adaptor.getOperands()) {
140+
escapedQubits.insert(returned);
141+
}
142+
138143
llvm::DenseSet<Value> seen;
139144
for (const auto& [/*qcQubit*/ _, qcoQubit] : state.qubitMap) {
140-
if (seen.insert(qcoQubit).second) {
145+
if (!escapedQubits.contains(qcoQubit) && seen.insert(qcoQubit).second) {
141146
liveQubits.push_back(qcoQubit);
142147
}
143148
}

0 commit comments

Comments
 (0)