Commit 44f46b0c authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixed a case whereby some Values have been converted to LLVM types



Also, symbol table to support measure Result tracking for bit array elements.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 83ef5679
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -234,7 +234,8 @@ def CreateCallableOp : QuantumOp<"createCallable", []> {
    let printer = [{  auto op = *this;
      p << "q.createCallable" << "(" << op.functors() << ") ";
      if (!op.captures().empty()) {
        p << "capture " << op.captures();
        p << "capture " << op.captures() << "(" << op.captures().getType()
          << ")";
      }
    }];
}
+0 −1
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ antlrcpp::Any qasm3_visitor::visitBranchingStatement(
      context->programBlock().size() == 1 &&
      symbol_table.try_lookup_meas_result(bit_check_conditional->var_name)
          .has_value()) {
    std::cout << "This is a simple Measure check\n";
    auto meas_var =
        symbol_table.try_lookup_meas_result(bit_check_conditional->var_name);
    
+8 −0
Original line number Diff line number Diff line
@@ -241,6 +241,14 @@ antlrcpp::Any qasm3_visitor::visitQuantumMeasurementAssignment(
        builder.create<mlir::StoreOp>(location, cast_bit_op.bit_result(),
                                      bit_value);
      } else {
        if (!symbol_table.has_symbol(indexIdentifierList->getText())) {
          // Added a measure Result* tracking to the bit array element:
          // e.g. track var name 'c[1]' -> Result*
          symbol_table.add_symbol(indexIdentifierList->getText(),
                                  cast_bit_op.bit_result());
          symbol_table.add_measure_bit_assignment(cast_bit_op.bit_result(),
                                                  instop.bit());
        }
        builder.create<mlir::StoreOp>(
            location, cast_bit_op.bit_result(), bit_value,
            llvm::makeArrayRef(std::vector<mlir::Value>{v}));
+13 −11
Original line number Diff line number Diff line
@@ -206,24 +206,25 @@ LogicalResult CreateCallableOpLowering::matchAndRewrite(
    } else {
      mlir::SmallVector<mlir::Type> tuple_struct_type_list;
      size_t tuple_size_in_bytes = 0;
      // Handle the case whereby some types have been converted to LLVM Type (pointers)
      const auto isQirType = [&](const mlir::Value &val,
                                 const std::string &qirTypeName) -> bool {
        return (val.getType().isa<mlir::OpaqueType>() &&
                val.getType().cast<mlir::OpaqueType>().getTypeData() ==
                    qirTypeName) ||
               val.getType() == LLVM::LLVMPointerType::get(
                                    get_quantum_type(qirTypeName, context));
      };
      for (const auto &captured_var : create_callable_op.captures()) {
        if (captured_var.getType().isa<mlir::OpaqueType>() &&
            captured_var.getType().cast<mlir::OpaqueType>().getTypeData() ==
                "Array") {
        if (isQirType(captured_var, "Array")) {
          tuple_struct_type_list.push_back(
              LLVM::LLVMPointerType::get(get_quantum_type("Array", context)));
          tuple_size_in_bytes += sizeof(void *);
        } else if (captured_var.getType().isa<mlir::OpaqueType>() &&
                   captured_var.getType()
                           .cast<mlir::OpaqueType>()
                           .getTypeData() == "Qubit") {
        } else if (isQirType(captured_var, "Qubit")) {
          tuple_struct_type_list.push_back(
              LLVM::LLVMPointerType::get(get_quantum_type("Qubit", context)));
          tuple_size_in_bytes += sizeof(void *);
        } else if (captured_var.getType().isa<mlir::OpaqueType>() &&
                   captured_var.getType()
                           .cast<mlir::OpaqueType>()
                           .getTypeData() == "Tuple") {
        } else if (isQirType(captured_var, "Tuple")) {
          tuple_struct_type_list.push_back(
              LLVM::LLVMPointerType::get(get_quantum_type("Tuple", context)));
          tuple_size_in_bytes += sizeof(void *);
@@ -235,6 +236,7 @@ LogicalResult CreateCallableOpLowering::matchAndRewrite(
          tuple_size_in_bytes += sizeof(int64_t);
        } else {
          std::cout << "WE DON'T SUPPORT TUPLE PACK FOR THE TYPE\n";
          create_callable_op.dump();
          exit(0);
        }
      }