Sector decomposition
|
#include <code_generation.h>
Public Member Functions | |
assign_lst (const std::string &T, const std::string &temp_var_base_name) | |
assign_lst (const std::string &T, const std::string &temp_var_base_name, const lst &lhs, const lst &rhs) | |
void | append (const ex &a, const ex &b) |
void | prepend (const ex &a, const ex &b) |
void | replace_common_subex (unsigned flag_type=subex_type::all) |
void | split_large_subex (size_t nmax) |
void | print (std::ostream &os) const |
ex | get_temporary_variables () const |
Private Member Functions | |
std::string | itos (int arg) const |
bool | check_substitution_type (const ex &expr, unsigned flag_type) const |
bool | check_large_subex (const ex &expr, size_t max_nops, lst &subexpr_lst) const |
void | split_large_line (const ex &a, const ex &b, lst &new_lhs_lst, lst &new_rhs_lst, size_t max_nops) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const assign_lst &arg) |
A class which transforms a list of assignments into an equivalent list of assignments. The intention is that when these assignments are printed out as C code, the transformed ones will give "better" C code.
Methods to manipulate the assignment list are:
Data members: A list of assignments
t0 = expr0; t1 = expr1; ... tn = exprn;
is stored in two lists
lhs = lst(t0,t1,...,tn); rhs = lst(expr0,expr1,...,exprn);
T is a string giving the data type in C of the expressions, usually something like "double" or "float". When printing out the assignment list, T is printed in front of every assignment:
T t0 = expr0; T t1 = expr1; ...
T can also be the empty string.
Intermediate variables obtain their names from temp_var_base_name, to which a serial number is attached, e.g. if temp_var_base_name=string("t"), the intermediate variables are labelled t0, t1, t2, etc..
temp_var is used only internally and is a vector holding the intermediate variables. A list of the additional intermediate variables can be obtained with the method get_temporary_variables().
assign_lst | ( | const std::string & | arg_T, |
const std::string & | arg_temp_var_base_name | ||
) |
Constructor.
T is initialised with arg_T, temp_var_base_name is initialised with arg_temp_var_base_name. lhs and rhs are empty.
assign_lst | ( | const std::string & | arg_T, |
const std::string & | arg_temp_var_base_name, | ||
const lst & | arg_lhs, | ||
const lst & | arg_rhs | ||
) |
Constructor.
T is initialised with arg_T, temp_var_base_name is initialised with arg_temp_var_base_name. lhs and rhs are initialised with arg_lhs and arg_rhs, respectively.
void append | ( | const ex & | a, |
const ex & | b | ||
) |
Appends the assignment a = b to the assignment list.
|
private |
Checks if expr contains large subexpressions of type add or mul with more than max_nops terms.
These large subexpressions are appended to subexpr_lst.
|
private |
Checks if an expression can potentially be substituted.
The flag "flag_type" determines which classes from the set (add, mul, power, function) are considered for this substitution.
ex get_temporary_variables | ( | ) | const |
Returns a list of the temporary variables.
|
private |
Helper function, which converts an integer into a string
void prepend | ( | const ex & | a, |
const ex & | b | ||
) |
Prepends the assignment a = b to the assignment list.
void print | ( | std::ostream & | os | ) | const |
Print method: Prints the assignment list as C code.
void replace_common_subex | ( | unsigned | flag_type = subex_type::all | ) |
This function substitutes all subexpressions which occur syntactially more than once (in the sense of "subs") in the assignment list.
The function proceeds iteratively and substitutes first subexpressions, which are "closer" to the root of the expression tree. If these subexpressions in turn contain subsubexpressions, which occur multiple times, the latter are substituted in subsequent iterations.
|
private |
Splits a single assignment into smaller pieces, if the right-hand-side contains a subexpression with more than max_nops operators.
The algorithm proceeds recursively, by introducing temporary variables for the first max_nops operands of the large subexpression and the remaining operands of the subexpression.
The assignments are appended to new_lhs_lst and new_rhs_lst. In the trivial case, where b does not contain any large subexpression, the method only appends a to new_lhs_lst and b to new_rhs_lst.
void split_large_subex | ( | size_t | max_nops | ) |
This method splits subexpressions with more than max_nops operands into smaller pieces.
|
friend |
Output operator. Prints the assignment list as C code.