PIPS
system_to_code.c File Reference
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "effects.h"
#include "misc.h"
#include "ri-util.h"
#include "effects-util.h"
#include "effects-generic.h"
#include "effects-convex.h"
#include "properties.h"
#include "conversion.h"
+ Include dependency graph for system_to_code.c:

Go to the source code of this file.

Functions

expression Psysteme_to_expression (Psysteme systeme)
 Standard includes. More...
 
list Pcontrainte_to_expression_list (Pcontrainte constraint, entity operator)
 
static bool vect_simple_definition_p (Pvecteur v, Variable *pvar, Value *pcoe, Value *pcst)
 here I store simple bounds on variables appearing in the systems to allow the code generation phase to use them to improve the code. More...
 
static void store_an_upper (entity var, int val)
 
static void store_a_lower (entity var, int val)
 
void set_information_for_code_optimizations (Psysteme s)
 I could keep the system for further optimizations... More...
 
void reset_information_for_code_optimizations ()
 
static bool range_of_variable (Variable var, Value *lb, Value *ub)
 this functions returns bounds for variable var if both are available. More...
 
static Value vecteur_lower_bound (Pvecteur v)
 returns v lower bound if found, or INT_MIN. More...
 
static bool evaluate_divide_if_possible (Pvecteur v, Value denominator, Value *result)
 
expression constraints_to_loop_bound (Pcontrainte c, Variable var, bool is_lower, entity divide)
 expression constraints_to_loop_bound(c, var, is_lower) More...
 
bool bounds_equal_p (Variable var, Pcontrainte lower, Pcontrainte upper)
 this function checks whether the lower and upper constraints are going to generate the same bound on variable var. More...
 
statement systeme_to_loop_nest (Psysteme sc, list vars, statement body, entity divide)
 sc is used to generate the loop nest bounds for variables vars. More...
 
statement generate_optional_if (Psysteme sc, statement stat)
 statement generate_optional_if(sc, stat) More...
 

Function Documentation

◆ bounds_equal_p()

bool bounds_equal_p ( Variable  var,
Pcontrainte  lower,
Pcontrainte  upper 
)

this function checks whether the lower and upper constraints are going to generate the same bound on variable var.

oeff for var in the constraint

??? the arithmetic ppcm version is on int instead of values

Parameters
varar
lowerower
upperpper

Definition at line 534 of file system_to_code.c.

538 {
539  Pvecteur v_lower, v_upper, sum;
540  Value val_lower, val_upper, the_ppcm;
541  bool result;
542 
543  if (nb_elems_list(lower)!=1 || nb_elems_list(upper)!=1) return(false);
544 
545  val_upper = vect_coeff(var, upper->vecteur); /*coeff for var in the constraint*/
546  val_lower = vect_coeff(var, lower->vecteur);
547 
548  /* ??? the arithmetic ppcm version is on int instead of values
549  */
550  the_ppcm = ppcm(value_uminus(val_lower), val_upper);
551 
552  v_lower = vect_dup(lower->vecteur);
553  v_lower = vect_multiply(v_lower,
554  value_div(value_uminus(the_ppcm),val_lower));
555 
556  v_upper = vect_dup(upper->vecteur);
557  v_upper = vect_multiply(v_upper,
558  value_div(the_ppcm,val_upper));
559 
560  sum = vect_add(v_lower, v_upper);
563 
564  result = VECTEUR_NUL_P(sum) ||
565  (sum->succ==NULL && var_of(sum)==TCST && val_of(sum)==0);
566 
567  vect_rm(v_lower), vect_rm(v_upper), vect_rm(sum);
568 
569  return result;
570 }
#define value_minus(v1, v2)
#define value_uminus(val)
unary operators on values
int Value
#define VALUE_ONE
#define value_div(v1, v2)
Value ppcm(Value, Value)
ppcm.c
Definition: ppcm.c:42
int nb_elems_list(Pcontrainte)
int nb_elems_list(Pcontrainte list): nombre de contraintes se trouvant dans une liste de contraintes
Definition: listes.c:129
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
t_real sum(int n1, int n2, int n3, t_real u[n1][n2][n3])
Definition: stencil.c:57
Pvecteur vecteur
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define val_of(varval)
#define VECTEUR_NUL_P(v)
#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
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_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_normalize(Pvecteur v)
void vect_normalize(Pvecteur v): division de tous les coefficients de v par leur pgcd; "normalisation...
Definition: unaires.c:59

References nb_elems_list(), ppcm(), sum(), TCST, val_of, value_div, value_minus, VALUE_ONE, value_uminus, var_of, vect_add(), vect_add_elem(), vect_coeff(), vect_dup(), vect_multiply(), vect_normalize(), vect_rm(), Scontrainte::vecteur, and VECTEUR_NUL_P.

Referenced by region_to_minimal_dimensions(), and systeme_to_loop_nest().

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

◆ constraints_to_loop_bound()

expression constraints_to_loop_bound ( Pcontrainte  c,
Variable  var,
bool  is_lower,
entity  divide 
)

expression constraints_to_loop_bound(c, var, is_lower)

the is_lower (lower/upper) loop bound for variable var relative to Pcontrainte c is generated. All the constraints in c are used, and they must be ok.

see also make_bound_expression in ri-util/bound_generation.c maybe move this function in ri-util/bound_generation.c? integer division to be called

the constraints are sorted first, to ensure a deterministic result ??? the sorting criterion is rather strange:-)

each constraint is considered in turn to generate a bound

ax+b <= 0 and a<0 => x >= (b+(-a-1))/(-a)

extract coefficients that are dividable by val... x = (ay+bz)/a -> x = y + bz/a

assert. no a.i=0 should have reached this point...

I perform some other optimizations here, by looking at the extent of the numerator, that may result in a constant after division by the denominator. For instance, x = y/a and 0 <= y < a would lead to x = 0, which is quite simpler... I need a hook from the callers of this function to retrieve the constant lower and upper bounds of each variable in order to perform this. ??? this optimizations should/could be perform earlier on the original system... but the implementation in a general context does not seems obvious to me...

use / instead of the provided idiv if operand >=0

final operation: MAX or MIN if more than one bound

and memory leak... (cons lost)

Parameters
varthe constraints of the bound
is_lowerthe index variable
dividelower or upper bound

Definition at line 374 of file system_to_code.c.

