PIPS
sc_new_loop_bound.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "linear_assert.h"
#include "boolean.h"
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "sc.h"
+ Include dependency graph for sc_new_loop_bound.c:

Go to the source code of this file.

Functions

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 the loop bounds) in the new basis G. More...
 
Psysteme get_other_constraints (Psysteme *psyst, Pbase vars)
 Psysteme get_other_constraints(psyst, vars) Psysteme *psyst; Pbase vars;. More...
 
void algorithm_row_echelon_generic (Psysteme scn, Pbase base_index, Psysteme *pcondition, Psysteme *penumeration, bool redundancy)
 each variable should be at least within one <= and one >=; scn IS NOT modified. More...
 
void algorithm_row_echelon (Psysteme scn, Pbase base_index, Psysteme *pcondition, Psysteme *penumeration)
 see comments above. More...
 
void sc_set_row_echelon_redundancy (bool b __attribute__((unused)))
 
void algorithm_tiling (Psysteme syst, Pbase outer, Pbase inner, Psysteme *pcondition, Psysteme *ptile_enum, Psysteme *piter_enum)
 

Function Documentation

◆ algorithm_row_echelon()

void algorithm_row_echelon ( Psysteme  scn,
Pbase  base_index,
Psysteme pcondition,
Psysteme penumeration 
)

see comments above.

Definition at line 248 of file sc_new_loop_bound.c.

253 {
255  (scn, base_index, pcondition, penumeration, false);
256 }
void algorithm_row_echelon_generic(Psysteme scn, Pbase base_index, Psysteme *pcondition, Psysteme *penumeration, bool redundancy)
each variable should be at least within one <= and one >=; scn IS NOT modified.

References algorithm_row_echelon_generic().

Referenced by build_third_comb(), copy_write_statement_with_cumulated_regions(), prepare_reindexing(), and verify_array_variable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ algorithm_row_echelon_generic()

void algorithm_row_echelon_generic ( Psysteme  scn,
Pbase  base_index,
Psysteme pcondition,
Psysteme penumeration,
bool  redundancy 
)

each variable should be at least within one <= and one >=; scn IS NOT modified.


ALGORITHM ROW ECHELON from Ancourt and Irigoin, PPoPP'91

The algorithm is slightly different:

conditions are taken out of the system built.

void algorithm_row_echelon(syst, scans, pcondition, penumeration) Psysteme syst; Pbase scans; Psysteme *pcondition, *penumeration;

IN: syst, scans

OUT: pcondition, penumeration

(c) FC 16/05/94

returns a a la Omega system, with no innerward redundancy. in fact this is just a quick approximation of that property. the way the system is computed may keep some outerward redundancies, because a constraint may be redundant with some not yet computed projection...

ELSE remove redundancy in the system...

include the original system again, to recover simple constraints that may have been removed. May not be interesting...

what is returned must be ok.

Parameters
base_indexinitial system, which is not touched.
pconditionenumeration variables, from outer to inner.
penumerationreturned condition (what remains from scn).
redundancyreturned enumeration system. whether to allow outwards redundancy.

Definition at line 134 of file sc_new_loop_bound.c.

