PIPS
type.c
Go to the documentation of this file.
1 /*
2 
3  $Id$
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 
28 //#include <stdio.h>
29 //#include <string.h>
30 
31 #include "genC.h"
32 #include "linear.h"
33 
34 #include "misc.h"
35 // #include "properties.h"
36 
37 #include "ri.h"
38 #include "effects.h"
39 
40 #include "ri-util.h"
41 #include "prettyprint.h"
42 #include "effects-util.h"
43 
44 #include "text-util.h"
45 
46 #include "effects-simple.h"
47 
48 #include "pips-libs.h"
49 
50 #include "transformer.h"
51 #include "semantics.h"
52 
53 // FI: these constants are not (yet) defined in ri-util-local.h
54 #define unsigned_char 11
55 #define unsigned_short_int 12
56 #define unsigned_int 14
57 #define unsigned_long_int 16
58 #define unsigned_long_long_int 18
59 
60 /* Add some of the constraints linked to the type of a variable */
62 {
64  Pbase b = vect_copy(sc_base(ps)); // FI: the basis may evolve when
65  // new constraints are added
66  Pbase cb = BASE_NULLE;
67 
68  for(cb=b; !BASE_NULLE_P(cb); cb = vecteur_succ(cb)) {
69  Variable v = vecteur_var(cb);
70  //entity ev = (entity) v;
71  if(v!=TCST && !local_old_value_entity_p(v)) { // FI: TCST check should be useless in a basis
74  if(unsigned_type_p(t)) {
76  int s = basic_int(tb);
77  // FI: the lower bound, lb, could also be defined, e.g. for "char"
78  long long int ub = -1/*, lb = 0*/;
79  long long int period = 0;
80  switch(s) {
81  case unsigned_char:
82  ub = 256-1, period = 256;
83  break;
84  case unsigned_short_int:
85  ub = 256*256-1, period = 256*256;
86  break;
87  case unsigned_int:
88  // We go straight to the overflows!
89  // ub = 256L*256L*256L*256L-1;
90  ub = 0, period = 256L*256L*256L*256L;
91  break;
92  case unsigned_long_int:
93  // We go straight to the overflows!
94  // ub = 256L*256L*256L*256L-1;
95  ub = 0, period = 256L*256L*256L*256L;
96  break;
98  // We go straight to the overflows!
99  //ub = 256*256*256*256*256*256*256*256-1;
100  //ub = 0; // FI: too dangerous
101  break;
102  default:
103  ub=-1; // do nothing
104  break;
105  }
106  if(ub>=0) {
107  /* We assume exists lambda s.t. e = ep + period*lambda */
111  if(ub>0) {
112  // Without this dangerous upperbound, we lose information
113  // but avoid giving wrong results.
114  // FI: The upperbound is dangerous because linear does not
115  // expect such large constants, especially my bounded normalization
116  // that should be itself bounded! See
117  // check_coefficient_reduction() and the stack allocation
118  // of arrays a, b and c!
120  }
121  Pvecteur eq =
123  ep, VALUE_ONE,
124  lambda, (Value) period, TCST, VALUE_ZERO, NULL);
125  tf = transformer_equality_add(tf, eq);
126  /* Compute the value of lambda */
127  Value pmin, pmax;
128  if(precondition_minmax_of_value(lambda, tf, (intptr_t*) &pmin, (intptr_t*) &pmax)) {
129  if(pmin==pmax)
130  tf = transformer_add_equality_with_integer_constant(tf, lambda, pmin);
131  }
132  /* Now we must get rid of lambda and e and possibly e's old value */
133  list p =
134  CONS(ENTITY, e, CONS(ENTITY, lambda, NIL));
135  pips_assert("ep is in tf basis",
136  base_contains_variable_p(sc_base(ps), ep));
137  pips_assert("lambda is in tf basis",
138  base_contains_variable_p(sc_base(ps), lambda));
140  entity old_e = entity_to_old_value(e);
141  p = CONS(ENTITY, old_e, p);
142  pips_assert("old_e is in tf basis",
143  base_contains_variable_p(sc_base(ps), ep));
144  }
145  /* Transformer projection removes variables from the
146  argument list as well as from the contraint system. */
148  tf = safe_transformer_projection(tf, p);
150  transformer_arguments(tf) = args;
151  gen_free_list(p);
152  /* Now we must substitute ep by e */
153  tf = transformer_value_substitute(tf, ep, e);
154  }
155  }
156  }
157  }
158  vect_rm(b);
159  return;
160 }
161 
163 {
165  return;
166 }
167 
169 {
170  pips_assert("entity has values", entity_has_values_p(v));
171  entity vv = entity_to_new_value(v);
175  return;
176 }
bool entity_is_argument_p(entity e, cons *args)
Definition: arguments.c:150
#define VALUE_ZERO
#define VALUE_MONE
int Value
#define VALUE_ONE
bool base_contains_variable_p(Pbase b, Variable v)
bool base_contains_variable_p(Pbase b, Variable v): returns true if variable v is one of b's elements...
Definition: base.c:136
transformer transformer_add_inequality_with_integer_constraint(transformer tf, entity v, long long int cst, bool less_than_p)
Add the inequality v <= cst or v >= cst.
Definition: basic.c:477
bool value_belongs_to_transformer_space(entity v, transformer tf)
Definition: basic.c:842
transformer transformer_add_equality_with_integer_constant(transformer tf, entity v, long long int cst)
Add an equality between a value and an integer constant: v==cst.
Definition: basic.c:450
transformer transformer_equality_add(transformer tf, Pvecteur i)
Definition: basic.c:383
void add_value_to_transformer_space(entity v, transformer tf)
Definition: basic.c:859
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
bool unsigned_type_p(type t)
Predicates on types.
Definition: type.c:2821
type entity_basic_concrete_type(entity e)
retrieves or computes and then returns the basic concrete type of an entity
Definition: type.c:3677
#define basic_int(x)
Definition: ri.h:616
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define type_variable(x)
Definition: ri.h:2949
#define transformer_relation(x)
Definition: ri.h:2873
#define transformer_arguments(x)
Definition: ri.h:2871
#define predicate_system(x)
Definition: ri.h:2069
#define variable_basic(x)
Definition: ri.h:3120
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108
bool precondition_minmax_of_value(entity val, transformer tr, intptr_t *pmin, intptr_t *pmax)
compute integer bounds pmax, pmin of value val under preconditions tr require value mappings set !
Definition: expression.c:5790
#define unsigned_long_int
Definition: type.c:57
#define unsigned_int
Definition: type.c:56
void transformer_add_variable_type_information(transformer tf, entity v)
Definition: type.c:168
#define unsigned_long_long_int
Definition: type.c:58
void transformer_add_type_information(transformer tf)
type.c
Definition: type.c:162
#define unsigned_short_int
Definition: type.c:55
#define unsigned_char
Definition: type.c:54
static void add_type_information(transformer tf)
Add some of the constraints linked to the type of a variable.
Definition: type.c:61
#define intptr_t
Definition: stdint.in.h:294
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
transformer safe_transformer_projection(transformer t, list args)
t may be undefined, args may contain values unrelated to t
Definition: transformer.c:1187
transformer transformer_value_substitute(transformer t, entity e1, entity e2)
transformer transformer_value_substitute(transformer t, entity e1, entity e2): if e2 does not appear ...
Definition: transformer.c:1993
entity make_local_temporary_value_entity(type)
Definition: value.c:605
entity entity_to_new_value(entity)
Definition: value.c:859
entity make_local_temporary_integer_value_entity(void)
Definition: value.c:629
bool entity_has_values_p(entity)
This function could be made more robust by checking the storage of e.
Definition: value.c:911
bool local_old_value_entity_p(entity)
Return true if an entity is a local old value (such as "o#0" for a global value "i#init"....
Definition: value.c:642
entity entity_to_old_value(entity)
Definition: value.c:869
entity value_to_variable(entity)
Get the primitive variable associated to any value involved in a transformer.
Definition: value.c:1624
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
#define vecteur_succ(v)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
#define BASE_NULLE
MACROS SUR LES BASES.
#define BASE_NULLE_P(b)
Pvecteur vect_make(Pvecteur v, Variable var, Value val,...)
Pvecteur vect_make(v, [var, val,]* 0, val) Pvecteur v; // may be NULL, use assigne anyway Variable va...
Definition: alloc.c:165
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
Pvecteur vect_new(Variable var, Value coeff)
Pvecteur vect_new(Variable var,Value coeff): allocation d'un vecteur colineaire au vecteur de base va...
Definition: alloc.c:110
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78