PIPS
ss.c
Go to the documentation of this file.
1 /*
2 
3  $Id: ss.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 #include "all.h"
28 
29 
30 /*{{{ my vect var subst function */
31 
32 /* mimicked this function from paf-tuil/utils.c
33  because it was misbehaving !!
34  */
36 {
38  Value val;
39 
40  if ((val = vect_coeff(var,vect)) != 0)
41  {
42  vect_erase_var(&vect,var);
43  vect_aux = vect_multiply(new_vect,val);
44  vect = vect_add(vect, vect_aux);
45  }
46 
47  return(vect);
48 }
49 
51 Pvecteur pvec1,pvec2;
52 {
53  int coeff;
54  Pvecteur dvec = vect_dup (pvec1);
55 /* Pvecteur var_val;
56  for (var_val = pvec2; var_val!= NIL;
57  vect_add_elem (&dvec,var_of(var_val),-val_of(var_val)),var_val=var_val->succ);
58  */
59 
60  Pvecteur v2 = pvec2;
61  for ( ; v2!= NULL; v2=v2->succ) {
62  coeff = 0-(val_of(v2));
63  vect_add_elem (&dvec,var_of(v2), coeff);
64  }
65 
66  return (dvec);
67 }
68 
69 /*}}}*/
70 
71 /*{{{ PrintSimpleSection */
72 /*{{{ PrintCompRegions */
73 void
75 {
76  if (CompList != NIL) {
77  MAP(COMP_DESC, Cdesc,
78  {
79  PrintSimp(Cdesc);
80  }, CompList);
81  }
82 }
83 
84 /*}}}*/
85 /*{{{ PrintLinExpr */
86 void
88 {
89  /* call the approprite print routine : check later */
90  if (Lin != NULL)
91  vect_debug(Lin);
92  else
93  fprintf(stderr, "NULL");
94 }
95 
96 /*}}}*/
97 /*{{{ PrintSimp */
98 void
100 {
101  fprintf(stderr, "*********************************************************************\n");
102  DisplayDad(Dad);
103  fprintf(stderr, "---------------------------------------------------------------------\n");
104 }
105 
106 void
108 {
111 
112  fprintf(stderr, "\nData Access Descriptor for %s \n", entity_minimal_name(Var));
113 
114  DisplayRefTemp(Dad);
116  fprintf(stderr, "\n");
117 
118 }
119 
120 /*}}}*/
121 /*{{{ DisplayRefTemp */
122 void
124 {
125  unsigned Rank;
126  unsigned int i;
128 
130 
131  fprintf(stderr, "\nReference Template :: \n[ ");
132  for (i = 0; i < Rank; i++) {
133  RefType = GetRefTemp(Dad, i);
134  switch (RefType) {
136  fprintf(stderr, "INV");
137  break;
138  case is_rtype_linvariant:
139  fprintf(stderr, "VAR");
140  break;
141  case is_rtype_nonlinear:
142  fprintf(stderr, "NON");
143  break;
144  default:
145  fprintf(stderr, "NUL");
146  break;
147  }
148 
149  if (i < (Rank - 1))
150  fprintf(stderr, ", ");
151  else
152  fprintf(stderr, " ]\n");
153  }
154  fprintf(stderr, "\n");
155 }
156 
157 /*}}}*/
158 /*{{{ DisplaySimpSec */
159 
160 void
162 {
163  unsigned int i, I, J, K;
164  unsigned Rank = context_info_rank(simple_section_context(Dad));
165 
166  fprintf(stderr, "\nBoundary Pairs ::\n");
167  /*{{{ xi = c */
168 
169  for (i = 0; i < Rank; i++) {
170  PrintLinExpr(LSEC(Dad, i));
171  fprintf(stderr, " <= X%d <= ", i);
172  PrintLinExpr(USEC(Dad, i));
173  fprintf(stderr, "\n");
174  }
175  /*}}}*/
176 
177  /*{{{ Xi+Xj = c */
178  I = 0;
179  K = Rank - I - 2;
180  J = I + 1;
181  for (; i < ((Rank * (Rank + 1)) / 2); i++) {
182  /*{{{ print */
183  PrintLinExpr(LSEC(Dad, i));
184  fprintf(stderr, " <= X%d + X%d <= ", I, J);
185  PrintLinExpr(USEC(Dad, i));
186  fprintf(stderr, "\n");
187  /*}}}*/
188  /*{{{ index */
189  if (K < 1) {
190  I += 1;
191  J = I + 1;
192  K = Rank - I - 2;
193  } else {
194  K -= 1;
195  J += 1;
196  }
197  /*}}}*/
198  }
199  /*}}}*/
200  /*{{{ Xi-Xj */
201  I = 0;
202  K = Rank - I - 2;
203  J = I + 1;
204  for (; i < (Rank * Rank); i++) {
205  PrintLinExpr(LSEC(Dad, i));
206  fprintf(stderr, " <= X%d - X%d <= ", I, J);
207  PrintLinExpr(USEC(Dad, i));
208  fprintf(stderr, "\n");
209  if (K < 1) {
210  I += 1;
211  J = I + 1;
212  K = Rank - I - 2;
213  } else {
214  K -= 1;
215  J += 1;
216  }
217  }
218  /*}}}*/
219 
220  fprintf(stderr, "\n");
221 
222 }
223 
224 /*}}}*/
225 /*}}}*/
226 /*{{{ auxilliary functions */
227 /*{{{ GetRefTemp */
228 tag
230 {
232  tag ret_tag = tag_undefined;
233 
234  FOREACH(REF_TEMP, Ref, Rtemp)
235  {
236  if (ref_temp_index(Ref) == DimNo) {
237  ret_tag = rtype_tag(ref_temp_rtype(Ref));
238  break;
239  }
240  }
241 
242  return(ret_tag);
243 }
244 
245 /*}}}*/
246 /*{{{ PutRefTemp */
247 void
249 {
251 
252  MAP(REF_TEMP, rt,
253  {
254  if (ref_temp_index(rt) == DimNo) {
256  return;
257  }
258  }, Rtemp);
259 
260 }
261 
262 /*}}}*/
263 /*{{{ GetBoundaryPair */
264 /* return the lower or upper boundary */
265 LinExpr
266 GetBoundary(simple_section Dad, int DimNo, unsigned Low)
267 {
268  list BoundPair = dad_struct_shape(simple_section_dad(Dad));
269  LinExpr Lin = NULL;
270 
271  MAP(BOUND_PAIR, bp,
272  {
273  if (bound_pair_index(bp) == DimNo) {
274  if (Low == 1) {
275  Lin = bound_pair_lb(bp);
276  } else {
277  Lin = bound_pair_ub(bp);
278  }
279  break;
280  }
281  }, BoundPair);
282 
283  return(Lin);
284 }
285 
286 /*}}}*/
287 /*{{{ PutBoundryPair */
288 /* substitute with new boundary */
289 void
291 {
292  list BoundPair = dad_struct_shape(simple_section_dad(Dad));
293 
294  ifdebug(5) {
295  pips_debug(5, "PutBoundPair : dump Low and Up vectors \n");
296  PrintLinExpr(Low);
297  PrintLinExpr(Up);
298  }
299 
300  MAP(BOUND_PAIR, bp,
301  {
302  if (bound_pair_index(bp) == DimNo) {
303  if (Low != NULL) {
304  /* check later vect_rm(bound_pair_lb(bp)); */
305  bound_pair_lb_(bp) = (Pvecteur) Low;
306  }
307  if (Up != NULL) {
308  /* check later vect_rm(bound_pair_ub(bp)); */
309  bound_pair_ub_(bp) = (Pvecteur) Up;
310  }
311  return;
312  }
313  }, BoundPair);
314 }
315 
316 /*}}}*/
317 /*{{{ MinBoundary */
318 /* substitute with new boundary */
319 LinExpr
321 {
322  int Result;
323 
324  Result = vect_compare(&Lin1, &Lin2);
325  if (Result < 0)
326  return (vect_dup(Lin1));
327  else
328  return (vect_dup(Lin2));
329 }
330 
331 /*}}}*/
332 /*{{{ MaxBoundary */
333 /* substitute with new boundary */
334 LinExpr
336 {
337  int Result;
338 
339  Result = vect_compare(&Lin1, &Lin2);
340  if (Result > 0)
341  return (vect_dup(Lin1));
342  else
343  return (vect_dup(Lin2));
344 }
345 
346 /*}}}*/
347 /*{{{ MergeLinExprs */
348 LinExpr
350 {
351  /* must free Expr1 because vect_add will return a copy : check later */
352  if (Op == PLUS)
353  return (vect_add(Expr1, Expr2));
354  else
355  return (my_vect_substract(Expr1, Expr2));
356 }
357 
358 /*}}}*/
359 /*{{{ ComputeIndex */
360 /* compute index of tSS array for a boundary */
361 unsigned int
362 ComputeIndex(unsigned int I, unsigned int J, unsigned int Rank)
363 {
364  unsigned int LoIndex, HiIndex, Index, i;
365 
366  LoIndex = (I < J) ? I : J;
367  HiIndex = (I < J) ? J : I;
368  Index = 0;
369  for (i = 1; i < (LoIndex + 1); i++)
370  Index = Index + (Rank - i);
371  Index = Index + (HiIndex - LoIndex) - 1;
372  return (Index);
373 }
374 
375 /*}}}*/
376 /*{{{ CopyAccVec */
377 LinExpr
379 {
380  /* re-used function from alloc.c */
381  return (vect_dup(Expr));
382 }
383 
384 /*}}}*/
385 
386 /* check whether a given expresion is a constant */
387 bool
389 {
390  return (vect_constant_p(Expr));
391 }
392 
393 
394 /* check whether loop index variable var is contained in LinExpr */
395 bool
397 {
398  entity ent;
399  Pvecteur Vec;
400  bool Val;
401 
402  ent = loop_index(Loop);
403  Vec = (Pvecteur) Lin;
404  Val = vect_contains_variable_p(Vec, (Variable) ent);
405  return (Val);
406 
407 }
408 
409 /* return the n'th subscript expression */
410 expression
411 GetAccVec(unsigned No, const reference ref)
412 {
413  unsigned Cur = 0;
414  list inds = reference_indices(ref);
415 
416  MAP(EXPRESSION, index,
417  {
418  if (Cur == No)
419  return (index);
420  Cur++;
421  }, inds);
422 
423  return (NULL);
424 
425 }
426 
427 unsigned int
429 {
430  /* re-used Pips functional programs !!! */
431  return gen_length(gl);
432 }
433 
434 
435 
436 /*}}}*/
437 /*{{{ allocate simple section */
438 /* allocate a structure to hold Dad */
439 dad_struct
441 {
442  dad_struct Dad;
443  bound_pair Bounds;
444  int cnt;
445  list RefTempList = NIL;
446  list BoundList = NIL;
448 
449  /* initialize the reference template */
450  for (cnt = 0; cnt < Rank; cnt++) {
451  RefTempList = gen_nconc(RefTempList,
452  CONS(REF_TEMP,make_ref_temp(cnt, Ref), NIL));
453  }
454 
455  /* initialize the shape */
456  for (cnt = 0; cnt < Rank * Rank; cnt++) {
457  Bounds = make_bound_pair(cnt, NULL, NULL);
458  BoundList = gen_nconc(BoundList, CONS(BOUND_PAIR, Bounds, NIL));
459  }
460 
461  Dad = make_dad_struct(RefTempList, BoundList);
462 
463  return (Dad);
464 }
465 
468 {
469 #define LINE 0
470  unsigned int Rank;
471  context_info Context;
472  dad_struct DadStruct;
473  simple_section Dad;
474  variable TmpVar;
475 
477 
478  /*{{{ intialize the data structure */
479  Rank = CardinalityOf(variable_dimensions(TmpVar));
480  Context = make_context_info(LINE, Rank, ZERO);
481  DadStruct = AllocateDadStruct(Rank);
482  Dad = make_simple_section(Context, DadStruct);
483  /*}}}*/
484  return (Dad);
485 }
486 
487 /*}}}*/
488 /*{{{ translate inner most references */
489 void
491 {
492  /*
493  * unfortunately an access vector cannot tell to which dimension it
494  * corresponds hence this round about of explicitly tracking the dimension
495  * number
496  */
497  unsigned int DimNo;
498  expression exp_ind;
499  simple_section Dad;
500  reference ref;
501  list inds;
502 
503  pips_debug(3, "begin\n");
504 
505  Dad = comp_sec_hull(comp_desc_section(Desc));
506  ref = comp_desc_reference(Desc);
507 
508  inds = reference_indices(ref);
509 
510  for (DimNo = 0; inds != NIL; DimNo++, inds = CDR(inds)) {
511  /*{{{ init RT and SS */
512  exp_ind = EXPRESSION(CAR(inds));
513  ComputeRTandSS(exp_ind, DimNo, Dad, Loop);
514  /*}}}*/
515  }
516 
517  pips_debug(3, "end\n");
518 
519 }
520 
521 /* initialise reference template and shapes for inner most references */
522 /* for an access vector */
523 void
524 ComputeRTandSS(expression Sub, unsigned DimNo, simple_section Dad, loop Loop)
525 {
526  normalized Nexpr;
527 
528  Nexpr = NORMALIZE_EXPRESSION(Sub);
529 
530  if (!normalized_linear_p(Nexpr)) {
531  /*{{{ non-linear */
532  /*
533  * non linear subscripts if it is non-linear we don't bother to
534  * distinguish between invariant and variant ; they are just non-linear
535  */
536  PutRefTemp(Dad, DimNo, is_rtype_nonlinear);
537  /*}}}*/
538  }
539  else {
540  LinExpr Low, Up;
541 
542  /*{{{ linear */
543  /* copy the subscript expression into the shape descriptor */
544  Low = CopyAccVec(normalized_linear(Nexpr));
545  Up = CopyAccVec(normalized_linear(Nexpr));
546 
547  PutBoundPair(Dad, DimNo, Low, Up);
548 
549  if(IsExprConst(normalized_linear(Nexpr)) == true ) {
550  PutRefTemp(Dad, DimNo, is_rtype_linvariant);
551  }
552  else {
553  /* linear subscripts : update if DIV exists */
554  if (DivExists(Loop, normalized_linear(Nexpr))) {
555  Low = Lbound(Loop, LSEC(Dad, DimNo));
556  Up = Ubound(Loop, USEC(Dad, DimNo));
557  PutBoundPair(Dad, DimNo, Low, Up);
558  PutRefTemp(Dad, DimNo, is_rtype_linvariant);
559  }
560  else {
561  PutRefTemp(Dad, DimNo, is_rtype_lininvariant);
562  }
563  }
564  /*}}}*/
565  }
566 }
567 
568 /*}}}*/
569 /*{{{ translate to outer loop comp list */
570 /*
571  * Input a list of complement descriptors and translate the sections to the
572  * enclosing loop context modifies : ListOfComplements
573  */
574 
575 /*{{{ translate the set to the outer loop */
576 void
577 TranslateRefsToLoop(loop ThisLoop, list ListOfComps)
578 {
579  MAP(COMP_DESC, Desc,
580  {
581  TranslateToLoop(ThisLoop, Desc);
582  }, ListOfComps);
583 
584 }
585 
586 /*}}}*/
587 /*{{{ translate to loop */
588 void
590 {
591  tVariants Vars;
592  simple_section Dad;
593 
594  if (GET_NEST(Desc) == ZERO) {
595  ScanAllDims(ThisLoop, Desc);
596  PUT_NEST(Desc,SINGLE);
597  }
598  else {
599  Vars = TransRefTemp(ThisLoop, Desc);
600  TransSimpSec(Desc, ThisLoop, &Vars);
601  PUT_NEST(Desc,MULTI);
602  }
603 
604  Dad = comp_sec_hull(comp_desc_section(Desc));
605  UpdateUnresolved(Dad, ThisLoop);
606 
607 }
608 
609 /*}}}*/
610 /*{{{ TransRefTemp */
611 tVariants
612 TransRefTemp(loop ThisLoop, comp_desc Desc)
613 {
614  tVariants Vars;
615  simple_section Dad;
616  _int DimNo, Rank;
617  normalized Nexpr;
618  expression TmpExpr;
619  list OldList, NewList, NewEle;
620 
621 
622  comp_sec Csec = comp_desc_section(Desc);
624 
625  Dad = comp_sec_hull(Csec);
627 
628  pips_debug(3, "begin\n");
629 
630  OldList = NIL;
631  NewList = NIL;
632 
633  /* iterate through all entries of reference template */
634  for (DimNo = 0; DimNo < Rank; DimNo++) {
635  /* process only linear elements */
636  if (!(GetRefTemp(Dad, DimNo) == is_rtype_nonlinear)) {
637  /* Pass only normalized expression into Divexists */
638  TmpExpr = GetAccVec(DimNo, Ref);
639  Nexpr = NORMALIZE_EXPRESSION(TmpExpr);
640 
641  if (DivExists(ThisLoop, normalized_linear(Nexpr))) {
642  /* variant w.r.t this loop index */
643  NewEle = CONS(INT, DimNo, NIL);
644  NewList = gen_nconc(NewList, NewEle);
645  PutRefTemp(Dad, DimNo, is_rtype_linvariant);
646  } else {
647  /*
648  * invariant w.r.t. this loop index; but variant w.r.t. previous loop
649  * constant subscripts will also get included in the old list
650  */
651  if (GetRefTemp(Dad, DimNo) == is_rtype_linvariant)
652  OldList = gen_nconc(OldList, CONS(INT, DimNo, NIL));
653  }
654  }
655  }
656 
657  Vars.Old = OldList;
658  Vars.New = NewList;
659 
660  pips_debug(3, "end\n");
661  return (Vars);
662 }
663 
664 /*}}}*/
665 /*{{{ TransSimpSec */
666 void
668 {
669  /*{{{ declarations */
670  unsigned Index, I, J;
671  LinExpr lbExpr, ubExpr;
672  unsigned ZhiExprNo;
673  unsigned Rank = context_info_rank(simple_section_context(Dad));
674  /*}}}*/
675  /*{{{ Update unresolved boundaries */
676  /*{{{ update parallel or diagonal boundaries with induction variable */
677  if (Loop != NULL) {
678  /*{{{ scan all dimensions */
679  for (ZhiExprNo = 0; ZhiExprNo < Rank; ZhiExprNo++) {
680  lbExpr = LSEC(Dad, ZhiExprNo);
681  ubExpr = USEC(Dad, ZhiExprNo);
682  if (DivExists(Loop, lbExpr))
683  lbExpr = Lbound(Loop, lbExpr);
684  if (DivExists(Loop, ubExpr))
685  ubExpr = Ubound(Loop, ubExpr);
686  PutBoundPair(Dad, ZhiExprNo, lbExpr, ubExpr);
687 
688  /* ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, ZhiExprNo); */
689 
690  }
691  /*}}}*/
692  }
693  /*}}}*/
694  /*{{{ update diagonal boundaries whose parallel components are constants */
695  for (I = 0; I < Rank; I++) {
696  for (J = I + 1; J < Rank; J++) {
697  if ((GetRefTemp(Dad, I) != is_rtype_nonlinear) && (GetRefTemp(Dad, J) != is_rtype_nonlinear)) {
698  /*{{{ process only linear subscripts */
699  /*{{{ compute index */
700  int PlusOffset, MinusOffset;
701  Index = ComputeIndex(I, J, Rank);
702  PlusOffset = Rank + Index;
703  MinusOffset = ((Rank * (Rank + 1)) / 2) + Index;
704  /*}}}*/
705  /*{{{ update diagonals */
706  /*{{{ update Xi + Xj */
707  /* lower boundary */
708  /* bug fix : check boundary otherwise it will get overwritten */
709  if (LSEC(Dad, PlusOffset) == NULL) {
710  /*{{{ update */
711  if (IsExprConst(LSEC(Dad, I)) && IsExprConst(LSEC(Dad, J))) {
712  /* copy done in MergeLinExpr lbExpr = CopyAccVec(LSEC(Dad, I)); */
713  lbExpr = MergeLinExprs(LSEC(Dad, I), LSEC(Dad, J), PLUS);
714  /* LSEC(Dad,PlusOffset) = lbExpr; */
715  PutBoundPair(Dad, PlusOffset, lbExpr, NULL);
716  }
717  /*}}}*/
718  }
719  /* upper boundary */
720  if (USEC(Dad, PlusOffset) == NULL) {
721  /*{{{ update */
722  if (IsExprConst(USEC(Dad, I)) && IsExprConst(USEC(Dad, J))) {
723  ubExpr = MergeLinExprs(USEC(Dad, I), USEC(Dad, J), PLUS);
724  /* USEC(PlusOffset) = ubExpr; */
725  PutBoundPair(Dad, PlusOffset, NULL, ubExpr);
726  }
727  /*}}}*/
728  }
729  /*}}}*/
730  /*{{{ update Xi - Xj */
731  /* lower boundary */
732  if (LSEC(Dad, MinusOffset) == NULL) {
733  /*{{{ upate */
734  if (IsExprConst(LSEC(Dad, J)) && IsExprConst(USEC(Dad, I))) {
735  /* lbExpr = CopyAccVec(LSEC(J)); */
736  lbExpr = MergeLinExprs(LSEC(Dad, J), USEC(Dad, I), MINUS);
737  /* LSEC(MinusOffset) = lbExpr; */
738  PutBoundPair(Dad, MinusOffset, lbExpr, NULL);
739  }
740  /*}}}*/
741  }
742  /* upper boundary */
743  if (USEC(Dad, MinusOffset) == NULL) {
744  /*{{{ update */
745  if (IsExprConst(USEC(Dad, J)) && IsExprConst(LSEC(Dad, I))) {
746  /* ubExpr = CopyAccVec(USEC(J)); */
747  ubExpr = MergeLinExprs(USEC(Dad, J), LSEC(Dad, I), MINUS);
748  /* USEC(MinusOffset) = ubExpr; */
749  PutBoundPair(Dad, MinusOffset, NULL, ubExpr);
750  }
751  /*}}}*/
752  }
753  /*}}}*/
754  /*}}}*/
755  /*}}}*/
756  }
757  }
758  }
759  /*}}}*/
760  /*}}}*/
761 }
762 
763 /* compute both boundary expression and store in the tSS array */
764 void
765 ComputeBoundaries(simple_section Dad, loop Loop, LinExpr lbExpr, LinExpr ubExpr, unsigned Offset)
766 {
767  LinExpr Low, Up;
768 
769  Low = lbExpr;
770  Up = ubExpr;
771 
772  /*{{{ about */
773  if (DivExists(Loop, lbExpr))
774  Low = Lbound(Loop, lbExpr);
775  if (DivExists(Loop, ubExpr))
776  Up = Ubound(Loop, ubExpr);
777  PutBoundPair(Dad, Offset, Low, Up);
778  /*}}}*/
779 }
780 
781 void
783 {
784  /*{{{ declarations */
785  unsigned Index, Offset;
786  LinExpr lbExpr, ubExpr, TmpExpr1, TmpExpr2;
787 
789  unsigned Rank = context_info_rank(simple_section_context(Dad));
790  list Old = Vars->Old;
791  list New = Vars->New;
792  /*}}}*/
793 
794  pips_debug(3, "begin\n");
795 
796  /*{{{ Diagonal Boundaries for old and new */
797  MAP(INT, I,
798  {
799  MAP(INT, J,
800  {
801  /*{{{ compute offset in the tSS array to store diagonal boundaries */
802  Index = ComputeIndex(I, J, Rank);
803  /*}}}*/
804  /*{{{ compute diagonal boundaries Xi + Xj */
805  /* compute index for tSS array */
806  Offset = Rank + Index;
807  /* copying done inside MergeLinExprs
808  lbExpr = CopyAccVec(LSEC(Dad, I));
809  TmpExpr1 = CopyAccVec(LSEC(Dad, J));
810  */
811  lbExpr = LSEC(Dad, I);
812  TmpExpr1 = LSEC(Dad, J);
813  lbExpr = MergeLinExprs(lbExpr, TmpExpr1, PLUS);
814  /*
815  ubExpr = CopyAccVec(USEC(Dad, I));
816  TmpExpr2 = CopyAccVec(USEC(Dad, J));
817  */
818  ubExpr = USEC(Dad, I);
819  TmpExpr2 = USEC(Dad, J);
820  ubExpr = MergeLinExprs(ubExpr, TmpExpr2, PLUS);
821  ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, Offset);
822  /*}}}*/
823  /*{{{ compute diagonal boundaries Xi - Xj */
824  /* compute index for tSS array */
825  Offset = (Rank * (Rank + 1)) / 2 + Index;
826  /*
827  lbExpr = CopyAccVec(LSEC(Dad, I));
828  TmpExpr1 = CopyAccVec(USEC(Dad, J));
829  */
830  lbExpr = LSEC(Dad, I);
831  TmpExpr1 = USEC(Dad, J);
832  lbExpr = MergeLinExprs(lbExpr, TmpExpr1, MINUS);
833  /*
834  ubExpr = CopyAccVec(USEC(Dad, I));
835  TmpExpr2 = CopyAccVec(LSEC(Dad, J));
836  */
837  ubExpr = USEC(Dad, I);
838  TmpExpr2 = LSEC(Dad, J);
839  ubExpr = MergeLinExprs(ubExpr, TmpExpr2, MINUS);
840  ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, Offset);
841  /*}}}*/
842  }, New);
843  }, Old);
844  /*}}}*/
845  /*{{{ Compute parallel boundaries only for new variants */
846  MAP(INT, J,
847  {
848  /*{{{ compute Xi = c */
849  /* bug unsigned Offset = J; */
850  lbExpr = CopyAccVec(LSEC(Dad, J));
851  ubExpr = CopyAccVec(USEC(Dad, J));
852  ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, J);
853  /*}}}*/
854  }, New);
855  /*}}}*/
856  /*{{{ Compute diagonal boundaries for new variants */
857  /* set size must be atleast 2 */
858  if (CardinalityOf(New) > 1) {
859  int I, J;
860 
861  /*{{{ compute diagonals */
862  /* set an iterator for the newvar */
863  list New_iter1;
864  list New_iter2;
865  New_iter1 = Vars->New;
866  for (; !ENDP(New_iter1); (New_iter1 = CDR(New_iter1))) {
867  /*{{{ iterators 1 and 2 */
868  I = INT(CAR(New_iter1));
869  /* set this iterator to next element in the first list */
870  New_iter2 = CDR(New_iter1);
871  /*}}}*/
872  for (; !ENDP(New_iter2); New_iter2 = CDR(New_iter2)) {
873  J = INT(CAR(New_iter2));
874  /*{{{ compute index for storing in tSS array */
875  Index = ComputeIndex(I, J, Rank);
876  /*}}}*/
877  /*{{{ compute diagonal boundary Xi + Xj */
878  Offset = Rank + Index;
879  TmpExpr1 = LSEC(Dad, J);
880  lbExpr = MergeLinExprs(LSEC(Dad, I), TmpExpr1, PLUS);
881  TmpExpr2 = USEC(Dad, J);
882  ubExpr = MergeLinExprs(USEC(Dad, I), TmpExpr2, PLUS);
883  ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, Offset);
884  /*}}}*/
885  /*{{{ compute diagonal boundary Xi - Xj */
886  Offset = ((Rank * (Rank + 1)) / 2) + Index;
887  TmpExpr1 = USEC(Dad, J);
888  lbExpr = MergeLinExprs(LSEC(Dad, I), TmpExpr1, MINUS);
889  TmpExpr2 = LSEC(Dad, J);
890  ubExpr = MergeLinExprs(USEC(Dad, I), TmpExpr2, MINUS);
891  ComputeBoundaries(Dad, Loop, lbExpr, ubExpr, Offset);
892  /*}}}*/
893  }
894  }
895  /*}}}*/
896  }
897  /*}}}*/
898 
899  pips_debug(3, "end\n");
900 }
901 
902 /*}}}*/
903 /*}}}*/
904 /*{{{ lbound and ubound */
905 /*
906  * compute lower bound input : a loop header and a linear expression output :
907  * updated boundary expression modifies : the input linear expression
908  */
909 LinExpr
910 Lbound(loop Loop, LinExpr Lin)
911 {
912  /*
913  * preconditions : lbound is invoked only if DivExists and if only on
914  * LinExprs
915  */
916 
917  expression TmpExpr;
918  normalized Nexpr;
919  LinExpr NewLin, NewVect;
920  entity Var = loop_index(Loop);
921 
922  /* only one step in pips ! it provides direct substitution functions */
923  /*{{{ substitution step */
924  /*
925  * use the lower/upper bound of the index variable depending on the sign of
926  * the coefficient
927  */
928  /*
929  * this needs to be changed if the representation for linear expression is
930  * changed to accommodate symbolic coefficients
931  */
932 
933  int Val = vect_coeff((Variable) Var, Lin);
934  if ((Val > 0)) {
935  /* substitute with lower bound */
936  TmpExpr = range_lower(loop_range(Loop));
937  } else {
938  /* substitute with upper bound */
939  TmpExpr = range_upper(loop_range(Loop));
940  }
941 
942  Nexpr = NORMALIZE_EXPRESSION(TmpExpr);
943  if (normalized_linear_p(Nexpr)) {
944  /* make a copy because vect_var_subst modifies NewVect */
945  NewVect = CopyAccVec(normalized_linear(Nexpr));
946  NewLin = my_vect_var_subst(Lin, (Variable) Var, NewVect);
947  }
948  else {
949  NewLin = NULL;
950  }
951 
952  /*}}}*/
953  return (NewLin);
954 }
955 
956 /*
957  * compute upper bound input : a loop header and a linear expression output :
958  * updated boundary expression modifies : the input linear expression
959  */
960 LinExpr
961 Ubound(loop Loop, LinExpr Lin)
962 {
963  /*
964  * preconditions : Ubound is invoked only if DivExists and only on LinExprs
965  */
966  expression TmpExpr;
967  LinExpr NewLin, NewVect;
968  normalized Nexpr;
969 
970  entity Var = loop_index(Loop);
971 
972  /* only one step in pips ! it provides direct substitution functions */
973  /*{{{ substitution step */
974  /*
975  * use the lower/upper bound of the index variable depending on the sign of
976  * the coefficient
977  */
978  /*
979  * this needs to be changed if the representation for linear expression is
980  * changed to accommodate symbolic coefficients
981  */
982 
983  int Val = vect_coeff((Variable) Var, Lin);
984  if ((Val < 0)) {
985  /* substitute with lower bound */
986  TmpExpr = range_lower(loop_range(Loop));
987  } else {
988  /* substitute with upper bound */
989  TmpExpr = range_upper(loop_range(Loop));
990  }
991 
992  Nexpr = NORMALIZE_EXPRESSION(TmpExpr);
993  if (normalized_linear_p(Nexpr) ) {
994  /* make a copy because vect_var_subst modifies NewVect */
995  NewVect = CopyAccVec(normalized_linear(Nexpr));
996  NewLin = my_vect_var_subst(Lin, (Variable) Var, NewVect);
997  }
998  else {
999  NewLin = NULL;
1000  }
1001 
1002  /*}}}*/
1003  return (NewLin);
1004 }
1005 
1006 /*}}}*/
1007 /*{{{ SimpUnion */
1008 /*
1009  * input : two simple descriptors output : the union descriptor modifies :
1010  * nothing
1011  */
1014 {
1015 /* SG: i am unsure this is a valid init */
1017  tag Variant;
1018  size_t i;
1019  LinExpr Low = NULL, Up = NULL;
1020  size_t Rank = context_info_rank(simple_section_context(S1));
1021 
1022  /* allocate a simple_section */
1023 
1024  /*{{{ update reference template */
1025  /* update reference template */
1026  /* if a subscript is invariant or boundary expression is not constant */
1027  /* then whole dimension is assumed to be used */
1028  for (i = 0; i < Rank; i++) {
1029  Variant = ((GetRefTemp(S1, i) == is_rtype_linvariant) &&
1030  (GetRefTemp(S2, i) == is_rtype_linvariant)) ?
1032  PutRefTemp(UnionDad, i, Variant);
1033  }
1034  /*}}}*/
1035  /*{{{ update simple sections */
1036  /* scan all boundary pairs */
1037  for (i = 0; i < (Rank * Rank); i++) {
1038  /* later insert code for releasing the space of LSEC and USEC */
1039  if ((LSEC(S1, i) != NULL) && (LSEC(S2, i) != NULL)) {
1040  /* compute new lower boundary in the union */
1041  Low = MinBoundary(LSEC(S1, i), LSEC(S2, i));
1042  }
1043  if ((USEC(S1, i) != NULL) && (USEC(S2, i) != NULL)) {
1044  /* compute new upper boundary in the union */
1045  Up = MaxBoundary(USEC(S1, i), USEC(S2, i));
1046  }
1047  PutBoundPair(UnionDad, i, Low, Up);
1048  }
1049  /*}}}*/
1050 
1051  return (UnionDad);
1052 }
1053 
1054 /*}}}*/
ref_temp make_ref_temp(intptr_t a1, rtype a2)
Definition: compsec.c:306
rtype make_rtype(enum rtype_utype tag, void *val)
Definition: compsec.c:356
bound_pair make_bound_pair(intptr_t a1, Pvecteur a2, Pvecteur a3)
Definition: compsec.c:54
simple_section make_simple_section(context_info a1, dad_struct a2)
Definition: compsec.c:407
context_info make_context_info(intptr_t a1, intptr_t a2, intptr_t a3)
Definition: compsec.c:222
dad_struct make_dad_struct(list a1, list a2)
Definition: compsec.c:264
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
int Value
@ INT
Definition: atomic.c:48
static hash_table Ref
Refs maps each statement to the effects it references.
Definition: chains.c:96
#define GET_NEST(d)
@ SINGLE
#define USEC(x, i)
#define LSEC(x, i)
accessing DAD components
#define PUT_NEST(d, val)
OpFlag
used for merging linear expressions
#define comp_desc_reference(x)
Definition: compsec.h:177
#define bound_pair_ub(x)
Definition: compsec.h:142
#define bound_pair_lb_(x)
Definition: compsec.h:139
#define dad_struct_shape(x)
Definition: compsec.h:324
#define bound_pair_index(x)
Definition: compsec.h:138
#define comp_desc_section(x)
Definition: compsec.h:181
#define BOUND_PAIR(x)
newgen_simple_section_domain_defined
Definition: compsec.h:107
#define ref_temp_index(x)
Definition: compsec.h:358
#define context_info_undefined
Definition: compsec.h:259
#define simple_section_dad(x)
Definition: compsec.h:451
#define comp_sec_hull(x)
Definition: compsec.h:247
#define bound_pair_ub_(x)
Definition: compsec.h:141
#define REF_TEMP(x)
REF_TEMP.
Definition: compsec.h:328
#define COMP_DESC(x)
COMP_DESC.
Definition: compsec.h:146
#define bound_pair_lb(x)
Definition: compsec.h:140
#define simple_section_context(x)
Definition: compsec.h:449
@ is_rtype_nonlinear
Definition: compsec.h:385
@ is_rtype_lininvariant
Definition: compsec.h:387
@ is_rtype_linvariant
Definition: compsec.h:386
#define dad_struct_rtemps(x)
Definition: compsec.h:322
#define rtype_tag(x)
Definition: compsec.h:406
#define context_info_rank(x)
Definition: compsec.h:286
#define ref_temp_rtype(x)
Definition: compsec.h:360
void vect_debug(Pvecteur v)
constraint.c
Definition: constraint.c:43
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 ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
const char * entity_minimal_name(entity e)
Do preserve scope informations.
Definition: naming.c:214
int tag
TAG.
Definition: newgen_types.h:92
#define tag_undefined
Definition: newgen_types.h:93
intptr_t _int
_INT
Definition: newgen_types.h:53
#define UU
Definition: newgen_types.h:98
#define MINUS
Definition: operator.h:42
#define Index(p, i, j)
Definition: pip__tab.h:45
#define New
#define Val
#define NORMALIZE_EXPRESSION(e)
#define normalized_linear_p(x)
Definition: ri.h:1779
#define reference_variable(x)
Definition: ri.h:2326
#define range_upper(x)
Definition: ri.h:2290
#define type_variable(x)
Definition: ri.h:2949
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_indices(x)
Definition: ri.h:2328
#define range_lower(x)
Definition: ri.h:2288
#define variable_dimensions(x)
Definition: ri.h:3122
#define loop_range(x)
Definition: ri.h:1642
#define entity_type(x)
Definition: ri.h:2792
#define normalized_linear(x)
Definition: ri.h:1781
#define loop_index(x)
Definition: ri.h:1640
#define PLUS
Definition: sc_gram.c:200
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 vect_aux
Definition: solpip.c:102
void TransSimpSec(comp_desc Desc, loop Loop, tVariants *Vars)
Definition: ss.c:782
void DisplaySimpleSection(simple_section Dad)
}}
Definition: ss.c:161
tVariants TransRefTemp(loop ThisLoop, comp_desc Desc)
}}
Definition: ss.c:612
bool IsExprConst(LinExpr Expr)
}}
Definition: ss.c:388
dad_struct AllocateDadStruct(int Rank)
}}
Definition: ss.c:440
unsigned int ComputeIndex(unsigned int I, unsigned int J, unsigned int Rank)
}}
Definition: ss.c:362
LinExpr GetBoundary(simple_section Dad, int DimNo, unsigned Low)
}}
Definition: ss.c:266
simple_section SimpUnion(simple_section S1, simple_section S2)
}}
Definition: ss.c:1013
void ComputeBoundaries(simple_section Dad, loop Loop, LinExpr lbExpr, LinExpr ubExpr, unsigned Offset)
compute both boundary expression and store in the tSS array
Definition: ss.c:765
void PrintCompRegions(list CompList)
}}
Definition: ss.c:74
void UpdateUnresolved(simple_section Dad, loop Loop)
}}
Definition: ss.c:667
simple_section AllocateSimpleSection(reference ref)
Definition: ss.c:467
Pvecteur my_vect_substract(Pvecteur pvec1, Pvecteur pvec2)
Definition: ss.c:50
LinExpr Ubound(loop Loop, LinExpr Lin)
Definition: ss.c:961
Pvecteur my_vect_var_subst(Pvecteur vect, Variable var, Pvecteur new_vect)
{{ my vect var subst function
Definition: ss.c:35
void ComputeRTandSS(expression Sub, unsigned DimNo, simple_section Dad, loop Loop)
initialise reference template and shapes for inner most references
Definition: ss.c:524
LinExpr MaxBoundary(LinExpr Lin1, LinExpr Lin2)
}}
Definition: ss.c:335
LinExpr MinBoundary(LinExpr Lin1, LinExpr Lin2)
}}
Definition: ss.c:320
void DisplayRefTemp(simple_section Dad)
}}
Definition: ss.c:123
void DisplayDad(comp_desc TheDad)
Definition: ss.c:107
void TranslateRefsToLoop(loop ThisLoop, list ListOfComps)
}}
Definition: ss.c:577
LinExpr Lbound(loop Loop, LinExpr Lin)
}}
Definition: ss.c:910
void PrintLinExpr(LinExpr Lin)
}}
Definition: ss.c:87
void PrintSimp(comp_desc Dad)
}}
Definition: ss.c:99
unsigned int CardinalityOf(list gl)
Definition: ss.c:428
LinExpr CopyAccVec(LinExpr Expr)
}}
Definition: ss.c:378
void PutBoundPair(simple_section Dad, _int DimNo, LinExpr Low, LinExpr Up)
}}
Definition: ss.c:290
void TranslateToLoop(loop ThisLoop, comp_desc Desc)
}}
Definition: ss.c:589
LinExpr MergeLinExprs(LinExpr Expr1, LinExpr Expr2, OpFlag Op)
}}
Definition: ss.c:349
expression GetAccVec(unsigned No, const reference ref)
return the n'th subscript expression
Definition: ss.c:411
tag GetRefTemp(simple_section Dad, _int DimNo)
}}
Definition: ss.c:229
void ScanAllDims(loop Loop, comp_desc Desc)
}}
Definition: ss.c:490
bool DivExists(loop Loop, LinExpr Lin)
check whether loop index variable var is contained in LinExpr
Definition: ss.c:396
#define LINE
void PutRefTemp(simple_section Dad, int DimNo, tag Val)
}}
Definition: ss.c:248
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 val_of(varval)
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 var_of(varval)
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_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
int vect_compare(Pvecteur *pv1, Pvecteur *pv2)
for qsort, returns:
Definition: unaires.c:352
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
bool vect_contains_variable_p(Pvecteur v, Variable var)
bool vect_contains_variable_p(Pvecteur v, Variable var) BA 19/05/94 input : a vector and a variable o...
Definition: unaires.c:415