25 #include "pips_config.h"
43 #include "resources.h"
50 #define DEBUG_NAME "TRANSFORMATION_OPTIMIZE_EXPRESSIONS_DEBUG_LEVEL"
101 #define OUT_FILE_NAME "/tmp/pips_to_eole"
102 #define IN_FILE_NAME "/tmp/eole_to_pips"
107 #define EOLE_FLAGS "EOLE_FLAGS"
108 #define EOLE_OPTIONS "EOLE_OPTIONS"
122 " -o ", in,
" ",
out, NULL));
256 #define SIZE_OF_BUFFER 100
286 test = fscanf(file,
"%d\n",&
num);
294 if (!strcmp(ent_type,
"constant")) {
298 test = fscanf(file,
" %d\n", &const_size);
366 for(; lcode; lcode=
CDR(lcode), lnew=
CDR(lnew))
427 free(cmd), cmd = NULL;
667 {
double w = expression_depth(e); cost = cost>w? cost: w; },
722 #define MAX_NAME "MAX"
723 #define MIN_NAME "MIN"
833 { {
"-",
"+",
"--",
false },
835 { NULL, NULL, NULL,
false }
986 pips_debug(9,
" %d elements in cost_expression array \n", size);
988 for (i=0; i<size; i++) {
991 pips_debug(9,
"\n - %d - cost : %f \n", i, tce[i].cost);
1009 tce[i].
cost = cost(e);
1027 while (i<n && ce.
cost<tce[i].
cost) i++;
1028 while (n>=i) tce[n]=tce[n-1], n--;
1061 fprintf(stderr,
"\n[call_rwt] --- (nargs=%d) < 2; Call = %s \n",
1082 tce[nargs-1].expr, tce[nargs-2].expr);
1097 free(tce), tce = NULL;
1165 "0",
true,
"",
true,
"-m",
1173 "0",
true,
"",
true,
"-m",
1181 "1",
true,
"",
true,
"-m",
1190 "0",
true,
"",
false,
"",
1198 "0",
true,
"",
true,
"-m",
1206 "0",
true,
"",
true,
"-m",
1214 "0",
true,
"",
true,
"-m",
1222 "0",
true,
"",
true,
"-m",
1230 "0",
true,
"",
true,
"-m",
1238 "1",
true,
"",
true,
"-m",
1246 "0",
false,
"",
false,
"",
1254 "0",
false,
"",
false,
"",
1262 "0",
false,
"",
false,
"",
1270 "0",
true,
"",
true,
"-m",
1279 "0",
true,
"",
true,
"-m",
1309 #define GRAPH_PREFIX "optimize_expressions_"
1310 #define GRAPH_SUFFIX ".daVinci"
1317 string dir, filename;
1325 free(dir), dir = NULL;
1331 free(filename), filename = NULL;
1409 pips_assert(
"consistency checking before optimizations",
1459 pips_assert(
"consistency checking after optimizations",
expressionwithlevel make_expressionwithlevel(list a1, expression a2)
void free_lexpressionwithlevel(lexpressionwithlevel p)
lexpressionwithlevel make_lexpressionwithlevel(list a)
void write_lexpressionwithlevel(FILE *f, lexpressionwithlevel p)
call make_call(entity a1, list a2)
expression make_expression(syntax a1, normalized a2)
void free_reference(reference p)
bool statement_consistent_p(statement p)
reference read_reference(FILE *f)
void free_expression(expression p)
void write_tabulated_entity(FILE *f)
syntax make_syntax(enum syntax_utype tag, void *val)
bool entity_consistent_p(entity p)
struct _newgen_struct_expression_ * expression
bool clean_up_sequences(statement s)
Recursively clean up the statement sequences by fusing them if possible and by removing useless one.
entity make_constant_entity(string name, tag bt, size_t size)
For historical reason, call the Fortran version.
const char * module_name(const char *s)
Return the module part of an entity name.
#define EXPRESSIONWITHLEVEL(x)
EXPRESSIONWITHLEVEL.
#define expressionwithlevel_expression(x)
#define lexpressionwithlevel_list(x)
void perform_icm_association(const char *, statement)
sequence_gcm_cse.c
void perform_ac_cse(const char *, statement)
FILE * safe_fopen(const char *filename, const char *what)
char * get_string_property(const char *)
int safe_fclose(FILE *stream, const char *filename)
char * safe_new_tmp_file(char *prefix)
SunOS forgets to declare this one.
void safe_unlink(const char *file_name)
Delete the given file.
#define gen_recurse(start, domain_number, flt, rwt)
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
statement set_current_module_statement(statement)
Set the current module statement.
statement get_current_module_statement(void)
Get the current module statement.
entity set_current_module_entity(entity)
static.c
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
list gen_nreverse(list cp)
reverse a list in place
#define NIL
The empty list (nil in Lisp)
list gen_copy_seq(list l)
Copy a list structure.
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
#define CAR(pcons)
Get the value of the first element of a list.
void gen_free_list(list l)
free the spine of the list
#define CDR(pcons)
Get the list less its first element.
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
void safe_system(string)
system.c
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define same_string_p(s1, s2)
static void eole_okay_call_rwt(call c, bool *okay)
static void optimize_simplify_nary_patterns(statement s)
static void write_list_of_rhs(FILE *out, list le)
export a list of expression of the current module.
static void loop_rwt(loop l, extract_expr_p context)
static entity binary_to_nary(entity e)
static void build_binary_operators_with_huffman(statement s, entity nary_operator, entity binary_operator, double(*cost)(expression), bool mode)
apply the huffman balancing on every call to nary_operator and build calls to binary_operator instead...
static void call_simplify_rwt(call c)
static void nary_call_rwt(call c)
bottom-up: + + -> +
static bool nary_call_flt(call c)
top-down: switch calls to nary form.
struct optimization_strategy * poptimization_strategy
static entity huffman_binary_operator
static string read_and_allocate_string_from_file(FILE *file)
static void optimize_simplify_patterns(statement s)
look for some expressions in s and simplify some patterns.
bool optimize_expressions(const char *module_name)
pipsmake interface to apply expression optimization according to various strategy.
static void switch_nary_to_binary(statement s)
switch nary operators to binary ones.
static void insert_last_into_array(cost_expression *tce, int n, cost_expression ce)
simply insert.
static void write_to_eole(const char *module, list le, const char *file_name)
export expressions to eole thru the newgen format.
static bool expr_filter(expression e, extract_expr_p context)
other expressions may be found in loops and so?
static void do_convert_to_standard_operators(call c)
static double expression_gravity_rc(expression e, double depth)
forward substitute if only there once.
void convert_to_standard_operators(void *v)
static void call_nary_rwt(call c)
static symetric_opertor_t * what_operator(entity e, int which_one)
static void reset_current_optimization_strategy(void)
static bool call_filter(call c, extract_expr_p context)
rhs expressions of assignments.
static symetric_opertor_t symop[]
static entity huffman_nary_operator
switch nary to binary with huffman algorithm.
static double(* huffman_cost)(expression)
#define OUT_FILE_NAME
file name prefixes to deal with eole.
static list read_from_eole(const char *module, const char *file_name)
import expressions from eole.
static poptimization_strategy strategy
current strategy.
static list get_list_of_rhs(statement s)
of expressionwithlevel
void naryfication_of_expressions(statement s)
optimize.c
static int cost_expression_cmp(const void *v1, const void *v2)
comparison function for qsort.
static optimization_strategy strategies[]
predefined optimization strategies.
static void insert_sorted_into_array(cost_expression *tce, int n, cost_expression ce)
insert ce in tce[0..n-1] by decreassing order.
static bool loop_flt(loop l, extract_expr_p context)
static void debug_cost_expression_array(string s, cost_expression *tce, int size)
debug function
#define EOLE
property names.
static double expression_gravity_inv(expression e)
static void generate_bminus(statement s)
static string get_eole_command(const char *in, const char *out, const char *flags)
returns the eole command to be executed in an allocated string.
static void read_new_entities_from_eole(FILE *file, const char *module)
import a list of entity that have been created during the eole transformations and create them
static void apply_eole_on_statement(const char *module_name, statement s, const char *flags)
apply eole on all expressions in s.
static expression is_uminus(expression e)
returns B if uminus(B), else 0
static void call_rwt(call c)
apply huffman balancing algorithm if it is a call to huffman_nary_operator.
void convert_to_c_operators(void *v)
static bool nary_operator_p(entity e)
static binary_to_nary_t bton[]
asocom_operator_t
switch binary to nary expressions where possible.
entity inverse_operator_of(entity e)
static void do_convert_to_c_operator(call c)
static void swap_syntax_in_expression(list lcode, list lnew)
swap term to term syntax field in expression list, as a side effect...
static double expression_gravity(expression e)
static void davinci_dump_expressions(const char *module_name, string phase, statement s)
dump all expressions in s as davinci graphs.
struct extract_expr_t * extract_expr_p
static cost_expression * list_of_expressions_to_array(list le, double(*cost)(expression))
build an cost_expression array from an expression list.
static entity bplus
A + (–B) -> A - B FMA -> FMS.
static bool is_inverse(expression e)
static void set_current_optimization_strategy(void)
static void add_one_more_expression(expression e, extract_expr_p context)
static bool huffman_mode
true: Huffman.
static bool inv_call_flt(call c)
static bool is_string_constant(entity e)
static bool eole_manageable_expression(expression e)
void inverse_normalization_of_expressions(statement s)
void unnormalize_expression(void *st)
void unnormalize_expression(expression exp): puts all the normalized field of expressions in "st" to ...
string db_get_current_workspace_directory(void)
void print_expression(expression e)
no file descriptor is passed to make is easier to use in a debugging stage.
void print_statement(statement)
Print a statement on stderr.
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define binary_call_rhs(c)
#define EOLE_FMA_OPERATOR_NAME
These operators are used within the optimize transformation in order to manipulate operators such as ...
#define MINUS_OPERATOR_NAME
#define ENTITY_MINUS_P(e)
#define PLUS_OPERATOR_NAME
#define INVERSE_OPERATOR_NAME
#define ENTITY_PLUS_C_P(e)
#define EOLE_FMS_OPERATOR_NAME
#define ENTITY_MINUS_C_P(e)
#define UNARY_MINUS_OPERATOR_NAME
#define binary_call_lhs(c)
#define EOLE_PROD_OPERATOR_NAME
#define EOLE_SUM_OPERATOR_NAME
#define MINUS_C_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
#define PLUS_C_OPERATOR_NAME
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
void simplify_expressions(void *obj)
void davinci_dump_all_expressions(FILE *out, statement s)
dump all expressions in s to out.
expression call_to_expression(call c)
Build an expression that call a function or procedure.
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
#define type_functional_p(x)
struct _newgen_struct_test_ * test
#define normalized_undefined
#define expression_domain
newgen_execution_domain_defined
#define loop_domain
newgen_language_domain_defined
#define basic_pointer_p(x)
#define value_constant_p(x)
#define call_domain
newgen_callees_domain_defined
#define basic_undefined_p(x)
#define EXPRESSION(x)
EXPRESSION.
struct _newgen_struct_mode_ * mode
#define reference_indices(x)
#define call_arguments(x)
#define basic_string_p(x)
#define expression_syntax(x)
#define entity_initial(x)
Value b1
booleen indiquant quel membre est en cours d'analyse
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static int lname(char *s, int look_for_entry)
check for keywords for subprograms return 0 if comment card, 1 if found name and put in arg string.
The structure used to build lists in NewGen.
this structure defines a strategy for eole.
double(* huffman_cost)(expression)
string eole_strategy
EOLE.
bool apply_nary_simplify
SIMPLIFY.
bool apply_eole2
not used yet
bool apply_balancing
HUFFMAN.
string name
NAME of the strategy.
static int depth
la sequence de nids