Skip to content

Commit 71bbe39

Browse files
committed
🔧 Enhance ConvertFuncReturnOp to exclude escaped qubits from the live qubits list.
1 parent 77e00a4 commit 71bbe39

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
@@ -136,9 +136,14 @@ struct ConvertFuncReturnOp final : StatefulOpConversionPattern<func::ReturnOp> {
136136
llvm::SmallVector<Value> liveQubits;
137137
liveQubits.reserve(state.qubitMap.size());
138138

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

0 commit comments

Comments
 (0)