379 {
380  int len = 0, sign = is_lower? -1: +1;
382  list le = NIL;
383  Psysteme s;
384 
385  pips_debug(5, "computing %ser bound for variable %s\n",
386  (is_lower?"low":"upp"), entity_local_name((entity) var));
387 
388  ifdebug(6)
389  {
390  fprintf(stderr, "[constraints_to_loop_bound] constraints are:\n");
392  }
393 
394  message_assert("some constraints", !CONTRAINTE_UNDEFINED_P(c));
395 
396  /* the constraints are sorted first, to ensure a deterministic result
397  * ??? the sorting criterion is rather strange:-)
398  */
399  s = sc_make(NULL, contraintes_dup(c));
400  vect_sort(sc_base(s), compare_Pvecteur);
401  sc_sort_constraints(s, sc_base(s));
402 
403  /* each constraint is considered in turn to generate a bound
404  */
405  for(c=sc_inegalites(s); c; c=c->succ)
406  {
407  Value val = vect_coeff(var, c->vecteur), computed;
408  Pvecteur vdiv = vect_del_var(c->vecteur, var), vadd = VECTEUR_NUL, v;
409  expression ediv, eadd, e;
410 
411  message_assert("coherent value and sign", sign*value_sign(val)>0);
412 
413  if (value_pos_p(val))
414  vect_chg_sgn(vdiv);
415  else
416  /* ax+b <= 0 and a<0 => x >= (b+(-a-1))/(-a)
417  */
418  value_oppose(val),
419  vect_add_elem(&vdiv, TCST, value_minus(val,VALUE_ONE));
420 
421  if (value_one_p(val))
422  {
423  le = CONS(EXPRESSION, make_vecteur_expression(vdiv), le);
424  continue;
425  }
426 
427  /* extract coefficients that are dividable by val...
428  * x = (ay+bz)/a -> x = y + bz/a
429  */
430  for (v=vdiv; v; v=v->succ)
431  {
432  Variable va = var_of(v);
433  Value vl = val_of(v);
434 
435  if (value_zero_p(value_mod(vl,val)))
436  vect_add_elem(&vadd, va, value_div(vl,val));
437  }
438 
439  for (v=vadd; v; v=v->succ)
440  vect_erase_var(&vdiv, var_of(v));
441 
442  /* assert. no a.i=0 should have reached this point...
443  */
444  message_assert("some expression", vdiv || vadd);
445 
446  /* I perform some other optimizations here, by looking at
447  * the extent of the numerator, that may result in a constant after
448  * division by the denominator. For instance, x = y/a and 0 <= y < a
449  * would lead to x = 0, which is quite simpler... I need a hook
450  * from the callers of this function to retrieve the constant lower
451  * and upper bounds of each variable in order to perform this.
452  * ??? this optimizations should/could be perform earlier on
453  * the original system... but the implementation in a general context
454  * does not seems obvious to me...
455  */
456  if (evaluate_divide_if_possible(vdiv, val, &computed))
457  {
458  vect_rm(vdiv), vdiv=VECTEUR_NUL;
459  vect_add_elem(&vadd, TCST, computed);
460  }
461 
462  if (vdiv)
463  {
464  ediv = make_vecteur_expression(vdiv);
465 
466  /* use / instead of the provided idiv if operand >=0
467  */
470  divide, ediv, Value_to_expression(val));
471 
472  if (vadd)
473  {
474  eadd = make_vecteur_expression(vadd);
476  eadd, ediv);
477  }
478  else
479  e = ediv;
480  }
481  else
482  e = make_vecteur_expression(vadd);
483 
484  vect_rm(vdiv), vect_rm(vadd);
485  le = CONS(EXPRESSION, e, le);
486  }
487 
488  /* final operation: MAX or MIN if more than one bound
489  */
490  // Added an option to automatically take the constant value over the other expressions
491  // Should not affect the function unless the property is set to True (False by default)
492  len = gen_length(le); message_assert("some expressions", len!=0);
493 
494  if (len==1)
495  {
496  result = EXPRESSION(CAR(le)); /* and memory leak... (cons lost) */
497  gen_free_list(le);
498  }
499  else if (get_bool_property("PSYSTEME_TO_LOOPNEST_FOR_RSTREAM")) {
500  int nb_constant = 0;
501  FOREACH(expression, exp, le) {
502  if (expression_constant_p(exp)) {
503  result = exp;
504  nb_constant++;
505  }
506  }
507  gen_free_list(le);
508  pips_assert("More than one constant expression in loop bounds", nb_constant == 1);
509  }
510  else
511  {
514  int c = gen_length(le);
516  le = CONS(EXPRESSION, ce, le);
517  result = make_call_expression(operator, le);
518  }
519  else { // Fortran case
521  result = make_call_expression(operator, le);
522  }
523  }
524 
525  sc_rm(s);
526 
527  return result;
528 }
#define value_pos_p(val)
#define value_sign(v)
trian operators on values
#define value_oppose(ref)
#define value_one_p(val)
#define value_zero_p(val)
#define divide(a, b)
#define value_mod(v1, v2)
#define value_posz_p(val)
int compare_Pvecteur(Pvecteur *pv1, Pvecteur *pv2)
comparison function for Pvecteur in pips, to be used by qsort.
Definition: constraint.c:50
#define CONTRAINTE_UNDEFINED_P(c)
Pcontrainte contraintes_dup(Pcontrainte c_in)
Pcontrainte contraintes_dup(Pcontrainte c_in) a list of constraints is copied.
Definition: alloc.c:146
void inegalites_fprint(FILE *, Pcontrainte, char *(*)(Variable))
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#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 FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
Definition: expression.c:2453
#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 message_assert(msg, ex)
Definition: newgen_assert.h:47
#define MAX_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define PIPS_C_MAX_OPERATOR_NAME
#define DIVIDE_OPERATOR_NAME
#define PIPS_C_MIN_OPERATOR_NAME
PIPS run-time support for C code generation.
#define MIN_OPERATOR_NAME
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
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression make_vecteur_expression(Pvecteur pv)
make expression for vector (Pvecteur)
Definition: expression.c:1650
expression make_call_expression(entity e, list l)
Build an expression that call an function entity with an argument list.
Definition: expression.c:321
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
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
expression Value_to_expression(Value v)
added interface for linear stuff.
Definition: expression.c:1251
bool c_language_module_p(entity m)
Definition: module.c:447
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define expression_undefined
Definition: ri.h:1223
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
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
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Psysteme sc_sort_constraints(Psysteme ps, Pbase base_index)
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
#define ifdebug(n)
Definition: sg.c:47
struct Scontrainte * succ
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
static Value vecteur_lower_bound(Pvecteur v)
returns v lower bound if found, or INT_MIN.
static bool evaluate_divide_if_possible(Pvecteur v, Value denominator, Value *result)
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
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
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
Pvecteur vect_del_var(Pvecteur v_in, Variable var)
Pvecteur vect_del_var(Pvecteur v_in, Variable var): allocation d'un nouveau vecteur egal a la project...
Definition: unaires.c:206
Pvecteur vect_sort(Pvecteur v, int *compare)
Pvecteur vect_sort(v, compare) Pvecteur v; int (*compare)();.
Definition: unaires.c:335

