PIPS
hyperplane.c
Go to the documentation of this file.
1 /*
2 
3  $Id: hyperplane.c 23495 2018-10-24 09:19:47Z 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 /* package hyperplane
28  */
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 
34 #include "genC.h"
35 #include "linear.h"
36 #include "ri.h"
37 #include "effects.h"
38 #include "misc.h"
39 #include "text.h"
40 
41 #include "boolean.h"
42 #include "vecteur.h"
43 #include "contrainte.h"
44 #include "sc.h"
45 #include "matrice.h"
46 #include "matrix.h"
47 
48 #include "sparse_sc.h"
49 #include "ri-util.h"
50 #include "effects-util.h"
51 #include "conversion.h"
52 
53 #include "hyperplane.h"
54 
55 
56 /* void hyperplane(cons *lls)
57  * Implementation of the hyperplane method
58  * "lls" is the list of nested loops
59  */
60 
62 {
63  Psysteme sci; /* sc initial */
64  Psysteme scn; /* sc nouveau */
65  Psysteme sc_row_echelon;
67  Pbase base_oldindex = NULL;
68  Pbase base_newindex = NULL;
69  matrice A;
70  matrice G;
71  matrice AG;
72  int n; /* number of index */
73  int m ; /* number of constraints */
74  Value *h;
75  int i;
76  statement s_lhyp;
77  Pvecteur *pvg;
78  Pbase pb;
79  expression lower, upper;
80  Pvecteur pv1;
81  loop l;
82 
83  debug_on("HYPERPLANE_DEBUG_LEVEL");
84 
85  debug(8," hyperplane","Begin:\n");
86 
87  /* make the system "sc" of constraints of iteration space */
88  sci = loop_iteration_domaine_to_sc(lls, &base_oldindex);
89 
90  ifdebug(8) {
91  /*DNDEBUG*/
92  (void) fprintf(stderr,"base_oldindex 0:\n");
93  base_fprint(stderr,base_oldindex,default_variable_to_string);
94  }
95 
96  /* create the matrix A of coefficients of index in (Psysteme)sci */
97  n = base_dimension(base_oldindex);
98  m = sci->nb_ineq;
99  A = matrice_new(m,n);
100  sys_matrice_index(sci, base_oldindex, A, n, m);
101 
102  ifdebug(8) {
103  /*DNDEBUG*/
104  (void) fprintf(stderr,"base_oldindex 1:\n");
105  base_fprint(stderr,base_oldindex,default_variable_to_string);
106  }
107  ifdebug(8) {
108  /*DNDEBUG*/
109  (void) fprintf(stderr,"Matrice A:\n");
110  matrice_fprint(stderr,A,m,n);
111  }
112  ifdebug(8) {
113  /*DNDEBUG*/
114  (void) fprintf(stderr,"sci:\n");
115  sc_default_dump(sci);
116  }
117  /* computation of the hyperplane direction */
118  /* use the hyperplane direction */
119  h = (Value*)(malloc(n*sizeof(Value)));
120 
122  pips_user_error("A proper hyperplane direction was not provided\n");
123  }
124 
125  ifdebug(8) {
126  debug(8," hyperplane","Vector h :");
127  for (i = 0; i<n; i++) {
128  (void) fprintf(stderr," " VALUE_FMT, *(h+i));
129  }
130  (void) fprintf(stderr,"\n");
131  }
132 
133  G = matrice_new(n,n);
134  /* computation of the scanning base G */
136  ifdebug(8) {
137  (void) fprintf(stderr,"The scanning base G is:");
138  matrice_fprint(stderr, G, n, n);
139  }
140 
141  /* the new matrice of constraints AG = A * G */
142  AG = matrice_new(m,n);
143  matrice_multiply(A, G, AG, m, n, n);
144 
145  ifdebug(8) {
146  /*DNDEBUG*/
147  (void) fprintf(stderr,"Matrice AG:\n");
148  matrice_fprint(stderr,AG,m,n);
149  }
150  /* create the new system of constraintes (Psysteme scn) with
151  AG and sci */
152  scn = sc_dup(sci);
153 
154  ifdebug(8) {
155  /*DNDEBUG*/
156  (void) fprintf(stderr,"base_oldindex 2:\n");
157  base_fprint(stderr,base_oldindex,default_variable_to_string);
158  }
159  ifdebug(8) {
160  /*DNDEBUG*/
161  (void) fprintf(stderr,"scn before matrice_index_sys :\n");
162  sc_default_dump(scn);
163  }
164  matrice_index_sys(scn, base_oldindex, AG, n,m );
165 
166  ifdebug(8) {
167  /*DNDEBUG*/
168  (void) fprintf(stderr,"scn after matrice_index_sys :\n");
169  sc_default_dump(scn);
170  }
171 
172  /* computation of the new iteration space in the new basis G */
173  sc_row_echelon = new_loop_bound(scn, base_oldindex);
174 
175  ifdebug(8) {
176  /*DNDEBUG*/
177  /* (void) fprintf(stderr,"scn after new_loop_bound:\n");
178  sc_default_dump(scn);
179  has been destroyed
180  */
181  (void) fprintf(stderr,"sc_row_echelon:\n");
182  sc_default_dump(sc_row_echelon);
183  }
184 
185  /* change of basis for index */
186  change_of_base_index(base_oldindex, &base_newindex);
187 
188  ifdebug(8) {
189  /*DNDEBUG*/
190  (void) fprintf(stderr,"base_oldindex:\n");
191  base_fprint(stderr,base_oldindex,default_variable_to_string);
192  (void) fprintf(stderr,"base_newindex:\n");
193  base_fprint(stderr,base_newindex,default_variable_to_string);
194  }
195 
196  sc_newbase = sc_change_baseindex(sc_dup(sc_row_echelon), base_oldindex, base_newindex);
197 
198  ifdebug(8) {
199  /*DNDEBUG*/
200  (void) fprintf(stderr,"sc_newbase:\n");
202  }
203 
204  /* generation of hyperplane code */
205  /* generation of bounds */
206  for (pb=base_newindex; pb!=NULL; pb=pb->succ) {
207  make_bound_expression(pb->var, base_newindex, sc_newbase, &lower, &upper);
208  }
209 
210  /* loop body generation */
211  pvg = (Pvecteur *)malloc((unsigned)n*sizeof(Svecteur));
212  scanning_base_to_vect(G,n,base_newindex,pvg);
213  pv1 = sc_row_echelon->inegalites->succ->vecteur;
214  (void)vect_change_base(pv1,base_oldindex,pvg);
215 
217  lower = range_upper(loop_range(l));
218  upper= expression_to_expression_newbase(lower, pvg, base_oldindex);
219 
220 
221  s_lhyp = code_generation(lls, pvg, base_oldindex, base_newindex, sc_newbase, true);
222 
223  debug(8," hyperplane","End\n");
224 
225  debug_off();
226 
227  return(s_lhyp);
228 }
#define VALUE_FMT
int Value
void change_of_base_index(Pbase base_oldindex, Pbase *base_newindex)
void change_of_base_index(Pbase base_oldindex, Pbase *base_newindex) change of variable index from ba...
Psysteme sc_change_baseindex(Psysteme sc, Pbase base_old, Pbase base_new)
Psysteme sc_change_baseindex(Psysteme sc, Pbase base_old, Pbase base_new) le changement de base d'ind...
expression expression_to_expression_newbase(expression e_old, pvg, Pbase base_oldindex)
expression expression_to_expression_newbase(expression e_old,Pvecteur pvg[], Pbase base_oldindex) com...
Pvecteur vect_change_base(Pvecteur pv_old, Pbase base_oldindex, pvg)
Pvecteur vect_change_base(Pvecteur pv_old, Pvecteur pvg[], Pbase base_oldindex, Pbase base_newindex) ...
void scanning_base_to_vect(matrice G, int n, Pbase base, pvg)
void scanning_base_to_vect(matrice G,int n,Pbase base,Pvecteur pvg[n]) compute G*base and put the res...
statement code_generation(list lls, Pvecteur pvg[], Pbase base_oldindex, Pbase base_newindex, Psysteme sc_newbase, bool preserve_entry_label_p)
package hyperplane
#define A(i, j)
comp_matrice.c
Definition: comp_matrice.c:63
Psysteme loop_iteration_domaine_to_sc(list, Pbase *)
loop_iteration_domaine_to_sc.c
void * malloc(YYSIZE_T)
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
Psysteme sc_newbase
include <sys/ddi.h>
statement hyperplane(list lls, _UNUSED_ bool(*u)(statement))
package hyperplane
Definition: hyperplane.c:61
void scanning_base_hyperplane(Value[], int, matrice)
scanning_base.c
bool interactive_hyperplane_direction(Value *, int)
hyperplane_direction.c
void base_fprint(FILE *f, Pbase b, get_variable_name_t variable_name)
void base_fprint(FILE * f, Pbase b, char * (*variable_name)()): impression d'une base sur le fichier ...
Definition: io.c:342
#define matrice_new(n, m)
Allocation et desallocation d'une matrice.
Definition: matrice-local.h:77
Value * matrice
package matrice
Definition: matrice-local.h:71
void matrice_multiply(matrice a, matrice b, matrice c, int p, int q, int r)
void matrice_multiply(matrice a, matrice b, matrice c, int p, int q, int r): multiply rational matrix...
Definition: matrice.c:82
void matrice_fprint(FILE *, matrice, int, int)
matrice_io.c
Definition: matrice_io.c:62
#define debug_on(env)
Definition: misc-local.h:157
#define _UNUSED_
Definition: misc-local.h:232
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
void make_bound_expression(Variable index, Pbase base, Psysteme sc, expression *lower, expression *upper)
void make_bound_expression(variable index, Pbase base, Psysteme sc, expression *lower,...
#define range_upper(x)
Definition: ri.h:2290
#define instruction_loop(x)
Definition: ri.h:1520
#define statement_instruction(x)
Definition: ri.h:2458
#define loop_range(x)
Definition: ri.h:1642
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
char * default_variable_to_string(Variable v)
Definition: sc_debug.c:245
void sc_default_dump(Psysteme sc)
void sc_default_dump(Psysteme sc): dump to stderr
Definition: sc_io.c:170
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Psysteme new_loop_bound(Psysteme scn, Pbase base_index)
Psysteme new_loop_bound(Psysteme scn, Pbase base_index) computation of the new iteration space (given...
#define G(j, a, b)
maybe most of them should be functions?
#define ifdebug(n)
Definition: sg.c:47
void sys_matrice_index(Psysteme, Pbase, matrice, int, int)
Warning! Do not modify this file that is automatically generated!
void matrice_index_sys(Psysteme, Pbase, matrice, int, int)
void matrice_index_sys(Psysteme sc, Pbase base_index, matrice AG, int n, int m) replace the coefficie...
Definition: pip__tab.h:25
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
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
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define base_dimension(b)
struct Svecteur Svecteur
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique