Commit c1a39f14 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

work to get tests passing with new value semantic instructions.

parent 04f0c90d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ void Qasm3SyntaxHandler::GetReplacement(Preprocessor &PP, Declarator &D,
  std::vector<std::string> unique_f_names{kernel_name};
  mlir::PassManager pm(&context);
  applyPassManagerCLOptions(pm);
  pm.addPass(std::make_unique<qcor::QuantumToLLVMLoweringPass>(pm, unique_f_names));
  pm.addPass(std::make_unique<qcor::QuantumToLLVMLoweringPass>(unique_f_names));
  auto module_op = (*module).getOperation();
  if (mlir::failed(pm.run(module_op))) {
    std::cout << "Pass Manager Failed\n";
+2 −2
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ mlir::Type get_custom_opaque_type(const std::string& type,
mlir::Value get_or_extract_qubit(const std::string& qreg_name,
                                 const std::size_t idx, mlir::Location location,
                                 ScopedSymbolTable& symbol_table,
                                 mlir::OpBuilder& builder) {
  auto key = qreg_name + std::to_string(idx);
                                 mlir::OpBuilder& builder, std::string prepended_st_name) {
  auto key = prepended_st_name + qreg_name + std::to_string(idx);
  if (symbol_table.has_symbol(key)) {
    return symbol_table.get_symbol(key);  // global_symbol_table[key];
  } else {
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ mlir::Type get_custom_opaque_type(const std::string& type,
mlir::Value get_or_extract_qubit(const std::string& qreg_name,
                                 const std::size_t idx, mlir::Location location,
                                 ScopedSymbolTable& symbol_table,
                                 mlir::OpBuilder& builder);
                                 mlir::OpBuilder& builder, std::string prepended_st_name = "");

mlir::Value get_or_create_constant_integer_value(
    const std::size_t idx, mlir::Location location, mlir::Type int_like_type,
+12 −1
Original line number Diff line number Diff line
#include "qasm3_utils.hpp"

#include "symbol_table.hpp"

#include <iostream>
@@ -15,6 +14,18 @@ using expression_t = exprtk::expression<double>;
using parser_t = exprtk::parser<double>;

namespace qcor {

void ScopedSymbolTable::replace_symbol(mlir::Value old_value,
                                       mlir::Value new_value) {
  auto key = replacement_helper[old_value.getAsOpaquePointer()];
  for (int i = current_scope; i >= 0; i--) { // again, nasty bug. MUST BE int NOT auto
    if (scoped_symbol_tables[i].find(key) != scoped_symbol_tables[i].end()) {
      scoped_symbol_tables[i].at(key) = new_value;
      replacement_helper[new_value.getAsOpaquePointer()] = key;
    }
  }
}

int64_t ScopedSymbolTable::evaluate_constant_integer_expression(
    const std::string expr_str) {
  auto all_constants = get_constant_integer_variables();
+12 −17
Original line number Diff line number Diff line
@@ -40,12 +40,15 @@ class ScopedSymbolTable {
  std::map<std::string, mlir::Type> global_constant_memref_types;
  std::map<std::string, double> global_constants;

 public:
  // Map Opaque Ptr of value to key in SymbolTable
  std::map<void*, std::string> replacement_helper;

 public:
  template <typename T>
  T get_global_constant(const std::string variable_name) {
    if (!global_constants.count(variable_name)) {
      printErrorMessage("Invalid global constant variable name: " + variable_name);
      printErrorMessage("Invalid global constant variable name: " +
                        variable_name);
    }
    return (T)global_constants[variable_name];
  }
@@ -100,18 +103,7 @@ class ScopedSymbolTable {
    return;
  }

  void replace_symbol(std::string key, mlir::Value new_value) {
    for (auto i = current_scope; i >= 0; i--) {
      if (scoped_symbol_tables[i].count(key)) {
        scoped_symbol_tables[i].find(key)->second = new_value;
        return;
      }
    }

    printErrorMessage("Cannot replace value - no variable " + key +
                      " in scoped symbol table (provided scope = " +
                      std::to_string(current_scope) + "). Did you allocate it?");
  }
  void replace_symbol(mlir::Value old_value, mlir::Value new_value);

  std::vector<std::string> get_seen_function_names() {
    std::vector<std::string> fnames;
@@ -263,6 +255,7 @@ class ScopedSymbolTable {
        scoped_symbol_tables[scope][variable_name] = value;
        variable_attributes[variable_name] = var_attributes;
        last_value_added = value;
        replacement_helper[value.getAsOpaquePointer()] = variable_name;
        return;
      }
    }
@@ -270,6 +263,8 @@ class ScopedSymbolTable {
    scoped_symbol_tables[scope].insert({variable_name, value});
    variable_attributes.insert({variable_name, var_attributes});
    last_value_added = value;
          
    replacement_helper.insert({value.getAsOpaquePointer(), variable_name});
  }

  // get symbol at the current scope, will search parent scopes
Loading