Skip to content

Commit

Permalink
Add symbol table version of callCircuitOp
Browse files Browse the repository at this point in the history
  • Loading branch information
taalexander committed Mar 12, 2024
1 parent b0841ad commit 1db129e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/Dialect/QUIR/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ std::tuple<Value, MeasureOp> qubitFromMeasResult(MeasureOp measureOp,
Value result);
std::tuple<Value, MeasureOp> qubitFromMeasResult(CallCircuitOp callCircuitOp,
Value result);
std::tuple<Value, MeasureOp> qubitFromMeasResult(CircuitOp circuitOp,
Value result);

} // end namespace mlir::quir

Expand Down
10 changes: 7 additions & 3 deletions lib/Dialect/QUIR/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,18 @@ std::tuple<Value, MeasureOp> qubitFromMeasResult(MeasureOp measureOp,

std::tuple<Value, MeasureOp> qubitFromMeasResult(CallCircuitOp callCircuitOp,
Value result) {
auto opRes = result.cast<OpResult>();
uint const resNum = opRes.getResultNumber();

Operation *findOp =
SymbolTable::lookupNearestSymbolFrom<mlir::quir::CircuitOp>(
callCircuitOp, callCircuitOp.getCalleeAttr());

auto circuitOp = dyn_cast<CircuitOp>(findOp);
return qubitFromMeasResult(circuitOp, result);
}

std::tuple<Value, MeasureOp> qubitFromMeasResult(CircuitOp circuitOp,
Value result) {
auto opRes = result.cast<OpResult>();
uint const resNum = opRes.getResultNumber();
auto returnOp = dyn_cast<quir::ReturnOp>(circuitOp.back().getTerminator());
auto circuitResult = returnOp->getOperand(resNum).cast<OpResult>();
auto measureOp = dyn_cast<MeasureOp>(circuitResult.getDefiningOp());
Expand Down

0 comments on commit 1db129e

Please sign in to comment.