PIPS
postcondition.c
Go to the documentation of this file.
1 /*
2 
3  $Id: postcondition.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 /* filtering of postconditions */
25 #ifdef HAVE_CONFIG_H
26  #include "pips_config.h"
27 #endif
28 
29 /* Standard includes
30  */
31 
32 #include <stdio.h>
33 #include <string.h>
34 
35 /* Psystems stuff
36  */
37 
38 #include "boolean.h"
39 #include "vecteur.h"
40 #include "contrainte.h"
41 #include "sc.h"
42 
43 /* Newgen stuff
44  */
45 
46 #include "genC.h"
47 #include "linear.h"
48 #include "ri.h"
49 #include "effects.h"
50 
51 /* PIPS stuff
52  */
53 
54 #include "ri-util.h"
55 #include "prettyprint.h"
56 #include "effects-util.h"
57 #include "misc.h"
58 #include "semantics.h"
59 #include "transformer.h"
60 
61 /************************************************ POSTCONDITIONS MAPPING */
62 
64 
65 static statement_mapping
68 
69 #define StorePost(stat, val) \
70  (debug(9, "StorePost", "storing 0x%x, 0x%x\n", stat, val), \
71  hash_put(current_postcondition_map, (char*) (stat), (char*) (val)))
72 
73 #define StorePre(stat, val) \
74  (debug(9, "StorePre", "storing 0x%x, 0x%x\n", stat, val), \
75  hash_put(current_precondition_map, (char*) (stat), (char*) (val)))
76 
77 #define LoadPost(stat) \
78  (debug(9, "LoadPost", "loading 0x%x\n", stat), \
79  (transformer) (hash_get(current_postcondition_map, (char*) stat)))
80 
81 #define LoadPre(stat) \
82  (debug(9, "LoadPre", "loading 0x%x\n", stat), \
83  (transformer) (hash_get(current_precondition_map, (char*) stat)))
84 
85 /* filter used by gen_recurse:
86  * Top-down computation of the postcondition mapping
87  */
89 {
91  transformer post = LoadPost(stat);
92 
93  pips_debug(5, "statement %p (post %p)\n", stat, post);
94 
95  ifdebug(9) {
96  pips_debug(9, "statement is\n");
97  print_statement(stat);
98  }
99 
100  /* ??? may happen in obscure unstructured... */
101  if (transformer_undefined_p(post)) return true;
102 
103  switch(instruction_tag(inst))
104  {
106  {
108 
109  pips_debug(6, "in block\n");
110 
111  MAP(STATEMENT, s,
112  {
113  StorePost(s, post);
114  post = LoadPre(s);
115  },
116  ls);
117 
118  gen_free_list(ls);
119  break;
120  }
121  case is_instruction_test:
122  {
123  test t = instruction_test(inst);
124  pips_debug(6, "in test\n");
125 
126  StorePost(test_true(t), post);
127  StorePost(test_false(t), post);
128 
129  break;
130  }
131  case is_instruction_loop:
132  pips_debug(6, "in loop\n");
133  StorePost(loop_body(instruction_loop(inst)), post);
134  break;
135  case is_instruction_goto:
136  /* ??? may be false... */
137  pips_internal_error("unexpected goto encountered");
138  break;
139  case is_instruction_call:
140  break;
142  /* ??? is just false... */
143  {
145  list blocks = NIL;
146 
147  pips_debug(6, "in unstructured\n");
148 
149  /* generates the full list */
150  CONTROL_MAP(__attribute__ ((unused)) ct, {}, c, blocks);
151 
153 
154  MAP(CONTROL, c,
155  {
157  StorePost(s, post);
158  post = LoadPre(s); /* ??? */
159  },
160  blocks);
161 
163 
164  break;
165  }
166  default:
167  pips_internal_error("unexpected instruction tag");
168  break;
169  }
170 
171  return true; /* must go downward */
172 }
173 
174 /* statement_mapping compute_postcondition(stat, post_map, pre_map)
175  * statement stat;
176  * statement_mapping post_map, pre_map;
177  *
178  * computes the postcondition mapping post_map from the
179  * precondition mapping pre_map and the related statement tree
180  * starting from stat. The rule applied is that the postcondition
181  * of one statement is the precondition of the following one.
182  * The last postcondition is arbitrary set to transformer_identity,
183  * what is not enough. (??? should I take the stat transformer?)
184  */
187  statement stat,
188  statement_mapping post_map,
189  statement_mapping pre_map)
190 {
191  debug_on("SEMANTICS_POSTCONDITION_DEBUG_LEVEL");
192  pips_debug(1, "computing!\n");
193 
194  current_postcondition_map = post_map;
195  current_precondition_map = pre_map;
196 
197  /* the initial postcondition is empty ??? */
199 
200  /* Top-down definition */
202 
205 
206  debug_off();
207  return post_map;
208 }
209 
210 /* that is all
211  */
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
transformer transformer_identity()
Allocate an identity transformer.
Definition: basic.c:110
static list blocks
lisp of loops
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
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
#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_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define GENERIC_CURRENT_MAPPING(name, result, type)
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
static statement_mapping current_postcondition_map
Definition: postcondition.c:67
#define StorePost(stat, val)
Definition: postcondition.c:69
#define LoadPre(stat)
Definition: postcondition.c:81
statement_mapping compute_postcondition(statement stat, statement_mapping post_map, statement_mapping pre_map)
statement_mapping compute_postcondition(stat, post_map, pre_map) statement stat; statement_mapping po...
static bool postcondition_filter(statement stat)
filter used by gen_recurse: Top-down computation of the postcondition mapping
Definition: postcondition.c:88
static statement_mapping current_precondition_map
filtering of postconditions
Definition: postcondition.c:66
#define LoadPost(stat)
Definition: postcondition.c:77
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#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)
#define loop_body(x)
Definition: ri.h:1644
#define transformer_undefined_p(x)
Definition: ri.h:2848
#define instruction_loop(x)
Definition: ri.h:1520
#define test_false(x)
Definition: ri.h:2837
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define CONTROL(x)
CONTROL.
Definition: ri.h:910
@ 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 test_true(x)
Definition: ri.h:2835
#define statement_instruction(x)
Definition: ri.h:2458
#define control_statement(x)
Definition: ri.h:941
#define instruction_test(x)
Definition: ri.h:1517
#define instruction_unstructured(x)
Definition: ri.h:1532
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41