PIPS
build_sc_machine.c
Go to the documentation of this file.
1 /*
2 
3  $Id: build_sc_machine.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 /* PACKAGE MOVEMENTS
28  *
29  * Corinne Ancourt - septembre 1991
30  */
31 
32 #include <stdio.h>
33 
34 
35 
36 #include "genC.h"
37 #include "linear.h"
38 #include "ri.h"
39 #include "ri-util.h"
40 #include "misc.h"
41 
42 #include "matrice.h"
43 #include "tiling.h"
44 #include "movements.h"
45 
46 /* this function builds the following system of constraints depending
47  * on the machine. It describes the implementation of array elements in
48  * the memory in function of bank, ligne size, ligne bank,...
49  *
50  * bn is the number of banks, ls the ligne size, ms the first array dimension
51  * bank is a variable giving the bank id., ligne a variable corresponding to
52  * a ligne in the bank, ofs a variable corresponding to an offset
53  * in a ligne of the bank.
54  *
55  * if COLUMN_MAJOR is true the system is the following one
56  *
57  * (VAR1-1) + (VAR2-1) *ms == bn*ls* ligne +ls*bank+ofs,
58  * 1 <= bank <= bn ,
59  * 1 <= proc <= pn ,
60  * 0 <= ofs <= ls-1
61  *
62  *else it is
63  *
64  * (VAR1-1) * ms + (VAR2-1) == bn*ls*ligne +ls*bank+ofs,
65  * 1 <= bank <= bn ,
66  * 1 <= proc <= pn ,
67  * 0 <= ofs <= ls-1
68 */
69 
71  int pn,
72  int bn,
73  int ls,
74  Psysteme sc_array_function,
75  entity proc_id,
76  Pbase bank_indices,
77  entity entity_var)
78 {
79 
80  type t = entity_type(entity_var);
81  Value ms=0;
82  Variable vbank,vligne,vofs;
83  Psysteme sc = sc_init_with_sc(sc_array_function);
84  Pcontrainte pc;
85  Pvecteur pv1,pv2;
86  int nb_bytes=1;
87 
88  debug(8,"build_sc_machine","begin\n");
89  if (type_variable_p(t)) {
90  variable var = type_variable(t);
91  cons * dims = variable_dimensions(var);
92  dimension dim1 = DIMENSION(CAR(dims));
93  expression lower= dimension_lower(dim1);
94  normalized norm1 = NORMALIZE_EXPRESSION(lower);
95  expression upper= dimension_upper(dim1);
96  normalized norm2 = NORMALIZE_EXPRESSION(upper);
97  Value min_ms =VALUE_ZERO, max_ms=VALUE_ZERO;
98  if (normalized_linear_p(norm1) && normalized_linear_p(norm2)) {
99  min_ms = vect_coeff(TCST,(Pvecteur) normalized_linear(norm1));
100  max_ms = vect_coeff(TCST,(Pvecteur) normalized_linear(norm2));
101  }
102  ms = value_plus(value_minus(max_ms,min_ms), VALUE_ONE);
103 
104  /* Si l'on veut utiliser le nombre d'octets il faut remplacer l'equation
105  par deux inequations du type
106 
107  if COLUMN_MAJOR is true the system is the following one
108 
109  (VAR1-1) + (VAR2-1) *ms <= bn*ls* (ligne-1) +ls*(bank-1)+ofs,
110  bn*ls* (ligne-1) +ls*(bank-1)+ofs <= (VAR1) + (VAR2-1) *ms
111 
112  else it is
113 
114  (VAR1-1) * ms + (VAR2-1) <= bn*ls*(ligne-1) +ls*(bank-1)+ofs,
115  bn*ls*(ligne-1) +ls*(bank-1)+ofs <= (VAR1-1) * ms + (VAR2)
116 
117  */
118 
119  /* nb_bytes = SizeOfElements(bas);*/
120 
121  }
122 
123  ifdebug(8) {
124  fprint_string_Value(stderr," MS = ",ms);
125  fprintf(stderr, " \n");
126  }
127 
128  vbank = vecteur_var(bank_indices);
129  vligne = vecteur_var(bank_indices->succ);
130  vofs = vecteur_var(bank_indices->succ->succ);
131  sc->base = vect_add_variable(sc->base,vbank);
132  sc->base = vect_add_variable(sc->base,vligne);
133  sc->base = vect_add_variable(sc->base,vofs);
134 
135  sc->dimension +=3;
136 
137  /* bank_indices is assumed to belong the three variables
138  bank_id, L and O (see documentation for more details) */
139 
140  /* if COLUMN_MAJOR is true then build the constraint
141  (VAR1-1) + (VAR2-1) *ms == bn*ls*L +ls*bank_id+O,
142  else build the constraint
143  (VAR1-1) * ms + (VAR2-1) == bn*ls*L +ls*bank_id+O,
144  VAR1 and VAR2 correspond to the image array function indices */
145  pv1 = vect_new(vbank,int_to_value(-ls));
146  vect_add_elem(&pv1,vligne,int_to_value((-bn*ls)));
147  vect_add_elem(&pv1,vofs,VALUE_MONE);
148  if (COLUMN_MAJOR)
149  pc = sc_array_function->inegalites;
150  else pc = sc_array_function->inegalites->succ;
151  /* to deal with MONO dimensional array */
152  if (pc==NULL) pc= contrainte_make(vect_new(TCST,VALUE_ONE));
153  pv2 = vect_dup(pc->vecteur);
155  pv2 = vect_multiply(pv2,int_to_value(nb_bytes));
156  pv1 = vect_add(pv1,pv2);
157  if (COLUMN_MAJOR)
158  pc = pc->succ;
159  else pc = sc_array_function->inegalites;
160  /* to deal with MONO dimensional array */
161  if (pc==NULL) pc= contrainte_make(vect_new(TCST,VALUE_ONE));
162  pv2 = vect_dup(pc->vecteur);
164  Value nbv = int_to_value(nb_bytes);
165  pv2 = vect_multiply(pv2,value_mult(ms, nbv));
166  pv1 = vect_add(pv1,pv2);
167  pc = contrainte_make(pv1);
168  sc_add_eg(sc,pc);
169 
170  /* build the constraints 0 <= bank_id <= bn-1 */
171 
172  pv2 = vect_new(vbank, VALUE_MONE);
173  pc = contrainte_make(pv2);
174  sc_add_ineg(sc,pc);
175  pv2 = vect_new(vbank, VALUE_ONE);
176  vect_add_elem(&pv2,TCST,int_to_value(- bn+1));
177  pc = contrainte_make(pv2);
178  sc_add_ineg(sc,pc);
179 
180  /* build the constraints 0 <= proc_id <= pn-1 */
181  sc->base = vect_add_variable(sc->base,(char *) proc_id);
182  sc->dimension++;
183  pv2 = vect_new((char *) proc_id, VALUE_MONE);
184  pc = contrainte_make(pv2);
185  sc_add_ineg(sc,pc);
186  pv2 = vect_new((char *) proc_id, VALUE_ONE);
187  vect_add_elem(&pv2,TCST,int_to_value(- pn+1));
188  pc = contrainte_make(pv2);
189  sc_add_ineg(sc,pc);
190 
191 
192  /* build the constraints 0 <= O <= ls -1 */
193 
194  pv2 = vect_new(vofs, VALUE_MONE);
195  pc = contrainte_make(pv2);
196  sc_add_ineg(sc,pc);
197  pv2 = vect_new(vofs, VALUE_ONE);
198  vect_add_elem(&pv2,TCST,int_to_value(- ls +1));
199  pc = contrainte_make(pv2);
200  sc_add_ineg(sc,pc);
201 
202 
203  /* build the constraints 0 <= L */
204 
205  pc = contrainte_make(vect_new(vligne,VALUE_MONE));
206  sc_add_ineg(sc,pc);
207  ifdebug(8) {
208  (void) fprintf(stderr,"Domain Machine :\n");
210  }
211  debug(8,"build_sc_machine","end\n");
212 
213  return(sc);
214 
215 }
216 
217 
218 
219 
220 
#define VALUE_ZERO
#define int_to_value(i)
end LINEAR_VALUE_IS_INT
#define value_minus(v1, v2)
#define VALUE_MONE
int Value
#define value_plus(v1, v2)
binary operators on values
#define VALUE_ONE
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
void fprint_string_Value(FILE *, char *, Value)
Definition: io.c:47
Pbase vect_add_variable(Pbase b, Variable v)
package vecteur - routines sur les bases
Definition: base.c:61
Psysteme build_sc_machine(int pn, int bn, int ls, Psysteme sc_array_function, entity proc_id, Pbase bank_indices, entity entity_var)
PACKAGE MOVEMENTS.
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define COLUMN_MAJOR
Package movements
#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 dimension_lower(x)
Definition: ri.h:980
#define type_variable(x)
Definition: ri.h:2949
#define dimension_upper(x)
Definition: ri.h:982
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define normalized_linear(x)
Definition: ri.h:1781
#define type_variable_p(x)
Definition: ri.h:2947
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
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 ...
Pvecteur vect_multiply(Pvecteur v, Value x)
Pvecteur vect_multiply(Pvecteur v, Value x): multiplication du vecteur v par le scalaire x,...
Definition: scalaires.c:123
#define ifdebug(n)
Definition: sg.c:47
Pvecteur vecteur
struct Scontrainte * succ
Pcontrainte inegalites
Definition: sc-local.h:71
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
struct Svecteur * succ
Definition: vecteur-local.h:92
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
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
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
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