References c_language_module_p(), CAR, compare_Pvecteur(), CONS, CONTRAINTE_UNDEFINED_P, contraintes_dup(), divide, DIVIDE_OPERATOR_NAME, entity_intrinsic(), entity_local_name(), evaluate_divide_if_possible(), exp, EXPRESSION, expression_constant_p(), expression_undefined, FOREACH, fprintf(), gen_free_list(), gen_length(), get_bool_property(), get_current_module_entity(), ifdebug, inegalites_fprint(), int_to_expression(), make_call_expression(), make_vecteur_expression(), MakeBinaryCall(), MAX_OPERATOR_NAME, message_assert, MIN_OPERATOR_NAME, NIL, pips_assert, PIPS_C_MAX_OPERATOR_NAME, PIPS_C_MIN_OPERATOR_NAME, pips_debug, PLUS_OPERATOR_NAME, sc_make(), sc_rm(), sc_sort_constraints(), Scontrainte::succ, Svecteur::succ, TCST, val_of, value_div, value_minus, value_mod, VALUE_ONE, value_one_p, value_oppose, value_pos_p, value_posz_p, value_sign, Value_to_expression(), value_zero_p, var_of, vect_add_elem(), vect_chg_sgn(), vect_coeff(), vect_del_var(), vect_erase_var(), vect_rm(), vect_sort(), Scontrainte::vecteur, vecteur_lower_bound(), and VECTEUR_NUL.

Referenced by do_array_expansion(), do_check_isolate_statement_preconditions_on_call(), do_isolate_statement_preconditions_satisified_p(), do_solve_hardware_constraints_on_nb_proc(), make_rectangular_area(), region_to_minimal_dimensions(), statement_insertion_fix_access(), systeme_to_loop_nest(), and variable_to_dimensions().

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

◆ evaluate_divide_if_possible()

static bool evaluate_divide_if_possible ( Pvecteur  v,
Value  denominator,
Value result 
)
static

Definition at line 328 of file system_to_code.c.

332 {
333  Value min=0, max=0;
334 
335  for(; v; v=v->succ)
336  {
337  Variable var = var_of(v);
338  Value coef = val_of(v), lb, ub;
339 
340  if (var==TCST)
341  value_addto(min,coef), value_addto(max,coef);
342  else
343  {
344  Value cu,cl;
345  if (!range_of_variable(var, &lb, &ub))
346  return false;
347  cu = value_mult(coef,ub);
348  cl = value_mult(coef,lb);
349 
350  if (value_pos_p(coef))
351  value_addto(min,cl), value_addto(max,cu);
352  else
353  value_addto(min,cu), value_addto(max,cl);
354  }
355  }
356 
357  value_pdivision(min, denominator);
358  value_pdivision(max, denominator);
359 
360  *result = min;
361  return value_eq(min,max);
362 }
#define value_addto(ref, val)
#define value_eq(v1, v2)
bool operators on values
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
#define value_pdivision(ref, val)
#define min(a, b)
#define max(a, b)
struct Svecteur * succ
Definition: vecteur-local.h:92
static bool range_of_variable(Variable var, Value *lb, Value *ub)
this functions returns bounds for variable var if both are available.

