PIPS
sc_unaires.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "linear_assert.h"
#include "boolean.h"
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "sc.h"
+ Include dependency graph for sc_unaires.c:

Go to the source code of this file.

Functions

Psysteme sc_elim_var (Psysteme sc, Variable v)
 package sur les systemes de contraintes sc More...
 
void sc_chg_var (Psysteme s, Variable v_old, Variable v_new)
 void sc_chg_var(Psysteme s, Variable v_old, Variable v_new) this function replace the variable v_old in the system s by the variable v_new. More...
 
void sc_vect_sort (Psysteme s, int(*compare)(Pvecteur *, Pvecteur *))
 the name is self explanatory, I guess. More...
 
void sc_sort (Psysteme sc, Pbase sort_base, int(*compare)(Pvecteur *, Pvecteur *))
 SORT a Psysteme according to sort_base and compare (given to qsort). More...
 
static bool vect_printout_order_decided_p (Pvecteur v)
 
Pvecteur vect_printout_order (Pvecteur v, int(*compare)(Pvecteur *, Pvecteur *))
 Try to guess the print out order for an equality already lexicographically sorted. More...
 
void sc_lexicographic_sort (Psysteme sc, int(*compare)(Pvecteur *, Pvecteur *))
 Minimize first the lexico-graphic weight of each constraint according to the comparison function "compare", and then sort the list of equalities and inequalities by increasing lexico-graphic weight. More...
 
bool sc_remove_large_coef (Psysteme sc, Value val, bool equalities, bool inequalities)
 remove constraints with large coefs, possibly to avoid overflows and to keep systems as simple as possible More...
 

Function Documentation

◆ sc_chg_var()

void sc_chg_var ( Psysteme  s,
Variable  v_old,
Variable  v_new 
)

void sc_chg_var(Psysteme s, Variable v_old, Variable v_new) this function replace the variable v_old in the system s by the variable v_new.

Definition at line 98 of file sc_unaires.c.

99 {
100  Pcontrainte pc;
101  if (s != NULL){
102  for (pc = s->egalites; pc != NULL; pc = pc->succ) {
103  vect_chg_var(&(pc->vecteur), v_old, v_new);
104  }
105 
106  for (pc = s->inegalites; pc != NULL; pc = pc->succ) {
107  vect_chg_var(&(pc->vecteur), v_old, v_new);
108  }
109  }
110 }
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
void vect_chg_var(Pvecteur *ppv, Variable v_old, Variable v_new)
void vect_chg_var(Pvecteur *ppv, Variable v_old, Variable v_new) replace the variable v_old by v_new
Definition: unaires.c:168

References Ssysteme::egalites, Ssysteme::inegalites, Scontrainte::succ, vect_chg_var(), and Scontrainte::vecteur.

Referenced by build_and_test_dependence_context(), and build_third_comb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_elim_var()

Psysteme sc_elim_var ( Psysteme  sc,
Variable  v 
)

package sur les systemes de contraintes sc

