PIPS
new_atomizer.c
Go to the documentation of this file.
1 
2 /*
3 
4  $Id: new_atomizer.c 23065 2016-03-02 09:05:50Z coelho $
5 
6  Copyright 1989-2016 MINES ParisTech
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 
24 */
25 #ifdef HAVE_CONFIG_H
26  #include "pips_config.h"
27 #endif
28 /* An atomizer that uses the one made by Fabien Coelho for HPFC,
29  * and is in fact just a hacked version of the one made by Ronan
30  * Keryell...
31  */
32 
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 
37 #include "genC.h"
38 #include "linear.h"
39 #include "ri.h"
40 #include "effects.h"
41 
42 #include "dg.h"
43 
46 
47 #include "graph.h"
48 #include "ri-util.h"
49 #include "effects-util.h"
50 #include "text-util.h"
51 #include "database.h"
52 #include "misc.h"
53 #include "pipsdbm.h"
54 #include "resources.h"
55 #include "control.h"
56 #include "arithmetique.h"
57 
58 #include "effects-generic.h"
59 #include "effects-simple.h"
60 #include "atomizer.h"
61 
62 
63 typedef struct {
67 
68 static void atomize_call(expression ,atomizer_param* );
69 static void do_atomize_call(expression parent,atomizer_param* p,list expressions)
70 {
71  bool safe=true;
72  /* stop if call directly involves a written reference */
73  FOREACH(EXPRESSION,arg,expressions)
74  {
75  if(expression_reference_p(arg)&&
77  {
82  { safe=false; break; }
83  if(!safe) break;
84  }
86  if(!safe) break;
87  }
88  }
89  /* go on and atomize, that is
90  * - create a variable to store call result
91  * - recurse on call arguments
92  */
93  if( safe )
94  {
95  basic bofe=basic_of_expression(parent);
99  entity_to_expression(result),
104  }
105 }
106 
107 static void atomize_call(expression parent,atomizer_param* p)
108 {
109  if(expression_call_p(parent))
110  {
111  call c = expression_call(parent);
112  do_atomize_call(parent,p,call_arguments(c));
113  }
114  else if(expression_reference_p(parent))
115  {
117  if(!ENDP(reference_indices(ref)))
119  }
120 }
121 
122 
124 {
125  pips_assert("true", p==p);
126  if(expression_call_p(parent))
127  {
128  call c= expression_call(parent);
129  entity op = call_function(c);
130  /* do not visit rhs of . and -> */
132  if(call_constant_p(c)) return false;
133  }
134  return true;
135 }
136 
137 static void atomize_all(void *v,atomizer_param* p)
138 {
141  0);
142 }
143 
144 /* This function is called for all statements in the code
145 */
146 static void atomize_statement(statement stat)
147 {
149  /* SG: we could atomize condition in test, loops etc too */
151  {
152  atomizer_param p = { NIL, NIL };
154  FOREACH(EFFECT,weff,weffects)
156  /* this may cause a useless atomization if i is an expression */
157  atomize_all(i,&p);
158  if(!ENDP(p.inserted_statements))
160  }
161 
162 }
163 
164 bool new_atomizer(char * mod_name)
165 {
166  /* get the resources */
169  set_cumulated_rw_effects((statement_effects)db_get_memory_resource(DBR_CUMULATED_EFFECTS, mod_name, true));
170  debug_on("NEW_ATOMIZER_DEBUG_LEVEL");
171 
172 
173  /* Now do the job */
175 
176  /* Reorder the module, because new statements have been added */
180 
181  /* update/release resources */
185  debug_off();
186 
187  return true;
188 }
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
syntax make_syntax_reference(reference _field_)
Definition: ri.c:2494
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
bool clean_up_sequences(statement s)
Recursively clean up the statement sequences by fusing them if possible and by removing useless one.
void set_cumulated_rw_effects(statement_effects)
list load_cumulated_rw_effects_list(statement)
list effects_write_effects(list)
void reset_cumulated_rw_effects(void)
list proper_effects_of_expression(expression)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
#define call_constant_p(C)
Definition: flint_check.c:51
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
void gen_full_free_list(list l)
Definition: genClib.c:1023
bool references_may_conflict_p(reference r1, reference r2)
Check if two references may conflict.
Definition: conflicts.c:426
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
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
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
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
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
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
statement make_assign_statement(expression, expression)
Definition: statement.c:583
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
#define debug_on(env)
Definition: misc-local.h:157
#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
bool new_atomizer(char *mod_name)
Mappings for the cumulated effects of statements.
Definition: new_atomizer.c:164
static bool atomize_call_filter(expression parent, atomizer_param *p)
Definition: new_atomizer.c:123
static void atomize_call(expression, atomizer_param *)
Definition: new_atomizer.c:107
dg_vertex_label vertex_label
Definition: new_atomizer.c:45
dg_arc_label arc_label
An atomizer that uses the one made by Fabien Coelho for HPFC, and is in fact just a hacked version of...
Definition: new_atomizer.c:44
static void atomize_statement(statement stat)
This function is called for all statements in the code.
Definition: new_atomizer.c:146
static void atomize_all(void *v, atomizer_param *p)
Definition: new_atomizer.c:137
static void do_atomize_call(expression parent, atomizer_param *p, list expressions)
Definition: new_atomizer.c:69
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define binary_call_rhs(c)
#define ENTITY_POINT_TO_P(e)
#define ENTITY_FIELD_P(e)
C data structure and pointer management.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
bool entity_field_p(entity e)
e is the field of a structure
Definition: entity.c:857
bool expression_call_p(expression e)
Definition: expression.c:415
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
call expression_call(expression e)
Definition: expression.c:445
void update_expression_syntax(expression e, syntax s)
frees expression syntax of e and replace it by the new syntax s
Definition: expression.c:3564
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
entity make_new_scalar_variable(entity, basic)
Definition: variable.c:741
void AddEntityToCurrentModule(entity)
Add a variable entity to the current module declarations.
Definition: variable.c:260
#define normalized_undefined
Definition: ri.h:1745
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define REFERENCE(x)
REFERENCE.
Definition: ri.h:2296
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_indices(x)
Definition: ri.h:2328
#define instruction_call_p(x)
Definition: ri.h:1527
#define statement_instruction(x)
Definition: ri.h:2458
#define syntax_undefined
Definition: ri.h:2676
#define call_arguments(x)
Definition: ri.h:711
#define expression_syntax(x)
Definition: ri.h:1247
#define instruction_expression_p(x)
Definition: ri.h:1539
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
list written_references
Definition: new_atomizer.c:64
list inserted_statements
Definition: new_atomizer.c:65
The structure used to build lists in NewGen.
Definition: newgen_list.h:41