References max, min, range_of_variable(), Svecteur::succ, TCST, val_of, value_addto, value_eq, value_mult, value_pdivision, value_pos_p, and var_of.

Referenced by constraints_to_loop_bound().

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

◆ generate_optional_if()

statement generate_optional_if ( Psysteme  sc,
statement  stat 
)

statement generate_optional_if(sc, stat)

if sc is Z^n then no if is required, if sc is empty, then statement is nop, else an if is required

Parameters
scc
stattat

Definition at line 667 of file system_to_code.c.

670 {
671  if (sc_rn_p(sc)) return(stat);
672  if (sc_empty_p(sc)) return(make_empty_statement());
673 
675  CONS(STATEMENT, stat, NIL),
676  NIL);
677 }
statement st_make_nice_test(expression, list, list)
Definition: statement.c:1585
#define make_empty_statement
An alias for make_empty_block_statement.
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
bool sc_rn_p(Psysteme sc)
bool sc_rn_p(Psysteme sc): check if the set associated to sc is the whole space, rn
Definition: sc_alloc.c:369
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
expression Psysteme_to_expression(Psysteme systeme)
Standard includes.

References CONS, make_empty_statement, NIL, Psysteme_to_expression(), sc_empty_p(), sc_rn_p(), st_make_nice_test(), and STATEMENT.

Referenced by build_third_comb(), generate_io_statements_for_shared_arrays(), GENERATION(), processor_loop(), and verify_array_variable().

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

◆ Pcontrainte_to_expression_list()

list Pcontrainte_to_expression_list ( Pcontrainte  constraint,
entity  operator 
)

a simple expression is generated.

a binary operator should be given, as eg, ne, lt, le, gt, ge.

Parameters
constraintonstraint
operatorperator

Definition at line 90 of file system_to_code.c.

93 {
94  list result = NIL;
95  Pcontrainte c = NULL;
96  Pvecteur vneg = VECTEUR_NUL, vpos = VECTEUR_NUL;
97 
98  for(c=constraint; c; c=c->succ)
99  if (entity_undefined_p(operator))
100 
101  /* a simple expression is generated.
102  */
103  result =
104  CONS(EXPRESSION,
106  result);
107  else
108 
109  /* a binary operator should be given, as eg, ne, lt, le, gt, ge.
110  */
112  result =
114  MakeBinaryCall(operator,
117  result),
118  vect_rm(vpos), vpos=VECTEUR_NUL,
119  vect_rm(vneg), vneg=VECTEUR_NUL;
120 
121  return result;
122 }
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
#define entity_undefined_p(x)
Definition: ri.h:2762
void Pvecteur_separate_on_sign(Pvecteur v, Pvecteur *pvpos, Pvecteur *pvneg)
void Pvecteur_separate_on_sign(v, pvpos, pvneg) Pvecteur v, *pvpos, *pvneg;
Definition: unaires.c:369

References CONS, contrainte_vecteur, entity_undefined_p, EXPRESSION, make_vecteur_expression(), MakeBinaryCall(), NIL, Pvecteur_separate_on_sign(), Scontrainte::succ, vect_rm(), and VECTEUR_NUL.

Referenced by Psysteme_to_expression().

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

◆ Psysteme_to_expression()

expression Psysteme_to_expression ( Psysteme  systeme)

Standard includes.

system_to_code.c

Psystems stuff Newgen stuff PIPS stuff expression Psysteme_to_expression(Psysteme systeme)

From a Psysteme, a logical expression that checks for the constraints is generated.

Parameters
systemeysteme

Definition at line 69 of file system_to_code.c.

71 {
72  entity
75  list conjonction;
76  expression result;
77 
78  conjonction =
79  gen_nconc
80  (Pcontrainte_to_expression_list(sc_egalites(systeme), equ),
81  Pcontrainte_to_expression_list(sc_inegalites(systeme), leq));
82 
83  result = expression_list_to_conjonction(conjonction);
84 
85  gen_free_list(conjonction);
86  return result;
87 }
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define EQUAL_OPERATOR_NAME
#define LESS_OR_EQUAL_OPERATOR_NAME
expression expression_list_to_conjonction(list l)
Definition: expression.c:1937
list Pcontrainte_to_expression_list(Pcontrainte constraint, entity operator)

References entity_intrinsic(), EQUAL_OPERATOR_NAME, expression_list_to_conjonction(), gen_free_list(), gen_nconc(), LESS_OR_EQUAL_OPERATOR_NAME, and Pcontrainte_to_expression_list().

Referenced by build_third_comb(), expression_less_than_in_context(), generate_optional_if(), and top_down_abc_dimension().

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

◆ range_of_variable()

static bool range_of_variable ( Variable  var,
Value lb,
Value ub 
)
static

this functions returns bounds for variable var if both are available.

whether bounds were found Upper Bound

no information available, that's for sure

Parameters
lbthe VARiable
ubLower Bound

Definition at line 264 of file system_to_code.c.

268 {
269  if (lowers_undefined_p() || uppers_undefined_p())
270  return false; /* no information available, that's for sure */
271 
272  if (!bound_lowers_p((entity) var) || !bound_uppers_p((entity) var))
273  return false;
274 
275  *lb = int_to_value(load_lowers((entity) var));
276  *ub = int_to_value(load_uppers((entity) var));
277 
278  return true;
279 }
#define int_to_value(i)
end LINEAR_VALUE_IS_INT

References int_to_value.

Referenced by evaluate_divide_if_possible().

+ Here is the caller graph for this function:

◆ reset_information_for_code_optimizations()

void reset_information_for_code_optimizations ( void  )

Definition at line 254 of file system_to_code.c.

255 {
256  close_lowers();
257  close_uppers();
258 }

Referenced by generate_io_collect_or_update(), and hpf_remapping().

+ Here is the caller graph for this function:

◆ set_information_for_code_optimizations()

void set_information_for_code_optimizations ( Psysteme  s)

I could keep the system for further optimizations...

Here, only direct lower and upper bounds are extracted and kept.

first look thru equalities

then thru inequalities

UPPER

LOWER

Definition at line 208 of file system_to_code.c.

210 {
211  Pcontrainte c;
212  Variable var;
213  Value coe, cst, val;
214 
215  init_lowers();
216  init_uppers();
217 
218  /* first look thru equalities
219  */
220  for (c=sc_egalites(s); c; c=c->succ)
221  {
222  if (vect_simple_definition_p(contrainte_vecteur(c), &var, &coe, &cst))
223  {
224  val = value_div(value_uminus(cst), coe);
225  store_an_upper((entity) var, VALUE_TO_INT(val));
226  store_a_lower((entity) var, VALUE_TO_INT(val));
227  }
228  }
229 
230  /* then thru inequalities
231  */
232  for (c=sc_inegalites(s); c; c=c->succ)
233  {
234  if (vect_simple_definition_p(contrainte_vecteur(c), &var, &coe, &cst))
235  {
236  if (value_pos_p(coe)) /* UPPER */
237  {
238  Value n = value_uminus(cst),
239  r = value_pdiv(n, coe);
241  }
242  else /* LOWER */
243  {
244  Value n = value_minus(cst,value_plus(coe,VALUE_ONE)),
245  d = value_uminus(coe),
246  r = value_pdiv(n,d);
247  store_a_lower((entity) var, VALUE_TO_INT(r));
248  }
249  }
250  }
251 }
#define VALUE_TO_INT(val)
#define value_pdiv(v1, v2)
#define value_plus(v1, v2)
binary operators on values
static bool vect_simple_definition_p(Pvecteur v, Variable *pvar, Value *pcoe, Value *pcst)
here I store simple bounds on variables appearing in the systems to allow the code generation phase t...
static void store_a_lower(entity var, int val)
static void store_an_upper(entity var, int val)

References contrainte_vecteur, store_a_lower(), store_an_upper(), Scontrainte::succ, value_div, value_minus, VALUE_ONE, value_pdiv, value_plus, value_pos_p, VALUE_TO_INT, value_uminus, and vect_simple_definition_p().

Referenced by generate_io_collect_or_update(), and hpf_remapping().

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

◆ store_a_lower()

static void store_a_lower ( entity  var,
int  val 
)
static

Definition at line 189 of file system_to_code.c.

192 {
193  pips_debug(9, "%s >= %d\n", entity_local_name(var), val);
194 
195  if (bound_lowers_p(var))
196  {
197  int old = load_lowers(var);
198  if (old<val) update_lowers(var, val);
199  }
200  else
201  store_lowers(var, val);
202 }

