User Guide
nmodl::visitor::DUInstance Class Reference

Represent use of a variable in the statement. More...

Detailed Description

Represent use of a variable in the statement.

For a given variable, say tau, when we have statement like a = tau + c + tau then def-use is simply [DUState::U, DUState::U]. But if we have if-else block like:

IF (...) {
a = tau
tau = c + d
} ELSE {
tau = b
}

Then to know the effective result, we have to analyze def-use in IF and ELSE blocks i.e. if variable is used in any of the if-elseif-else block then it needs to mark as DUState::U. Hence we keep the track of all children in case of statements like if-else.

Definition at line 85 of file defuse_analyze_visitor.hpp.

#include <defuse_analyze_visitor.hpp>

Public Member Functions

 DUInstance (DUState state, const std::shared_ptr< const ast::BinaryExpression > binary_expression)
 
DUState eval (DUVariableType variable_type) const
 analyze all children and return "effective" usage More...
 
DUState sub_block_eval (DUVariableType variable_type) const
 if, elseif and else evaluation More...
 
DUState conditional_block_eval (DUVariableType variable_type) const
 evaluate global usage i.e. with [D,U] states of children More...
 
void print (printer::JSONPrinter &printer) const
 DUInstance to JSON string. More...
 

Public Attributes

DUState state
 state of the usage More...
 
std::vector< DUInstancechildren
 usage of variable in case of if like statements More...
 
std::shared_ptr< const ast::BinaryExpressionbinary_expression
 binary expression in which the variable is used/defined More...
 

Constructor & Destructor Documentation

◆ DUInstance()

nmodl::visitor::DUInstance::DUInstance ( DUState  state,
const std::shared_ptr< const ast::BinaryExpression binary_expression 
)
inlineexplicit

Definition at line 93 of file defuse_analyze_visitor.hpp.

Member Function Documentation

◆ conditional_block_eval()

DUState nmodl::visitor::DUInstance::conditional_block_eval ( DUVariableType  variable_type = DUVariableType::Global) const

evaluate global usage i.e. with [D,U] states of children

Evaluate conditional block containing sub-blocks like if, elseif and else.

Note that sub-blocks are already evaluated by sub_block_eval() and has only leaf nodes. In order to find effective defuse, following rules are used:

  • If variable is "used" in any of the sub-block then it's effectively "U". This is because any branch can be taken at runtime.
  • If variable is "defined" in all sub-blocks doesn't mean that it's effectively "D". This is because if we can have just "if-elseif" which could never be taken. Same for empty "if". In order to decide if it is "D", we make sure there is no empty block and there must be "else" block with "D". Note that "U" definitions are already covered in 1) and hence this rule is safe.
  • If there is an "if" with "D" or empty "if" followed by "D" in "else" block, we can't say it's definition. In this case we return "CD".
  • If there is empty "if" followed by "U" in "else" block, we can say it's "use". This is because we don't want to "localize" such variables.
  • If we reach else block with either D or CD and if there is no empty block encountered, this means every block has either "D" or "CD". In this case we can say that entire block effectively has "D".

Definition at line 133 of file defuse_analyze_visitor.cpp.

◆ eval()

DUState nmodl::visitor::DUInstance::eval ( DUVariableType  variable_type = DUVariableType::Global) const

analyze all children and return "effective" usage

Find "effective" usage of variable from def-use chain.

Note that we are interested in "global" variable usage and hence we consider only [U,D] states and not [LU, LD]

Definition at line 165 of file defuse_analyze_visitor.cpp.

◆ print()

void nmodl::visitor::DUInstance::print ( printer::JSONPrinter printer) const

DUInstance to JSON string.

Definition at line 57 of file defuse_analyze_visitor.cpp.

◆ sub_block_eval()

DUState nmodl::visitor::DUInstance::sub_block_eval ( DUVariableType  variable_type = DUVariableType::Global) const

if, elseif and else evaluation

Evaluate sub-blocks like if, elseif and else As these are innermost blocks, we have to just check first use of variable in this block and that's the result of this block.

Definition at line 89 of file defuse_analyze_visitor.cpp.

Member Data Documentation

◆ binary_expression

std::shared_ptr<const ast::BinaryExpression> nmodl::visitor::DUInstance::binary_expression

binary expression in which the variable is used/defined

We use the binary expression because it is used in both:

  • x = ... // expression statement, binary expression
  • IF (x == 0) // not an expression statement, binary expression

We also want the outermost binary expression. Thus, we do not keep track of the interior ones. For example:

\( tau = tau + 1 \)

we want to return the full statement, not only \( tau + 1 \)

Definition at line 123 of file defuse_analyze_visitor.hpp.

◆ children

std::vector<DUInstance> nmodl::visitor::DUInstance::children

usage of variable in case of if like statements

Definition at line 91 of file defuse_analyze_visitor.hpp.

◆ state

DUState nmodl::visitor::DUInstance::state

state of the usage

Definition at line 88 of file defuse_analyze_visitor.hpp.


The documentation for this class was generated from the following files: