PIPS
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "boolean.h"
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "ray_dte.h"
#include "sommet.h"
#include "sg.h"
#include "sc.h"
#include "polyedre.h"
#include "union.h"
#include "matrice.h"
#include "matrix.h"
#include "ri.h"
#include "ri-util.h"
#include "constants.h"
#include "graph.h"
#include "paf_ri.h"
#include "text.h"
#include "text-util.h"
#include "misc.h"
#include "static_controlize.h"
#include "paf-util.h"
#include "prgm_mapping.h"
Go to the source code of this file.
Typedefs | |
typedef dfg_vertex_label | vertex_label |
Internal variables More... | |
typedef dfg_arc_label | arc_label |
typedef bool(* | argh) (Pvecteur *, Pvecteur *) |
======================================================================== More... | |
Functions | |
list | insert_sort (list l, bool(*compare_obj)()) |
======================================================================== More... | |
bool | is_index_coeff_p (entity e) |
======================================================================== More... | |
bool | compare_coeff (chunk *c1, chunk *c2) |
======================================================================== More... | |
bool | compare_nodes_dim (chunk *n1, chunk *n2) |
======================================================================== More... | |
bool | compare_dfs_weight (chunk *d1, chunk *d2) |
======================================================================== More... | |
bool | compare_unks_frenq (chunk *e1, chunk *e2) |
======================================================================== More... | |
entity | make_coeff (string prefix, int n) |
======================================================================== More... | |
entity | find_or_create_coeff (string prefix, int n) |
======================================================================== More... | |
list | rm_non_x_var (list l) |
======================================================================== More... | |
list | unify_lists (list l1, list l2) |
======================================================================== More... | |
Psysteme | new_elim_var_with_eg (Psysteme ps, list *init_l, list *elim_l) |
======================================================================== More... | |
Psysteme | plc_elim_var_with_eg (Psysteme ps, list *init_l, list *elim_l) |
======================================================================== More... | |
int | count_implicit_equation (Psysteme ps) |
======================================================================== More... | |
list | put_source_ind (list le) |
======================================================================== More... | |
Ppolynome | apply_farkas (Ppolynome F, Psysteme D, list *L, int *count_lambdas) |
list | get_graph_dataflows (graph g) |
======================================================================== More... | |
list | get_stmt_index_coeff (int stmt, hash_table StoL) |
======================================================================== More... | |
Psysteme | completer_base (Psysteme sys, list var_l, list par_l) |
======================================================================== More... | |
list | diff_lists (list l1, list l2) |
======================================================================== More... | |
bool | vecteurs_libres_p (Psysteme sys, Pbase v_base, Pbase c_base) |
======================================================================== More... | |
Psysteme | append_eg (Psysteme M1, Psysteme M2) |
======================================================================== More... | |
void | di_polynome_var_subst_null (Ppolynome *pp, entity var) |
======================================================================== More... | |
Psysteme | nullify_factors (Ppolynome *pp, list var_l, bool with_remnants) |
======================================================================== More... | |
bool | is_broadcast_p (dataflow df) |
======================================================================== More... | |
int | communication_dim (dataflow df) |
======================================================================== More... | |
bool | is_reduction_p (dataflow df) |
======================================================================== More... | |
bool | is_shift_p (dataflow df) |
======================================================================== More... | |
void | my_substitute_var_with_vec (Psysteme ps, entity var, int val, Pvecteur vec) |
=========================================================================== More... | |
Pvecteur | old_prototype_factorize (Ppolynome pp, Variable var) |
======================================================================== More... | |
Variables | |
char | vcid_prgm_mapping_utils [] = "$Id: utils.c 23065 2016-03-02 09:05:50Z coelho $" |
list | prgm_parameter_l |
lint More... | |
typedef dfg_arc_label arc_label |
========================================================================
Ppolynome apply_farkas(Ppolynome F, Psysteme D, list *L, int *count_lambdas) returns the affine from of farkas lemma computed from the polynome "F" (the affine form) and the domain of its variables "ps_dom".
Let D be a non empty polyhedron defined by n affine inequalities: Ik(x) >= 0, k in 1,..,n
Then an affine form F is a non negative everywhere in D iff it is a positive affine combination of the above inequalities: F(x) >= 0 in D <=> F(x) == L0 + L1.I1(x) + .. + Ln.In(x) with Lk >= 0, k in 1,..,n
Here, *L" is the list (L0,..,Ln). If we note P(x) = L0 + L1.I1(x) + .. + Ln.In(x), the polynome returned is the Farkas polynome: FP = F(x) - P(x)
We also have to add the structure parameters that do not appear in D and that are in the global var "prgm_parameter_l". For instance, if "p" (in "prgm_parameter_l") does not appear in D, we'll have: P(x) = L0 + L1.I1(x) + .. + Ln.In(x) + Ln+1.p and "*L" will be (L0,..,Ln,Ln+1)
In the following code, variable "P" is the opposite of our P(x). In doing so, we'll be able to simplified the final calculus (F(x) - P(x)) by an addition.
typedef dfg_vertex_label vertex_label |
========================================================================
Definition at line 946 of file utils.c.
References M1, M2, sc_creer_base(), Scontrainte::succ, and vect_rm().
Referenced by base_complete(), completer_base(), completer_n_base(), cutting_conditions(), and partial_broadcast_coefficients().
Constant term: L0
We associate to each equation or inequation a different coefficient, so the addition is never simplified, it just put a few monomes to the end of "P", i.e. "last_P". We do not used "polynome_add()" because this function looks for similar monomes.
An equality (v == 0) is also two inequalities (v >= 0, v <= 0)
We add to (-P) the parameters that do not appear in D
pu_is_inferior_var is not implemented and does not match prototype...
FP = F + (-P) We are sure that F-P can not be simplified, i.e. that there are similar monomes; this is because each monome of P has a variable that never appear outside of P.
Definition at line 669 of file utils.c.
References base_to_list(), CAR, CONS, D, ENDP, ENTITY, F, find_or_create_coeff(), gen_append(), LAMBD_COEFF, make_polynome(), NIL, polynome_used_var(), POP, prgm_parameter_l, pu_is_inferior_var(), same_entity_p(), Scontrainte::succ, Spolynome::succ, vect_new(), Scontrainte::vecteur, and vecteur_mult().
Referenced by valuer().
========================================================================
int communication_dim(dataflow df): returns the number of directions vectors of the dataflow if it a broadcast or a reduction. Oterwise, returns 0.
Definition at line 1116 of file utils.c.
References communication_broadcast, communication_reduction, communication_undefined, dataflow_communication, Ssysteme::egalites, predicate_system, predicate_undefined, and Scontrainte::succ.
Referenced by edge_weight().
bool compare_coeff | ( | chunk * | c1, |
chunk * | c2 | ||
) |
========================================================================
bool compare_coeff(c1, c2):
returns a bool saying true if "c1" is before "c2" in the lexicographic order, else FALSE. "c1" and "c2" are entities, we compare their name.
Definition at line 161 of file utils.c.
References entity_local_name().
Referenced by plc_make_vvs_with_vector(), and valuer().
bool compare_dfs_weight | ( | chunk * | d1, |
chunk * | d2 | ||
) |
========================================================================
Definition at line 181 of file utils.c.
References DtfToWgh, and hash_get().
Referenced by prgm_mapping().
bool compare_nodes_dim | ( | chunk * | n1, |
chunk * | n2 | ||
) |
========================================================================
Definition at line 170 of file utils.c.
References hash_get(), StmtToDim, and vertex_int_stmt().
Referenced by sort_dfg_node().
bool compare_unks_frenq | ( | chunk * | e1, |
chunk * | e2 | ||
) |
========================================================================
Definition at line 192 of file utils.c.
References hash_get(), and UnkToFrenq.
Referenced by sort_unknowns().
========================================================================
Definition at line 832 of file utils.c.
References append_eg(), Ssysteme::base, CAR, contrainte_make(), ENDP, ENTITY, gen_length(), list_to_base(), POP, sc_add_egalite(), sc_creer_base(), sc_dup(), sc_new(), sc_rm(), vect_new(), and vecteurs_libres_p().
Referenced by broadcast_conditions(), and system_inversion_restrict().
========================================================================
int new_count_implicit_equation(Psysteme ps): returns the number of implicit equations there are in the system "ps".
Practically, we construct a system containing all the implicit equations, then we count the number of equations (there should be no redondant equation since find_implicit_equation() normalizes its result).
See the description of find_implicit_equation().
If impl_ps is empty, then no data are communicated
Definition at line 562 of file utils.c.
References find_implicit_equation(), fprintf(), get_debug_level(), and Ssysteme::nb_eq.
Referenced by edge_weight().
========================================================================
Definition at line 980 of file utils.c.
References entity_undefined, Spolynome::monome, pips_internal_error, POLYNOME_UNDEFINED, POLYNOME_UNDEFINED_P, same_entity_p(), Spolynome::succ, Svecteur::succ, term(), and Svecteur::var.
========================================================================
Definition at line 868 of file utils.c.
References CAR, CHUNK, CONS, ENDP, gen_nconc(), NIL, and POP.
========================================================================
entity find_or_create_coeff(string prefix, int n): returns the entity that represent the coefficient numbered "n" and prefixed by "prefix". If it does not exist yet, we create it.
We create it, if it does not exist yet
Definition at line 238 of file utils.c.
References concatenate(), entity_domain, entity_undefined, free(), gen_find_tabulated(), int2a(), make_coeff(), MAPPING_MODULE_NAME, MODULE_SEP_STRING, num, prefix, and strdup().
Referenced by apply_farkas(), put_source_ind(), and valuer().
========================================================================
list get_graph_dataflows(graph g): returns the list of dataflows of the DFG graph "g". Each edge of "g" contains a list of dataflows, so we concatenate these lists into one.
Definition at line 765 of file utils.c.
References CAR, ENDP, gen_append(), gen_nconc(), graph_vertices, NIL, POP, SUCC_DATAFLOWS, SUCCESSOR, VERTEX, and vertex_successors.
Referenced by prgm_mapping().
list get_stmt_index_coeff | ( | int | stmt, |
hash_table | StoL | ||
) |
========================================================================
Definition at line 792 of file utils.c.
References CAR, CDR, ENDP, ENTITY, gen_append(), hash_get(), is_index_coeff_p(), NIL, pl, and POP.
Referenced by broadcast_conditions().
========================================================================
list insert_sort(list l, bool (*compare_obj)()): returns the result of sorting the list "l" using the comparison function "compare_obj". This bool function should retuns true if its first argument has to be placed before its second argument in the sorted list, else FALSE.
This is a generic function that accepts any homogene list of newgen objects. The comparison function must be coded by the user, its prototype should be: bool my_compare_obj(chunk * obj1, chunk * obj2);
This function uses the insert sort algorithm which has a mean and worst case complexity of n^2.
Definition at line 110 of file utils.c.
References CAR, CDR, CHUNK, CONS, gen_nconc(), and NIL.
========================================================================
bool is_broadcast_p(dataflow df): returns true if the dataflow "df" has a defined broadcast communication. Otherwise it returns FALSE.
Definition at line 1088 of file utils.c.
References communication_broadcast, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.
Referenced by broadcast_conditions(), and edge_weight().
========================================================================
Definition at line 144 of file utils.c.
References entity_local_name(), INDEX_COEFF, and MU_COEFF.
Referenced by get_stmt_index_coeff(), partition_unknowns(), rm_non_x_var(), and sort_unknowns().
========================================================================
bool is_reduction_p(dataflow df): returns true if the dataflow "df" has a defined reduction communication. Otherwise it returns FALSE.
Definition at line 1150 of file utils.c.
References communication_reduction, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.
Referenced by edge_weight().
========================================================================
bool is_shift_p(dataflow df): returns true if the dataflow "df" has a defined shift communication. Otherwise it returns FALSE.
Definition at line 1176 of file utils.c.
References communication_shift, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.
========================================================================
entity make_coeff(string prefix, int n): returns a new entity which will be used as a coefficient in a prototype of a placement function. All coefficients differ in their name which is something like: "MAPPING:prefix#" where # is the integer value of "n".
Definition at line 209 of file utils.c.
References concatenate(), free(), int2a(), is_basic_int, is_storage_rom, is_type_variable, is_value_unknown, make_basic(), make_entity, make_storage(), make_type(), make_value(), make_variable(), MAPPING_MODULE_NAME, MODULE_SEP_STRING, NIL, num, prefix, strdup(), and UU.
Referenced by find_or_create_coeff(), initialize_mu_list(), and plc_make_proto().
===========================================================================
void my_substitute_var_with_vec(Psysteme ps, entity var, int val, Pvecteur vec): Substitutes in a system ("ps") a variable ("var"), factor of a positive value ("val"), by an expression ("vec").
This substitution is done on all assertions of the system (equalities and inequalities). For each assertion (represented by a vector Vold) we have:
Vold = c*var + Vaux val*var = vec
Vnew represents the new assertion. With: p = gcd(c, val) >= 1, we have:
Vnew = (c/p)*vec + (val/p)*Vaux = (c/p)*vec + (val/p)*(Vold - c*var)
Note: we have: Vold == 0 <=> (val/p)*Vold == 0 Vold > 0 <=> (val/p)*Vold > 0 ...
because "val" is positive.
If we want to substitute a NULL vector, we just erase "Var"
"val" must be positive.
Vnew = (c/p)*vec + (val/p)*Vaux = (c/p)*vec + (val/p)*(Vold - c*var)
Definition at line 1219 of file utils.c.
References assert, fprint_psysteme(), fprintf(), get_debug_level(), NO_OFL_CTRL, pgcd, sc_creer_base(), vect_chg_sgn(), vect_cl2_ofl_ctrl(), vect_coeff(), vect_erase_var(), vect_new(), vect_rm(), and VECTEUR_NUL_P.
Referenced by plc_elim_var_with_eg().
========================================================================
Psysteme new_elim_var_with_eg(Psysteme ps, list *init_l, list *elim_l): Computes the gaussian elimination of variables in the system "ps". The modifications are directly done on "ps".
However, we keep all the eliminated equations in "sc_elim", and return that system.
Initially, "init_l" gives the list of variables that can be eliminated, at the end, it only contains the variables that were not eliminated. We take the order of this list in our process of eliminating.
Initially, "elim_l" is empty, at the end it contains the variables that were eliminated.
During the computation, we modify *init_l, so we duplicate it. We use "el" not *elim_l, which should be empty at the beginning.
si eq etait en tete il faut l'enlever de la liste, sinon, eq a ete enleve dans la fonction contrainte_var_min_coeff().
Definition at line 338 of file utils.c.
References Ssysteme::base, CAR, CONS, contrainte_subst_ofl_ctrl(), contrainte_var_min_coeff(), egalite_normalize(), Ssysteme::egalites, ENDP, ENTITY, entity_local_name(), eq, fprint_entity_list(), fprint_psysteme(), fprintf(), gen_append(), gen_remove(), get_debug_level(), Ssysteme::inegalites, NIL, NO_OFL_CTRL, pips_internal_error, POP, pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), Scontrainte::succ, and Scontrainte::vecteur.
========================================================================
For each variable, we nullify its factor in the polynome.
We get the current variable.
We get its factor in the polynome.
We add a new equality in the system.
We delete the occurences of this variable in the polynome.
The remnants are zero out and are added as one equation.
Definition at line 1026 of file utils.c.
References CAR, CDR, contrainte_make(), ENTITY, fprint_psysteme(), fprintf(), get_debug_level(), NIL, polynome_fprint(), POLYNOME_NUL, POLYNOME_NUL_P, polynome_to_contrainte(), prototype_factorize(), prototype_var_subst(), pu_is_inferior_var(), pu_variable_name(), pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), sc_normalize(), and VECTEUR_NUL_P.
Referenced by cutting_conditions(), and valuer().
========================================================================
Definition at line 1300 of file utils.c.
References entity_undefined, int, Spolynome::monome, pips_internal_error, POLYNOME_NUL_P, polynome_TCST(), same_entity_p(), Spolynome::succ, Svecteur::succ, TCST, term(), Svecteur::var, VARIABLE_UNDEFINED, vect_new(), and VECTEUR_NUL.
========================================================================
Psysteme plc_elim_var_with_eg(Psysteme ps, list *init_l, list *elim_l): Computes the gaussian elimination of variables in the system "ps". The modifications are directly done on "ps".
However, we keep all the eliminated equations in "sc_elim", and return that system.
Initially, "init_l" gives the list of variables that can be eliminated, at the end, it only contains the variables that were not eliminated. We take the order of this list in our process of eliminating.
Initially, "elim_l" is empty, at the end it contains the variables that were eliminated.
We use "vl" during the computation, not *init_l
We use "el" during the computation, not *elim_l
This elimination works only on equalities. While there remains equalities, we can eliminate variables.
We look, in vl (i.e. init_l), for a variable that we can eliminate in ve, i.e. with a coefficient equal to 1 or -1.
If we get such a variable, we eliminate it.
First, we remove it from "vl".
Then, we add it to "el".
We keep a copy of the initial vector.
We compute the expression (pv_elim) by which we are going to substitute our variable (var):
We have: var = pv_elim
The equality is: V = 0, with: V = val*var + Vaux, and: val in {-1,1}
So, we have: pv_elim = -val*Vaux, with: Vaux = V - val*var
So: pv_elim = -val(V - val*var) i.e.: pv_elim = -val+V + (val^2)*var but: val in {-1,1}, so: val^2 = 1
so: pv_elim = -val*V + var
We substitute var by its value (pv_elim) in "ps".
We substitute var by its value (pv_elim) in "sc_elim".
The initial equality is added to "sc_elim".
We reinitialize the list of equalities.
Else, we try on the next equality.
Definition at line 426 of file utils.c.
References Ssysteme::base, CAR, CDR, CONS, contrainte_make(), ENTITY, entity_local_name(), entity_undefined, fprint_entity_list(), fprint_psysteme(), fprintf(), gen_remove(), get_debug_level(), int, my_substitute_var_with_vec(), NIL, NO_OFL_CTRL, pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), sc_normalize(), Scontrainte::succ, vect_cl2_ofl_ctrl(), vect_coeff(), vect_dup(), vect_new(), vect_rm(), and Scontrainte::vecteur.
========================================================================
list put_source_ind(list le): returns a list of expressions computed from the list given in argument ("le").
We want to associate a variable (var) to each expression (exp) in order to have some kind of equality : 0 = exp - var which means in fact : var = exp
The name of the variables are not important, however, we need a different variable for each expression.
Note: the variables are entities.
This counter makes sure that each new variable is different for the preceding one.
The resulting list is initialized to NIL.
For each expression we compute the new expression.
We get a new variable (an entity).
We make the new expression : exp - var.
This expression is added to the new list. The order is kept.
Definition at line 596 of file utils.c.
References CAR, CDR, CONS, count, EXPRESSION, expression_normalized, find_or_create_coeff(), gen_nconc(), INDEX_VARIA, is_normalized_linear, make_entity_expression(), make_op_exp(), make_vecteur_expression(), MINUS_OPERATOR_NAME, NIL, NO_OFL_CTRL, NORMALIZE_EXPRESSION, normalized_linear, normalized_tag, vect_cl_ofl_ctrl(), and vect_new().
Referenced by edge_weight().
========================================================================
Definition at line 260 of file utils.c.
References CAR, CDR, ENDP, ENTITY, fprint_entity_list(), fprintf(), get_debug_level(), is_index_coeff_p(), NIL, and POP.
========================================================================
Definition at line 295 of file utils.c.
References CAR, CHUNK, CONS, ENDP, gen_append(), gen_nconc(), NIL, and POP.
========================================================================
add 1, because of the TCST
Definition at line 903 of file utils.c.
References A, B, base_dimension, contraintes_with_sym_cst_to_matrices(), matrice_free, matrice_hermite(), matrice_hermite_rank(), matrice_new, and Q.
Referenced by base_complete(), broadcast_conditions(), completer_base(), completer_n_base(), mapping_on_broadcast(), prepare_reindexing(), and stmt_bdt_directions().
|
extern |
lint
Name : utils.c Package : prgm_mapping Author : Alexis Platonoff Date : 23 september 1993
Historic :
Documents:
Comments : This file contains useful functions used for the computation of prgm_mapping. Ansi includes
Newgen includes
C3 includes
Pips includes
Useful constants Macro functions
Global variables
lint
Definition at line 115 of file prgm_mapping.c.
Referenced by apply_farkas(), cutting_conditions(), partial_broadcast_coefficients(), plc_make_proto(), prgm_mapping(), and valuer().