PIPS
Psc.c
Go to the documentation of this file.
1 /*
2 
3  $Id: Psc.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  /* NewGen interface with C3 type Psysteme for PIPS project
28  *
29  * Systems of linear equalities and inequalities are stored as a triplet,
30  * a base followed by two vector lists, the sets of equalities and
31  * inequalities: (b leq lineq).
32  *
33  * Each vector list is also parenthesized:
34  * (v1 v2 v3). Each vector itself (see Pvecteur.c) is a parenthesized
35  * list of couples value/variable.
36  *
37  * For instance, the empty system (the whole space as defined by basis b) is:
38  * (b()())
39  * where basis vector b is stored as a regular vector (see Pvecteur.c).
40  *
41  * To cope with the absence of unget() for f(), each vectors in the list
42  * is separated by a space.
43  *
44  * Redundant information, the number of equalities and the number of
45  * inequalities and the system dimension, is discarded.
46  *
47  * Francois Irigoin, November 1990
48  */
49 
50 #include <stdio.h>
51 #include <string.h>
52 
53 #include "linear.h"
54 #include "genC.h"
55 #include "ri.h"
56 #include "misc.h"
57 
58 #include "newgen.h"
59 
60 /* Sigh, sigh, sigh:
61  - either ri-util.h must be included, as well as all underlaying libraries
62  - or vect_gen_read() and vect_gen_write() must be locally declared,
63  at the risk of a future inconsistency
64 */
65 
66 /* sigh no more, lady, sigh no more,
67  * man, who decieves ever,
68  * one foot in sea, and one on shore,
69  * to one thing, constant never.
70  * so sigh not so,
71  * but let them go,
72  * and be your blith
73  * ...
74  *
75  * - I forgot some part of it I guess. FC
76  */
77 
78 #define error(fun, msg) { \
79  fprintf(stderr, "pips internal error in %s: %s\n", fun, msg); exit(2); \
80 }
81 
82 void sc_gen_write(FILE *fd, Psysteme s)
83 {
84  Pcontrainte c;
85  Psysteme stored_s;
86  static Psysteme undefined_s = SC_UNDEFINED;
87 
88  /* FI: we cannot not store SC_UNDEFINED as it is used in regions;
89  we cannot store it like a system with an empty basis, no inequalities
90  and no equalities because it is used to define transformer identity;
91  conclusion: region library has to be changed and to use
92  transformer_undefined as context
93 
94  Current kludge: SC_UNDEFINED is stored but retrieved as a system
95  with 0 equalities and 0 inequalities over a space of dimension 0
96  */
97  if(SC_UNDEFINED_P(s)) {
98  if(SC_UNDEFINED_P(undefined_s))
100  stored_s = undefined_s;
101  }
102  else
103  stored_s = s;
104 
105  pips_assert("sc_gen_write",!SC_UNDEFINED_P(stored_s));
106 
107  /*
108  ifdebug(10){
109  fprintf(stderr, "[sc_gen_write] sys 0x%x\n", (unsigned int) s);
110  syst_debug(s); }
111  */
112 
113  (void) fputc('(',fd);
114 
115  vect_gen_write(fd,stored_s->base);
116 
117  (void) fputc('(',fd);
118 
119  for (c = stored_s->egalites; c != NULL; c = c->succ) {
120  (void) fputc(' ', fd);
121  vect_gen_write(fd,c->vecteur);
122  }
123 
124  (void) fputc(')',fd);
125 
126  (void) fputc('(',fd);
127 
128  for (c = stored_s->inegalites; c != NULL; c = c->succ) {
129  (void) fputc(' ', fd);
130  vect_gen_write(fd, c->vecteur);
131  }
132 
133  (void) fputc(')',fd);
134 
135  (void) fputc(')',fd);
136 
137 }
138 
139 Psysteme sc_gen_read(FILE * fd /* ignored */, int (*f)())
140 {
141  Psysteme s = sc_new();
142  int c;
143 
144  if ((c = f()) != '(') {
145  error("sc_gen_read","initial '(' missing\n");
146  }
147 
148  s->base = vect_gen_read(fd, f);
149 
150  if ((c = f()) != '(') {
151  error("sc_gen_read","equalities '(' missing\n");
152  }
153 
154  while ((c = f()) != ')') {
155  Pvecteur v = vect_gen_read(fd, f);
157 
158  pips_assert("sc_gen_read", c==' ');
159 
160  sc_add_egalite(s, e);
161  }
162 
163  if ((c = f()) != '(') {
164  error("sc_gen_read","inequalities '(' missing\n");
165  }
166 
167  while ((c = f()) != ')') {
168  Pvecteur v = vect_gen_read(fd, f);
170 
171  pips_assert("sc_gen_read", c==' ');
172 
173  sc_add_inegalite(s, i);
174  }
175 
176  if ((c = f()) != ')') {
177  error("sc_gen_read","closing ')' missing\n");
178  }
179 
180  /* It might be a good idea to check that the basis is consistent
181  with the equalities and inequalities that were read, later... */
182 
183  s->dimension = vect_size(s->base);
184 
185  /* FI: doesn't work because it's just the definition of
186  transformer_identity */
187  /*
188  if(s->dimension == 0) {
189  pips_assert("sc_gen_read", s->nb_eq == 0 && s->nb_ineq == 0);
190  sc_rm(s);
191  s = SC_UNDEFINED;
192  }
193  */
194 
195  return s;
196 }
197 
199 {
200  sc_rm(s);
201 }
202 
204 {
205  return sc_copy(s);
206 }
207 
209 {
210  return contrainte_gen_allocated_memory(sc_egalites(s))
211  + contrainte_gen_allocated_memory(sc_inegalites(s))
212  + vect_gen_allocated_memory(sc_base(s))
213  + sizeof(Ssysteme) ;
214 }
215 
216 /* That is all
217  */
void sc_gen_write(FILE *fd, Psysteme s)
Psc.c.
Definition: Psc.c:82
Psysteme sc_gen_read(FILE *fd, int(*f)())
Definition: Psc.c:139
Psysteme sc_gen_copy_tree(Psysteme s)
Definition: Psc.c:203
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
Definition: Psc.c:78
int sc_gen_allocated_memory(Psysteme s)
Definition: Psc.c:208
void sc_gen_free(Psysteme s)
Definition: Psc.c:198
#define CONTRAINTE_UNDEFINED
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void vect_gen_write(FILE *, Pvecteur)
Pvecteur.c.
Definition: Pvecteur.c:108
Pvecteur vect_gen_read(FILE *, int(*)(void))
int contrainte_gen_allocated_memory(Pcontrainte)
Definition: Pvecteur.c:176
int vect_gen_allocated_memory(Pvecteur)
Definition: Pvecteur.c:168
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
struct Ssysteme Ssysteme
Psysteme sc_make(Pcontrainte leg, Pcontrainte lineg)
Psysteme sc_make(Pcontrainte leg, Pcontrainte lineg): allocation et initialisation d'un systeme d'equ...
Definition: sc.c:78
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
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_copy(Psysteme ps)
Psysteme sc_copy(Psysteme ps): duplication d'un systeme (allocation et copie complete des champs sans...
Definition: sc_alloc.c:230
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
Pbase base
Definition: sc-local.h:75
int dimension
Definition: sc-local.h:74
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89