PIPS
sav_alias_classes.c
Go to the documentation of this file.
1 /*
2 
3  $Id: sav_alias_classes.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 
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include <setjmp.h>
32 
33 #include "genC.h"
34 #include "linear.h"
35 #include "ri.h"
36 #include "effects.h"
37 #include "database.h"
38 
39 #include "ri-util.h"
40 #include "effects-util.h"
41 #include "constants.h"
42 #include "misc.h"
43 #include "text.h"
44 
45 #include "boolean.h"
46 #include "vecteur.h"
47 #include "contrainte.h"
48 #include "sc.h"
49 #include "sommet.h"
50 #include "ray_dte.h"
51 #include "sg.h"
52 #include "polyedre.h"
53 #include "union.h"
54 
55 #include "effects-generic.h"
56 #include "effects-simple.h"
57 #include "effects-convex.h"
58 
59 #include "semantics.h"
60 #include "transformer.h"
61 
62 #include "pipsdbm.h"
63 #include "resources.h"
64 
65 #include "alias-classes.h"
66 
69 
70 /* The algorithms below depend on the following properties
71  * of Alias Lists and Alias Classes:
72  * - an Alias List contains no repeated elements
73  * - two Alias Lists of the same module never have the same
74  * head (distinct heads)
75  * - an element from one Alias List of a particular module can also
76  * be present in another Alias List of the same module (not disjoint sets)
77  * - no element from one Alias Class of a particular module is also
78  * present in another Alias Class of the same module (disjoint sets)
79  */
80 
81 
82 /* global variables IN: l_alias_lists
83  * gloabl variables modified: l_alias_lists
84  * add a copy of each element in additional_list
85  * not already present in initial_reg_list
86  * to the end of initial_reg_list
87  */
88 static list
89 append_all_not_present(list initial_reg_list, list additional_list)
90 {
91  list new_reg_list;
92 
93  pips_debug(4,"begin\n");
94 
95  MAP(EFFECT,additional_reg,
96  {
97  new_reg_list = append_reg_if_not_present(initial_reg_list,
98  region_dup(additional_reg));
99  },
100  additional_list);
101 
102  pips_debug(4,"end\n");
103 
104  return new_reg_list;
105 }
106 
107 
108 /* global variables IN: rest_list, other_lists
109  * global variables modified: rest_list, other_lists
110  */
111 static void
112 compare_other_list(region elem, list other_list)
113 {
114  bool result = false;
115  region other_elem;
116  list rest_other_list;
117 
118  ifdebug(4)
119  {
120  pips_debug(4,"begin for elem:\n");
122  print_region(elem);
124  pips_debug(4,"and list:\n");
125  print_inout_regions(other_list);
126  }
127 
128  if (other_list != NIL)
129  {
130  rest_other_list = other_list;
131  do {
132  other_elem = EFFECT(CAR(rest_other_list));
133  rest_other_list = CDR(rest_other_list);
134 
135  ifdebug(9)
136  {
137  pips_debug(9,"compare elem:\n");
139  print_region(other_elem);
141  }
142 
143  if ( effect_exact_p(other_elem) )
144  {
145  pips_debug(9,"exact\n");
146 
147  if ( same_reg_ignore_action(elem,other_elem) )
148  {
149  pips_debug(9,"same\n");
150 
152  result = true;
153  }
154  }
155  } while (result == false && rest_other_list != NIL);
156  if (result == false)
157  other_lists = gen_nconc(other_lists,CONS(LIST,other_list,NIL));
158  }
159  pips_debug(4,"end\n");
160 }
161 
162 
163 /* global variables IN: rest_list, rest_other_lists, other_lists
164  * global variables modified: rest_list, other_lists, rest_other_lists
165  * ATTENTION: recursive function
166  * compares "elem" (the current element from
167  * the list currently being made into a class)
168  * to each element of each list of "rest_other_lists"
169  * (the other lists not yet made into classes)
170  * if a match is found, "other_list"
171  * (the other list containing the matching element "other_elem")
172  * is appended to "rest_list" (the not yet treated elements from the list
173  * currently being made into a class)
174  * and "other_list" will no longer be a member of "other_lists"
175  * if not, "other_list" is appended to "other_lists"
176  */
177 static void
179 {
180  list other_list;
181 
182  if (rest_other_lists != NIL)
183  {
184  ifdebug(4)
185  {
186  pips_debug(4,"begin for:\n");
188  print_region(elem);
190  }
191 
192  other_list = LIST(CAR(rest_other_lists));
194  compare_other_list(elem, other_list);
195 
196  if(rest_other_lists != NIL)
198 
199  pips_debug(4,"end\n");
200  }
201 }
202 
203 
204 /* global variables IN: class, rest_other_lists, other_lists
205  * global variables modified: class, other_lists, rest_other_lists, rest_list
206  */
207 static void
209 {
210  region elem;
211 
212  ifdebug(4)
213  {
214  pips_debug(4,"begin for:\n");
215  print_inout_regions(reg_list);
216  }
217 
218  if (reg_list != NIL)
219  {
220  rest_list = reg_list;
221  do {
222  elem = EFFECT(CAR(rest_list));
224 
225  ifdebug(9)
226  {
227  pips_debug(9,"elem:\n");
229  print_region(elem);
231  }
232 
233  if ( effect_exact_p(elem) )
234  {
235  pips_debug(9,"exact\n");
236 
238  other_lists = NIL;
240  }
241  class = gen_nconc(class,CONS(EFFECT,elem,NIL));
242  } while(rest_list != NIL);
243  }
244 
245  pips_debug(4,"end\n");
246 }
247 
248 
249 /* global variables IN: other_lists
250  * global variables modified:class, other_lists, rest_other_lists, rest_list
251  * ATTENTION: recursive function
252  */
253 static void
255 {
256  list next_list;
257 
258  if (other_lists != NIL)
259  {
260  pips_debug(4,"begin\n");
261 
262  next_list = LIST(CAR(other_lists));
263 /* rest_other_lists = CDR(other_lists); */
264 /* other_lists = NIL; */
266  class = NIL;
267 
268  make_class_from_list(next_list);
270 
271  ifdebug(9)
272  {
273  pips_debug(9,"class:\n");
274  print_inout_regions(class);
275  pips_debug(9,"other_lists:\n");
276  MAP(LIST,alias_list,
277  {
278  print_inout_regions(alias_list);
279  pips_debug(9,"---\n");
280  },
281  other_lists);
282  }
283 
285 
286  pips_debug(4,"end\n");
287  }
288 }
289 
290 
291 /* global variables IN: l_alias_lists
292  * global variables modified: l_alias_lists
293  * returns true if l_alias_lists modified,
294  * i.e. if callee_class_elem is present
295  * in one or more of the callers alias lists,
296  * in which case,
297  * the whole callee_alias_class is added to
298  * each of these caller alias lists
299  */
300 static bool
301 match_this_callee_class_elem(region callee_class_elem, list callee_alias_class)
302 {
303  bool result = false;
304  list rest_alias_lists, alias_list;
305  region formal_reg_caller_list;
306 
307  ifdebug(4)
308  {
309  pips_debug(4,"begin for elem:\n");
311  print_region(callee_class_elem);
313  }
314 
315  rest_alias_lists = l_alias_lists;
316  if (l_alias_lists != NIL)
317  do{
318  alias_list = LIST( CAR(rest_alias_lists) );
319  formal_reg_caller_list = EFFECT( CAR(alias_list) );
320 
321  ifdebug(9)
322  {
323  pips_debug(9,"compare with:\n");
325  print_region(formal_reg_caller_list);
327  }
328 
329  if ( same_reg_ignore_action(formal_reg_caller_list,
330  callee_class_elem) )
331  {
332  pips_debug(9,"match\n");
333  ifdebug(9)
334  {
335  pips_debug(9,"old alias list:\n");
336  print_inout_regions(alias_list);
337  }
338 
339  result = true;
340  alias_list =
341  append_all_not_present(alias_list,
342  callee_alias_class);
343 
344  ifdebug(9)
345  {
346  pips_debug(9,"new alias list:\n");
347  print_inout_regions(alias_list);
348  }
349 
350  }
351  rest_alias_lists = CDR(rest_alias_lists);
352  }while (rest_alias_lists != NIL && result == false);
353 
354  pips_debug(4,"end\n");
355 
356  return result;
357 }
358 
359 
360 /* global variables IN: l_alias_lists
361  * global variables modified: l_alias_lists
362  */
363 static bool
364 add_callee_class_to_lists(list callee_alias_class )
365 {
366  bool result = false;
367 
368  pips_debug(4,"begin\n");
369 
370  MAP(EFFECT,callee_class_elem,
371  {
372  if ( match_this_callee_class_elem(callee_class_elem,
373  callee_alias_class) )
374  result = true;
375  },
376  callee_alias_class);
377 
378  pips_debug(4,"end\n");
379 
380  return result;
381 }
382 
383 
384 /* global variables IN: other_lists
385  * global variables modified: other_lists
386  */
387 static void
388 save_callee_class(list callee_alias_class )
389 {
390  pips_debug(4,"begin\n");
391 
392  other_lists =
394  CONS(LIST,regions_dup(callee_alias_class),NIL));
395 
396  pips_debug(4,"end\n");
397 }
398 
399 
400 /* global variables IN: l_alias_lists, other_lists
401  * global variables modified: l_alias_lists, other_lists
402  */
403 static void
404 add_classes_for_this_callee( string callee_name )
405 {
406  list callee_alias_classes;
407 
408  pips_debug(4,"begin for callee %s\n",callee_name);
409 
410  callee_alias_classes = effects_to_list((effects)
411  db_get_memory_resource(DBR_ALIAS_CLASSES,
412  callee_name,
413  true));
414  MAP(LIST,callee_alias_class,
415  {
416  ifdebug(9)
417  {
418  pips_debug(9,"add class:\n");
419  print_inout_regions(callee_alias_class);
420  }
421 
422  if (!add_callee_class_to_lists(callee_alias_class))
423  save_callee_class(callee_alias_class);
424  },
425  callee_alias_classes);
426 
427  pips_debug(4,"end\n");
428 }
429 
430 
431 static void
433 {
434  callees all_callees;
435 
436  pips_debug(4,"begin\n");
437 
438  all_callees = (callees) db_get_memory_resource(DBR_CALLEES,
439  module_name,
440  true);
441 
442  MAP(STRING, callee_name,
443  {
444  add_classes_for_this_callee(callee_name);
445  },
446  callees_callees(all_callees));
447 
448  pips_debug(4,"end\n");
449 }
450 
451 
452 bool alias_classes(const string module_name)
453 {
455  entity module;
456 
457  debug_on("ALIAS_CLASSES_DEBUG_LEVEL");
458  pips_debug(4,"begin for module %s\n",module_name);
459  ifdebug(9)
460  {
461  /* ATTENTION: we have to do ALL this
462  * just to call print_inout_regions for debug !!
463  */
468  db_get_memory_resource(DBR_CODE,
469  module_name,
470  true) );
473  DBR_CUMULATED_EFFECTS,
474  module_name,
475  true));
478  DBR_PROPER_EFFECTS,
479  module_name,
480  true));
482  /* and this to call print_region
483  set_action_interpretation(ACTION_IN,ACTION_OUT); */
484  /* that's it, but we musn't forget to reset everything below */
485  }
486 
487  l_alias_lists = NIL;
489  other_lists = NIL;
490 
491 /*
492  alias_lists =
493  effects_to_list((effects)
494  db_get_memory_resource(DBR_ALIAS_LISTS,
495  module_name,
496  true));
497 */
498 
499  alias_lists =
501  db_get_memory_resource(DBR_ALIAS_LISTS,
502  module_name,
503  true));
504 
505  MAP(LIST,alias_list,
506  {
507  l_alias_lists =
508  gen_nconc(CONS(LIST,regions_dup(alias_list),NIL),
509  l_alias_lists);
510  },
511  alias_lists);
512 
513  ifdebug(9)
514  {
515  pips_debug(9,"alias lists:\n");
516  MAP(LIST,alias_list,
517  {
518  print_inout_regions(alias_list);
519  pips_debug(9,"---\n");
520  },
521  l_alias_lists);
522  }
523 
525 
526  ifdebug(9)
527  {
528  pips_debug(9,"alias lists:\n");
529  MAP(LIST,alias_list,
530  {
531  print_inout_regions(alias_list);
532  pips_debug(9,"---\n");
533  },
534  l_alias_lists);
535  pips_debug(9,"callee classes:\n");
536  MAP(LIST,alias_class,
537  {
538  print_inout_regions(alias_class);
539  pips_debug(9,"---\n");
540  },
541  other_lists);
542  }
543 
545 
547 
548  DB_PUT_MEMORY_RESOURCE(DBR_ALIAS_CLASSES,
551 
552  ifdebug(9)
553  {
554 /* reset_action_interpretation(); */
560  }
561  pips_debug(4,"end\n");
562  debug_off();
563 
564  return true;
565 }
566 
effects_classes make_effects_classes(list a)
Definition: effects.c:526
bool alias_lists(const string)
alias_lists.c
Definition: alias_lists.c:328
#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_exact_p(eff)
list effects_to_list(effects)
Definition: effects.c:209
#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
#define STRING(x)
Definition: genC.h:87
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
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675
static void save_callee_class(list callee_alias_class)
global variables IN: other_lists global variables modified: other_lists
static void compare_rest_other_lists(region elem)
global variables IN: rest_list, rest_other_lists, other_lists global variables modified: rest_list,...
static void make_classes_from_lists()
global variables IN: other_lists global variables modified:class, other_lists, rest_other_lists,...
static void add_classes_callees(const char *module_name)
static bool match_this_callee_class_elem(region callee_class_elem, list callee_alias_class)
global variables IN: l_alias_lists global variables modified: l_alias_lists returns true if l_alias_l...
static bool add_callee_class_to_lists(list callee_alias_class)
global variables IN: l_alias_lists global variables modified: l_alias_lists
static list other_lists
static void make_class_from_list(list reg_list)
global variables IN: class, rest_other_lists, other_lists global variables modified: class,...
bool alias_classes(const string module_name)
static list l_alias_lists
static list append_all_not_present(list initial_reg_list, list additional_list)
The algorithms below depend on the following properties of Alias Lists and Alias Classes:
static list rest_other_lists
static list rest_list
static void add_classes_for_this_callee(string callee_name)
global variables IN: l_alias_lists, other_lists global variables modified: l_alias_lists,...
static list class
static list l_alias_classes
static void compare_other_list(region elem, list other_list)
global variables IN: rest_list, other_lists global variables modified: rest_list, other_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