PIPS
movement_computation.c
Go to the documentation of this file.
1 /*
2 
3  $Id: movement_computation.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 <stdlib.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 
37 #include "genC.h"
38 #include "misc.h"
39 #include "linear.h"
40 #include "ri.h"
41 #include "ri-util.h"
42 #include "constants.h"
43 #include "text-util.h"
44 #include "arithmetique.h"
45 #include "vecteur.h"
46 #include "contrainte.h"
47 #include "sc.h"
48 #include "matrice.h"
49 #include "sommet.h"
50 #include "matrix.h"
51 #include "sparse_sc.h"
52 #include "tiling.h"
53 #include "movements.h"
54 
55 /* build the base of the image domain. It corresponds to the
56  * loop indices of the generated code. Then it is
57  *
58  * Si COLUMN_MAJOR TRUE
59  * Bank_id, LJ,L,LI in case of engine code and
60  * Proc_id, LJ,L,O in case of bank code
61  * Si COLUMN_MAJOR FALSE
62  * Bank_id, LI,L,LJ in case of engine code and
63  * Proc_id, LI,L,O in case of bank code
64  *
65  * In these examples L_I, resp. L_J, corresponds to the first, resp. second,
66  * array subscript.
67  *
68  */
69 
70 #define sys_debug(level, msg, sc) \
71  ifdebug(level) { \
72  pips_debug(level, msg); \
73  sc_fprint(stderr, sc, (get_variable_name_t) entity_local_name); \
74  }
75 
77  bool bank_code,
78  Pbase proc_id,
79  Pbase bank_indices,
80  Pbase tile_indices)
81 {
82  Pvecteur pb,ti;
83  Pbase invt = base_reversal(tile_indices);
84  Pbase dupt = base_dup(tile_indices);
85 
86  debug_on("MOVEMENT_DEBUG_LEVEL");
87  debug(8,"build_image_base","begin\n");
88 
89  ti = (COLUMN_MAJOR) ? dupt:invt ;
90 
91  if (bank_code)
92  pb = vect_new(vecteur_var(bank_indices->succ->succ),VALUE_ONE);
93  else
94  pb = vect_new(ti->var,VALUE_ONE);
95  vect_add_elem(&pb,vecteur_var(bank_indices->succ),VALUE_ONE);
96 
97  if (!VECTEUR_NUL_P(ti->succ))
99 
100  if (bank_code)
101  vect_add_elem(&pb,vecteur_var(proc_id),VALUE_ONE);
102  else
103  vect_add_elem(&pb,vecteur_var(bank_indices),VALUE_ONE);
104 
105  vect_rm(dupt);
106  vect_rm(invt);
107  debug(8,"build_image_base","end\n");
108  debug_off();
109  return ((Pbase) pb);
110 }
111 
112 
113 void
115 {
116  Pvecteur pv;
117  for (pv = sb; pv !=NULL;
118  (void) fprintf(stderr,"%s_%s,",
119  entity_module_name((entity)(pv->var)),
120  entity_local_name((entity)(pv->var))),
121  pv=pv->succ);
122  (void) fprintf(stderr,"\n");
123 }
124 
125 /* Update all the basis needed for data movement generation.
126 
127  -loop_body_offsets: indices such as O or LI or LJ used to describe
128  the range of contiguous values accessed on line (of tile or bank).
129 
130  -loop_body_indices: list of the loop indices that are not
131  parameters of the tiling transformation and are situated in the
132  loop body of the tile
133 */
134 
135 void
136 update_basis(scbase,index_base,const_base,image_base,bank_indices,tile_indices,lindex,lvar_coeff_nunit,lvar_coeff_unit,loop_body_offsets,loop_body_indices, bank_code,ppid)
137 Pbase scbase;
138 Pbase *index_base;
139 Pbase *const_base;
140 Pbase *image_base;
141 Pbase bank_indices;
142 Pbase tile_indices;
143 Pbase *lindex;
144 Pbase *lvar_coeff_nunit;
145 Pbase *lvar_coeff_unit;
146 Pbase *loop_body_offsets;
147 Pbase *loop_body_indices;
148 bool bank_code;
149 Pbase ppid;
150 {
151 
152  Pvecteur pv,pv1;
153 
154  debug(8,"update_basis","begin\n");
155  ifdebug(8) {
156  (void) fprintf(stderr,"BASIS PRINTING: \n");
157  (void) fprintf(stderr," sc_base :");
158  print_fullname_base(scbase);
159  (void) fprintf(stderr," const_base :");
160  print_fullname_base(*const_base);
161  (void) fprintf(stderr," bank_indices ");
162  print_fullname_base(bank_indices);
163  (void) fprintf(stderr," index_base");
164  print_fullname_base(*index_base);
165  (void) fprintf(stderr," tile_indices");
166  print_fullname_base(tile_indices);
167  (void) fprintf(stderr," loop_body_indices");
168  print_fullname_base(*loop_body_indices); }
169 
170  for (pv = bank_indices; !VECTEUR_NUL_P(pv); pv = pv->succ)
171  vect_chg_coeff(const_base,pv->var, VALUE_ZERO);
172 
173  vect_chg_coeff(const_base,ppid->var, VALUE_ZERO);
174 
175  if (bank_code)
176  vect_chg_coeff(const_base,vecteur_var(bank_indices), VALUE_ONE);
177  else
178  vect_chg_coeff(const_base,vecteur_var(ppid), VALUE_ONE);
179 
180  for (pv = tile_indices; !VECTEUR_NUL_P(pv); pv = pv->succ)
181  vect_chg_coeff(const_base,pv->var, VALUE_ZERO);
182 
183  for (pv = *loop_body_indices; !VECTEUR_NUL_P(pv); pv = pv->succ)
184  vect_erase_var(const_base,pv->var);
185 
186  *index_base = vect_dup(scbase);
187  *lindex = vect_dup(scbase);
188  *lvar_coeff_nunit = base_dup(scbase);
189 
190  for (pv = *const_base; !BASE_NULLE_P(pv);
191  vect_erase_var(lvar_coeff_nunit, vecteur_var(pv)),
192  vect_erase_var(index_base, vecteur_var(pv)),
193  vect_erase_var(lindex, vecteur_var(pv)),
194  pv= pv->succ);
195 
196  *image_base = build_image_base(bank_code,ppid,bank_indices,tile_indices);
197 
198  for (pv1 = *image_base;
199  !BASE_NULLE_P(pv1);
200  vect_erase_var(lvar_coeff_nunit,vecteur_var(pv1)),
201  vect_erase_var(index_base,vecteur_var(pv1)),
202  vect_erase_var(lindex,vecteur_var(pv1)),
203  pv1=pv1->succ);
204 
205  *lvar_coeff_unit = base_dup(*lvar_coeff_nunit);
206  *index_base = vect_add(vect_dup(*index_base),vect_dup(*image_base));
207  *lindex = vect_add(*image_base,vect_dup(*lindex));
208  *lindex = vect_add(vect_dup(*lindex),vect_dup(*const_base));
209 
210  if (bank_code)
211  *loop_body_offsets = vect_dup(bank_indices->succ);
212  else
213  *loop_body_offsets = base_dup(tile_indices);
214  ifdebug(8) {
215  (void) fprintf(stderr,"New BASIS:");
216  print_fullname_base(*image_base);
217  (void) fprintf(stderr," base lindex:");
218  print_fullname_base(*lindex);
219  (void) fprintf(stderr," base index:");
220  print_fullname_base(*index_base);
221  (void) fprintf(stderr," lvar_coeff_nunit:");
222  print_fullname_base(*lvar_coeff_nunit);
223  (void) fprintf(stderr," lvar_coeff_unit:");
224  print_fullname_base(*lvar_coeff_unit);
225  }
226  debug(8,"update_basis","end\n");
227 }
228 
229 
230 /* Sort the tile indices base, such that the indices correspond to the
231  * tile indices of the array elements accessed by the local entity.
232  * Example: If A[I,K] is referenced. the tile indices base sould be
233  * L_I,L_K...
234 */
235 void
236 sort_tile_indices(tile_indices,new_tile_indices,Q,m)
237 Pbase tile_indices;
238 Pbase *new_tile_indices;
239 matrice Q;
240 int m;
241 {
242  register int i,j;
243  Pvecteur pv,pv2;
245 
246  for (i=1;i<=m;i++) {
247  for (j=1,pv=tile_indices; pv!=NULL;j++,pv=pv->succ) {
248  if (ACCESS(Q,m,i,j) && vect_coeff(pv->var,pv3)==0 ) {
249  pv2 = vect_new(pv->var,ACCESS(Q,m,i,j));
250  if (*new_tile_indices ==BASE_NULLE)
251  *new_tile_indices =pv2 ;
252  else pv3->succ= pv2;
253  pv3 = pv2;
254  }
255  }
256  }
257 }
258 
259 /* Build the system of inequations of sc1 no-redundant with system sc2 */
260 
261 Psysteme
262 elim_redund_sc_with_sc(sc1,sc2,index_base,dim)
263 Psysteme sc1,sc2;
264 Pbase index_base;
265 int dim;
266 {
267  Pcontrainte pc,pc2;
268  Psysteme ps1 = sc_init_with_sc(sc1);
269  Psysteme ps2 = sc_dup(sc2);
270 
271  for (pc =sc1->inegalites; pc != NULL;pc = pc->succ) {
272 
273  pc2 = contrainte_dup(pc);
274  if (search_higher_rank(pc2->vecteur,index_base) > dim ||
275  !ineq_redund_with_sc_p(ps2,pc2)) {
276  pc2 = contrainte_dup(pc);
277  sc_add_ineg(ps1,pc2);
278  pc2 = contrainte_dup(pc);
279  sc_add_ineg(ps2,pc2);
280  }
281  }
282  ps2 = sc_dup(sc2);
283 
284  for (pc = ps1->inegalites; pc != NULL;pc = pc->succ) {
285  pc2 = contrainte_dup(pc);
286  if (search_higher_rank(pc2->vecteur,index_base) > dim ||
287  !ineq_redund_with_sc_p(ps2,pc2)) {
288  pc2 = contrainte_dup(pc);
289  sc_add_ineg(ps2,pc2);
290  }
291  else eq_set_vect_nul(pc);
292  }
293 
294  sc_rm_empty_constraints(ps1, false);
295  return (ps1);
296 }
297 
298 Pbase
300  code ce) {
301  Pbase b= BASE_NULLE;
302  MAPL(p,{
303  entity e = ENTITY(CAR(p));
304  if (BASE_UNDEFINED_P(b))
305  b = vect_new((Variable) e, VALUE_ONE);
306  else vect_add_elem(&b,(Variable) e, VALUE_ONE);
307  }, code_declarations(ce));
308 
309  return(b);
310 }
311 
312 
313 /* Calcul des nouvelles bornes des boucles et de la nouvelle fonction d'acces a
314  * une reference d'un tableau permettant d'exprimer l'ensemble des elements
315  * references dans une base. Cette base est pour le moment la base de Hermite
316  * associee a la fonction d'acces au tableau
317  */
318 
319 
320 statement
322  entity module,
323  bool used_def,
324  bool bank_code, /* is true if it is the generation of code for bank
325  false if it is for engine */
326  bool receive_code, /* is true if the generated code must be a
327  RECEIVE, false if it must be a SEND*/
328  entity private_entity, /* local entity */
329  Psysteme sc_image, /* domain of image */
330  Pbase const_base,
331  Pbase bank_indices, /* contains the index describing the bank:
332  bank_id, L (ligne of bank) and O (offset in
333  the ligne) */
334  Pbase tile_indices, /* contains the local indices LI, LJ,.. of tile */
335  Pbase ppid,
336  Pbase loop_body_indices, /* contains the loop indices situated in the
337  tile*/
338  int n,
339  int dim_h)
340 {
341  Psysteme sc_proj,*list_of_systems,sc_proj2,sc_image2,sc_on_constants;
343  Pvecteur lvar_coeff_nunit = VECTEUR_NUL;
344  /* constains the list of variables for which integer projection
345  might be necessary */
346  Pvecteur lvar_coeff_unit= VECTEUR_NUL;
347 
348  Pbase lindex = BASE_NULLE;
349  /* constains the variables remaining in the system after all the
350  projections i.e. constants, index loops. It is usefull to project (FM)
351  on these variables at the end for collecting more informations on
352  variables and to eliminate redundant constraints */
353 
354  Pbase image_base=BASE_NULLE;
355  /* corresponds to the loop indices of the generated code. Then it is
356  Bank_id, LJ,L,LI in case of engine code
357  and Bank_id, LJ,L,O in case of bank code */
358 
359 
360  Pbase loop_body_offsets;
361  /* contains the local indices O and L if it is the generation of bank
362  code and LI, LJ if it is for engine code */
363 
364  Pbase index_base=BASE_NULLE;
365  Pbase const_base2;
366  Pbase var_id;
367  int dim_h2= dim_h;
368  unsigned space;
369 #define maxscinfosize 100
370  /* int sc_info[sc_image->dimension+1][3]; // this is NOT ANSI C */
371  int sc_info[maxscinfosize][4];
372  int i;
373  Pvecteur pv1= NULL;
374  Pbase btmp = BASE_NULLE;
375  debug_on("MOVEMENT_DEBUG_LEVEL");
376  debug(3,"movement_computation","begin\n");
377 
378  assert(sc_image->dimension<maxscinfosize); /* added */
379 
380  /* Translate each entity in its appropriated entity full name
381  for generating module code */
382 
384  sc_image = sc_variables_rename(sc_image, bank_indices, btmp,
386  sc_image = sc_variables_rename(sc_image, const_base, btmp,
388  sc_image = sc_variables_rename(sc_image,tile_indices, btmp,
390  bank_indices= vect_rename(bank_indices, btmp,
392  tile_indices= vect_rename(tile_indices, btmp,
394  const_base= vect_rename(const_base, btmp,
396  ppid = vect_rename(ppid, btmp,
398 
399  const_base2 =base_dup(const_base);
400  sc_image2 = sc_dup(sc_image);
401  sc_proj = sc_dup(sc_image2);
402  n = sc_image2->dimension;
403 
404  /* allocation d'un tableau de systemes et d'une table
405  contenant des infos sur ces systemes*/
406 
407  space = (n+1) * sizeof(Ssysteme);
408  list_of_systems = (Psysteme *) malloc((unsigned) space);
409  /* update the different basis */
410 
411  update_basis(sc_image2->base,&index_base,&const_base2,&image_base,
412  bank_indices,tile_indices,&lindex,&lvar_coeff_nunit,
413  &lvar_coeff_unit,&loop_body_offsets,&loop_body_indices,
414  bank_code,ppid);
415 
416 
417  dim_h2 = vect_size(image_base);
418 
419  sys_debug(2, "Domain before Projection :\n",sc_proj);
420 
421  /* Projection on each variable having unity coefficients in the system */
422 
423  for (pv1 = lvar_coeff_unit;!VECTEUR_UNDEFINED_P(pv1);pv1=pv1->succ) {
424  if (var_with_unity_coeff_p(sc_proj,vecteur_var(pv1))) {
425  sc_proj = sc_projection(sc_proj,vecteur_var(pv1));
426  sc_proj= sc_normalize(sc_proj);
427  vect_chg_coeff(&lvar_coeff_nunit,vecteur_var(pv1),0);
428  }
429  }
430 
431  sys_debug(2, " After FM projection :\n", sc_proj);
432 
433  sc_proj->inegalites = contrainte_sort(sc_proj->inegalites,
434  sc_proj->base, index_base,
435  true,false);
436  ifdebug(2) {
437  pips_debug(2," After FM projection and sort:\n");
438  sc_fprint(stderr, sc_proj, (get_variable_name_t) entity_local_name);
439  }
440 
441  /* Projection on the others variables having to be eliminated from
442  the system. In case of Copy-in local memory code generation, the
443  FM projection algorithm is used. For Copy-back code generation
444  interger projection algorithm is used.*/
445 
446  if (!used_def)
447  sc_proj = sc_integer_projection_along_variables(
448  sc_image2,sc_proj, index_base, lvar_coeff_nunit, sc_info,dim_h2,n);
449  else {
450  for (pv1 = lvar_coeff_nunit;!VECTEUR_UNDEFINED_P(pv1);pv1=pv1->succ) {
451  sc_proj = sc_projection(sc_proj,vecteur_var(pv1));
452  sc_proj= sc_normalize(sc_proj);
453  }
454  /* vect_chg_coeff(&lvar_coeff_nunit,vecteur_var(pv1),0);*/
455 
456  }
457 
458  ifdebug(2) {
459  sys_debug(2," Before contrainte sort :\n",sc_proj);
460  pips_debug(2," Base index :\n");
461  vect_fprint(stderr, index_base, (get_variable_name_t) entity_local_name);
462  }
463  sc_proj->inegalites = contrainte_sort(sc_proj->inegalites,
464  sc_proj->base, index_base,
465  true,false);
466 
467  sys_debug(5," After contrainte sort:\n",sc_proj);
468 
469  build_sc_nredund_1pass(&sc_proj);
470 
471  sys_debug(5,"After Integer Projection :\n",sc_proj);
472 
473  /* Computation of sample constraints contraining only index variables
474  */
475  sc_proj2 = sc_dup(sc_proj);
476 
477  sys_debug(4, "sc_proj2 [dup] = \n", sc_proj2);
478 
479  if (vect_size(sc_image2->base) <= 11) /* why 11? */
480  {
481  for (pv1 = const_base2; pv1 != NULL; pv1 = pv1->succ)
482  vect_erase_var(&lindex, vecteur_var(pv1));
483 
484  sc_proj = sc_projection_on_list_of_variables
485  (sc_image2, image_base, lindex);
486  sys_debug(9, "sc_proj = \n", sc_proj);
487 
488  sc_proj2 = sc_intersection(sc_proj2,sc_proj2,sc_proj);
489  sys_debug(4, "sc_proj2 [inter] = \n", sc_proj2);
490 
491  sc_proj2 = sc_normalize(sc_proj2);
492  sys_debug(4, "sc_proj2 [norm] = \n", sc_proj2);
493 
494  sys_debug(9, "sc_image2 [minmax] = \n", sc_image2);
495  sc_minmax_of_variables(sc_image2,sc_proj2,const_base2);
496  sys_debug(4, "sc_proj2 [minmax] = \n", sc_proj2);
497  }
498  else /*more restrictive system */
499  sc_minmax_of_variables(sc_image2,sc_proj2,image_base);
500 
501  sys_debug(2, "Iterat. Domain Before redundancy elimin.:\n",sc_proj2);
502 
503  /* Elimination of redundant constraints for integer systems*/
504 
505  sc_proj2->inegalites =
506  contrainte_sort(sc_proj2->inegalites,
507  sc_proj2->base, index_base,
508  false,false);
509 
510  sys_debug(2,"Iterat. Domain After 1rst sort:\n",sc_proj2);
511 
512  sc_integer_projection_information(sc_proj2,index_base, sc_info,dim_h2,n);
513  sc_proj2=build_integer_sc_nredund(sc_proj2,index_base,sc_info,1,dim_h2,n);
514  sys_debug(2," After redundancy elimination :\n",sc_proj2);
515 
516  for (i=1;i<=n;i++)
517  list_of_systems[i] = sc_init_with_sc(sc_proj2);
518 
519  /* Constraints distribution. Lsc[i] will contain all constraints
520  contraining the i-th index variable */
521 
522  constraint_distribution(sc_proj2,list_of_systems,index_base,sc_info);
523 
524  /* Computation of constraints contraining symbolic constants */
525  sc_on_constants= sc_init_with_sc(sc_proj2);
526  for (pv1 = tile_indices; pv1!=NULL; pv1=pv1->succ)
527  vect_erase_var(&const_base2, vecteur_var(pv1));
528  for (pv1 = bank_indices; pv1!=NULL; pv1=pv1->succ)
529  vect_erase_var(&const_base2, vecteur_var(pv1));
530  for (pv1 = ppid; pv1!=NULL; pv1=pv1->succ)
531  vect_erase_var(&const_base2, vecteur_var(pv1));
532 
533  /* Elimination of constraints redundant in list_of_systems[i] with the
534  "symbolic constant system" */
535 
536  sc_minmax_of_variables(sc_image2,sc_on_constants,const_base2);
537  for (i = 1; sc_on_constants != NULL && i <=vect_size(image_base);i++) {
538  list_of_systems[i] = elim_redund_sc_with_sc(list_of_systems[i],
539  sc_on_constants,
540  index_base,
541  dim_h2);
542  ifdebug(8) {
543  pips_debug(8,"Constraints on the %d-th var.:\n",i);
544  sc_fprint(stderr, list_of_systems[i], (get_variable_name_t) entity_local_name);
545  }
546  }
547 
548  var_id = (bank_code) ? vect_dup(ppid) :
549  vect_new(vecteur_var(bank_indices), VALUE_ONE);
550  stat = bound_generation(module,bank_code,receive_code,
551  private_entity,
552  loop_body_offsets,var_id,
553  list_of_systems,index_base,n,sc_info);
554 
555  ifdebug(4) {
556  /* if you get through this pp, it core dumps much later on:-) */
557  pips_debug(3, "returning:\n");
559  }
560  debug(3,"movement_computation","end\n");
561  debug_off();
562 
563  return (stat);
564 }
565 
566 
567 /* This function computes the system of constraints characterizing the
568  * image by the array function of the iteration domain
569 */
570 
571 
572 Psysteme sc_image_computation(module,entity_var,sc_domain,sc_array_function, index_base,const_base,proc_id,bank_indices,tile_indices,new_tile_indices,pn,bn,ls,n,dim_h)
573 entity module; /* module */
574 entity entity_var; /* entity */
575 Psysteme sc_domain; /* domain of iteration */
576 Psysteme sc_array_function;/* system of constraints of the array function */
577 Pbase index_base; /* index basis */
578 Pbase *const_base;
579 entity proc_id;
580 Pbase bank_indices; /* contains the index describing the bank:
581  bank_id, L (ligne of bank) and O (offset in
582  the ligne) */
583 Pbase tile_indices;
584 Pbase *new_tile_indices;
585 int pn,bn,ls; /* bank number and line size (depends on the
586  machine) */
587 int *n,*dim_h;
588 {
589 
590  Psysteme sc_image = SC_UNDEFINED;
591  Psysteme sc_machine = SC_UNDEFINED;
592  Psysteme sc_domain2 = sc_dup(sc_domain);
594  Pbase new_index_base = BASE_NULLE;
595  Pvecteur pv = VECTEUR_NUL;
596  Pvecteur pvnew = VECTEUR_NUL;
597  Pvecteur pv1= VECTEUR_NUL;
598  Pvecteur pvi=VECTEUR_NUL;
599 
600  Pbase pbv, list_new_var=BASE_NULLE;
601  matrice A,B,F0,P,HERM,HERF,R;
602  matrice F = 0;
603  matrice Q = NULL;
604  int n1,mb,i;
605  Value det_p, det_q;
606  int n2 = 0;
607  int ma =0;
608  Variable new_var;
609 
610  debug_on("MOVEMENT_DEBUG_LEVEL");
611  debug(3,"sc_image_computation","begin\n");
612 
613  ifdebug(3) {
614  pips_debug(3,"ITERATION DOMAIN:\n");
615  sc_fprint(stderr, sc_domain2, (get_variable_name_t) entity_local_name);
616  pips_debug(3,"ARRAY FUNCTION :\n");
617  sc_fprint(stderr, sc_array_function, (get_variable_name_t) entity_local_name);
618  }
619  if (!sc_faisabilite(sc_domain2))
620  (void) fprintf(stderr,"systeme non faisable en reels \n");
621  else {
622 
623  /* Computation of the system depending on the machine */
624  sc_machine = build_sc_machine(pn,bn,ls,sc_array_function,proc_id,
625  bank_indices,entity_var);
626  sc_domain2 = sc_append(sc_domain2,sc_machine);
627 
628  /* conversion des egalites en deux inegalites */
629  sc_transform_eg_in_ineg(sc_domain2);
630 
631  /*update the base of constants in the system */
632 
633  pv1 =vect_dup(sc_domain2->base);
634  for (pv = index_base;
635  !VECTEUR_NUL_P(pv);
636  vect_chg_coeff(&pv1,vecteur_var(pv),0),pv=pv->succ);
637  *const_base = pv1;
638  ifdebug(8) {
639  pips_debug(8,"\n constant basis - sc_image_computation:");
640  base_fprint(stderr, *const_base,
642  }
643 
644  /* initialisation du nombre de constantes symboliques du systeme */
645 
646  for (pv1 = index_base, ma=0;
647  !VECTEUR_NUL_P(pv1);
648  ma ++, pv1 = pv1->succ);
649  for (pv1 = *const_base, mb=1;
650  !VECTEUR_NUL_P(pv1);
651  mb ++, pv1 = pv1->succ);
652 
653  sc_image = sc_new();
654  n1 = sc_domain2->nb_ineq;
655  n2 = sc_array_function->nb_ineq;
656 
657  /* allocation et initialisation des matrices utiles */
658  A = matrice_new(n1,ma);
659  B = matrice_new(n1,mb);
660  F = matrice_new(n2,ma);
661  F0 = matrice_new(n2,mb);
662  R = matrice_new(n1,ma);
663  P = matrice_new(n2,n2);
664  Q = matrice_new(ma,ma);
665  HERM = matrice_new(n2,ma);
666  HERF= matrice_new(n2,ma);
667 
668  matrice_nulle(R,n1,ma);
669  matrice_nulle(HERF,n2,ma);
670  matrice_identite(P,n2,0);
671 
672  *n= ma;
673 
674  /* conversion du premier systeme relatif au domaine d'iteration
675  et du deuxieme systeme relatif a la fonction d'acces
676  aux elements du tableau */
677  loop_sc_to_matrices(sc_domain2,index_base,*const_base,A,B,n1,ma,mb);
678 
679  loop_sc_to_matrices(sc_array_function,index_base,
680  *const_base,F,F0,n2,ma,mb);
681 
682  /* mise sous forme normale de matrice_hermite */
683  matrice_hermite(F,n2,ma,P,HERM,Q,&det_p,&det_q);
684  ifdebug(8) {
685  sc_fprint(stderr, sc_array_function, (get_variable_name_t) entity_local_name);
686  (void) fprintf(stderr," matrice F\n");
687  matrice_fprint(stderr,F,n2,ma);
688  }
689 
690  ifdebug(8) {
691  (void) fprintf(stderr," matrice P\n");
692  matrice_fprint(stderr,P,n2,n2);
693  (void) fprintf(stderr," matrice Q\n");
694  matrice_fprint(stderr,Q,ma,ma);
695  }
696 
697  /* calcul de la dimension reelle de la fonction d'acces */
698  *dim_h = dim_H(HERM,n2,ma);
699 
700  /** Computation of the new iteration domain **/
701  matrice_multiply(A,Q,R,n1,ma,ma);
702  ifdebug(8) {
703  (void) fprintf(stderr," matrix of new iteration domain \n");
704  matrice_fprint(stderr,R,n1,ma);
705  }
706  /* conversion de la matrice en systeme */
707  for (i = 1; i<= ma;i++) {
708  new_var = sc_add_new_variable_name(module,sc_image);
709  if (i==1) {
710  new_index_base= vect_new(new_var,VALUE_ONE);
711  pvi = new_index_base;
712  }
713  else { pvi->succ = vect_new(new_var,VALUE_ONE);
714  pvi=pvi->succ;
715  }
716  }
717  matrices_to_loop_sc(sc_image,new_index_base,
718  *const_base,R,B,n1,ma,mb);
719  list_new_var = new_index_base;
720  for (i = 1,pc=sc_array_function->inegalites,pbv = list_new_var;
721  i<= ma && !CONTRAINTE_UNDEFINED_P(pc) && !VECTEUR_NUL_P(pbv);
722  i++,pc =pc->succ,pbv=pbv->succ) {
723  if (vect_size(pc->vecteur) == 1 && pc->vecteur->var == TCST) {
724  pvnew = vect_make(NULL,
725  pbv->var,VALUE_ONE,
726  TCST,value_uminus(pc->vecteur->val));
727  sc_add_inegalite(sc_image,contrainte_make(pvnew));
728  pvnew = vect_make(NULL,
729  pbv->var,VALUE_MONE,
730  TCST,pc->vecteur->val);
731  sc_add_inegalite(sc_image,contrainte_make(pvnew));
732  }
733  }
734  ifdebug(3) {
735  pips_debug(3,"NEW ITERATION DOMAIN:\n");
736  sc_fprint(stderr, sc_image, (get_variable_name_t) entity_local_name);
737  }
738 
739  /** Computation of the new matrix for array function **/
740  matrice_multiply(P,HERM,HERF,n2,n2,ma);
741  ifdebug(3) {
742  pips_debug(3," New Matrix for Array Function \n");
743  matrice_fprint(stderr,HERF,n2,ma);
744  matrice_fprint(stderr,F0,n2,mb);
745  }
746  /* conversion from matrix to system */
747  matrices_to_loop_sc(sc_array_function,
748  new_index_base,*const_base,
749  HERF,
750  F0,
751  n2,
752  ma,mb);
753  ifdebug(3) {
754  pips_debug(3,"New Array Function :\n");
755  sc_fprint(stderr, sc_array_function, (get_variable_name_t) entity_local_name);
756  }
757  }
758 
759  /* sc_transform_ineg_in_eg(sc_image);*/
760  *new_tile_indices = BASE_NULLE;
761  sort_tile_indices(tile_indices,new_tile_indices,F,n2);
762 
763 
764  ifdebug(3) {
765  pips_debug(3,"New Iteration Domain :\n");
766  sc_fprint(stderr, sc_image, (get_variable_name_t) entity_local_name);
767  }
768  debug(3,"sc_image_computation","end\n");
769  debug_off();
770 
771  return(sc_image);
772 }
773 
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
#define VALUE_ZERO
#define value_uminus(val)
unary operators on values
#define VALUE_MONE
int Value
#define VALUE_ONE
Pvecteur vect_rename(Pvecteur v, Pbase b, char *(*variable_name)(Variable))
Pvecteur vect_rename(Pvecteur v, Pbase b, char * (*variable_name)()): modify vector v so that its coo...
Definition: base.c:247
Pbase base_reversal(Pbase b_in)
Pbase base_reversal(Pbase b_in): produces a basis b_out, having the same basis vectors as b_in,...
Definition: base.c:221
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
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.
#define A(i, j)
comp_matrice.c
Definition: comp_matrice.c:63
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.
#define CONTRAINTE_UNDEFINED_P(c)
#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
Pcontrainte contrainte_dup(Pcontrainte c_in)
Pcontrainte contrainte_dup(Pcontrainte c_in): allocation d'une contrainte c_out prenant la valeur de ...
Definition: alloc.c:132
void eq_set_vect_nul(Pcontrainte)
void_eq_set_vect_nul(Pcontrainte c): transformation d'une contrainte en une contrainte triviale 0 == ...
Definition: unaires.c:84
#define F
Definition: freia-utils.c:51
void * malloc(YYSIZE_T)
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
#define B(A)
Definition: iabrev.h:61
float_t space[SIZE][SIZE]
Definition: jacobi.c:7
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
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
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
void wp65_debug_print_text(entity m, statement s)
include "values.h"
#define ACCESS(matrix, column, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrice-local.h:86
#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
int dim_H(matrice H, int n, int m)
Calcul de la dimension de la matrice de Hermite H.
Definition: hermite.c:197
void matrice_hermite(Value *MAT, int n, int m, Value *P, Value *H, Value *Q, Value *det_p, Value *det_q)
package matrice
Definition: hermite.c:78
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_nulle(matrice Z, int n, int m)
void matrice_nulle(matrice Z, int n, int m): Initialisation de la matrice Z a la valeur matrice nulle
Definition: matrice.c:311
void matrice_identite(matrice, int, int)
void matrice_identite(matrice ID, int n, int level) Construction d'une sous-matrice identite dans ID(...
Definition: sous-matrice.c:322
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 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
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
void print_fullname_base(Pbase sb)
void update_basis(Pbase scbase, Pbase *index_base, Pbase *const_base, Pbase *image_base, Pbase bank_indices, Pbase tile_indices, Pbase *lindex, Pbase *lvar_coeff_nunit, Pbase *lvar_coeff_unit, Pbase *loop_body_offsets, Pbase *loop_body_indices, bool bank_code, Pbase ppid)
Update all the basis needed for data movement generation.
#define sys_debug(level, msg, sc)
build the base of the image domain.
Pbase variables_in_declaration_list(entity __attribute__((unused)) module, code ce)
Psysteme elim_redund_sc_with_sc(Psysteme sc1, Psysteme sc2, Pbase index_base, int dim)
Build the system of inequations of sc1 no-redundant with system sc2.
Psysteme sc_image_computation(entity module, entity entity_var, Psysteme sc_domain, Psysteme sc_array_function, Pbase index_base, Pbase *const_base, entity proc_id, Pbase bank_indices, Pbase tile_indices, Pbase *new_tile_indices, int pn, int bn, int ls, int *n, int *dim_h)
This function computes the system of constraints characterizing the image by the array function of th...
#define maxscinfosize
void sort_tile_indices(Pbase tile_indices, Pbase *new_tile_indices, matrice Q, int m)
Sort the tile indices base, such that the indices correspond to the tile indices of the array element...
Pbase build_image_base(bool bank_code, Pbase proc_id, Pbase bank_indices, Pbase tile_indices)
cproto-generated files
statement movement_computation(entity module, bool used_def, bool bank_code, bool receive_code, entity private_entity, Psysteme sc_image, Pbase const_base, Pbase bank_indices, Pbase tile_indices, Pbase ppid, Pbase loop_body_indices, int n, int dim_h)
Calcul des nouvelles bornes des boucles et de la nouvelle fonction d'acces a une reference d'un table...
#define COLUMN_MAJOR
Package movements
statement bound_generation(entity module, bool bank_code, bool receive_code, entity ent, Pbase loop_body_indices, Pbase var_id, Psysteme *lsystem, Pbase index_base, int n, int sc_info[][4])
Generation of the new loop nest characterizing the new domain.
Variable sc_add_new_variable_name(entity, Psysteme)
sc_add_variable.c
#define assert(ex)
Definition: newgen_assert.h:41
#define Q
Definition: pip__type.h:39
static char * module
Definition: pips.c:74
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
code entity_code(entity e)
Definition: entity.c:1098
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define code_declarations(x)
Definition: ri.h:784
#define entity_undefined
Definition: ri.h:2761
#define statement_undefined
Definition: ri.h:2419
Psysteme sc_variables_rename(Psysteme s, Pvecteur pv_old, Pvecteur pv_new, get_variable_name_t variable_name)
Psysteme sc_variables_rename(Psysteme s, Pvecteur pv_old, Pvecteur pv_new): reecriture du systeme s r...
Definition: sc.c:224
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
Definition: sc_alloc.c:55
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_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_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
void build_sc_nredund_1pass(Psysteme volatile *ps)
Computation of a new system sc from the system ps, where each constraint of the system ps is added to...
bool ineq_redund_with_sc_p(Psysteme sc, Pcontrainte ineq)
This function returns true if the inequation ineq is redundant for the system ps and false otherwise.
Psysteme build_integer_sc_nredund(volatile Psysteme ps, Pbase index_base, int tab_info[][4], int loop_level, int dim_h __attribute__((unused)), int n __attribute__((unused)))
Computation of a new system sc from the system ps, where each constraint of the system ps is added to...
void sc_rm_empty_constraints(Psysteme ps, bool process_equalities)
package sc: elimination de redondance simple
Definition: sc_elim_eq.c:56
void sc_minmax_of_variables(Psysteme ps1, Psysteme ps2, Pbase b)
This function uses sc_minmax_of_variable to compute the min and max of each variable belonging to bas...
Definition: sc_eval.c:212
void sc_integer_projection_information(Psysteme sc, Pbase index_base, int sc_info[][4], int dim_h, int n)
This function gives information about the variables and the constraints of the system.
bool var_with_unity_coeff_p(Psysteme sc, Variable var)
This function returns true: if all positive OR all negative coefficients of the variable var in the s...
Psysteme sc_append(Psysteme s1, Psysteme s2)
Psysteme sc_append(Psysteme s1, Psysteme s2): calcul de l'intersection des polyedres definis par s1 e...
Psysteme sc_intersection(Psysteme s1, Psysteme s2, Psysteme s3)
Psysteme sc_intersection(Psysteme s1, Psysteme s2, Psysteme s3): calcul d'un systeme de contraintes s...
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 ...
Psysteme sc_normalize(Psysteme ps)
Psysteme sc_normalize(Psysteme ps): normalisation d'un systeme d'equation et d'inequations lineaires ...
void sc_transform_eg_in_ineg(Psysteme sc)
Package sc.
Pcontrainte contrainte_sort(Pcontrainte c, Pbase base, Pbase sort_base, bool inner_first, bool complex_first)
#define ifdebug(n)
Definition: sg.c:47
void loop_sc_to_matrices(Psysteme, Pbase, Pbase, matrice, matrice, int, int, int)
Creation de la matrice A correspondant au systeme lineaire et de la matrice correspondant a la partie...
void matrices_to_loop_sc(Psysteme, Pbase, Pbase, matrice, matrice, int, int, int)
Definition: pip__tab.h:25
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
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
Definition: statement.c:4047
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define BASE_UNDEFINED_P(b)
#define VECTEUR_UNDEFINED
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
#define VECTEUR_NUL_P(v)
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_NULLE
MACROS SUR LES BASES.
#define BASE_NULLE_P(b)
#define VECTEUR_UNDEFINED_P(v)
Pvecteur vect_make(Pvecteur v, Variable var, Value val,...)
Pvecteur vect_make(v, [var, val,]* 0, val) Pvecteur v; // may be NULL, use assigne anyway Variable va...
Definition: alloc.c:165
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
Pbase base_dup(Pbase b)
Pbase base_dup(Pbase b) Note: this function changes the value of the pointer.
Definition: alloc.c:268
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
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
Pvecteur vect_add(Pvecteur v1, Pvecteur v2)
package vecteur - operations binaires
Definition: binaires.c:53
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106
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
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val)
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val): mise de la coordonnee var du vecteur *pp...
Definition: unaires.c:143