Commit 10ad175a authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixes some edge cases in auto modifier auto gen (optimization cases)



Also, directly use replaceAllUsesWith rather than doing a loop over users in QVS Op lowering.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 1bc16c06
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -124,13 +124,9 @@ LogicalResult ValueSemanticsInstOpLowering::matchAndRewrite(
  for (size_t i = 0; i < n_qbits; i++) {
    func_args.push_back(operands[i]);
    auto result = results[i];

    for (auto user : result.getUsers()) {

    // Want to replace the next use of this result
    // with the given operand[i];
      user->replaceUsesOfWith(result, operands[i]);
    }
    result.replaceAllUsesWith(operands[i]);
  }

  // once again, return type should be void unless its a measure
+15 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ void ModifierBlockInlinerPass::handlePowU() {
    mlir::OpBuilder rewriter(op);
    assert(op.pow().getType().isIndex());
    mlir::Value powVal = op.pow();
    if (!mlir::isValidDim(powVal)) {
      return;
    }
    mlir::Value lbs_val = rewriter.create<mlir::ConstantOp>(
        op.getLoc(), mlir::IntegerAttr::get(rewriter.getIndexType(), 0));
    mlir::Block &powBlock = op.body().getBlocks().front();
@@ -763,6 +766,18 @@ void ModifierBlockInlinerPass::handleCtrlU() {
    assert(op.body().getBlocks().size() == 1);
    mlir::OpBuilder rewriter(op);
    mlir::Block &ctrlBlock = op.body().getBlocks().front();
    for (auto &subOp : ctrlBlock.getOperations()) {
      if (mlir::dyn_cast_or_null<mlir::quantum::ModifierEndOp>(&subOp)) {
        break;
      }
      // Limit the auto ctrl-gate auto gen to sequence of gates only atm.
      // TODO: The inline MLIR tree modification procedure (wrapping ops into
      // new regions, etc.) is not robust for all cases.
      if (!is_quantum_op(subOp)) {
        return;
      }
    }

    for (auto &subOp : ctrlBlock.getOperations()) {
      // We're at the end
      if (auto terminator =