70 int nCtrlsOp2,
int nTgtsOp2) {
71 auto currentGate = dyn_cast_or_null<T2>(*currentOp);
76 if (currentGate.getControls().size() != nCtrlsOp2 ||
77 currentGate.getTargets().size() != nTgtsOp2)
84 auto previousGate = dyn_cast_or_null<T1>(prevOp);
89 if (previousGate.getControls().size() != nCtrlsOp1 ||
90 previousGate.getTargets().size() != nTgtsOp1)
93 previousGate.getTargets()[0].getDefiningOp());
95 currentGate.getTargets()[0].getDefiningOp());
96 if (targetPrev != targetCurr)
99 llvm::outs() <<
"Current Operation: ";
100 currentGate->print(llvm::outs());
101 llvm::outs() <<
"\n";
102 llvm::outs() <<
"Previous Operation: ";
103 previousGate->print(llvm::outs());
104 llvm::outs() <<
"\n";
108 mlir::IRRewriter rewriter(currentGate->getContext());
109 rewriter.setInsertionPointAfter(currentGate);
110 auto newGate = rewriter.create<T1>(
111 previousGate.getLoc(), previousGate.isAdj(), previousGate.getParameters(),
112 previousGate.getControls(), previousGate.getTargets());
113 rewriter.setInsertionPoint(newGate);
114 rewriter.create<T2>(currentGate.getLoc(), currentGate.isAdj(),
115 currentGate.getParameters(), currentGate.getControls(),
116 currentGate.getTargets());
118 rewriter.eraseOp(currentGate);
119 rewriter.eraseOp(previousGate);
void commuteOperation(mlir::Operation *currentOp, int nCtrlsOp1, int nTgtsOp1, int nCtrlsOp2, int nTgtsOp2)
Commutes two quantum operations if they match a specific pattern.
Definition CommutateOperations.hpp:69