140 {
141  int i, dimension = vect_size(base_index);
142  Psysteme ps_interm, ps_project, ps_tmp;
143  Pbase reverse_base;
144  Pvecteur pb;
145  Pcontrainte ineq = NULL,
146  *c = (Pcontrainte*) malloc(sizeof(Pcontrainte)*(dimension+1));
147 
148  if (VECTEUR_NUL_P(base_index))
149  {
150  *penumeration = sc_rn(NULL);
151  *pcondition = sc_dup(scn);
152  return;
153  }
154 
155  // check base consistency
156  assert(vect_in_basis_p(base_index, scn->base));
157 
158  ps_project = sc_dup(scn);
159  sc_transform_eg_in_ineg(ps_project);
160  ps_project = sc_sort_constraints(ps_project, base_index);
161  ps_project = sc_elim_redond(ps_project);
162 
163  if (SC_UNDEFINED_P(ps_project))
164  ps_project = sc_empty(base_difference(sc_base(scn), base_index));
165 
166  if (sc_empty_p(ps_project))
167  {
168  *penumeration = sc_empty(base_index);
169  *pcondition = ps_project;
170  return;
171  }
172 
173  reverse_base = base_reversal(base_index);
174 
175  for (pb=reverse_base, i=dimension;
176  !VECTEUR_NUL_P(pb);
177  pb=pb->succ, i--)
178  {
179  c[i] = contrainte_dup_extract(sc_inegalites(ps_project), pb->var);
180 
181  ps_project = sc_projection(ps_project, pb->var);
182  vect_erase_var(&sc_base(ps_project), pb->var);
183  ps_project->dimension--;
184  ps_project = sc_triang_elim_redund(ps_project, base_index);
185  }
186 
187  if (ps_project==NULL || sc_empty_p(ps_project))
188  {
189  *penumeration = sc_empty(base_index);
190  *pcondition = ps_project;
191  return;
192  }
193 
194  c[0] = contrainte_dup_extract(sc_inegalites(ps_project), NULL);
195  sc_rm(ps_project);
196 
197  for (i=0; i<dimension+1; i++)
198  ineq = contrainte_append(c[i], ineq);
199 
200  ps_interm = sc_make(NULL, ineq);
201 
202  /* returns a a la Omega system, with no innerward redundancy.
203  * in fact this is just a quick approximation of that property.
204  * the way the system is computed may keep some outerward redundancies,
205  * because a constraint may be redundant with some not yet computed
206  * projection...
207  */
208  if (redundancy)
209  {
210  *pcondition = get_other_constraints(&ps_interm, base_index);
211  sc_transform_ineg_in_eg(*pcondition);
212  *penumeration = ps_interm;
213 
214  return;
215  }
216 
217  /* ELSE remove redundancy in the system...
218  *
219  * include the original system again, to recover simple
220  * constraints that may have been removed.
221  * May not be interesting...
222  */
223  ps_tmp = sc_dup(scn);
224  sc_transform_eg_in_ineg(ps_tmp);
225  //assert(sc_consistent_p(ps_tmp));
226  //assert(sc_consistent_p(ps_interm));
227  // sc_fusion() is declared obsolete: sc_append() and
228  // sc_intersection() are suggested as replacements
229  //ps_interm = sc_fusion(ps_interm, ps_tmp);
230  ps_interm = sc_append(ps_interm, ps_tmp);
231  //assert(sc_consistent_p(ps_interm));
232  ps_interm = sc_triang_elim_redund(ps_interm, base_index);
233 
234  *pcondition = get_other_constraints(&ps_interm, base_index);
235  sc_transform_ineg_in_eg(*pcondition);
236  *penumeration = ps_interm;
237 
238  base_rm(reverse_base), free(c);
239 
240  /* what is returned must be ok.
241  */
242  assert(!SC_UNDEFINED_P(*pcondition) && !SC_UNDEFINED_P(*penumeration));
243 }
Pbase base_difference(Pbase b1, Pbase b2)
Pbase base_difference(Pbase b1, Pbase b2): allocate b; b = b1 - b2 – with the set meaning return b;.
Definition: base.c:621
bool vect_in_basis_p(Pvecteur v, Pbase b)
Pvecteur vect_in_basis_p(Pvecteur v, Pbase b): check that all coordinates in v are in b,...
Definition: base.c:342
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
Pcontrainte contrainte_append(Pcontrainte c1, Pcontrainte c2)
Pcontrainte contrainte_append(c1, c2) Pcontrainte c1, c2;.
Definition: binaires.c:267
Pcontrainte contrainte_dup_extract(Pcontrainte, Variable)
Pcontrainte contrainte_dup_extract(c, var) Pcontrainte c; Variable var;.
Definition: unaires.c:215
void * malloc(YYSIZE_T)
void free(void *)
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
#define assert(ex)
Definition: newgen_assert.h:41
Psysteme sc_make(Pcontrainte leg, Pcontrainte lineg)
Psysteme sc_make(Pcontrainte leg, Pcontrainte lineg): allocation et initialisation d'un systeme d'equ...
Definition: sc.c:78
Psysteme sc_empty(Pbase b)
Psysteme sc_empty(Pbase b): build a Psysteme with one unfeasible constraint to define the empty subsp...
Definition: sc_alloc.c:319
Psysteme sc_rn(Pbase b)
Psysteme sc_rn(Pbase b): build a Psysteme without constraints to define R^n, where n is b's dimension...
Definition: sc_alloc.c:336
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
bool sc_empty_p(Psysteme sc)
bool sc_empty_p(Psysteme sc): check if the set associated to sc is the constant sc_empty or not.
Definition: sc_alloc.c:350
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
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 get_other_constraints(Psysteme *psyst, Pbase vars)
Psysteme get_other_constraints(psyst, vars) Psysteme *psyst; Pbase vars;.
void sc_transform_ineg_in_eg(Psysteme sc)
Transform the two constraints A.x <= b and -A.x <= -b of system sc into an equality A....
void sc_transform_eg_in_ineg(Psysteme sc)
Package sc.
Psysteme sc_sort_constraints(Psysteme ps, Pbase base_index)
Psysteme sc_triang_elim_redund(Psysteme ps, Pbase base_index)
sort contrainte c, base b, relatively to sort_base, as defined by the switches.
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
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
#define VECTEUR_NUL_P(v)
#define base_rm(b)
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

References assert, Ssysteme::base, base_difference(), base_reversal(), base_rm, contrainte_append(), contrainte_dup_extract(), Ssysteme::dimension, free(), get_other_constraints(), malloc(), sc_append(), sc_dup(), sc_empty(), sc_empty_p(), sc_make(), sc_rm(), sc_rn(), sc_sort_constraints(), sc_transform_eg_in_ineg(), sc_transform_ineg_in_eg(), sc_triang_elim_redund(), Svecteur::succ, Svecteur::var, vect_erase_var(), vect_in_basis_p(), vect_size(), and VECTEUR_NUL_P.

Referenced by algorithm_row_echelon(), algorithm_tiling(), hpfc_algorithm_row_echelon(), new_loop_bound(), and Psysteme_to_loop_nest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ algorithm_tiling()

void algorithm_tiling ( Psysteme  syst,
Pbase  outer,
Pbase  inner,
Psysteme pcondition,
Psysteme ptile_enum,
Psysteme piter_enum 
)

ALGORITHM TILING from Ancourt and Irigoin, PPoPP'91

The algorithm is slightly different:

constraints may appear thru the projections that do not contain the desired loop variables. These constraints are taken out of the systems. The inner ones are reinjected to help for the outer loop, and those of the outer loop are stored as conditions to be checked before the loop nest. The intuition is that if these constraints are violated, the polyhedron is empty, and the loop nest must be avoided.

Corinne ANCOURT, Fabien COELHO, Apr 1 94.

  • may be improved by recognizing equalities? then deducable variables could be rebuilt.
  • there should be no equalities on the scanners...

void algorithm_tiling(syst, outer, inner, pcondition, ptile_enum, piter_enum) Psysteme syst; Pbase outer, inner; Psysteme *pcondition, *ptile_enum, *piter_enum;

 IN: syst, outer, inner
OUT: pcondition, ptile_enum, piter_enum

tiles iterations enumeration row echelon

project variables

tiles enumeration row echelon

clean bases

Definition at line 292 of file sc_new_loop_bound.c.

299 {
300  Psysteme sc = SC_UNDEFINED, transfer = SC_UNDEFINED;
301  Pbase b = BASE_NULLE;
302 
303  /* tiles iterations enumeration row echelon
304  */
305  algorithm_row_echelon_generic(syst, inner, &transfer, piter_enum, true);
306 
307  if (sc_empty_p(transfer))
308  {
309  sc_rm(transfer), sc_rm(*piter_enum),
310  *piter_enum = sc_empty(BASE_NULLE),
311  *ptile_enum = sc_empty(BASE_NULLE),
312  *pcondition = sc_empty(BASE_NULLE);
313  return;
314  }
315 
316  /* project variables
317  */
318  for(b=inner, sc=sc_safe_intersection(sc_rn(BASE_NULLE), syst, transfer);
319  b!=BASE_NULLE;
320  sc=sc_projection(sc, var_of(b)), b=b->succ);
321 
322  sc_rm(transfer);
323  sc_nredund(&sc);
324 
325  /* tiles enumeration row echelon
326  */
327  algorithm_row_echelon_generic(sc, outer, pcondition, ptile_enum, true);
328 
329  if (sc_empty_p(*pcondition))
330  {
331  sc_rm(*piter_enum), sc_rm(*ptile_enum),
332  *piter_enum = sc_empty(BASE_NULLE),
333  *ptile_enum = sc_empty(BASE_NULLE);
334  return;
335  }
336 
337  /* clean bases
338  */
339  sc_base(*ptile_enum)=(base_rm(sc_base(*ptile_enum)), BASE_NULLE),
340  sc_creer_base(*ptile_enum);
341 
342  sc_base(*piter_enum)=(base_rm(sc_base(*piter_enum)), BASE_NULLE),
343  sc_creer_base(*piter_enum);
344 }
void sc_creer_base(Psysteme ps)
void sc_creer_base(Psysteme ps): initialisation des parametres dimension et base d'un systeme lineair...
Definition: sc_alloc.c:129
Psysteme sc_safe_intersection(Psysteme s1, Psysteme s2, Psysteme s3)
Psysteme sc_safe_intersection(Psysteme s1, Psysteme s2, Psysteme s3) input : output : calcul d'un sys...
#define var_of(varval)
#define BASE_NULLE
MACROS SUR LES BASES.

References algorithm_row_echelon_generic(), BASE_NULLE, base_rm, sc_creer_base(), sc_empty(), sc_empty_p(), sc_rm(), sc_rn(), sc_safe_intersection(), Svecteur::succ, and var_of.

Referenced by hpfc_algorithm_tiling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_other_constraints()

Psysteme get_other_constraints ( Psysteme psyst,
Pbase  vars 
)

Psysteme get_other_constraints(psyst, vars) Psysteme *psyst; Pbase vars;.

    IN: vars
IN/OUT: psyst
   OUT: returned system

returns the constraints that do not contain any of the variables listed in Pbase vars, which are removed from the original Psysteme *psyst. if the original system is undefined, the same thing is returned.

(c) FC 16/05/94

else

result in built and syst is modified.

Definition at line 84 of file sc_new_loop_bound.c.

87 {
89  egothers = (Pcontrainte) NULL,
90  inothers = (Pcontrainte) NULL,
91  egsyst = (Pcontrainte) NULL,
92  insyst = (Pcontrainte) NULL;
93 
94  assert(!SC_UNDEFINED_P(*psyst));
95 
96  if (sc_empty_p(*psyst))
97  return(sc_empty(base_difference(sc_base(*psyst), vars)));
98  /* else
99  */
100  Pcontrainte_separate_on_vars(sc_egalites(*psyst),
101  vars, &egsyst, &egothers);
102  Pcontrainte_separate_on_vars(sc_inegalites(*psyst),
103  vars, &insyst, &inothers);
104 
105  /* result in built and syst is modified.
106  */
107  *psyst = (sc_rm(*psyst), sc_make(egsyst, insyst));
108  return sc_make(egothers, inothers);
109 }
struct Scontrainte * Pcontrainte
void Pcontrainte_separate_on_vars(Pcontrainte, Pbase, Pcontrainte *, Pcontrainte *)
void Pcontrainte_separate_on_vars(initial, vars, pwith, pwithout) Pcontrainte initial; Pbase vars; Pc...
Definition: unaires.c:140

References assert, base_difference(), Pcontrainte_separate_on_vars(), sc_empty(), sc_empty_p(), sc_make(), and sc_rm().

Referenced by algorithm_row_echelon_generic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_loop_bound()

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 the loop bounds) in the new basis G.

scn is destroyed

if the list of indexes is empty, the system is assumed to be a list of constraints that have to be verified for the set of solutions not to be empty, so scn is returned.

Reference about the algorithm PPoPP'91

Definition at line 51 of file sc_new_loop_bound.c.

54 {
55  Psysteme
56  result = NULL,
57  condition = NULL,
58  enumeration = NULL;
59 
60  algorithm_row_echelon_generic(scn, base_index,
61  &condition, &enumeration, false);
62 
63  sc_rm(scn);
64  scn = NULL;
65  result = sc_fusion(condition, enumeration);
66 
67  return result;
68 }
Psysteme sc_fusion(Psysteme s1, Psysteme s2)
package sc

References algorithm_row_echelon_generic(), sc_fusion(), and sc_rm().

Referenced by hyperplane(), make_scanning_over_one_tile(), make_scanning_over_tiles(), terapix_loop_handler(), tiling_transformation(), and unimodular().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_set_row_echelon_redundancy()

void sc_set_row_echelon_redundancy ( bool b   __attribute__(unused))

Definition at line 258 of file sc_new_loop_bound.c.

259 {
260  return;
261 }