PIPS
continuation.c
Go to the documentation of this file.
1 /*
2 
3  $Id: continuation.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 /* package continuation : Be'atrice Creusillet, 1996
28  *
29  * This File contains the functions computing continuation conditions
30  * of a module (over- and under-approximations.
31  *
32  *
33  */
34 #include <stdio.h>
35 #include <string.h>
36 
37 #include "linear.h"
38 
39 #include "genC.h"
40 #include "ri.h"
41 #include "effects.h"
42 #include "database.h"
43 
44 #include "ri-util.h"
45 #include "effects-util.h"
46 #include "constants.h"
47 #include "misc.h"
48 #include "text-util.h"
49 #include "text.h"
50 #include "effects-generic.h"
51 #include "transformer.h"
52 #include "semantics.h"
53 
54 #include "pipsdbm.h"
55 #include "resources.h"
56 
57 #include "continuation.h"
58 
59 /*********************************************************************************/
60 /* LOCAL DEFINITIONS */
61 /*********************************************************************************/
62 
63 /* CONTINUATION CONDITION MAPS AND SUMMARIES */
64 GENERIC_MAPPING(/**/,must_continuation,transformer,statement)
65 GENERIC_MAPPING(/**/,may_continuation,transformer,statement)
66 
69 
70 /* statement stack */
72 
73 
74 /*********************************************************************************/
75 /* LOCAL FUNCTION HEADERS */
76 /*********************************************************************************/
79 static void block_continuation_conditions(list l_stat);
80 static void test_continuation_conditions(test t);
81 static void loop_continuation_conditions(loop l);
82 static void call_continuation_conditions(call c);
85 
86 
87 /*********************************************************************************/
88 /* INTERFACE */
89 /*********************************************************************************/
90 
92 {
93 
94  /* Get the code of the module. */
96  db_get_memory_resource(DBR_CODE, module_name, true) );
97  /* predicates defining summary regions from callees have to be
98  translated into variables local to module */
100  /* cumulated effects */
102  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
104  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
106 
107  /* Get the transformers of the module. */
109  db_get_memory_resource(DBR_TRANSFORMERS, module_name, true) );
110 
111  /* initialisation of local maps */
114 
115  debug_on("CONTINUATION_DEBUG_LEVEL");
118  debug_off();
119 
120  DB_PUT_MEMORY_RESOURCE(DBR_MUST_CONTINUATION,
122  (char*) get_must_continuation_map() );
123  DB_PUT_MEMORY_RESOURCE(DBR_MAY_CONTINUATION,
125  (char*) get_may_continuation_map() );
126  DB_PUT_MEMORY_RESOURCE(DBR_MUST_SUMMARY_CONTINUATION,
128  (char*) must_sum_cont_t);
129  DB_PUT_MEMORY_RESOURCE(DBR_MAY_SUMMARY_CONTINUATION,
131  (char*) may_sum_cont_t);
140 
141  return(true);
142 }
143 
144 /*********************************************************************************/
145 /* LOCAL FUNCTION */
146 /*********************************************************************************/
147 
148 /* INTRAPROCEDURAL PROPAGATION */
149 
150 /* static void module_continuation_conditions(statement mod_stat)
151  * input : main statement of the current module
152  * output : nothing
153  * modifies : continuation conditions maps
154  * comment :
155  */
157 {
158  make_current_stmt_stack();
161  free_current_stmt_stack();
162 }
163 
164 
165 
166 /* static void statement_continuation_conditions(statement s)
167  * input : the current instruction
168  * output : nothing
169  * modifies : continuation conditions maps
170  * comment :
171  */
173 {
175 
176  pips_debug(1, "BEGIN: statement %03td\n", statement_number(s));
177 
178  current_stmt_push(s);
179  switch(instruction_tag(i))
180  {
181  case is_instruction_goto:
184  break;
185 
187  pips_debug(3, "block\n");
189  break;
190 
191  case is_instruction_test:
192  pips_debug(3, "test\n");
194  break;
195 
196  case is_instruction_loop:
197  pips_debug(3, "loop\n");
199  break;
200 
201  case is_instruction_call:
202  pips_debug(3, "call\n");
204  break;
205 
207  pips_debug(3, "unstructured\n");
209  break ;
210 
211  default:
212  pips_debug(1, "unexpected tag %d\n", instruction_tag(i));
213  }
214  current_stmt_pop();
215  pips_debug(1,"END: statement %03td\n", statement_number(s));
216 }
217 
219 {
220  pips_assert("true", l_stat==l_stat);
221 
223 
226 }
227 
229 {
230  pips_assert("true", t==t);
232 
235 }
236 
238 {
239  pips_assert("true", l==l);
240 
242 
245 }
246 
248 {
249  pips_assert("true", c==c);
250 
252 
255 }
256 
258 {
259  pips_assert("true", u==u);
260 
262  transformer must_cont_t, may_cont_t;
263  control c;
264 
265  c = unstructured_control( u );
266 
268  {
269  /* there is only one statement in u; no need for a fix-point */
270  must_cont_t = transformer_dup
272  may_cont_t = transformer_dup
274  }
275  else
276  {
277  /* nothing clever for the moment - 28/2/96 - BC*/
278  must_cont_t = transformer_empty();
279  may_cont_t = transformer_identity();
280  }
281  store_statement_must_continuation(s,must_cont_t);
282  store_statement_may_continuation(s,may_cont_t);
283 }
284 
285 
286 /* INTERPROCEDURAL SUMMARIZATION */
287 
288 /* static void module_summary_continuation_conditions(statement mod_stat)
289  * input : main statement of the current module
290  * output : nothing
291  * modifies : continuation conditions maps
292  * comment :
293  */
295 {
296  pips_assert("true", mod_stat==mod_stat);
297 
300 }
transformer transformer_dup(transformer t_in)
transformer package - basic routines
Definition: basic.c:49
transformer transformer_identity()
Allocate an identity transformer.
Definition: basic.c:110
transformer transformer_empty()
Allocate an empty transformer.
Definition: basic.c:120
bool continuation_conditions(const string module_name)
INTERFACE
Definition: continuation.c:91
static void statement_continuation_conditions(statement s)
static void statement_continuation_conditions(statement s) input : the current instruction output : n...
Definition: continuation.c:172
static transformer may_sum_cont_t
Definition: continuation.c:68
static void loop_continuation_conditions(loop l)
Definition: continuation.c:237
static void block_continuation_conditions(list l_stat)
Definition: continuation.c:218
static void test_continuation_conditions(test t)
Definition: continuation.c:228
static void unstructured_continuation_conditions(unstructured u)
Definition: continuation.c:257
static void module_continuation_conditions(statement mod_stat)
statement stack
Definition: continuation.c:156
static void call_continuation_conditions(call c)
Definition: continuation.c:247
static transformer must_sum_cont_t
package continuation : Be'atrice Creusillet, 1996
Definition: continuation.c:67
static void module_summary_continuation_conditions(statement mod_stat)
INTERPROCEDURAL SUMMARIZATION.
Definition: continuation.c:294
statement_mapping get_must_continuation_map(void)
transformer load_statement_must_continuation(statement)
void set_may_continuation_map(statement_mapping)
transformer load_statement_may_continuation(statement)
void set_must_continuation_map(statement_mapping)
void store_statement_must_continuation(statement, transformer)
void store_statement_may_continuation(statement, transformer)
void reset_may_continuation_map(void)
void reset_must_continuation_map(void)
statement_mapping get_may_continuation_map(void)
static statement current_stmt
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
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
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
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
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 current_stmt_head()
We want to keep track of the current statement inside the recurse.
Definition: icfg_scan.c:76
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
#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_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
#define MAKE_STATEMENT_MAPPING()
Definition: newgen-local.h:43
#define GENERIC_MAPPING(PREFIX, name, result, type)
PIPS level:
#define DEFINE_LOCAL_STACK(name, type)
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
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 transformer_undefined
Definition: ri.h:2847
#define control_predecessors(x)
Definition: ri.h:943
#define instruction_loop(x)
Definition: ri.h:1520
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ 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 control_successors(x)
Definition: ri.h:945
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define control_statement(x)
Definition: ri.h:941
#define instruction_test(x)
Definition: ri.h:1517
#define statement_number(x)
Definition: ri.h:2452
#define instruction_unstructured(x)
Definition: ri.h:1532
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
void set_transformer_map(statement_mapping)
void reset_transformer_map(void)
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