14 #include "utils/logger.hpp"
24 const auto&
type =
node.get_node_type();
33 const std::vector<ast::AstNodeType> blocks_to_analyze = {
49 auto it =
std::find(blocks_to_analyze.begin(), blocks_to_analyze.end(),
type);
50 auto node_to_analyze = !(it == blocks_to_analyze.end());
52 return node_to_analyze || solve_procedure;
60 if (
node.is_procedure_block()) {
62 if (symbol && symbol->has_any_property(NmodlType::to_solve)) {
70 std::vector<std::string>
result;
72 const NmodlType excluded_var_properties = NmodlType::extern_var
73 | NmodlType::extern_neuron_variable
74 | NmodlType::read_ion_var
75 | NmodlType::write_ion_var
76 | NmodlType::prime_name
77 | NmodlType::nonspecific_cur_var
78 | NmodlType::pointer_var
79 | NmodlType::bbcore_pointer_var
80 | NmodlType::electrode_cur_var
81 | NmodlType::state_var;
83 const NmodlType global_var_properties = NmodlType::range_var
84 | NmodlType::assigned_definition
85 | NmodlType::param_assign;
95 for (
const auto& variable: variables) {
96 if (!variable->has_any_property(excluded_var_properties)) {
97 result.push_back(variable->get_name());
107 logger->warn(
"LocalizeVisitor :: symbol table is not setup, returning");
112 for (
const auto& varname: variables) {
113 const auto& blocks =
node.get_blocks();
114 std::map<DUState, std::vector<std::shared_ptr<ast::Node>>> block_usage;
116 logger->debug(
"LocalizeVisitor: Checking DU chains for {}", varname);
119 for (
const auto& block: blocks) {
122 const auto& usages =
v.analyze(*block, varname);
123 auto result = usages.eval();
124 block_usage[
result].push_back(block);
125 logger->debug(
"\tDU chain in block {} is {}",
126 block->get_node_type_name(),
134 if (it == block_usage.end()) {
135 logger->debug(
"LocalizeVisitor : localized variable {}", varname);
140 for (
auto& block: block_usage[state]) {
141 auto block_ptr =
dynamic_cast<ast::Block*
>(block.get());
146 if (symbol->is_array()) {
154 symbol->mark_localized();
157 const auto& symtab = statement_block->get_symbol_table();
158 auto new_symbol = std::make_shared<Symbol>(varname, variable);
159 new_symbol->add_property(NmodlType::local_var);
160 new_symbol->mark_created();
161 symtab->insert(new_symbol);
Auto generated AST classes declaration.
Base class for all block scoped nodes.
Base class for all AST node.
Represents top level AST node for whole NMODL input.
std::vector< std::shared_ptr< Symbol > > get_variables_with_properties(syminfo::NmodlType properties, bool all=false) const
get variables with properties
std::shared_ptr< Symbol > lookup(const std::string &name) const
check if symbol with given name exist in the current table (but not in parents)
Visitor to return Def-Use chain for a given variable in the block/node
bool node_for_def_use_analysis(const ast::Node &node) const
symtab::SymbolTable * program_symtab
void visit_program(const ast::Program &node) override
visit node of type ast::Program
bool is_solve_procedure(const ast::Node &node) const
std::vector< std::string > variables_to_optimize() const
bool ignore_verbatim
ignore verbatim blocks while localizing
Visitor to return Def-Use chain for a given variable in the block/node
virtual std::shared_ptr< StatementBlock > get_statement_block() const
Return associated statement block for the AST node.
@ CONSTRUCTOR_BLOCK
type of ast::ConstructorBlock
@ BREAKPOINT_BLOCK
type of ast::BreakpointBlock
@ DERIVATIVE_BLOCK
type of ast::DerivativeBlock
@ BEFORE_BLOCK
type of ast::BeforeBlock
@ DESTRUCTOR_BLOCK
type of ast::DestructorBlock
@ DISCRETE_BLOCK
type of ast::DiscreteBlock
@ NET_RECEIVE_BLOCK
type of ast::NetReceiveBlock
@ AFTER_BLOCK
type of ast::AfterBlock
@ INITIAL_BLOCK
type of ast::InitialBlock
@ NON_LINEAR_BLOCK
type of ast::NonLinearBlock
@ FOR_NETCON
type of ast::ForNetcon
@ LINEAR_BLOCK
type of ast::LinearBlock
@ BA_BLOCK
type of ast::BABlock
Visitor to transform global variable usage to local
NmodlType
NMODL variable properties.
@ CD
global or local variable is conditionally defined
@ U
global variable is used
@ D
global variable is defined
LocalVar * add_local_variable(StatementBlock &node, Identifier *varname)
encapsulates code generation backend implementations
static Node * node(Object *)
int find(const int, const int, const int, const int, const int)
Implement various classes to represent various Symbol properties.