PIPS
misc_paf_utils.c
Go to the documentation of this file.
1 /*
2 
3  $Id: misc_paf_utils.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 
28 // To have asprintf:
29 #include <stdio.h>
30 
31 #include "linear.h"
32 #include "genC.h"
33 
34 #include "misc.h"
35 
36 #include "ri-util.h"
37 #include "text-util.h"
38 
39 #define STATIC_CONTROLIZE_MODULE_NAME "STATCON"
40 #define NLC_PREFIX "NLC"
41 #define NSP_PREFIX "NSP"
42 #define NUB_PREFIX "NUB"
43 
44 /* list base_to_list(Pbase v): translates a Pbase into a list of entities, in
45  * the same order.
46  */
48 {
49  list l = NIL;
50 
51  for( ; b != NULL; b = b->succ)
52  l = gen_nconc(l, CONS(ENTITY, (entity) b->var, NIL));
53 
54  return(l);
55 }
56 
57 /* Pbase list_to_base(list l): returns the Pbase that contains the variables
58  * of list "l", of entities, in the same order.
59  */
61 list l;
62 {
63  Pbase new_b = NULL;
64  list el_l;
65 
66  for(el_l = l ; el_l != NIL; el_l = CDR(el_l))
67  vect_add_elem((Pvecteur *) &new_b, (char *) ENTITY(CAR(el_l)), VALUE_ONE);
68 
69  new_b = base_reversal(new_b);
70  return(new_b);
71 }
72 
73 /*=================================================================*/
74 /* expression make_max_exp(entity ent, expression exp1, expression exp2)
75  * computes MAX( exp1, exp2 ) if exp1 and exp2 are constant expressions.
76  * If it is not the case, it returns MAX( exp1, exp2 )
77  */
78 expression make_max_exp( ent, exp1, exp2 )
79 entity ent;
80 expression exp1, exp2;
81 {
82  expression rexp;
83 
84  /* pips_debug(7, "doing MAX( %s, %s ) \n", */
85  /* expression_to_string(exp1), */
86  /* expression_to_string(exp2) ); */
87  if (expression_constant_p( exp1 ) && expression_constant_p( exp2 )) {
88  int val1 = expression_to_int( exp1 );
89  int val2 = expression_to_int( exp2 );
90  if (val1 > val2) rexp = int_to_expression(val1);
91  else rexp = int_to_expression( val2 );
92  }
93  else rexp = MakeBinaryCall( ent, exp1, exp2 );
94 
95  return rexp ;
96 }
97 
98 
99 /*=================================================================*/
100 /* entity make_nlc_entity(int *Gcount_nlc):
101  *
102  * Returns a new entity. Its local name is "NLC#", where '#' represents
103  * the value of "Gcount_nlc". This variable counts the number of NLCs
104  * variables.
105  *
106  * These entities have a special full name. The first part of it is the
107  * concatenation of the define constant STATIC_CONTROLIZE_MODULE_NAME and
108  * the local name of the current module.
109  *
110  * The type ("basic") of these variables is INTEGER.
111  *
112  * These variables are local to the current module, so they have a
113  * "storage_ram" with DYNAMIC "area".
114  *
115  * NLC means Normalized Loop Counter.
116  */
118 int *Gcount_nlc;
119 {
120  entity new_ent, mod_ent;
121  char *name, *num;
123  ram new_dynamic_ram;
124 
125 
126  debug( 7, "make_nlc_entity", "doing\n");
127  (*Gcount_nlc)++;
128  (void) asprintf(&num, "%d", *Gcount_nlc);
129 
131 
134  MODULE_SEP_STRING, NLC_PREFIX, num, (char *) NULL));
135 
136  new_ent = make_entity(name,
139  NIL,NIL)),
142 
145 
146  new_dynamic_ram = make_ram(mod_ent,
147  dynamic_area,
149  NIL);
150 
151  storage_ram(entity_storage(new_ent)) = new_dynamic_ram;
152 
153  return(new_ent);
154 }
155 
156 /*=================================================================*/
157 
159 
161 
162 /* entity make_nsp_entity()
163  * Makes a new NSP (for New Structural Parameter) .
164  */
166 {
167  entity new_ent, mod_ent;
168  char *name, *num;
170  ram new_dynamic_ram;
171 
172  debug( 7, "make_nsp_entity", "doing\n");
173  Gcount_nsp++;
174  (void) asprintf(&num, "%d", Gcount_nsp);
175 
177 
180  MODULE_SEP_STRING, NSP_PREFIX, num, (char *) NULL));
181 
182  new_ent = make_entity(name,
185  NIL,NIL)),
188 
191 
192  new_dynamic_ram = make_ram(mod_ent,
193  dynamic_area,
195  NIL);
196 
197  storage_ram(entity_storage(new_ent)) = new_dynamic_ram;
198 
199  return new_ent;
200 }
201 
202 /*=================================================================*/
203 /* entity make_nub_entity()
204  * Makes a new NUB (for New Upper Bound) .
205  */
207 {
208  entity new_ent, mod_ent;
209  char *name, *num;
211  ram new_dynamic_ram;
212 
213 
214  debug( 7, "make_nub_entity", "doing\n");
215  Gcount_nub++;
216  (void) asprintf(&num, "%d", Gcount_nub);
217 
219 
222  MODULE_SEP_STRING, NUB_PREFIX, num, (char *) NULL));
223 
224  new_ent = make_entity(name,
227  NIL,NIL)),
230 
233 
234  new_dynamic_ram = make_ram(mod_ent,
235  dynamic_area,
237  NIL);
238 
239  storage_ram(entity_storage(new_ent)) = new_dynamic_ram;
240 
241  return new_ent;
242 }
243 
244 /*=================================================================*/
245 /* entity current_module(entity mod): returns the current module entity,
246  * that is the entity of the module in which we are working currently.
247  * If the entity "mod" is undefined, it returns the static entity already known;
248  * Else, the static entity is updated to the entity "mod".
249  */
251 entity mod;
252 {
253  static entity current_mod;
254 
255  debug( 7, "current_module", "doing\n");
256  if (mod != entity_undefined) {
257  pips_assert("current_module_entity", entity_module_p(mod));
258  current_mod = mod;
259  }
260  return(current_mod);
261 }
262 
263 #define ADD_ELEMENT_TO_LIST( _list, _type, _element) \
264  (_list = gen_nconc( _list, CONS( _type, _element, NIL)))
265 
266 
267 /*==================================================================*/
268 
269 /* bool undefined_statement_list_p( (list) l ) AL 04/93
270  * Returns true if l is made of 2 undefined or continue statement.
271  */
273 list l;
274 {
275  bool local_bool;
276  statement first, second;
277 
278  debug(7, "undefined_statement_list_p","doing\n");
279  if ( (l == NIL) || (gen_length(l) != 2) )
280  return( false );
281 
282  first = STATEMENT(CAR( l ));
283  second = STATEMENT(CAR(CDR( l )));
284  local_bool = ( first == statement_undefined )
285  && ( second == statement_undefined );
286 
287  /* Newgen does not support list of undefined objects */
288  if(!local_bool) {
289  local_bool = continue_statement_p(first) && continue_statement_p(second);
290  }
291 
292  return( local_bool );
293 }
294 
295 /*=================================================================*/
296 /* entity expression_int_scalar((expression) exp)
297  * Returns the scalar entity if this expression is a scalar.
298  */
301 {
303  tag t = syntax_tag( s );
304  entity ent = entity_undefined;
305 
306  debug( 7, "expression_int_scalar", "doing \n");
307  switch( t ) {
308  case is_syntax_reference: {
309  entity local;
311  if (entity_integer_scalar_p(local)) ent = local;
312  break;
313  }
314  default: break;
315  }
316  debug( 7, "expression_int_scalar",
317  "returning : %s\n",
318  ((ent == entity_undefined)?"entity_undefined":
319  entity_local_name( ent )) );
320  return( ent );
321 }
322 
323 /* entity scalar_assign_call((call) c)
324  * Detects if the call is an assignement
325  * and if the value assigned is a scalar. If it is so, it
326  * returns this scalar.
327  */
329 call c;
330 {
331  entity ent = entity_undefined;
332 
333  debug( 7, "scalar_assign_call", "doing \n");
335  {
336  expression lhs;
337 
338  lhs = binary_call_lhs(c);
339  ent = expression_int_scalar( lhs );
340  }
341  debug( 7, "scalar_assign_call", "returning : %s \n",
342  ((ent == entity_undefined)?"entity_undefined":
343  entity_name(ent)) );
344  return( ent );
345 }
346 
347 /* scalar_written_in_call((call) the_call)
348  * Detects and puts a scalar written in an assignement call,
349  * in the global list Gscalar_written_forward if Genclosing_loops
350  * or Genclosing_tests are not empty.
351  */
352 void scalar_written_in_call( the_call, ell, etl, swfl)
353 call the_call;
354 list *ell, *etl, *swfl;
355 {
356  entity ent;
357 
358  debug( 7, "scalar_written_in_call", "doing\n");
359  if ( ((ent = scalar_assign_call(the_call)) != entity_undefined)
360  && ( (*ell != NIL) || (*etl != NIL) )
361  && entity_integer_scalar_p( ent ) )
362 
363  ADD_ELEMENT_TO_LIST(*swfl, ENTITY, ent);
364 }
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
storage make_storage(enum storage_utype tag, void *val)
Definition: ri.c:2273
ram make_ram(entity a1, entity a2, intptr_t a3, list a4)
Definition: ri.c:1999
value make_value(enum value_utype tag, void *val)
Definition: ri.c:2832
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
static entity current_mod
Definition: alias_check.c:120
#define VALUE_ONE
static entity mod_ent
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
static int num
Definition: bourdoncle.c:137
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
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 CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool continue_statement_p(statement)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: statement.c:203
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
Definition: expression.c:2453
#define asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
int Gcount_nsp
================================================================
list base_to_list(Pbase b)
list base_to_list(Pbase v): translates a Pbase into a list of entities, in the same order.
#define NUB_PREFIX
entity scalar_assign_call(call c)
entity scalar_assign_call((call) c) Detects if the call is an assignement and if the value assigned i...
entity make_nlc_entity(int *Gcount_nlc)
================================================================
entity make_nub_entity()
================================================================
bool undefined_statement_list_p(list l)
=================================================================
entity expression_int_scalar(expression exp)
================================================================
entity make_nsp_entity()
entity make_nsp_entity() Makes a new NSP (for New Structural Parameter) .
Pbase list_to_base(list l)
Pbase list_to_base(list l): returns the Pbase that contains the variables of list "l",...
expression make_max_exp(entity ent, expression exp1, expression exp2)
================================================================
#define ADD_ELEMENT_TO_LIST(_list, _type, _element)
void scalar_written_in_call(call the_call, list *ell, list *etl, list *swfl)
scalar_written_in_call((call) the_call) Detects and puts a scalar written in an assignement call,...
int Gcount_nub
#define NSP_PREFIX
#define STATIC_CONTROLIZE_MODULE_NAME
#define NLC_PREFIX
entity current_module(entity mod)
================================================================
#define DYNAMIC_AREA_LOCAL_NAME
Definition: naming-local.h:69
#define MODULE_SEP_STRING
Definition: naming-local.h:30
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
int tag
TAG.
Definition: newgen_types.h:92
#define UUINT(i)
Definition: newgen_types.h:99
#define UU
Definition: newgen_types.h:98
static entity dynamic_area
#define ENTITY_ASSIGN_P(e)
#define make_entity(n, t, s, i)
#define binary_call_lhs(c)
int current_offset_of_area(entity a, entity v)
Definition: area.c:174
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 FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
Definition: entity.c:1586
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool entity_module_p(entity e)
Definition: entity.c:683
int expression_to_int(expression exp)
================================================================
Definition: expression.c:2205
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
bool entity_integer_scalar_p(entity)
for variables (like I), not constants (like 1)! use integer_constant_p() for constants
Definition: variable.c:1130
@ is_basic_int
Definition: ri.h:571
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define ram_undefined
Definition: ri.h:2221
#define entity_storage(x)
Definition: ri.h:2794
@ is_value_unknown
Definition: ri.h:3035
@ is_syntax_reference
Definition: ri.h:2691
@ is_storage_ram
Definition: ri.h:2492
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define storage_ram(x)
Definition: ri.h:2521
@ is_type_variable
Definition: ri.h:2900
#define expression_syntax(x)
Definition: ri.h:1247
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
char * strdup()
int Gcount_nlc
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
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207
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