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

Go to the source code of this file.

Functions

Psysteme sc_restricted_to_variables_transitive_closure (Psysteme sc, Pbase variables)
 for an improved dependence test (Beatrice Creusillet) More...
 
bool sc_constrains_variable_p (Psysteme sc, Variable var, bool is_equations_p)
 Does "var" appears with a non-zero coefficient in any equation or inequality of constraint system "sc? More...
 
bool sc_equations_constrain_variable_p (Psysteme sc, Variable var)
 
bool sc_inequalities_constrain_variable_p (Psysteme sc, Variable var)
 

Function Documentation

◆ sc_constrains_variable_p()

bool sc_constrains_variable_p ( Psysteme  sc,
Variable  var,
bool  is_equations_p 
)

Does "var" appears with a non-zero coefficient in any equation or inequality of constraint system "sc?

Definition at line 177 of file sc_misc.c.

178 {
179  Pcontrainte e = is_equations_p? sc_egalites(sc) :sc_inegalites(sc);
180  bool found_p = false;
181 
182  for (; !CONTRAINTE_UNDEFINED_P(e) && !found_p; e = e->succ) {
184  Value val = vect_coeff(var, ev);
185  found_p = (val!=VALUE_ZERO);
186  }
187  return found_p;
188 }
#define VALUE_ZERO
int Value
#define CONTRAINTE_UNDEFINED_P(c)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
struct Scontrainte * succ
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
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 CONTRAINTE_UNDEFINED_P, contrainte_vecteur, Scontrainte::succ, VALUE_ZERO, and vect_coeff().

Referenced by sc_equations_constrain_variable_p(), and sc_inequalities_constrain_variable_p().

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

◆ sc_equations_constrain_variable_p()

bool sc_equations_constrain_variable_p ( Psysteme  sc,
Variable  var 
)

Definition at line 190 of file sc_misc.c.

191 {
192  return sc_constrains_variable_p(sc, var, true);
193 }
bool sc_constrains_variable_p(Psysteme sc, Variable var, bool is_equations_p)
Does "var" appears with a non-zero coefficient in any equation or inequality of constraint system "sc...
Definition: sc_misc.c:177

References sc_constrains_variable_p().

Referenced by transformer_equations_constrain_variable_p().

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

◆ sc_inequalities_constrain_variable_p()

bool sc_inequalities_constrain_variable_p ( Psysteme  sc,
Variable  var 
)

Definition at line 195 of file sc_misc.c.

196 {
197  return sc_constrains_variable_p(sc, var, false);
198 }

References sc_constrains_variable_p().

Referenced by transformer_inequalities_constrain_variable_p().

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

◆ sc_restricted_to_variables_transitive_closure()

Psysteme sc_restricted_to_variables_transitive_closure ( Psysteme  sc,
Pbase  variables 
)

for an improved dependence test (Beatrice Creusillet)

The routine name says it all. Only constraints transitively connected to a constraint referencing a variable of interest with a non-zero coefficient are copied from sc to sc_res.

Input: sc: unchanged variables: list of variables of interest (e.g. phi variables of regions) Output: sc_res: a newly allocated restricted version of sc Temporary: sc: the pointer is modified to make debugging more interesting:-( (no impact on the value pointed to by sc on procedure entry)

FI: I'm sceptical... OK for speed, quid of accuracy? Nonfeasibility due to existencial variables is lost if these variables are not transitively related to the so-called variables of interest, isn'it? Well, I do not manage to build a counter example because existential problems are caught by the precondition normalization. Although it is not as strong as one could wish, it gets lots of stuff...

if a constraint is found in sc, that contains a variable that already belongs to the base of sc_res, then this constraint is removed from sc, added to sc_res and its variables are added to the base of sc_res

if a constraint is found in sc, that contains a variable that already belongs to the base of sc_res, then this constraint is removed from sc, added to sc_res and its variables are added to the base of sc_res

Definition at line 64 of file sc_misc.c.

67 {
68  Psysteme sc_res;
69  Pcontrainte c, c_pred, c_suiv;
70  Pvecteur v;
71 
72  // first, handle special cases
73  if (sc_rn_p(sc)){
74  // we return a sc_rn predicate,on the space of the input variables
75  sc_res = sc_rn(variables);
76  return sc_res;
77  }
78  if (sc_empty_p(sc)) {
79  // we return an empty predicate,on the space of the input variables */
80  sc_res = sc_empty(variables);
81  return sc_res;
82  }
83 
84  // sc has no particularity. We just scan its equalities and inequalities
85  // to find which variables are related to the PHI variables
86  sc = sc_dup(sc);
87  base_rm(sc->base);
88  sc->base = BASE_NULLE;
89  sc_creer_base(sc);
90 
91  sc_res = sc_new();
92  sc_res->base = variables;
93  sc_res->dimension = vect_size(variables);
94 
95  while (vect_common_variables_p(sc->base, sc_res->base))
96  {
97  // equalities first
98  c = sc_egalites(sc);
99  c_pred = (Pcontrainte) NULL;
100  while (c != (Pcontrainte) NULL) {
101  c_suiv = c->succ;
102 
103  /* if a constraint is found in sc, that contains a variable
104  * that already belongs to the base of sc_res, then this
105  * constraint is removed from sc, added to sc_res and its
106  * variables are added to the base of sc_res */
107  if (vect_common_variables_p(c->vecteur,sc_res->base)){
108 
109  // the constraint is removed from sc
110  if (c_pred != (Pcontrainte) NULL)
111  c_pred->succ = c_suiv;
112  else
113  sc_egalites(sc) = c_suiv;
114 
115  // and added to sc_res
116  c->succ = (Pcontrainte) NULL;
117  sc_add_egalite(sc_res, c);
118 
119  // sc_res base is updated with the variables occuring in c
120  for(v = c->vecteur; !VECTEUR_NUL_P(v); v = v->succ) {
121  if (vecteur_var(v) != TCST)
122  sc_base_add_variable(sc_res, vecteur_var(v));
123  }
124  }
125  else
126  c_pred = c;
127  c = c_suiv;
128  }
129 
130  // inequalities then
131  c = sc_inegalites(sc);
132  c_pred = (Pcontrainte) NULL;
133  while (c != (Pcontrainte) NULL) {
134  c_suiv = c->succ;
135 
136  /* if a constraint is found in sc, that contains a variable
137  * that already belongs to the base of sc_res, then this
138  * constraint is removed from sc, added to sc_res and its
139  * variables are added to the base of sc_res */
140  if (vect_common_variables_p(c->vecteur,sc_res->base)){
141  // the constraint is removed from sc
142  if (c_pred != (Pcontrainte) NULL)
143  c_pred->succ = c_suiv;
144  else
145  sc_inegalites(sc) = c_suiv;
146 
147  // and added to sc_res
148  c->succ = (Pcontrainte) NULL;
149  sc_add_inegalite(sc_res, c);
150 
151  // sc_res base is updated with the variables occuring in c
152  for(v = c->vecteur; !VECTEUR_NUL_P(v); v = v->succ) {
153  if (vecteur_var(v) != TCST)
154  sc_base_add_variable(sc_res, vecteur_var(v));
155  }
156  }
157  else
158  c_pred = c;
159  c = c_suiv;
160  }
161 
162  // update sc base
163  base_rm(sc->base);
164  sc_base(sc) = (Pbase) NULL;
165  (void) sc_creer_base(sc);
166  } // while()
167 
168  sc_rm(sc);
169  sc = NULL;
170 
171  return sc_res;
172 }
struct Scontrainte * Pcontrainte
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
void sc_base_add_variable(Psysteme sc, Variable var)
Definition: sc.c:248
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
Psysteme sc_empty(Pbase b)
Psysteme sc_empty(Pbase b): build a Psysteme with one unfeasible constraint to define the empty subsp...
Definition: sc_alloc.c:319
Psysteme sc_rn(Pbase b)
Psysteme sc_rn(Pbase b): build a Psysteme without constraints to define R^n, where n is b's dimension...
Definition: sc_alloc.c:336
void sc_creer_base(Psysteme ps)
void sc_creer_base(Psysteme ps): initialisation des parametres dimension et base d'un systeme lineair...
Definition: sc_alloc.c:129
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
void sc_add_egalite(Psysteme p, Pcontrainte e)
void sc_add_egalite(Psysteme p, Pcontrainte e): macro ajoutant une egalite e a un systeme p; la base ...
Definition: sc_alloc.c:389
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
Definition: sc_alloc.c:55
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
void sc_add_inegalite(Psysteme p, Pcontrainte i)
void sc_add_inegalite(Psysteme p, Pcontrainte i): macro ajoutant une inegalite i a un systeme p; la b...
Definition: sc_alloc.c:406
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
static int variables[MAX_VAR]
Pvecteur vecteur
Pbase base
Definition: sc-local.h:75
int dimension
Definition: sc-local.h:74
struct Svecteur * succ
Definition: vecteur-local.h:92
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
struct Svecteur * Pbase
#define VECTEUR_NUL_P(v)
#define base_rm(b)
#define BASE_NULLE
MACROS SUR LES BASES.
bool vect_common_variables_p(Pvecteur v1, Pvecteur v2)
bool vect_common_variables_p(Pvecteur v1, v2) BA 19/05/94 input : two vectors.
Definition: unaires.c:397

References Ssysteme::base, BASE_NULLE, base_rm, Ssysteme::dimension, sc_add_egalite(), sc_add_inegalite(), sc_base_add_variable(), sc_creer_base(), sc_dup(), sc_empty(), sc_empty_p(), sc_new(), sc_rm(), sc_rn(), sc_rn_p(), Scontrainte::succ, Svecteur::succ, TCST, variables, vect_common_variables_p(), vect_size(), Scontrainte::vecteur, VECTEUR_NUL_P, and vecteur_var.

Referenced by build_and_test_dependence_context(), efficient_sc_check_inequality_feasibility(), filter_transformer(), and restrict_to_phi_constraints().

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