PIPS
sav_alias_lists.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sav_alias_lists.c 23412 2017-08-09 15:07:09Z irigoin $
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 #include <stdio.h>
28 #include <string.h>
29 
30 #include <setjmp.h>
31 
32 #include "genC.h"
33 #include "linear.h"
34 #include "ri.h"
35 #include "effects.h"
36 #include "database.h"
37 
38 #include "ri-util.h"
39 #include "effects-util.h"
40 #include "constants.h"
41 #include "misc.h"
42 #include "text.h"
43 
44 #include "boolean.h"
45 #include "vecteur.h"
46 #include "contrainte.h"
47 #include "sc.h"
48 #include "sommet.h"
49 #include "ray_dte.h"
50 #include "sg.h"
51 #include "polyedre.h"
52 #include "union.h"
53 
54 #include "effects-generic.h"
55 #include "effects-simple.h"
56 #include "effects-convex.h"
57 
58 #include "semantics.h"
59 #include "transformer.h"
60 
61 #include "pipsdbm.h"
62 #include "resources.h"
63 
64 #define BACKWARD TRUE
65 #define FORWARD FALSE
66 
68 
69 /*
70 static bool
71 no_alias_for(region reg)
72 {
73  list rest_alias_lists = l_alias_lists;
74  list alias_list;
75  region alias_reg;
76  Psysteme reg_sys, alias_reg_sys;
77  bool result = true;
78 
79  if (l_alias_lists != NIL)
80  do {
81  alias_list = LIST( CAR(rest_alias_lists) );
82  alias_reg = EFFECT( CAR(alias_list) );
83  if ( effects_same_action_p(reg,alias_reg) )
84  {
85  reg_sys = region_system(reg);
86  alias_reg_sys = region_system(alias_reg);
87  if ( sc_equal_p_ofl(reg_sys,alias_reg_sys) )
88  result = false;
89  }
90  rest_alias_lists = CDR(rest_alias_lists);
91  } while (rest_alias_lists != NIL && result == true);
92  return result;
93 }
94 */
95 
96 /*
97 static void
98 make_alias_list_sub_region(region reg, const char* module_name)
99 {
100  list alias_list, l_pairs;
101 */
102  /* put reg in list of one element for call to alias_pairs */
103 /* l_pairs = alias_pairs( module_name, CONS(EFFECT,reg,NIL) );
104  */
105  /* turn list_pairs into an alias list */
106 /* alias_list = CONS(EFFECT,reg,NIL);
107  MAP(EFFECTS,alias_pair,
108  {
109  alias_list = gen_nconc(alias_list,CDR(alias_pair));
110  },
111  l_pairs);
112  l_alias_lists = gen_nconc(l_alias_lists,CONS(LIST,alias_list,NIL));
113 }
114 */
115 
116 /*
117 static void
118 make_alias_list_if_sub_region(region reg, const char* module_name)
119 {
120  Psysteme reg_sys, alias_reg_sys;
121  region alias_reg;
122 */
123 /* if there is no alias for reg in this module */
124 /* if ( no_alias_for(reg) )
125  {
126  */
127 /* for each alias_list=[alias_reg|list_trans_alias_reg] of this module,... */
128 /* MAP(LIST,alias_list,
129  {
130  alias_reg = EFFECT( CAR(alias_list) );
131  */
132 /* ... except for COMMON region alias_lists, do */
133 /* if ( ! storage_ram_p(
134  entity_storage(region_entity(alias_reg))
135  ))
136  {
137  */
138 /* see if reg is properly included in alias_reg */
139 /* if ( effects_same_action_p(alias_reg,reg) )
140  {
141  reg_sys = region_system(reg);
142  alias_reg_sys = region_system(alias_reg);
143  if (sc_inclusion_p_ofl(reg_sys,alias_reg_sys) &&
144  ! sc_inclusion_p_ofl(alias_reg_sys,reg_sys) )
145  */
146 /* and, if so, add alias list for reg to this module */
147 /* make_alias_list_sub_region(reg,module_name);
148 
149  }
150  }
151  },
152  l_alias_lists);
153  }
154 }
155 */
156 
157 /*
158 static void
159 make_alias_lists_for_sub_regions(const char* module_name)
160 {
161  entity module_entity = local_name_to_top_level_entity(module_name);
162  callees module_callees;
163  list callee_alias_lists;
164 */
165  /* we need the callees of the current module */
166 /* module_callees = (callees) db_get_memory_resource(DBR_CALLEES,
167  module_name,
168  true);
169  */
170  /* for each callee do */
171 /* MAP(STRING, callee_name,
172  {
173  callee_alias_lists = (list) db_get_memory_resource(DBR_ALIAS_LISTS,
174  callee_name,
175  true);
176  */
177  /* for each alias list do */
178 /* MAP(EFFECTS, alias_list_effects,
179  {
180  list callee_alias_list = regions_dup(effects_to_list(alias_list_effects));
181 */
182 /* don't treat COMMON regions */
183 /* if ( ! storage_ram_p(
184  entity_storage(region_entity(EFFECT(CAR(callee_alias_list))))
185  ))
186  {
187 */
188 
189 /* for any alias in this module do */
190 /* MAP(EFFECT, trans_reg,
191  {
192  if ( module_entity == region_entity(trans_reg) )
193 */
194 
195 /* if it is a sub-region of an IN or OUT region of this module */
196 /* then make an alias list for it in this module */
197 /* make_alias_list_if_sub_region(trans_reg, module_name);
198  },
199  CDR(callee_alias_list));
200  }
201  },
202  callee_alias_lists);
203  },
204  callees_callees(module_callees));
205 }
206 */
207 
208 /* tests if reg1 and reg2 are the same,
209  * ignoring their action_tags (read/write)
210  * but checking their precision (may/exact)
211  */
212 bool
214  {
215  Psysteme reg1_sys, reg2_sys;
216  bool result = false;
217 
218  pips_debug(4,"begin\n");
219 
220 /*
221  ifdebug(9)
222  {
223  pips_debug(9,"compare:\n\t");
224  print_region(reg1);
225  pips_debug(9,"with:\n\t");
226  print_region(reg2);
227  }
228  */
229 
230  if (effect_undefined_p(reg1) || effect_undefined_p(reg2)) return result;
231 
232  if (effect_entity(reg1) == effect_entity(reg2))
233  {
234  if (effect_approximation_tag(reg1) ==
236  {
237  reg1_sys = region_system(reg1);
238  reg2_sys = region_system(reg2);
239  if ( sc_equal_p_ofl(reg1_sys,reg2_sys) )
240  {
241  result = true;
242 
243  pips_debug(4,"same region\n");
244  }
245  }
246  }
247  pips_debug(4,"end\n");
248 
249  return result;
250  }
251 
252 
253 /* tests if reg and any member of reg_list
254  * are same_reg_ignore_action
255  */
256 static bool
257 member(region reg, list reg_list)
258  {
259  region elem;
260  list rest_list;
261  bool result = false;
262 
263  pips_debug(4,"begin\n");
264 
265 /*
266  ifdebug(9)
267  {
268  pips_debug(9,"test if:\n\t");
269  print_region(reg);
270  pips_debug(9,"is in:\n\t");
271  print_inout_regions(reg_list);
272  }
273  */
274 
275  rest_list = reg_list;
276 
277  if (reg_list != NIL)
278 
279  do{
280  elem = EFFECT(CAR(rest_list));
281  if (same_reg_ignore_action(elem,reg))
282  {
283  result = true;
284 
285  pips_debug(4,"is member\n");
286  }
287 
289  }while (rest_list != NIL && result == false);
290 
291  pips_debug(4,"end\n");
292 
293  return result;
294  }
295 
296 /* adds reg as final element on the end of reg_list
297  * unless reg is already present in reg_list */
298 list
300 {
301  list new_reg_list;
302 
303  pips_debug(4,"begin\n");
304 
305 
306 /*
307  ifdebug(9)
308  {
309  pips_debug(9,"add:\n\t");
310  print_region(reg);
311  pips_debug(9,"to:\n\t");
312  print_inout_regions(reg_list);
313  }
314 */
315 
316  if (!member(reg,reg_list))
317  new_reg_list = gen_nconc(reg_list,
318  CONS(EFFECT,region_dup(reg),NIL));
319  else
320  new_reg_list = reg_list;
321 
322  pips_debug(4,"end\n");
323 
324  return new_reg_list;
325 }
326 
327 
328 /* GLOBAL IN: l_alias_lists
329  * GLOBAL OUT: l_alias_lists
330  */
331 static bool
333 {
334  list rest_alias_lists, alias_list;
335  region formal_reg_pair, formal_reg_list, actual_reg_pair;
336  bool result = false;
337 
338  pips_debug(4,"begin\n");
339 
340  formal_reg_pair = EFFECT( CAR(alias_pair) );
341 
342  ifdebug(9)
343  {
345  pips_debug(9,"compare:\n\t");
346  print_region(formal_reg_pair);
347  }
348 
349  rest_alias_lists = l_alias_lists;
350  if (l_alias_lists != NIL)
351  do {
352  alias_list = LIST( CAR(rest_alias_lists) );
353  formal_reg_list = EFFECT( CAR(alias_list) );
354 
355  ifdebug(9)
356  {
357  pips_debug(9,"with:\n\t");
358  print_region(formal_reg_list);
359  }
360 
361  if ( same_reg_ignore_action(formal_reg_pair,formal_reg_list) )
362  {
363  result = true;
364  actual_reg_pair = EFFECT(CAR(CDR(alias_pair)));
365  ifdebug(9)
366  {
367  pips_debug(9,"add:\n\t");
368  print_region(actual_reg_pair);
369  pips_debug(9,"to:\n\t");
370  print_inout_regions(alias_list);
371  }
372  alias_list =
373  append_reg_if_not_present(alias_list,actual_reg_pair);
374  }
375  rest_alias_lists = CDR(rest_alias_lists);
376  } while (rest_alias_lists != NIL && result == false);
377 
378  ifdebug(9)
379  {
381  }
382  pips_debug(4,"end\n");
383 
384  return result;
385 }
386 
387 /* GLOBAL OUT: l_alias_lists */
388 bool
389 alias_lists( const char* module_name )
390  {
391 /* list in_alias_pairs, out_alias_pairs, in_alias_pair, out_alias_pair; */
393  entity module;
394 
395  l_alias_lists = NIL;
396 
397  debug_on("ALIAS_LISTS_DEBUG_LEVEL");
398  pips_debug(4,"begin for module %s\n",module_name);
399 
400  ifdebug(9)
401  {
402  /* ATTENTION: we have to do ALL this
403  * just to call print_inout_regions for debug !!
404  */
409  db_get_memory_resource(DBR_CODE,
410  module_name,
411  true) );
414  DBR_CUMULATED_EFFECTS,
415  module_name,
416  true));
419  DBR_PROPER_EFFECTS,
420  module_name,
421  true));
423  /* that's it, but we musn't forget to reset everything below */
424  }
425 
426  /* make alias lists from the IN_alias_pairs */
427 
428  /* DBR_IN_ALIAS_PAIRS is a newgen structure of type effects_classes
429  * which has one field called classes
430  * which is a list of newgen structures of type effects
431  * (and each newgen structure of type effects
432  * has one field called effects which is a list of elements
433  * of type effect)
434  */
435 
438  db_get_memory_resource(DBR_IN_ALIAS_PAIRS,
439  module_name,
440  true));
441 
442 
443 /* wrong but did work:
444 
445  in_alias_pairs =
446  effects_to_list((effects)
447  db_get_memory_resource(DBR_IN_ALIAS_PAIRS,
448  module_name,
449  true));
450 */
451 
452 /* seems right but didn't work (gets 2nd element of each pair only):
453 
454  MAP(EFFECTS, alias_pair_effects,
455  {
456  list alias_pair = effects_effects(alias_pair_effects);
457 
458 */
459 
460  MAP(LIST, alias_pair,
461  {
462  list in_alias_pair = regions_dup(alias_pair);
463 
464  ifdebug(9)
465  {
466  pips_debug(9,"IN alias pair : \n");
467  print_inout_regions(in_alias_pair);
468  }
469 
470  if ( ! add_pair_to_existing_list(in_alias_pair) )
471  l_alias_lists =
472  gen_nconc(l_alias_lists,CONS(LIST,in_alias_pair,NIL));
473 
474  pips_debug(9,"IN pair added\n");
475  },
477 
478  /* make alias lists from the OUT_alias_pairs */
481  db_get_memory_resource(DBR_OUT_ALIAS_PAIRS,
482  module_name,
483  true));
484 
485  MAP(LIST, alias_pair,
486  {
487  list out_alias_pair = regions_dup(alias_pair);
488 
489  ifdebug(9)
490  {
491  pips_debug(9,"OUT alias pair : \n");
492  print_inout_regions(out_alias_pair);
493  }
494 
495  if ( ! add_pair_to_existing_list(out_alias_pair) )
496  l_alias_lists =
497  gen_nconc(l_alias_lists,CONS(LIST,out_alias_pair,NIL));
498 
499  pips_debug(9,"OUT pair added\n");
500  },
502 
503  /* check all callees for sub-regions of existing aliases */
504 /* make_alias_lists_for_sub_regions(module_name); */
505 
506  DB_PUT_MEMORY_RESOURCE(DBR_ALIAS_LISTS,
509 
510  ifdebug(9)
511  {
517  }
518  pips_debug(4,"end\n");
519  debug_off();
520 
521  return(true);
522 }
523 
effects_classes make_effects_classes(list a)
Definition: effects.c:526
bool in_alias_pairs(const string)
cproto-generated files
Definition: alias_pairs.c:587
bool out_alias_pairs(const char *)
top-level creation of pairs of aliases of OUT regions of the module modifies global vars callee,...
Definition: alias_pairs.c:623
static list rest_list
Definition: alias_classes.c:55
#define region_system(reg)
#define region
simulation of the type region
list regions_dup(list)
effect region_dup(effect)
void print_inout_regions(list)
#define ACTION_IN
#define ACTION_OUT
void reset_action_interpretation(void)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void set_action_interpretation(string, string)
prettyprint.c
void reset_cumulated_rw_effects(void)
#define effect_approximation_tag(eff)
entity effect_entity(effect)
cproto-generated files
Definition: effects.c:52
#define effect_undefined_p(x)
Definition: effects.h:615
#define effects_classes_classes(x)
Definition: effects.h:678
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define LIST(x)
Definition: genC.h:93
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
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
#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
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define debug_off()
Definition: misc-local.h:160
static char * module
Definition: pips.c:74
#define print_region(x)
Definition: print.c:343
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
static bool member(region reg, list reg_list)
tests if reg and any member of reg_list are same_reg_ignore_action
bool alias_lists(const char *module_name)
GLOBAL OUT: l_alias_lists.
static list l_alias_lists
static bool add_pair_to_existing_list(list alias_pair)
GLOBAL IN: l_alias_lists GLOBAL OUT: l_alias_lists.
list append_reg_if_not_present(list reg_list, region reg)
adds reg as final element on the end of reg_list unless reg is already present in reg_list
bool same_reg_ignore_action(region reg1, region reg2)
put reg in list of one element for call to alias_pairs
char * strdup()
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212
#define sc_equal_p_ofl(ps1, ps2)
Definition: union-local.h:84