![]() |
User Guide
|
Visitor to return Def-Use chain for a given variable in the block/node More...
Visitor to return Def-Use chain for a given variable in the block/node
Motivation: For global to local variable transformation aka localizer pass, we need to compute Def-Use chains for all global variables. For example, if we have variable usage like:
In the above example if we look at variable beta then it's defined before it's usage and hence it can be safely made local. But variable alpha is used in first block and defined in second block. Hence it can't be made local. A variable can be made local if it is defined before it's usage (in all global blocks). We exclude procedures/functions because we expect inlining to be done prior to this pass.
The analysis of if-elseif-else needs special attention because the def-use chain needs re-cursive evaluation in order to find end-result. For example:
For if-else statements, in the above example, if the variable is used in any of the if-elseif-else part then it is considered as "used". And this is done recursively from innermost level to the top.
Definition at line 214 of file defuse_analyze_visitor.hpp.
#include <defuse_analyze_visitor.hpp>
Public Member Functions | |
DefUseAnalyzeVisitor ()=delete | |
DefUseAnalyzeVisitor (symtab::SymbolTable &symtab) | |
DefUseAnalyzeVisitor (symtab::SymbolTable &symtab, bool ignore_verbatim) | |
void | visit_binary_expression (const ast::BinaryExpression &node) override |
Nmodl grammar doesn't allow assignment operator on rhs (e.g. More... | |
void | visit_if_statement (const ast::IfStatement &node) override |
visit node of type ast::IfStatement More... | |
void | visit_function_call (const ast::FunctionCall &node) override |
Nothing to do if called function is not defined or it's external but if there is a function call for internal function that means there is no inlining happened. More... | |
void | visit_statement_block (const ast::StatementBlock &node) override |
visit node of type ast::StatementBlock More... | |
void | visit_verbatim (const ast::Verbatim &node) override |
We are not analyzing verbatim blocks yet and hence if there is a verbatim block we assume there is variable usage. More... | |
DUChain | analyze (const ast::Ast &node, const std::string &name) |
compute def-use chain for a variable within the node More... | |
unsupported statements | |
/ we aren't sure how to handle this "yet" and hence variables used in any of the below statements are handled separately | |
void | visit_reaction_statement (const ast::ReactionStatement &node) override |
unsupported statements : we aren't sure how to handle this "yet" and hence variables used in any of the below statements are handled separately More... | |
void | visit_non_lin_equation (const ast::NonLinEquation &node) override |
visit node of type ast::NonLinEquation More... | |
void | visit_lin_equation (const ast::LinEquation &node) override |
visit node of type ast::LinEquation More... | |
void | visit_from_statement (const ast::FromStatement &node) override |
visit node of type ast::FromStatement More... | |
void | visit_conserve (const ast::Conserve &node) override |
visit node of type ast::Conserve More... | |
void | visit_var_name (const ast::VarName &node) override |
visit node of type ast::VarName More... | |
void | visit_name (const ast::Name &node) override |
visit node of type ast::Name More... | |
void | visit_indexed_name (const ast::IndexedName &node) override |
visit node of type ast::IndexedName More... | |
statements | |
/ nodes that should not be used for def-use chain analysis | |
void | visit_conductance_hint (const ast::ConductanceHint &node) override |
statements / nodes that should not be used for def-use chain analysis More... | |
void | visit_local_list_statement (const ast::LocalListStatement &node) override |
visit node of type ast::LocalListStatement More... | |
void | visit_argument (const ast::Argument &node) override |
visit node of type ast::Argument More... | |
Private Member Functions | |
void | process_variable (const std::string &name) |
void | process_variable (const std::string &name, int index) |
void | update_defuse_chain (const std::string &name) |
Update the Def-Use chain for given variable. More... | |
void | visit_unsupported_node (const ast::Node &node) |
void | visit_with_new_chain (const ast::Node &node, DUState state) |
void | start_new_chain (DUState state) |
Private Attributes | |
symtab::SymbolTable * | global_symtab = nullptr |
symbol table containing global variables More... | |
std::vector< DUInstance > * | current_chain = nullptr |
def-use chain currently being constructed More... | |
symtab::SymbolTable * | current_symtab = nullptr |
symbol table for current statement block (or of parent block if doesn't have) should be initialized by caller somehow More... | |
std::stack< symtab::SymbolTable * > | symtab_stack |
symbol tables in call hierarchy More... | |
std::string | variable_name |
variable for which to construct def-use chain More... | |
DUVariableType | variable_type |
variable type (Local or Global) More... | |
bool | unsupported_node = false |
indicate that there is unsupported construct encountered More... | |
bool | ignore_verbatim = false |
ignore verbatim blocks More... | |
bool | visiting_lhs = false |
starting visiting lhs of assignment statement More... | |
std::shared_ptr< const ast::BinaryExpression > | current_binary_expression = nullptr |
|
delete |
|
inlineexplicit |
Definition at line 257 of file defuse_analyze_visitor.hpp.
|
inline |
Definition at line 260 of file defuse_analyze_visitor.hpp.
DUChain nmodl::visitor::DefUseAnalyzeVisitor::analyze | ( | const ast::Ast & | node, |
const std::string & | name | ||
) |
compute def-use chain for a variable within the node
re-initialize state
new chain
analyze given node
Definition at line 419 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 393 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 399 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 414 of file defuse_analyze_visitor.cpp.
|
private |
Update the Def-Use chain for given variable.
name | Name of the variable excluding index or dimension |
Update def-use chain if we encounter a variable that we are looking for. If we encounter non-supported construct then we mark that variable as "use" because we haven't completely analyzed the usage. Marking that variable "U" make sures that won't get optimized. Then we distinguish between local and non-local variables. All variables that appear on lhs are marked as "definitions" whereas the one on rhs are marked as "usages".
Definition at line 369 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::Argument
Implements nmodl::visitor::ConstVisitor.
Definition at line 354 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
Nmodl grammar doesn't allow assignment operator on rhs (e.g.
a = b + (b=c) and hence not necessary to keep track of assignment operator using stack.
Implements nmodl::visitor::ConstVisitor.
Definition at line 229 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
statements / nodes that should not be used for def-use chain analysis
Implements nmodl::visitor::ConstVisitor.
Definition at line 350 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::Conserve
Implements nmodl::visitor::ConstVisitor.
Definition at line 313 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::FromStatement
Implements nmodl::visitor::ConstVisitor.
Definition at line 309 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
Nothing to do if called function is not defined or it's external but if there is a function call for internal function that means there is no inlining happened.
In this case we mark the call as unsupported.
Implements nmodl::visitor::ConstVisitor.
Definition at line 204 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::IfStatement
store previous chain
starting new if block
visiting if sub-block
visiting else if sub-blocks
visiting else sub-block
restore to previous chain
Implements nmodl::visitor::ConstVisitor.
Definition at line 249 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::IndexedName
index should be an integer (e.g. after constant folding) if this is not the case and then we can't determine exact def-use chain
check if variable name without index part is same
Implements nmodl::visitor::ConstVisitor.
Definition at line 327 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::LinEquation
Implements nmodl::visitor::ConstVisitor.
Definition at line 305 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::LocalListStatement
Implements nmodl::visitor::ConstVisitor.
Definition at line 352 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::Name
Implements nmodl::visitor::ConstVisitor.
Definition at line 322 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::NonLinEquation
Implements nmodl::visitor::ConstVisitor.
Definition at line 301 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
unsupported statements : we aren't sure how to handle this "yet" and hence variables used in any of the below statements are handled separately
Implements nmodl::visitor::ConstVisitor.
Definition at line 297 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::StatementBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 214 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 193 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
visit node of type ast::VarName
Implements nmodl::visitor::ConstVisitor.
Definition at line 317 of file defuse_analyze_visitor.cpp.
|
overridevirtual |
We are not analyzing verbatim blocks yet and hence if there is a verbatim block we assume there is variable usage.
Implements nmodl::visitor::ConstVisitor.
Definition at line 287 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 407 of file defuse_analyze_visitor.cpp.
|
private |
Definition at line 244 of file defuse_analyze_visitor.hpp.
|
private |
def-use chain currently being constructed
Definition at line 220 of file defuse_analyze_visitor.hpp.
|
private |
symbol table for current statement block (or of parent block if doesn't have) should be initialized by caller somehow
Definition at line 224 of file defuse_analyze_visitor.hpp.
|
private |
symbol table containing global variables
Definition at line 217 of file defuse_analyze_visitor.hpp.
|
private |
ignore verbatim blocks
Definition at line 239 of file defuse_analyze_visitor.hpp.
|
private |
symbol tables in call hierarchy
Definition at line 227 of file defuse_analyze_visitor.hpp.
|
private |
indicate that there is unsupported construct encountered
Definition at line 236 of file defuse_analyze_visitor.hpp.
|
private |
variable for which to construct def-use chain
Definition at line 230 of file defuse_analyze_visitor.hpp.
|
private |
variable type (Local or Global)
Definition at line 233 of file defuse_analyze_visitor.hpp.
|
private |
starting visiting lhs of assignment statement
Definition at line 242 of file defuse_analyze_visitor.hpp.