PIPS
rstream_interface.c
Go to the documentation of this file.
1 #ifdef HAVE_CONFIG_H
2  #include "pips_config.h"
3 #endif
4 
5 
6 #include <stdio.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include "boolean.h"
10 
11 
12 #include "genC.h"
13 #include "linear.h"
14 #include "ri.h"
15 #include "effects.h"
16 #include "database.h"
17 #include "misc.h"
18 #include "text.h"
19 #include "text-util.h"
20 #include "ri-util.h"
21 #include "effects-util.h"
22 
23 #include "effects-generic.h"
24 #include "effects-simple.h"
25 
26 #include "pipsdbm.h"
27 #include "resources.h"
28 #include "control.h"
29 #include "conversion.h"
30 #include "properties.h"
31 #include "transformations.h"
32 
33 /*static_control*/
34 #include "arithmetique.h"
35 #include "vecteur.h"
36 #include "contrainte.h"
37 #include "ray_dte.h"
38 #include "sommet.h"
39 #include "sg.h"
40 #include "sc.h"
41 #include "polyedre.h"
42 #include "matrix.h"
43 
44 /* Pips includes */
45 #include "ri.h"
46 /* Types arc_label and vertex_label must be defined although they are
47  not used */
48 typedef void * arc_label;
49 typedef void * vertex_label;
50 #include "graph.h"
51 #include "paf_ri.h"
52 #include "database.h"
53 #include "ri-util.h"
54 #include "constants.h"
55 #include "misc.h"
56 #include "control.h"
57 #include "text-util.h"
58 #include "pipsdbm.h"
59 #include "resources.h"
60 #include "paf-util.h"
61 #include "static_controlize.h"
62 #include "pocc-interface.h"
63 #include "preprocessor.h"
64 #include "callgraph.h" // For compute_callees()
65 #include "effects-generic.h" // For compute_callees()
66 #include "accel-util.h" // For outliner()
67 
68 #define PRAGMA_TEMP_BEGIN "nonscop"
69 #define PRAGMA_TEMP_END "endnonscop"
70 #define PREFIX_TEMP "nonscopf"
71 
72 #define statement_has_this_pragma_string_p(stmt,str) \
73 (get_extension_from_statement_with_pragma(stmt,str)!=NULL)
74 
76 static int hasPragma = 0;
77 
79  if (statement_with_pragma_p(s)) {
80  hasPragma++;
81  }
82  return true;
83 }
84 
85 static bool searchPragma (statement s) {
87  if (hasPragma != 0) {
88  hasPragma = 0;
89  return true;
90  }
91  else {
92  hasPragma = 0;
93  return false;
94  }
95 }
96 
97 static void insert_endscop_before_stmt(statement stmt, bool* pragma_added_p, sequence seqInst, list stmts, statement last_added_pragma) {
98  if (!is_SCOP_rich(seqInst, last_added_pragma, stmt, pragma_added_p))
99  return;
102  *pragma_added_p = false;
103  sequence_statements(seqInst) = gen_insert_before(endscop, stmt, stmts);
104 }
105 
106 static void insert_endscop_after_stmt(statement stmt, bool* pragma_added_p, sequence seqInst, statement last_added_pragma) {
107  if (!is_SCOP_rich(seqInst, last_added_pragma, stmt, pragma_added_p))
108  return;
111  *pragma_added_p = false;
112  gen_insert_after(endscop, stmt, sequence_statements(seqInst));
113 }
114 
115 static void insert_endscop_in_sequence(statement stmt, bool* pragma_added_p, bool insertBefore) {
118  *pragma_added_p = false;
119  // Insert the continue statement after the statement parameter, thereby creating a sequence
120  insert_statement(stmt, endscop, insertBefore);
121 }
122 
123 static void add_to_stmt(statement stmt, bool* pragma_added_p) {
125  *pragma_added_p = true;
126 }
127 
128 
129 void pragma_nonscop (statement s, bool pragma_added_p, bool in_loop_p) {
130 
131  statement save_stmt = statement_undefined,
132  last_added_pragma = statement_undefined;
133  instruction instTop = statement_instruction(s);
134 
135  switch (instruction_tag(instTop)) {
136 
138  {
139  sequence seqInst = instruction_sequence(instTop);
140  list stmts = sequence_statements(seqInst);
141  FOREACH(statement, stmt, stmts) {
142  save_stmt = stmt;
144  static_control sc;
145  switch (instruction_tag(inst)) {
146  case is_instruction_loop :
147  {
148  bool insideScop = searchPragma(stmt);
149  bool currentScop = statement_with_pragma_p(stmt);
150  loop l = instruction_loop(inst);
152  if (!static_control_yes(sc) && !pragma_added_p && !insideScop) {
153  add_to_stmt(stmt, &pragma_added_p);
154  last_added_pragma = stmt;
155  }
156  else if (!static_control_yes(sc) && !pragma_added_p && insideScop && !currentScop) {
157  pragma_nonscop(stmt, pragma_added_p, true);
158  }
159  else if (static_control_yes(sc) && pragma_added_p) {
160  insert_endscop_before_stmt(stmt, &pragma_added_p, seqInst, stmts, last_added_pragma);
161  }
162  }
163  break;
164  case is_instruction_test :
165  {
166  bool insideScop = searchPragma(stmt);
168  if (!static_control_yes(sc) && !pragma_added_p && !insideScop) {
169  add_to_stmt(stmt, &pragma_added_p);
170  last_added_pragma = stmt;
171  }
172  else if (!in_loop_p && !pragma_added_p && insideScop) {
173  pragma_nonscop(stmt, pragma_added_p, in_loop_p);
174  }
175  else if (static_control_yes(sc) && pragma_added_p) {
176  insert_endscop_before_stmt(stmt, &pragma_added_p, seqInst, stmts, last_added_pragma);
177  }
178  }
179  break;
181  {
182  bool insideScop = searchPragma(stmt);
183  if (!insideScop && !pragma_added_p) {
184  add_to_stmt(stmt, &pragma_added_p);
185  last_added_pragma = stmt;
186  }
187  else if (insideScop) {
188  pragma_nonscop(whileloop_body(instruction_whileloop(inst)), pragma_added_p, in_loop_p);
189  }
190  }
191  break;
192  case is_instruction_call :
193  {
195  bool isDeclaration = declaration_statement_p(stmt);
196  if (return_statement_p(stmt) && pragma_added_p) {
197  insert_endscop_before_stmt(stmt, &pragma_added_p, seqInst, stmts, last_added_pragma);
198  }
199  else if (!static_control_yes(sc) && !pragma_added_p && !isDeclaration) {
200  add_to_stmt(stmt, &pragma_added_p);
201  last_added_pragma = stmt;
202  }
203  else if (static_control_yes(sc) && pragma_added_p) {
204  insert_endscop_before_stmt(stmt, &pragma_added_p, seqInst, stmts, last_added_pragma);
205  }
206  }
207  break;
208  default :
209  {
211  bool currentScop = statement_with_pragma_p(stmt);
212  bool insideScop = searchPragma(stmt);
213  if (pragma_added_p && static_control_yes(sc)) {
214  insert_endscop_before_stmt(stmt, &pragma_added_p, seqInst, stmts, last_added_pragma);
215  }
216  else if (!pragma_added_p && !static_control_yes(sc) && !currentScop && !insideScop) {
217  add_to_stmt(stmt, &pragma_added_p);
218  last_added_pragma = stmt;
219  }
220  }
221  break;
222  }
223  }
224  if (pragma_added_p) {
225  insert_endscop_after_stmt(save_stmt, &pragma_added_p, seqInst, last_added_pragma);
226  }
227  }
228  break;
229  case is_instruction_loop :
230  {
231  loop loopAlone = instruction_loop(instTop);
233  bool insideScop = searchPragma(s);
234  bool currentScop = statement_with_pragma_p(s);
235  if (!static_control_yes(scAlone) && !pragma_added_p && !insideScop && !currentScop) {
236  add_to_stmt(s, &pragma_added_p);
237  last_added_pragma = s;
238  insert_endscop_in_sequence(s, &pragma_added_p, false);
239  }
240  else if (!static_control_yes(scAlone) && insideScop && !currentScop) {
241  pragma_nonscop(loop_body(loopAlone), pragma_added_p, in_loop_p);
242  }
243  }
244  break;
245 
247  {
248  }
249  break;
250 
252  {
253  whileloop whileAlone = instruction_whileloop(instTop);
254  bool currentScop = statement_with_pragma_p(s);
255  if (!currentScop)
256  pragma_nonscop(whileloop_body(whileAlone), pragma_added_p, in_loop_p);
257  }
258  break;
259 
260  case is_instruction_test :
261  {
262  test testAlone = instruction_test(instTop);
263  bool currentScop = statement_with_pragma_p(s);
264  if (!currentScop) {
265  pragma_nonscop(test_true(testAlone), pragma_added_p, in_loop_p);
266  pragma_nonscop(test_false(testAlone), pragma_added_p, in_loop_p);
267  }
268  }
269  break;
270 
271  default :
272  break;
273  }
274  return;
275 }
276 
277 /* Phase in charge of putting pragmas around the non-SCoP of the code
278  This phase only works if there has been a previous phase applied putting
279  pragmas around SCoP of the code.
280 */
282  statement module_stat;
285 
286  module_stat = get_current_module_statement();
287 
288  Gsc_map = (statement_mapping)db_get_memory_resource(DBR_STATIC_CONTROL, module_name, true);
289 
290  pragma_nonscop(module_stat, false, false);
291 
292  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name,module_stat);
293 
296 
297  return true;
298 }
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
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
#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
void gen_insert_after(const void *no, const void *o, list l)
Definition: list.c:223
list gen_insert_before(const void *no, const void *o, list l)
Definition: list.c:238
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
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
bool statement_with_pragma_p(statement)
Test if a statement has some pragma.
Definition: statement.c:3836
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
statement make_continue_statement(entity)
Definition: statement.c:953
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
#define GET_STATEMENT_MAPPING(map, stat)
Definition: newgen-local.h:49
hash_table statement_mapping
these macros are obsolete! newgen functions (->) should be used instead
Definition: newgen-local.h:42
struct _newgen_struct_static_control_ * static_control
Definition: paf_ri.h:184
#define static_control_yes(x)
Definition: paf_ri.h:753
bool is_SCOP_rich(sequence, statement, statement, bool *)
Checks if there is at least one loop in the sequence.
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
entity entity_empty_label(void)
Definition: entity.c:1105
void add_pragma_str_to_statement(statement st, const char *s, bool copy_flag)
Add a string as a pragma to a statement.
Definition: pragma.c:425
#define loop_body(x)
Definition: ri.h:1644
#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
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_test(x)
Definition: ri.h:1517
#define statement_undefined
Definition: ri.h:2419
static void add_to_stmt(statement stmt, bool *pragma_added_p)
#define PRAGMA_TEMP_END
static bool searchPragma(statement s)
static int hasPragma
bool rstream_interface(char *module_name)
Phase in charge of putting pragmas around the non-SCoP of the code This phase only works if there has...
static bool statement_with_pragma_p_inv(statement s)
static statement_mapping Gsc_map
static void insert_endscop_after_stmt(statement stmt, bool *pragma_added_p, sequence seqInst, statement last_added_pragma)
static void insert_endscop_in_sequence(statement stmt, bool *pragma_added_p, bool insertBefore)
static void insert_endscop_before_stmt(statement stmt, bool *pragma_added_p, sequence seqInst, list stmts, statement last_added_pragma)
void * arc_label
tatic_control
void * vertex_label
#define PRAGMA_TEMP_BEGIN
void pragma_nonscop(statement s, bool pragma_added_p, bool in_loop_p)
Warning! Do not modify this file that is automatically generated!
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54