References entity_local_name(), and pips_debug.

Referenced by set_information_for_code_optimizations().

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

◆ store_an_upper()

static void store_an_upper ( entity  var,
int  val 
)
static

Definition at line 173 of file system_to_code.c.

176 {
177  pips_debug(9, "%s <= %d\n", entity_local_name(var), val);
178 
179  if (bound_uppers_p(var))
180  {
181  int old = load_uppers(var);
182  if (old>val) update_uppers(var, val);
183  }
184  else
185  store_uppers(var, val);
186 }

References entity_local_name(), and pips_debug.

Referenced by set_information_for_code_optimizations().

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

◆ systeme_to_loop_nest()

statement systeme_to_loop_nest ( Psysteme  sc,
list  vars,
statement  body,
entity  divide 
)

sc is used to generate the loop nest bounds for variables vars.

vars may be empty. the loop statement is returned.

sc is not touched... I have to give the divide entity to be called

duplicate sc

??? could do a better job with =

reverse the list of vars

VAR = LOWER body

DO VAR = LOWER, UPPER, 1 body ENDDO

Parameters
scc
varsof entity
bodyody
divideivide

Definition at line 578 of file system_to_code.c.

583 {
584  range rg;
585  Pcontrainte c, lower, upper;
586  list reverse;
587  statement assign, current = body;
588  Psysteme s;
589 
590  if (ENDP(vars)) return body;
591 
592  s = sc_dup(sc); /* duplicate sc*/
593  sc_transform_eg_in_ineg(s); /* ??? could do a better job with = */
594  c = sc_inegalites(s);
595 
596  reverse = gen_nreverse(gen_copy_seq(vars)); /* reverse the list of vars*/
597 
598  message_assert("no equalities, now", sc_nbre_egalites(s)==0);
599 
600  FOREACH(ENTITY,e,reverse)
601  {
602  Variable var = (Variable) e;
603 
604  pips_debug(5, "variable %s loop\n", entity_name((entity) var));
605 
606  constraints_for_bounds(var, &c, &lower, &upper);
607  if( !CONTRAINTE_UNDEFINED_P(lower) && !CONTRAINTE_UNDEFINED_P(upper) )
608  {
609 
610  if (bounds_equal_p(var, lower, upper))
611  {
612  /* VAR = LOWER
613  * body
614  */
615  assign =
617  constraints_to_loop_bound(lower, var,
618  true, divide));
619  current =
622  NIL)));
623 
624  }
625  else
626  {
627  /* DO VAR = LOWER, UPPER, 1
628  * body
629  * ENDDO
630  */
631  rg = make_range(constraints_to_loop_bound(lower, var,
632  true, divide),
633  constraints_to_loop_bound(upper, var,
634  false, divide),
635  int_to_expression(1));
636 
637  current =
641  make_loop((entity) var,
642  rg,
643  current,
646  NIL)));
647  }
648 
649  contraintes_free(lower);
650  contraintes_free(upper);
651  }
652  }
653 
654  gen_free_list(reverse);
655  sc_inegalites(s)=c, sc_rm(s);
656 
657  return current;
658 }
execution make_execution(enum execution_utype tag, void *val)
Definition: ri.c:838
loop make_loop(entity a1, range a2, statement a3, entity a4, execution a5, list a6)
Definition: ri.c:1301
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
range make_range(expression a1, expression a2, expression a3)
Definition: ri.c:2041
Pcontrainte contraintes_free(Pcontrainte pc)
Pcontrainte contraintes_free(Pcontrainte pc): desallocation de toutes les contraintes de la liste pc.
Definition: alloc.c:226
void constraints_for_bounds(Variable, Pcontrainte *, Pcontrainte *, Pcontrainte *)
void constraints_for_bounds(var, pinit, plower, pupper) Variable var; Pcontrainte *pinit,...
Definition: unaires.c:176
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
statement make_assign_statement(expression, expression)
Definition: statement.c:583
#define UU
Definition: newgen_types.h:98
entity entity_empty_label(void)
Definition: entity.c:1105
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
@ is_instruction_loop
Definition: ri.h:1471
#define entity_name(x)
Definition: ri.h:2790
@ is_execution_sequential
Definition: ri.h:1189
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
void sc_transform_eg_in_ineg(Psysteme sc)
Package sc.
static size_t current
Definition: string.c:115
expression constraints_to_loop_bound(Pcontrainte c, Variable var, bool is_lower, entity divide)
expression constraints_to_loop_bound(c, var, is_lower)
bool bounds_equal_p(Variable var, Pcontrainte lower, Pcontrainte upper)
this function checks whether the lower and upper constraints are going to generate the same bound on ...

References bounds_equal_p(), CONS, constraints_for_bounds(), constraints_to_loop_bound(), CONTRAINTE_UNDEFINED_P, contraintes_free(), current, divide, ENDP, ENTITY, entity_empty_label(), entity_name, entity_to_expression(), FOREACH, gen_copy_seq(), gen_free_list(), gen_nreverse(), instruction_to_statement(), int_to_expression(), is_execution_sequential, is_instruction_loop, make_assign_statement(), make_block_statement(), make_execution(), make_instruction(), make_loop(), make_range(), message_assert, NIL, pips_debug, sc_dup(), sc_rm(), sc_transform_eg_in_ineg(), STATEMENT, and UU.

Referenced by broadcast(), copy_write_statement_with_cumulated_regions(), elements_loop(), generate_io_statements_for_shared_arrays(), GENERATION(), initialize_array_variable(), make_array_communication_statement(), processor_loop(), Psysteme_to_loop_nest(), and verify_array_variable().

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

◆ vect_simple_definition_p()

static bool vect_simple_definition_p ( Pvecteur  v,
Variable pvar,
Value pcoe,
Value pcst 
)
static

here I store simple bounds on variables appearing in the systems to allow the code generation phase to use them to improve the code.

returns the lower and upper bounds of var if available the concept could be transfered to SC ?

size == 2

Definition at line 133 of file system_to_code.c.

138 {
139  Variable var;
140  int size = vect_size(v);
141  if (size>2 || size<1) return false;
142 
143  var = var_of(v);
144  if (var==TCST && size<=1) return false;
145 
146  if (var==TCST) /* size == 2 */
147  {
148  *pvar = var_of(v->succ);
149  *pcoe = val_of(v->succ);
150  *pcst = val_of(v);
151  return true;
152  }
153  else
154  {
155  *pvar = var;
156  *pcoe = val_of(v);
157  if (!v->succ)
158  {
159  *pcst = 0;
160  return true;
161  }
162 
163  if (var_of(v->succ)!=TCST) return false;
164  *pcst = val_of(v->succ);
165  return true;
166  }
167 }
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47

References Svecteur::succ, TCST, val_of, var_of, and vect_size().

Referenced by set_information_for_code_optimizations().

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

◆ vecteur_lower_bound()

static Value vecteur_lower_bound ( Pvecteur  v)
static

returns v lower bound if found, or INT_MIN.

no information available, that's for sure

val < 0, I guess

Definition at line 283 of file system_to_code.c.

285 {
286  Value bound = 0, val;
287  Variable var;
288 
289  if (lowers_undefined_p() || uppers_undefined_p())
290  return VALUE_MIN; /* no information available, that's for sure */
291 
292  for(; v; v=v->succ)
293  {
294  var = var_of(v);
295  val = val_of(v);
296 
297  if (var==TCST)
298  value_addto(bound,val) ;
299  else
300  {
301  int il;
302  Value vl,p;
303  if (value_pos_p(val))
304  {
305  if (!bound_lowers_p((entity) var))
306  return VALUE_MIN;
307  else
308  il = load_lowers((entity) var);
309  }
310  else /* val < 0, I guess */
311  {
312  if (!bound_uppers_p((entity) var))
313  return VALUE_MIN;
314  else
315  il = load_uppers((entity) var);
316  }
317 
318  vl = int_to_value(il);
319  p = value_mult(val,vl);
320  value_addto(bound,p);
321  }
322  }
323 
324  return bound;
325 }
#define VALUE_MIN

References int_to_value, Svecteur::succ, TCST, val_of, value_addto, VALUE_MIN, value_mult, value_pos_p, and var_of.

Referenced by constraints_to_loop_bound().

+ Here is the caller graph for this function: