![]() |
User Guide
|
Perform constant folding of integer/float/double expressions. More...
Perform constant folding of integer/float/double expressions.
MOD file from user could have binary expressions that could be expanded at compile time. For example, KINETIC blocks could have
For passes like loop unroll, we need to evaluate NANN-2
at compile time and this pass perform such operations.
Definition at line 53 of file constant_folder_visitor.hpp.
#include <constant_folder_visitor.hpp>
|
default |
|
overridevirtual |
Visit parenthesis expression and simplify it.
node | AST node representing an expression with parenthesis |
AST could have expression like (1+2). In this case, it has following form in the AST :
parenthesis_exp => wrapped_expr => binary_expression => ...
To make constant folding simple, we can remove intermediate wrapped_expr and directly replace binary_expression inside parenthesis_exp :
parenthesis_exp => binary_expression => ...
Implements nmodl::visitor::Visitor.
Definition at line 78 of file constant_folder_visitor.cpp.
|
overridevirtual |
Visit wrapped node type and perform constant folding.
node | AST node that wrap other node types |
MOD file has expressions like
a = 1 + 2 DEFINE NN 10 FROM i=0 TO NN-2 {
}
which need to be turned into
a = 1 + 2 DEFINE NN 10 FROM i=0 TO 8 {
}
first expression which is wrapped
if wrapped expression is parentheses
opposite to visit_paren_expression, we might have a = (2+1) in this case we can pick inner expression.
we want to simplify binary expressions only
wrapped expression might be parenthesis expression like (2) which we can simplify to 2 to help next evaluations
in case of expression like a = 2 + ((1) + (3)) we are in the innermost expression i.e. ((1) + (3)) where (1) and (3) are wrapped expression themself. we can remove these extra wrapped expressions
once we simplify, lhs and rhs must be numbers for constant folding
compute the value of expression
if both operands are not integers or floats, result is double
Implements nmodl::visitor::Visitor.
Definition at line 107 of file constant_folder_visitor.cpp.