PIPS
loop_iteration_domaine_to_sc.c
Go to the documentation of this file.
1 /*
2 
3  $Id: loop_iteration_domaine_to_sc.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 conversion
29  */
30 #include <stdio.h>
31 
32 #include "linear.h"
33 
34 #include "genC.h"
35 #include "ri.h"
36 #include "ri-util.h"
37 #include "misc.h"
38 
39 #include "conversion.h"
40 
41 /* Psysteme loop_iteration_domaine_to_sc(cons *lls , Pbase *baseindex)
42  * transform the iteration domain of the nested loops (contained lls)
43  * in a system of constraints (sc)
44  *
45  * New loop indices are added at the head of the list baseindex. The
46  * field base of sc contains all the system variables. Variables are
47  * not in a specific order.
48  *
49  * CA: Ajout du cas ou l'increment de boucle est different de 1 le 1/9/91
50  */
51 
53  Pbase *baseindex)
54 {
55  Psysteme sc;
56 
57  debug_on("CONVERSION_DEBUG_LEVEL");
58 
59  pips_debug(8, "begin\n");
60 
61  sc = sc_new();
62  for (; lls != NIL; lls = CDR(lls)){
64  entity ind = loop_index(l);
65  range r = loop_range(l);
66 
67  /* add the current index "ind" to the index basis */
68  base_add_dimension(baseindex, (Variable) ind);
69 
70  /*add the constraints to sc*/
72  }
73  sc->nb_ineq = nb_elems_list(sc->inegalites);
74  sc_creer_base(sc);
75 
76  ifdebug(8) {
77  vect_fprint(stderr, *baseindex, (get_variable_name_t) entity_local_name);
78  }
79 
80  debug(8,"loop_iteration_domaine_to_sc", "end\n");
81 
82  debug_off();
83  return sc;
84 }
85 
87 range r;
88 entity ind;
89 Psysteme sc;
90 {
91  Pvecteur pv;
92  Pcontrainte pc;
93  Pvecteur
94  vlow = VECTEUR_NUL,
95  vup = VECTEUR_NUL,
96  pv_incr = VECTEUR_NUL;
97 
98  Value incr= VALUE_ONE;
99 
100  expression low = range_lower(r);
101  expression up = range_upper(r);
102  normalized low_norm = NORMALIZE_EXPRESSION(low);
103  normalized up_norm = NORMALIZE_EXPRESSION(up);
105 
106 
107  debug_on("CONVERSION_DEBUG_LEVEL");
108 
109  debug(8,"loop_index_domaine_to_contrainte", "begin\n");
110 
111  if (normalized_linear_p(low_norm) && normalized_linear_p(up_norm)){
112  vlow = (Pvecteur) normalized_linear(low_norm);
113  vup = (Pvecteur) normalized_linear(up_norm);
114 
115  }
116  else
117  user_error("loop_iteration_domaine_to_sc","untractable loop bound\n");
118 
119  if (normalized_linear_p(incr_norm))
120  pv_incr = (Pvecteur) normalized_linear(incr_norm);
121  if (vect_constant_p(pv_incr)) {
122  if (value_one_p(incr = vecteur_val(pv_incr))) {
123  /*make two constraints for the current index:
124  I-vup<=0, -I+vlow<=0 */
125  pv = vect_dup(vup);
126  vect_chg_sgn(pv);
127  vect_add_elem(&pv, (Variable) ind, VALUE_ONE);
128  pc = contrainte_make(pv);
129  sc_add_ineg(sc,pc);
130  pv = vect_dup(vlow);
131  vect_add_elem(&pv, (Variable) ind, VALUE_MONE);
132  pc = contrainte_make(pv);
133  sc_add_ineg(sc,pc);
134  }
135  else {
136  Variable new_var = creat_new_var(sc);
137  sc->dimension++;
138  sc->base = vect_add_variable(sc->base, (Variable) new_var);
139  /* build - new_var <= 0 */
140  pv = vect_new((Variable) ind, VALUE_MONE);
141  pc = contrainte_make(pv);
142  sc_add_ineg(sc,pc);
143  /* build incr * new_var - vup + vlow <= 0 */
144  pv = vect_dup(vup);
145  vect_chg_sgn(pv);
146  pv = vect_add(pv,vect_dup(vlow));
147  vect_add_elem(&pv, (Variable) new_var, incr);
148  pc = contrainte_make(pv);
149  sc_add_ineg(sc,pc);
150  /* build ind == vlow + incr * new_var */
151  pv = vect_dup(vlow);
152  vect_chg_sgn(pv);
153  pv = vect_add(pv,vect_new((Variable) ind, VALUE_ONE));
154  pv = vect_add(pv,vect_new((Variable) new_var, value_uminus(incr)));
155  pc = contrainte_make(pv);
156  sc_add_eg(sc,pc);
157  }
158  }
159 
160  debug(8,"loop_index_domaine_to_contrainte", "end\n");
161 
162  debug_off();
163 }
#define value_uminus(val)
unary operators on values
#define value_one_p(val)
#define VALUE_MONE
int Value
#define VALUE_ONE
Pbase vect_add_variable(Pbase b, Variable v)
package vecteur - routines sur les bases
Definition: base.c:61
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
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
bool vect_constant_p(Pvecteur)
bool vect_constant_p(Pvecteur v): v contains only a constant term, may be zero
Definition: predicats.c:211
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
void vect_fprint(FILE *f, Pvecteur v, get_variable_name_t variable_name)
void vect_fprint(FILE * f, Pvecteur v, char * (*variable_name)()): impression d'un vecteur creux v su...
Definition: io.c:124
void loop_index_domaine_to_contrainte(range r, entity ind, Psysteme sc)
Psysteme loop_iteration_domaine_to_sc(list lls, Pbase *baseindex)
package conversion
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define debug_off()
Definition: misc-local.h:160
#define user_error(fn,...)
Definition: misc-local.h:265
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define NORMALIZE_EXPRESSION(e)
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
#define normalized_linear_p(x)
Definition: ri.h:1779
#define range_upper(x)
Definition: ri.h:2290
#define instruction_loop(x)
Definition: ri.h:1520
#define range_increment(x)
Definition: ri.h:2292
#define range_lower(x)
Definition: ri.h:2288
#define statement_instruction(x)
Definition: ri.h:2458
#define loop_range(x)
Definition: ri.h:1642
#define normalized_linear(x)
Definition: ri.h:1781
#define loop_index(x)
Definition: ri.h:1640
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
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
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
Definition: sc_alloc.c:55
Variable creat_new_var(Psysteme ps)
char * noms_var(int i): cette fonction convertit un numero de variable en chaine de caracteres
Definition: sc_var.c:102
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
#define ifdebug(n)
Definition: sg.c:47
Pcontrainte inegalites
Definition: sc-local.h:71
Pbase base
Definition: sc-local.h:75
int dimension
Definition: sc-local.h:74
int nb_ineq
Definition: sc-local.h:73
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define vecteur_val(v)
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
struct Svecteur * Pvecteur
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
#define base_add_dimension(b, 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
Pvecteur vect_new(Variable var, Value coeff)
Pvecteur vect_new(Variable var,Value coeff): allocation d'un vecteur colineaire au vecteur de base va...
Definition: alloc.c:110
Pvecteur vect_add(Pvecteur v1, Pvecteur v2)
package vecteur - operations binaires
Definition: binaires.c:53
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