Loading mlir/parsers/qasm3/handler/qasm3_handler.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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"; Loading mlir/parsers/qasm3/utils/qasm3_utils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading mlir/parsers/qasm3/utils/qasm3_utils.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading mlir/parsers/qasm3/utils/symbol_table.cpp +12 −1 Original line number Diff line number Diff line #include "qasm3_utils.hpp" #include "symbol_table.hpp" #include <iostream> Loading @@ -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(); Loading mlir/parsers/qasm3/utils/symbol_table.hpp +12 −17 Original line number Diff line number Diff line Loading @@ -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]; } Loading Loading @@ -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; Loading Loading @@ -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; } } Loading @@ -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 Loading
mlir/parsers/qasm3/handler/qasm3_handler.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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"; Loading
mlir/parsers/qasm3/utils/qasm3_utils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading
mlir/parsers/qasm3/utils/qasm3_utils.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading
mlir/parsers/qasm3/utils/symbol_table.cpp +12 −1 Original line number Diff line number Diff line #include "qasm3_utils.hpp" #include "symbol_table.hpp" #include <iostream> Loading @@ -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(); Loading
mlir/parsers/qasm3/utils/symbol_table.hpp +12 −17 Original line number Diff line number Diff line Loading @@ -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]; } Loading Loading @@ -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; Loading Loading @@ -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; } } Loading @@ -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