PIPS
alias_lists.c
Go to the documentation of this file.
1 /*
2 
3  $Id: 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 
37 #include "ri-util.h"
38 #include "effects-util.h"
39 #include "misc.h"
40 
41 #include "effects-generic.h"
42 #include "effects-convex.h"
43 
44 #include "semantics.h"
45 #include "transformer.h"
46 
47 #include "pipsdbm.h"
48 
52 
53 
54 /* tests if reg1 and reg2 are the same,
55  * including same action_tags (IN/OUT)
56  * and precision (may/exact)
57  */
58 static bool
59 same_reg(region reg1, region reg2)
60  {
61  Psysteme reg1_sys, reg2_sys;
62  bool result = false;
63 
64  pips_debug(4,"begin\n");
65 
66  if (effect_undefined_p(reg1) || effect_undefined_p(reg2)) return result;
67 
68  if (effect_entity(reg1) == effect_entity(reg2))
69  {
70 /* pips_debug(1,"same entity\n"); */
71 
72  if (effect_approximation_tag(reg1) ==
74  {
75 /* pips_debug(1,"same approx\n"); */
76 
77  if (effect_action_tag(reg1) ==
78  effect_action_tag(reg2))
79  {
80 /* pips_debug(1,"same action\n"); */
81 
82  ifdebug(1)
83  {
85  pips_debug(1,"compare:\n\t");
86  print_region(reg1);
87  pips_debug(1,"with:\n\t");
88  print_region(reg2);
90  }
91 
92  reg1_sys = region_system(reg1);
93  reg2_sys = region_system(reg2);
94  if ( sc_equal_p_ofl(reg1_sys,reg2_sys) )
95  {
96  result = true;
97 
98  pips_debug(1,"same region\n");
99  }
100  else
101  pips_debug(1,"not same region\n");
102  }
103  }
104  }
105  pips_debug(4,"end\n");
106 
107  return result;
108  }
109 
110 
111 /* global variables IN: unmatched_alias_pairs, l_alias_lists
112  * modifies global variable: l_alias_lists
113  */
114 static void
116 {
117  pips_debug(4,"begin\n");
118 
119  MAP(LIST,alias_pair,
120  {
121  l_alias_lists =
122  CONS(EFFECTS,
123  make_effects(regions_dup(alias_pair)),
124  l_alias_lists);
126 
127  pips_debug(4,"end\n");
128 }
129 
130 
131 /* global variables IN: matched_alias_pairs, l_alias_lists
132  * modifies global variable: l_alias_lists
133  */
134 static bool
136  region alias_list_reg,
137  list callee_alias_list)
138 {
139  region formal_reg;
140 
141  pips_debug(4,"begin\n");
142 
143  MAP(LIST,alias_pair,
144  {
145  formal_reg = EFFECT(CAR(alias_pair));
146 
147  ifdebug(9)
148  {
150  pips_debug(9,"compare to:\n");
151  print_region(formal_reg);
153  }
154 
155 /* must take the action of the regions into account here because
156  * we are checking whether formal_reg is the result of the
157  * propagation of alias_list_reg
158  */
159  if ( same_reg(formal_reg,alias_list_reg) )
160  {
161  pips_debug(9,"match\n");
162 
163  l_alias_lists =
164  CONS(EFFECTS,
165  make_effects(gen_nconc(regions_dup(callee_alias_list),
166  regions_dup(CDR(alias_pair)))),
167  l_alias_lists);
168  result = true;
169  }
171 
172  pips_debug(4,"end\n");
173 
174  return result;
175 }
176 
177 
178 /* global variables IN: matched_alias_pairs,
179  * unmatched_alias_pairs,
180  * l_alias_lists
181  * modifies global variables: matched_alias_pairs,
182  * unmatched_alias_pairs,
183  * l_alias_lists
184  */
185 static bool
186 compare_unmatched_alias_pairs(region alias_list_reg, list callee_alias_list)
187 {
188  region formal_reg;
189  list rest_unmatched_alias_pairs = unmatched_alias_pairs;
190  bool result = false;
191 
192  ifdebug(4)
193  {
195  pips_debug(4,"begin for alias_list_reg:\n");
196  print_region(alias_list_reg);
198  }
199 
201 
202  MAP(LIST,alias_pair,
203  {
204  formal_reg = EFFECT(CAR(alias_pair));
205 
206  ifdebug(9)
207  {
209  pips_debug(9,"compare to:\n");
210  print_region(formal_reg);
212  }
213 
214 /* must take the action of the regions into account here because
215  * we are checking whether formal_reg is the result of the
216  * propagation of alias_list_reg
217  */
218  if ( same_reg(formal_reg,alias_list_reg) )
219  {
220  pips_debug(9,"match\n");
221 
222  l_alias_lists =
223  CONS(EFFECTS,
224  make_effects(gen_nconc(regions_dup(callee_alias_list),
225  regions_dup(CDR(alias_pair)))),
226  l_alias_lists);
228  CONS(LIST,alias_pair,matched_alias_pairs);
229  result = true;
230  }
231  else
233  CONS(LIST,alias_pair,unmatched_alias_pairs);
234  },rest_unmatched_alias_pairs);
235 
236  pips_debug(4,"end\n");
237 
238  return result;
239 }
240 
241 
242 /* global variables IN: matched_alias_pairs,
243  * unmatched_alias_pairs,
244  * l_alias_lists
245  * modifies global variables: matched_alias_pairs,
246  * unmatched_alias_pairs,
247  * l_alias_lists
248  */
249 static void
250 add_alias_lists_callee( string callee_name )
251 {
252  list callee_alias_lists;
253  bool result;
254  region alias_list_reg;
255 
256  pips_debug(4,"begin for callee %s\n",callee_name);
257 
258  callee_alias_lists =
260  db_get_memory_resource(DBR_ALIAS_LISTS,
261  callee_name,
262  true));
263  MAP(EFFECTS,callee_alias_list_effects,
264  {
265  list callee_alias_list =
266  effects_effects(callee_alias_list_effects);
267 
268  ifdebug(9)
269  {
270  pips_debug(9,"add list:\n");
271  print_inout_regions(callee_alias_list);
272  }
273 
274  if (callee_alias_list != NIL)
275  {
276  alias_list_reg = EFFECT(CAR(gen_last(callee_alias_list)));
277  result =
278  compare_unmatched_alias_pairs(alias_list_reg,
279  callee_alias_list);
280  result =
282  alias_list_reg,
283  callee_alias_list);
284  if (result == false)
285  l_alias_lists =
286  CONS(EFFECTS,
287  make_effects(regions_dup(callee_alias_list)),
288  l_alias_lists);
289  }
290  },callee_alias_lists);
291 
292  pips_debug(4,"end\n");
293 }
294 
295 
296 /* global variables IN: unmatched_alias_pairs,
297  * l_alias_lists
298  * modifies global variables: matched_alias_pairs,
299  * unmatched_alias_pairs,
300  * l_alias_lists
301  */
302 static void
304 {
305  callees l_callees;
306 
307  pips_debug(4,"begin\n");
308 
310 
311  l_callees = (callees) db_get_memory_resource(DBR_CALLEES,
312  module_name,
313  true);
314 
315  MAP(STRING, callee_name,
316  {
317  add_alias_lists_callee(callee_name);
318  },callees_callees(l_callees));
319 
320  pips_debug(4,"end\n");
321 }
322 
323 
324 /* modifies global variables: matched_alias_pairs,
325  * unmatched_alias_pairs,
326  * l_alias_lists
327  */
328 bool alias_lists(const string module_name)
329  {
331  entity module;
332 
333  l_alias_lists = NIL;
335 
336  debug_on("ALIAS_LISTS_DEBUG_LEVEL");
337  pips_debug(4,"begin for module %s\n",module_name);
338 
339  ifdebug(1)
340  {
341  /* ATTENTION: we have to do ALL this
342  * just to call print_inout_regions for debug !!
343  */
348  db_get_memory_resource(DBR_CODE,
349  module_name,
350  true) );
353  DBR_CUMULATED_EFFECTS,
354  module_name,
355  true));
358  DBR_CUMULATED_EFFECTS,
359  module_name,
360  true));
362  /* that's it, but we musn't forget to reset everything below */
363  }
364 
365  /* make alias lists from the IN_alias_pairs */
366 
367  /* DBR_IN_ALIAS_PAIRS is a newgen structure of type effects_classes
368  * which has one field called classes
369  * which is a list of newgen structures of type effects
370  * (and each newgen structure of type effects
371  * has one field called effects which is a list of elements
372  * of type effect)
373  */
374 
377  db_get_memory_resource(DBR_IN_ALIAS_PAIRS,
378  module_name,
379  true));
380 
381 
382 /* wrong but did work:
383 
384  in_alias_pairs =
385  effects_to_list((effects)
386  db_get_memory_resource(DBR_IN_ALIAS_PAIRS,
387  module_name,
388  true));
389 */
390 
391 /* MAP(LIST, alias_pair,
392  {
393  list in_alias_pair = regions_dup(alias_pair);
394  */
395 
396  MAP(EFFECTS, alias_pair_effects,
397  {
398  list alias_pair = effects_effects(alias_pair_effects);
399 
400  ifdebug(9)
401  {
402  pips_debug(9,"IN alias pair : \n");
403  print_inout_regions(alias_pair);
404  }
406  CONS(LIST,alias_pair,unmatched_alias_pairs);
407  },in_alias_pairs);
408 
409  /* make alias lists from the OUT_alias_pairs */
412  db_get_memory_resource(DBR_OUT_ALIAS_PAIRS,
413  module_name,
414  true));
415 
416 /* MAP(LIST, alias_pair,
417  {
418  list out_alias_pair = regions_dup(alias_pair);*/
419 
420  MAP(EFFECTS, alias_pair_effects,
421  {
422  list alias_pair = effects_effects(alias_pair_effects);
423 
424  ifdebug(9)
425  {
426  pips_debug(9,"OUT alias pair : \n");
427  print_inout_regions(alias_pair);
428  }
429 
431  CONS(LIST,alias_pair,unmatched_alias_pairs);
432  },out_alias_pairs);
433 
434  ifdebug(9)
435  {
436  pips_debug(9,"unmatched_alias_pairs:\n");
437  MAP(LIST,alias_pair,
438  {
439  print_inout_regions(alias_pair);
440  pips_debug(9,"---\n");
442  }
443 
445 
446  ifdebug(9)
447  {
448  pips_debug(9,"l_alias_lists:\n");
449  MAP(EFFECTS,alias_list,
450  {
452  pips_debug(9,"---\n");
453  },l_alias_lists);
454  pips_debug(9,"matched_alias_pairs:\n");
455  MAP(LIST,alias_pair,
456  {
457  print_inout_regions(alias_pair);
458  pips_debug(9,"---\n");
460  pips_debug(9,"unmatched_alias_pairs:\n");
461  MAP(LIST,alias_pair,
462  {
463  print_inout_regions(alias_pair);
464  pips_debug(9,"---\n");
466  }
467 
469 
470  ifdebug(9)
471  {
472  pips_debug(9,"l_alias_lists:\n");
473  MAP(EFFECTS,alias_list,
474  {
476  pips_debug(9,"---\n");
477  },l_alias_lists);
478  }
479 
480  DB_PUT_MEMORY_RESOURCE(DBR_ALIAS_LISTS,
483 
484  ifdebug(1)
485  {
491  }
492  pips_debug(4,"end\n");
493  debug_off();
494 
495  return(true);
496 }
497 
effects_classes make_effects_classes(list a)
Definition: effects.c:526
effects make_effects(list a)
Definition: effects.c:568
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 bool same_reg(region reg1, region reg2)
tests if reg1 and reg2 are the same, including same action_tags (IN/OUT) and precision (may/exact)
Definition: alias_lists.c:59
bool alias_lists(const string module_name)
modifies global variables: matched_alias_pairs, unmatched_alias_pairs, l_alias_lists
Definition: alias_lists.c:328
static void add_alias_lists_callee(string callee_name)
global variables IN: matched_alias_pairs, unmatched_alias_pairs, l_alias_lists modifies global variab...
Definition: alias_lists.c:250
static list l_alias_lists
Definition: alias_lists.c:49
static void add_alias_lists_callees(const char *module_name)
global variables IN: unmatched_alias_pairs, l_alias_lists modifies global variables: matched_alias_pa...
Definition: alias_lists.c:303
static void add_unmatched_alias_pairs()
global variables IN: unmatched_alias_pairs, l_alias_lists modifies global variable: l_alias_lists
Definition: alias_lists.c:115
static bool compare_matched_alias_pairs(bool result, region alias_list_reg, list callee_alias_list)
global variables IN: matched_alias_pairs, l_alias_lists modifies global variable: l_alias_lists
Definition: alias_lists.c:135
static list unmatched_alias_pairs
Definition: alias_lists.c:50
static list matched_alias_pairs
Definition: alias_lists.c:51
static bool compare_unmatched_alias_pairs(region alias_list_reg, list callee_alias_list)
global variables IN: matched_alias_pairs, unmatched_alias_pairs, l_alias_lists modifies global variab...
Definition: alias_lists.c:186
#define region_system(reg)
#define region
simulation of the type region
list regions_dup(list)
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)
#define effect_action_tag(eff)
entity effect_entity(effect)
cproto-generated files
Definition: effects.c:52
#define effect_undefined_p(x)
Definition: effects.h:615
#define EFFECTS(x)
EFFECTS.
Definition: effects.h:682
#define effects_effects(x)
Definition: effects.h:710
#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
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
#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
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