Yi-Qing YANG, 20/05/92 Psysteme sc_elim_var(Psysteme sc, Variable v)` This function eliminate all the contraints containing the variable v

Definition at line 49 of file sc_unaires.c.

50 {
51  Pcontrainte pr = NULL, eq;
52 
53  if (sc == NULL) return sc;
54  else {
55  eq = sc->egalites;
56  while (eq != NULL) {
57  if (vect_coeff(v,eq->vecteur) != 0) {
58  if (pr == NULL) {
59  sc->egalites = eq = eq->succ;
60  }
61  else {
62  pr->succ = eq = eq->succ;
63  }
64  }
65  else {
66  pr = eq;
67  eq = eq->succ;
68  }
69  }
70 
71  eq = sc->inegalites;
72  pr = NULL;
73  while (eq != NULL) {
74  if (vect_coeff(v,eq->vecteur) != 0) {
75  if (pr == NULL) {
76  sc->inegalites = eq = eq->succ;
77  }
78  else {
79  pr->succ = eq = eq->succ;
80  }
81  }
82  else {
83  pr = eq;
84  eq = eq->succ;
85  }
86  }
87 
88  sc->nb_eq = nb_elems_list(sc->egalites);
89  sc->nb_ineq = nb_elems_list(sc->inegalites);
90  return sc;
91  }
92 }
int nb_elems_list(Pcontrainte)
int nb_elems_list(Pcontrainte list): nombre de contraintes se trouvant dans une liste de contraintes
Definition: listes.c:129
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
int nb_ineq
Definition: sc-local.h:73
int nb_eq
Definition: sc-local.h:72
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228

References Ssysteme::egalites, eq, Ssysteme::inegalites, nb_elems_list(), Ssysteme::nb_eq, Ssysteme::nb_ineq, Scontrainte::succ, vect_coeff(), and Scontrainte::vecteur.

Referenced by apply_abstract_effect_to_transformer(), parametric_transformer_empty_p(), sc_minmax_of_variable2(), sc_projection_concat_proj_on_variables(), TestDependence(), transformer_combine(), transformer_filter(), and transformer_projection_with_redundancy_elimination_and_check().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_lexicographic_sort()

void sc_lexicographic_sort ( Psysteme  sc,
int(*)(Pvecteur *, Pvecteur *)  compare 
)

Minimize first the lexico-graphic weight of each constraint according to the comparison function "compare", and then sort the list of equalities and inequalities by increasing lexico-graphic weight.

Francois Irigoin

sort the system basis

sort each constraint

minimize equations: when equations are printed out, terms are moved to eliminate negative coefficients and the inner lexicographic order is broken. Furthermore, an equation can be multiplied by -1 and stay the same but be printed out differently.

we are in trouble: v1 and v2 are different but not comparable because the compare function is not strong enough

This may occur if the same local names are used for two different variables that can be live simultaneously. For instance, "predict!predict_mb:pict_struct" and "TOP-LEVEL:pict_struct" which are or seem to be both int variables in mpeg2enc. We could take a default action here or force the user to improve his/her comparison function where more information is available.

sort equalities and inequalities

Definition at line 206 of file sc_unaires.c.

209 {
211 
212  if (sc==NULL || sc_empty_p(sc) || sc_rn_p(sc))
213  return;
214 
215  /* sort the system basis */
216  vect_sort_in_place(&(sc->base), compare);
217 
218  /* sort each constraint */
219  contrainte_vect_sort(sc_egalites(sc), compare);
220  contrainte_vect_sort(sc_inegalites(sc), compare);
221 
222  /* minimize equations: when equations are printed out, terms are moved
223  to eliminate negative coefficients and the inner lexicographic
224  order is broken. Furthermore, an equation can be multiplied by -1
225  and stay the same but be printed out differently. */
226  for(c = sc_egalites(sc); !CONTRAINTE_UNDEFINED_P(c); c = contrainte_succ(c))
227  {
229 
231  int cmp = 0;
232  Pvecteur v1 = vect_dup(v);
234 
235  v1 = vect_printout_order(v1, compare);
236  v2 = vect_printout_order(v2, compare);
237  cmp = vect_lexicographic_compare(v1, v2, compare);
238  if(cmp>0) {
239  contrainte_vecteur(c) =
241  vect_rm(v1);
242  vect_rm(v2);
243  }
244  else if(cmp<0) {
245  vect_rm(v1);
246  vect_rm(v2);
247  }
248  else {
249  /* we are in trouble: v1 and v2 are different but not
250  comparable because the compare function is not strong
251  enough */
252  /* This may occur if the same local names are used for two
253  different variables that can be live simultaneously. For
254  instance, "predict!predict_mb:pict_struct" and
255  "TOP-LEVEL:pict_struct" which are or seem to be both int
256  variables in mpeg2enc. We could take a default action here
257  or force the user to improve his/her comparison function
258  where more information is available. */
259  assert(false);
260  }
261  }
262  }
263 
264  /* sort equalities and inequalities */
265  sc->egalites = equations_lexicographic_sort(sc->egalites, compare);
267 }
#define VALUE_MONE
#define CONTRAINTE_UNDEFINED_P(c)
#define contrainte_succ(c)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
#define CONTRAINTE_UNDEFINED
Pcontrainte inequalities_lexicographic_sort(Pcontrainte, int(*)(Pvecteur *, Pvecteur *))
Definition: unaires.c:449
Pcontrainte equations_lexicographic_sort(Pcontrainte, int(*)(Pvecteur *, Pvecteur *))
Definition: unaires.c:438
void contrainte_vect_sort(Pcontrainte, int(*)(Pvecteur *, Pvecteur *))
#define assert(ex)
Definition: newgen_assert.h:41
bool sc_rn_p(Psysteme sc)
bool sc_rn_p(Psysteme sc): check if the set associated to sc is the whole space, rn
Definition: sc_alloc.c:369
bool sc_empty_p(Psysteme sc)
bool sc_empty_p(Psysteme sc): check if the set associated to sc is the constant sc_empty or not.
Definition: sc_alloc.c:350
Pvecteur vect_printout_order(Pvecteur v, int(*compare)(Pvecteur *, Pvecteur *))
Try to guess the print out order for an equality already lexicographically sorted.
Definition: sc_unaires.c:170
static bool vect_printout_order_decided_p(Pvecteur v)
Definition: sc_unaires.c:149
Pvecteur vect_multiply(Pvecteur v, Value x)
Pvecteur vect_multiply(Pvecteur v, Value x): multiplication du vecteur v par le scalaire x,...
Definition: scalaires.c:123
Pbase base
Definition: sc-local.h:75
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define VECTEUR_NUL_P(v)
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
int vect_lexicographic_compare(Pvecteur v1, Pvecteur v2, int(*compare)(Pvecteur *, Pvecteur *))
qsort() is not safe if the comparison function is not antisymmetric.
Definition: unaires.c:433
void vect_sort_in_place(Pvecteur *pv, int *compare)
void vect_sort_in_place(pv, compare) Pvecteur *pv; int (*compare)(Pvecteur *, Pvecteur *);
Definition: unaires.c:290

References assert, Ssysteme::base, contrainte_succ, CONTRAINTE_UNDEFINED, CONTRAINTE_UNDEFINED_P, contrainte_vect_sort(), contrainte_vecteur, Ssysteme::egalites, equations_lexicographic_sort(), Ssysteme::inegalites, inequalities_lexicographic_sort(), sc_empty_p(), sc_rn_p(), VALUE_MONE, vect_dup(), vect_lexicographic_compare(), vect_multiply(), vect_printout_order(), vect_printout_order_decided_p(), vect_rm(), vect_sort_in_place(), and VECTEUR_NUL_P.

Referenced by make_bound_expression(), text_continuation(), text_pointer_value(), text_points_to_relation(), and text_transformer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_remove_large_coef()

bool sc_remove_large_coef ( Psysteme  sc,
Value  val,
bool  equalities,
bool  inequalities 
)

remove constraints with large coefs, possibly to avoid overflows and to keep systems as simple as possible

Parameters
scsystem to consider, which may be modified
valmaximum coef allowed, >=0, 0 meant to do nothing
equalitieswhether to process equalities
inequalitieswhether to process inequalities
Returns
whether the system was changed

Definition at line 277 of file sc_unaires.c.

279 {
280  bool changed = false;
281 
282  // nothing to do in some simple cases
283  if (sc==NULL || sc_empty_p(sc) || sc_rn_p(sc))
284  return changed;
285 
286  if (equalities && sc->egalites) {
287  int nb = sc->nb_eq;
289  sc->nb_eq = nb_elems_list(sc->egalites);
290  changed |= nb!=sc->nb_eq;
291  }
292 
293  if (inequalities && sc->inegalites) {
294  int nb = sc->nb_ineq;
296  sc->nb_ineq = nb_elems_list(sc->inegalites);
297  changed |= nb!=sc->nb_ineq;
298  }
299 
300  return changed;
301 }
Pcontrainte contrainte_remove_large_coef(Pcontrainte, Value)
Definition: listes.c:179

References contrainte_remove_large_coef(), Ssysteme::egalites, Ssysteme::inegalites, nb_elems_list(), Ssysteme::nb_eq, Ssysteme::nb_ineq, sc_empty_p(), and sc_rn_p().

+ Here is the call graph for this function:

◆ sc_sort()

void sc_sort ( Psysteme  sc,
Pbase  sort_base,
int(*)(Pvecteur *, Pvecteur *)  compare 
)

SORT a Psysteme according to sort_base and compare (given to qsort).

Each constraint is first sorted according to the compare function. Then list of constraints are sorted.

The only expected property is that two calls to this function with the same system (whatever its order) and same sort_base that covers all variables and same compare function should give the same result.

The function is quite peculiar and the order is relevant for some code generation issues...

Definition at line 137 of file sc_unaires.c.

141 {
142  sc_vect_sort(sc, compare);
143  sc->inegalites =
144  contrainte_sort(sc->inegalites, sc->base, sort_base, true, true);
145  sc->egalites =
146  contrainte_sort(sc->egalites, sc->base, sort_base, true, true);
147 }
Pcontrainte contrainte_sort(Pcontrainte c, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)
void sc_vect_sort(Psysteme s, int(*compare)(Pvecteur *, Pvecteur *))
the name is self explanatory, I guess.
Definition: sc_unaires.c:116

References Ssysteme::base, contrainte_sort(), Ssysteme::egalites, Ssysteme::inegalites, and sc_vect_sort().

Referenced by generate_io_collect_or_update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_vect_sort()

void sc_vect_sort ( Psysteme  s,
int(*)(Pvecteur *, Pvecteur *)  compare 
)

the name is self explanatory, I guess.

FC 24/11/94 the vectors of the system are sorted. see man qsort about the compare functions.

Definition at line 116 of file sc_unaires.c.

117 {
118  if (s==NULL || sc_empty_p(s) || sc_rn_p(s))
119  return;
120 
121  contrainte_vect_sort(sc_egalites(s), compare);
122  contrainte_vect_sort(sc_inegalites(s), compare);
123 }

References contrainte_vect_sort(), sc_empty_p(), and sc_rn_p().

Referenced by generate_io_collect_or_update(), generate_io_system(), sc_sort(), and sort_psysteme().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vect_printout_order()

Pvecteur vect_printout_order ( Pvecteur  v,
int(*)(Pvecteur *, Pvecteur *)  compare 
)

Try to guess the print out order for an equality already lexicographically sorted.

before cc might be freed

append v_neg to v

do not follow v_neg for ever

Definition at line 170 of file sc_unaires.c.

172 {
173  Pvecteur v_neg = VECTEUR_NUL;
176 
177  for(cc = v; !VECTEUR_NUL_P(cc); cc = succ) {
178  succ = vecteur_succ(cc); /* before cc might be freed */
179  if(vecteur_val(cc) < 0 || vecteur_var(cc)==TCST) {
180  vect_add_elem(&v_neg, vecteur_var(cc), vecteur_val(cc));
181  vect_erase_var(&v, vecteur_var(cc));
182  }
183  }
184 
185  vect_sort_in_place(&v, compare);
186  vect_sort_in_place(&v_neg, compare);
187 
188  /* append v_neg to v */
189  for(cc=v; !VECTEUR_NUL_P(cc); cc = vecteur_succ(cc)) {
190  if(VECTEUR_NUL_P(vecteur_succ(cc))) {
191  vecteur_succ(cc) = v_neg;
192  break; /* do not follow v_neg for ever */
193  }
194  }
195 
196  return v;
197 }
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_val(v)
#define vecteur_var(v)
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define VECTEUR_UNDEFINED
#define vecteur_succ(v)
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106
void vect_add_elem(Pvecteur *pvect, Variable var, Value val)
void vect_add_elem(Pvecteur * pvect, Variable var, Value val): addition d'un vecteur colineaire au ve...
Definition: unaires.c:72

References TCST, vect_add_elem(), vect_erase_var(), vect_sort_in_place(), VECTEUR_NUL, VECTEUR_NUL_P, vecteur_succ, VECTEUR_UNDEFINED, vecteur_val, and vecteur_var.

Referenced by sc_lexicographic_sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vect_printout_order_decided_p()

static bool vect_printout_order_decided_p ( Pvecteur  v)
static

constant vectors are considered decided

Definition at line 149 of file sc_unaires.c.

150 {
151  bool decided_p = false;
152  int positive_terms = 0;
153  int negative_terms = 0;
154  Pvecteur coord = VECTEUR_UNDEFINED;
155 
156  for(coord = v; !VECTEUR_NUL_P(coord); coord = coord->succ) {
157  if(vecteur_var(coord)!= TCST)
158  (value_pos_p(vecteur_val(coord))) ?
159  positive_terms++ : negative_terms++;
160  }
161  /* constant vectors are considered decided */
162  decided_p = ((positive_terms!=negative_terms) ||
163  (positive_terms==0 && negative_terms==0));
164 
165  return decided_p;
166 }
#define value_pos_p(val)
struct Svecteur * succ
Definition: vecteur-local.h:92

References Svecteur::succ, TCST, value_pos_p, VECTEUR_NUL_P, VECTEUR_UNDEFINED, vecteur_val, and vecteur_var.

Referenced by sc_lexicographic_sort().

+ Here is the caller graph for this function: