PIPS
bound_generation.c File Reference
#include <stdio.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "ri.h"
#include "ri-util.h"
+ Include dependency graph for bound_generation.c:

Go to the source code of this file.

Functions

int bound_generation_compare_vector_component (Pvecteur *pv1, Pvecteur *pv2)
 Generation of bound expressions from constraint systems of the Linear library. More...
 
void make_bound_expression (Variable index, Pbase base, Psysteme sc, expression *lower, expression *upper)
 void make_bound_expression(variable index, Pbase base, Psysteme sc, expression *lower, expression *upper) More...
 

Function Documentation

◆ bound_generation_compare_vector_component()

int bound_generation_compare_vector_component ( Pvecteur pv1,
Pvecteur pv2 
)

Generation of bound expressions from constraint systems of the Linear library.

bound_generation.c

Used for sorting each constraint and in between constraints, hopefully

Parameters
pv1v1
pv2v2

Definition at line 40 of file bound_generation.c.

41 {
42  entity e1 = (entity) vecteur_var(*pv1);
43  entity e2 = (entity) vecteur_var(*pv2);
44  // FI: is "less" a well-chosen name?
45  // int less = strcmp(entity_local_name(e1), entity_local_name(e2));
46  int less;
47 
48  if(e1==NULL) {
49  if(e2==NULL)
50  less = 0;
51  else
52  less = -1;
53  }
54  else if(e2==NULL)
55  less = 1;
56  else
57  less = strcmp(entity_user_name(e1), entity_user_name(e2));
58 
59 #if 0
60  if(less==0) {
61  Value v1 = vecteur_val(*pv1);
62  Value v2 = vecteur_val(*pv2);
63  if(value_gt(v1,v2))
64  less = 1;
65  else if(value_lt(v1,v2))
66  less = -1;
67  else
68  /* To satisfy a later assert not so well designed */
69  less = pv1<pv2? 1 : -1;
70  }
71 #endif
72 
73  return less;
74 }
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
#define value_gt(v1, v2)
int Value
#define value_lt(v1, v2)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
#define vecteur_val(v)
#define vecteur_var(v)

References entity_user_name(), value_gt, value_lt, vecteur_val, and vecteur_var.

Referenced by make_bound_expression().

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

◆ make_bound_expression()

void make_bound_expression ( Variable  index,
Pbase  base,
Psysteme  sc,
expression lower,
expression upper 
)

void make_bound_expression(variable index, Pbase base, Psysteme sc, expression *lower, expression *upper)

build the expressions "lower" and "upper" for the lower and upper bounds of variable "index". Variable "index" must appear in "base" and have lower and upper bounds in "sc"

Beware of degenerated cases where constraints are reduced to equations because the upper and lower bounds are identical.

The constraints are sorted according to the lexicographic order using bound_generation_compare_vector_component().

see also constraints_to_loop_bound (in conversion system_to_code.c)

compute the rank d of the index in the basis

The constraints should be lexicographically sorted to avoid secondary variations in linear

search constraints referencing "index" among inequalities and create the list of expressions for lower and upper bounds

found

ifdebug(7) {

fprintf(stderr, "\n expression after :");

print_expression(ex);

}

add the expression to the list of lower bounds or to the list of upper bounds

search equation constraints referencing "index" and create the list of expressions for lower and upper bounds. We may have to generate useless loops with only one iteration.

found

ifdebug(7) {

fprintf(stderr, "\n expression after :");

print_expression(ex);

}

add the expression to the list of lower bounds and to the list of upper bounds

Reverse the expression order

build expressions for the lower and upper bounds

To avoid clash with Fortran intrinsics

pips_min and pips_max are supposed to be part of PIPS run-time. They are varargs and their first argument is the count of arguments

and memory leak... (cons lost)

idem...

print_expression(*lower);

print_expression(*upper);

Parameters
indexndex
basease
scc
lowerower
upperpper

Definition at line 91 of file bound_generation.c.

96 {
97  Pcontrainte pc;
98  cons *ll = NIL;
99  cons *lu = NIL;
100 
101  expression ex;
102  entity min, max;
103 
104  int i;
105  int rank_index ;
106 
107  /* compute the rank d of the index in the basis */
108  rank_index =
111 
112  pips_debug(7, "index :%s\n", entity_name_or_TCST(index));
113  pips_debug(8, "rank_index = %d\n", rank_index);
114 
115  /* The constraints should be lexicographically sorted to avoid
116  secondary variations in linear */
117  // contrainte_vect_sort(ll, bound_generation_compare_vector_component);
118  ifdebug(7) {
119  fprintf(stderr, "Constraints before sorting:\n");
120  sc_dump(sc);
121  }
123  ifdebug(7) {
124  fprintf(stderr, "Constraints after sorting:\n");
125  sc_dump(sc);
126  }
127 
128  /* search constraints referencing "index" among inequalities and
129  create the list of expressions for lower and upper bounds */
130  for (pc=sc->inegalites; pc!=NULL; pc=pc->succ) {
131  i = level_contrainte(pc, base);
132  pips_debug(8,"level: %d\n",i);
133  if (ABS(i)==rank_index){ /* found */
134  ifdebug(7) {
135  (void) fprintf(stderr, "\n constraint before :");
136  contrainte_fprint(stderr, pc, true,
138  }
139  ex = make_constraint_expression(pc->vecteur, (Variable) index);
140  // FI: to avoid cycles betwen librairies ri-util and prettyprint
141  /* ifdebug(7) { */
142  /* fprintf(stderr, "\n expression after :"); */
143  /* print_expression(ex); */
144  /* } */
145  /* add the expression to the list of lower bounds
146  or to the list of upper bounds*/
147  if (i>0)
148  lu = CONS(EXPRESSION, ex, lu);
149  else
150  ll = CONS(EXPRESSION, ex, ll);
151  }
152  }
153 
154  /* search equation constraints referencing "index" and create the
155  list of expressions for lower and upper bounds. We may have to
156  generate useless loops with only one iteration. */
157  for (pc=sc->egalites; pc!=NULL; pc=pc->succ) {
158  i = level_contrainte(pc, base);
159  pips_debug(8,"level: %d\n",i);
160  if (ABS(i)==rank_index){ /* found */
161  ifdebug(7) {
162  (void) fprintf(stderr, "\n constraint before :");
163  contrainte_fprint(stderr, pc, true,
165  }
166  if(i>0) {
167  Pvecteur mv = vect_copy(pc->vecteur);
168  mv = vect_multiply(mv, VALUE_MONE);
169  ex = make_constraint_expression(mv, (Variable) index);
170  vect_rm(mv);
171  }
172  else
173  ex = make_constraint_expression(pc->vecteur, (Variable) index);
174  // FI: to avoid cycles betwen librairies ri-util and prettyprint
175  /* ifdebug(7) { */
176  /* fprintf(stderr, "\n expression after :"); */
177  /* print_expression(ex); */
178  /* } */
179 
180  /* add the expression to the list of lower bounds
181  and to the list of upper bounds*/
182  lu = CONS(EXPRESSION, ex, lu);
183  ll = CONS(EXPRESSION, ex, ll);
184  }
185  }
186 
187  /* Reverse the expression order */
188  ll = gen_nreverse(ll);
189  lu = gen_nreverse(lu);
190 
191  /* build expressions for the lower and upper bounds */
193  /* To avoid clash with Fortran intrinsics */
194  /* pips_min and pips_max are supposed to be part of PIPS
195  run-time. They are varargs and their first argument is the
196  count of arguments */
199  }
200  else { // Fortran case
203  }
204 
205  pips_assert("entities for min and max are found",
207 
208  if (gen_length(ll) > 1) {
210  int c = gen_length(ll);
212  ll = CONS(EXPRESSION, ce, ll);
213  }
215  make_call(max,ll)),
217  }
218  else {
219  *lower = EXPRESSION(CAR(ll)); /* and memory leak... (cons lost) */
220  gen_free_list(ll);
221  }
222 
223  if (gen_length(lu) > 1 ) {
225  int c = gen_length(lu);
227  lu = CONS(EXPRESSION, ce, lu);
228  }
230  make_call(min,lu)),
232  }
233  else {
234  *upper = EXPRESSION(CAR(lu)); /* idem... */
235  gen_free_list(lu);
236  }
237 
238  ifdebug(7) {
239  pips_debug(9, "returning: \n");
240  // FI: to avoid cycles betwen librairies ri-util and prettyprint
241  /* print_expression(*lower); */
242  /* print_expression(*upper); */
243  }
244 }
call make_call(entity a1, list a2)
Definition: ri.c:269
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
syntax make_syntax(enum syntax_utype tag, void *val)
Definition: ri.c:2491
#define VALUE_MONE
#define ABS(x)
was: #define value_mult(v,w) value_direct_multiply(v,w) #define value_product(v,w) value_direct_produ...
int base_find_variable_rank(Pbase b, Variable v, char *(*variable_name)(Variable))
int base_find_variable_rank(Pbase b, Variable v, char * (*variable_name)()): returns variable v's ran...
Definition: base.c:194
bdt base
Current expression.
Definition: bdt_read_paf.c:100
int level_contrainte(Pcontrainte, Pbase)
int level_contrainte(Pcontrainte pc, Pbase base_index) compute the level (rank) of the constraint pc ...
Definition: unaires.c:292
void contrainte_fprint(FILE *, Pcontrainte, bool, char *(*)(Variable))
io.c
#define min(a, b)
#define max(a, b)
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#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
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define MAX_OPERATOR_NAME
#define PIPS_C_MAX_OPERATOR_NAME
#define PIPS_C_MIN_OPERATOR_NAME
PIPS run-time support for C code generation.
#define MIN_OPERATOR_NAME
int bound_generation_compare_vector_component(Pvecteur *pv1, Pvecteur *pv2)
Generation of bound expressions from constraint systems of the Linear library.
const char * entity_name_or_TCST(entity e)
Return a name valid for sorting variables in vectors and constraint systems.
Definition: entity.c:627
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression make_constraint_expression(Pvecteur v, Variable index)
Make an expression from a constraint v for a given index.
Definition: expression.c:1748
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
bool c_language_module_p(entity m)
Definition: module.c:447
#define normalized_undefined
Definition: ri.h:1745
@ is_syntax_call
Definition: ri.h:2693
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined
Definition: ri.h:2761
void sc_dump(Psysteme sc)
void sc_dump(Psysteme sc): dump to stderr
Definition: sc_io.c:142
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
void sc_lexicographic_sort(Psysteme sc, int(*compare)(Pvecteur *, Pvecteur *))
Minimize first the lexico-graphic weight of each constraint according to the comparison function "com...
Definition: sc_unaires.c:206
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
Pcontrainte egalites
Definition: sc-local.h:70
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
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
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78

References ABS, base, base_find_variable_rank(), bound_generation_compare_vector_component(), c_language_module_p(), CAR, CONS, contrainte_fprint(), Ssysteme::egalites, entity_intrinsic(), entity_name_or_TCST(), entity_undefined, EXPRESSION, fprintf(), gen_free_list(), gen_length(), gen_nreverse(), get_current_module_entity(), ifdebug, Ssysteme::inegalites, int_to_expression(), is_syntax_call, level_contrainte(), make_call(), make_constraint_expression(), make_expression(), make_syntax(), max, MAX_OPERATOR_NAME, min, MIN_OPERATOR_NAME, NIL, normalized_undefined, pips_assert, PIPS_C_MAX_OPERATOR_NAME, PIPS_C_MIN_OPERATOR_NAME, pips_debug, sc_dump(), sc_lexicographic_sort(), Scontrainte::succ, VALUE_MONE, vect_copy(), vect_multiply(), vect_rm(), and Scontrainte::vecteur.

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

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