PIPS
filter_proper_effects.c
Go to the documentation of this file.
1 /*
2 
3  $Id: filter_proper_effects.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 #include <stdio.h>
29 #include <string.h>
30 
31 #include "genC.h"
32 #include "linear.h"
33 #include "ri.h"
34 #include "effects.h"
35 
36 #include "misc.h"
37 #include "ri-util.h"
38 #include "effects-util.h"
39 #include "database.h"
40 #include "resources.h"
41 #include "pipsdbm.h"
42 #include "properties.h"
43 #include "effects-generic.h"
44 #include "effects-simple.h"
45 
46 static list /* of entity */ get_variables_to_filter()
47 {
48  string names = strdup(get_string_property("EFFECTS_FILTER_ON_VARIABLE"));
49  list le = NIL;
50  entity var;
51  string saved = names, s;
52 
53  pips_assert("property EFFECTS_FILTER_ON_VARIABLE is defined",
54  !same_string_p(names, ""));
55 
56  for (s=names; *s; s++)
57  {
58  var = NULL;
59  if (*s==',')
60  {
61  *s = '\0';
62  var = gen_find_tabulated(names, entity_domain);
63 
64  if (!var || entity_undefined_p(var))
65  {
66  pips_user_warning("reference variable '%s' not found\n", names);
67  }
68  else
69  {
70  le = CONS(ENTITY, var, le);
71  }
72  *s = ',';
73  names = s+1;
74  }
75  }
76 
77  var = gen_find_tabulated(names, entity_domain);
78 
79  if (!var || entity_undefined_p(var))
80  {
81  pips_user_warning("reference variable '%s' not found\n", names);
82  }
83  else
84  {
85  le = CONS(ENTITY, var, le);
86  }
87 
88  free(saved), saved = NULL;
89 
90  return le;
91 }
92 
93 /************************************** CHECK WHETHER A CONFLICTING W EFFECT */
94 
95 static list /* of entity */ variables_to_filter = NIL;
96 
97 static bool there_is_a_conflict(entity var)
98 {
99  MAP(ENTITY, v,
100  {
101  if (entities_may_conflict_p(var, v))
102  return true;
103  },
105  return false;
106 }
107 
108 /***************************** (should) CHECK WHETHER A REFERENCE IS WRITTEN */
109 
110 static bool direct_reference_found = false;
111 static entity a_variable = NULL;
112 
113 /* it should be a check on call arguments, whether they are W + ref
114  * for user define functions, use summary effects
115  * for intrinsics? =, implied-do, read...
116  */
117 static void reference_rwt(reference r)
118 {
120  {
121  direct_reference_found = true;
122  gen_recurse_stop(NULL);
123  }
124 }
125 
126 static void check_if_direct_reference(void * x)
127 {
129 }
130 
132 {
134  direct_reference_found = false;
135  a_variable = var;
136 
137  switch (instruction_tag(i))
138  {
139  case is_instruction_call:
141  break;
142  case is_instruction_loop:
143  {
144  loop l = instruction_loop(i);
147  direct_reference_found = true;
148  break;
149  }
152  break;
153  case is_instruction_test:
155  break;
156  default:
157  /* should not happen on a statement with proper effects */
158  pips_internal_error("unexpected instruction tag...");
159  }
160 
161  a_variable = NULL;
162  return direct_reference_found;
163 }
164 
165 /*************************************** FILTER PROPER EFFECTS OF STATEMENTS */
166 
167 static bool stmt_flt(statement s)
168 {
169  list /* of effect */ lpe = load_proper_rw_effects_list(s);
170  MAP(EFFECT, e,
171  {
172  entity var = effect_variable(e);
173  if (effect_write_p(e) && there_is_a_conflict(var))
174  {
175  if (direct_written_reference(s, var))
176  {
177  int order = statement_ordering(s);
178  int on; int os;
179  if (order!=STATEMENT_ORDERING_UNDEFINED)
180  {
181  on = ORDERING_NUMBER(order);
182  os = ORDERING_STATEMENT(order);
183  }
184  else
185  {
186  on = -1;
187  os = -1;
188  }
189 
190  user_log("## %s o=(%d,%d)/n=%d\n",
191  entity_name(var), on, os, statement_number(s));
192  }
193  }
194  },
195  lpe);
196  return true;
197 }
198 
199 /***************************************************************** INTERFACE */
200 
202 {
203  debug_on("FILTER_PROPER_EFFECTS_DEBUG_LEVEL");
204  pips_debug(1, "considering module %s\n", module_name);
205 
206  /* gets what is needed from PIPS DBM
207  */
210  db_get_memory_resource(DBR_CODE, module_name, true));
212  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
213 
215 
219 
222 
223  /* returns the result to the DBM... */
225  (DBR_FILTERED_PROPER_EFFECTS, module_name, NULL);
226 
230 
231  debug_off();
232  return true;
233 }
void user_log(const char *format,...)
Definition: message.c:234
list load_proper_rw_effects_list(statement)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
#define effect_write_p(eff)
#define effect_variable(e)
For COMPATIBILITY purpose only - DO NOT USE anymore.
#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
char * get_string_property(const char *)
static bool there_is_a_conflict(entity var)
static bool direct_reference_found
static list variables_to_filter
of entity
static void check_if_direct_reference(void *x)
static bool direct_written_reference(statement s, entity var)
bool filter_proper_effects(const char *module_name)
filter_proper_effects.c
static list get_variables_to_filter()
of entity
static void reference_rwt(reference r)
it should be a check on call arguments, whether they are W + ref for user define functions,...
static bool stmt_flt(statement s)
static entity a_variable
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
void free(void *)
bool entities_may_conflict_p(entity e1, entity e2)
Check if two entities may conflict.
Definition: conflicts.c:984
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
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#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
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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 pips_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
#define same_string_p(s1, s2)
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
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
#define reference_variable(x)
Definition: ri.h:2326
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define instruction_loop(x)
Definition: ri.h:1520
#define statement_ordering(x)
Definition: ri.h:2454
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define entity_undefined_p(x)
Definition: ri.h:2762
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define entity_name(x)
Definition: ri.h:2790
#define test_condition(x)
Definition: ri.h:2833
#define instruction_whileloop(x)
Definition: ri.h:1523
#define statement_instruction(x)
Definition: ri.h:2458
#define loop_range(x)
Definition: ri.h:1642
#define instruction_test(x)
Definition: ri.h:1517
#define whileloop_condition(x)
Definition: ri.h:3160
#define statement_number(x)
Definition: ri.h:2452
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define loop_index(x)
Definition: ri.h:1640
char * strdup()
static char * x
Definition: split_file.c:159
The structure used to build lists in NewGen.
Definition: newgen_list.h:41