PIPS
constraint_distribution.c
Go to the documentation of this file.
1 /*
2 
3  $Id: constraint_distribution.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * PACKAGE MOVEMENTS
29  *
30  * Corinne Ancourt - juin 1990
31  */
32 
33 #include <stdio.h>
34 #include "genC.h"
35 #include "linear.h"
36 #include "ri.h"
37 #include "ri-util.h"
38 #include "constants.h"
39 #include "misc.h"
40 #include "vecteur.h"
41 #include "contrainte.h"
42 #include "sc.h"
43 
44 
45 
46 /* Distribution of the constraints of the system ps in three systems.
47  * System ps contains only contraints having to be used to generate
48  * bound expressions for the index of rank "rank".
49  * sc_neg contains the constraints corresponding to lower bounds for
50  * the variable of rank "rank".
51  * sc_pos contains the constraints corresponding to upper bounds for
52  * the variable of rank "rank".
53  * sc_test contains the constraints having to be added in the guard
54  *
55 */
56 
57 void
58 bound_distribution(pps,index_base,sc_info,nb_loop,sc_neg,sc_pos,sc_test)
59 Psysteme *pps;
60 Pbase index_base;
61 int sc_info[][4];
62 int nb_loop;
63 Psysteme *sc_neg,*sc_pos,sc_test;
64 {
65  Pcontrainte ineq;
66  Variable var;
67  int higher_rank,rank;
68 
69  debug_on("MOVEMENT_DEBUG_LEVEL");
70  debug(8,"bound_distribution","begin\n");
71 
72 
73  for (rank = 1; rank<=nb_loop; rank++) {
74  var = variable_of_rank(index_base,rank);
75 
76  sc_neg[rank] = sc_init_with_sc(pps[rank]);
77  sc_pos[rank] = sc_init_with_sc(pps[rank]);
78 
79  for (ineq = pps[rank]->inegalites;
80  !CONTRAINTE_UNDEFINED_P(ineq);
81  ineq=ineq->succ) {
82  if ((higher_rank = search_higher_rank(ineq->vecteur,
83  index_base))>0) {
84  if (sc_info[rank][1]) {
85  /* This condition is true if the variable must be kept
86  like loop index. Then all the constraints are kept in
87  the system (and not in the system of guards) */
88  if (higher_rank<= rank) {
89  /* This condition is true when the constraint constrains
90  directly the variable */
91 
92  if (vect_coeff(var,ineq->vecteur) < 0)
93  insert_ineq_begin_sc(sc_neg[rank],ineq);
94  else
95  insert_ineq_begin_sc(sc_pos[rank],ineq);
96  }
97  else {
98  /* This condition is true when the variable of rank
99  "higher_rank" could be eliminated from the
100  two constraints ineq and ineq->succ in order
101  to obtain a new constraint on the variable "var" */
102  int left_rank,right_rank;
103  Value left_coeff,right_coeff;
104  Variable left_var, right_var;
105 
107  (index_base,ineq,ineq->succ,higher_rank,
108  &right_var, &right_rank, &right_coeff,
109  &left_var, &left_rank, &left_coeff);
110 
111  /* the two constraints ineq and ineq->succ are added to
112  the end of the system */
113  if (((right_rank>left_rank) && (right_coeff >0))
114  || ((right_rank < left_rank) && (left_coeff>0)))
115  insert_2ineq_end_sc(sc_pos[rank],ineq);
116  else
117  insert_2ineq_end_sc(sc_neg[rank],ineq);
118  ineq = ineq->succ;
119  }
120  }
121  else {
122  /* If some constraints are in the system constraining a
123  variable which must not be kept as loop index, these
124  constraints are put in guards */
125  insert_2ineq_end_sc(sc_test,ineq);
126  ineq = ineq->succ;
127  }
128  }
129  }
130  ifdebug(9) {
131  (void) fprintf(stderr,"systeme negatif \n");
133  (void) fprintf(stderr,"systeme positif \n");
135  }
136  }
137  debug(8,"bound_distribution","end\n");
138  debug_off();
139 }
140 
141 
142 
143 
144 
145 /* Distribution of the constraints of the system sc into several systems.
146  * System sc contains all the contraints having to be used to generate
147  * bound expressions for all loop indices.
148  *
149  * A new system is defined for each system variable.
150  * Each new system defines the set of constraints needed for the generation
151  * of loop bound expressions for one variable.
152  *
153  * The constraint constraining directly a variable of rank "rank_hr"
154  * is added to the system corresponding to the variable "var_hr"
155  * except if this variable must not be kept (var_hr is not a loop index).
156  * In this last case, the constraint must be combined with another constraint
157  * in order to eliminate the variable "var_hr" and to deduce a constraint
158  * constrainnig another variable of rank "rank".
159  * In that case, the two constraints are added to the system corresponding
160  * to the variable "var = variable_of_rank(rank)"
161  *
162 */
163 
165  Psysteme sc,
166  Psysteme *bound_systems,
167  Pbase index_base,
168  int sc_info[][4])
169 {
170  Pcontrainte pc1,pc2;
171  int rank,rank_hr,rank_pc1,rank_pc2;
172  Value coeff1,coeff2;
173  int sign1,sign2,i;
174  Variable var_hr;
175  Psysteme sc2 = sc_init_with_sc(sc);
176 
177  debug_on("MOVEMENT_DEBUG_LEVEL");
178  debug(8,"constraint_distribution","begin\n");
179 
180 
181  for (pc1=sc->inegalites; !CONTRAINTE_UNDEFINED_P(pc1); pc1 = pc1->succ) {
182  if ((rank_hr = search_higher_rank(pc1->vecteur,index_base))>0) {
183  if (sc_info[rank_hr][1]) {
184  /* This condition is true if the variable must be kept like
185  loop index. All the constraints constraining directly the
186  variable of rank "rank_hr" are kept in the system
187  bound_systems[rank_hr] */
188 
189  insert_ineq_end_sc(bound_systems[rank_hr],pc1);
190  insert_ineq_end_sc(sc2,pc1);
191  }
192  else {
193  var_hr = variable_of_rank(index_base,rank_hr);
194  rank_pc1 = rank_of_variable
195  (index_base,
197  index_base,
198  var_hr));
199 
200  coeff1 = vect_coeff(var_hr,pc1->vecteur);
201  sign1 = value_sign(coeff1);
202  for (pc2 = pc1; !CONTRAINTE_UNDEFINED_P(pc2);
203  pc2= pc2->succ) {
204  coeff2 = vect_coeff(var_hr,pc2->vecteur);
205  sign2 = value_sign(coeff2);
206  if (value_notzero_p(coeff2) && sign1 == -sign2
207  && !bound_redund_with_sc_p(sc2,pc1,pc2,var_hr)) {
208  /* this condition is true if the combination of the
209  two constraints pc1 and pc2 is not redundant for the
210  system. Then the two constraints are added to the
211  system of the variable of higher rank */
212 
214  index_base,
215  var_hr);
216  rank_pc2 = rank_of_variable(index_base,var2);
217 
218  if (rank_pc1 !=rank_pc2)
219  rank=(rank_pc1 >rank_pc2) ? rank_pc1:rank_pc2;
220  else rank = rank_hr;
221  insert_ineq_end_sc(bound_systems[rank],pc1);
222  insert_ineq_end_sc(bound_systems[rank],pc2);
223  insert_ineq_end_sc(sc2,pc1);
224  insert_ineq_end_sc(sc2,pc2);
225  }
226  }
227  }
228  }
229  }
230  ifdebug(8) {
231  for (i=1;i<=vect_size(index_base);i++) {
232  (void) fprintf(stderr,"Le systeme sur la var. %d est:\n",i);
233  sc_fprint(stderr, bound_systems[i], (get_variable_name_t) entity_local_name);
234  }
235  }
236 
237  debug(8,"constraint_distribution","end\n");
238  debug_off();
239 }
240 
242  Psysteme sc,
243  Psysteme *bound_systems,
244  Pbase index_base)
245 {
246  Pcontrainte pc1;
247  int rank;
248 
249  debug_on("MOVEMENT_DEBUG_LEVEL");
250  debug(8,"egalite_distribution","begin\n");
251 
252  for (pc1=sc->egalites; !CONTRAINTE_UNDEFINED_P(pc1); pc1 = pc1->succ) {
253  if ((rank = search_higher_rank(pc1->vecteur,index_base))>0) {
254  sc_add_eg(bound_systems[rank],pc1);
255  }
256  }
257  debug(8,"egalite_distribution","end\n");
258  debug_off();
259 }
260 
#define value_sign(v)
trian operators on values
#define value_notzero_p(val)
int Value
int rank_of_variable(Pbase base, Variable var)
this function returns the rank of the variable var in the base 0 encodes TCST, but I do not know why,...
Definition: base.c:497
int search_higher_rank(Pvecteur vect, Pbase base)
int search_higher_rank(): this fonction returns the rank of the variable of higher rank in the vecteu...
Definition: base.c:541
void constraint_distribution(Psysteme sc, Psysteme *bound_systems, Pbase index_base, int sc_info[][4])
Distribution of the constraints of the system sc into several systems.
void bound_distribution(Psysteme *pps, Pbase index_base, sc_info, int nb_loop, Psysteme *sc_neg, Psysteme *sc_pos, Psysteme sc_test)
Distribution of the constraints of the system ps in three systems.
void egalite_distribution(Psysteme sc, Psysteme *bound_systems, Pbase index_base)
#define CONTRAINTE_UNDEFINED_P(c)
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
static entity rank
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...
Definition: entity.c:453
Psysteme sc_init_with_sc(Psysteme sc)
This function returns a new empty system which has been initialized with the same dimension and base ...
Definition: sc_alloc.c:303
bool bound_redund_with_sc_p(Psysteme sc, Pcontrainte ineq1, Pcontrainte ineq2, Variable var)
This function returns true if the constraint C (resulting of the combination of the two constraints i...
void insert_ineq_end_sc(Psysteme sc, Pcontrainte ineq)
This function inserts one constraint ineq at the end of the system of inequalities of sc.
Definition: sc_insert_eq.c:81
void insert_ineq_begin_sc(Psysteme sc, Pcontrainte ineq)
This function inserts the constraint ineq at the beginning of the system of inequalities of sc.
Definition: sc_insert_eq.c:40
void insert_2ineq_end_sc(Psysteme sc, Pcontrainte ineq)
This function inserts two constraints ineq and ineq->succ at the end of the system of inequalities of...
Definition: sc_insert_eq.c:54
Variable search_var_of_higher_rank()
Variable variable_of_rank()
void constraint_integer_combination(Pbase index_base, Pcontrainte ineq1, Pcontrainte ineq2, int rank, Variable *right_var, int *right_rank, Value *right_coeff, Variable *left_var, int *left_rank, Value *left_coeff)
This function computes the coefficients of the constraint resulting from the elimination of the varia...
void sc_fprint(FILE *fp, Psysteme ps, get_variable_name_t nom_var)
void sc_fprint(FILE * f, Psysteme ps, char * (*nom_var)()): cette fonction imprime dans le fichier po...
Definition: sc_io.c:220
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define ifdebug(n)
Definition: sg.c:47
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
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