PIPS
prettyprintcray.c
Go to the documentation of this file.
1 /*
2 
3  $Id: prettyprintcray.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 
25 // is this really a transformation?
26 // do not compile unless required
27 #include "phases.h"
28 #ifdef BUILDER_PRINT_PARALLELIZEDCRAY_CODE
29 
30 #ifdef HAVE_CONFIG_H
31  #include "pips_config.h"
32 #endif
33 #include <stdio.h>
34 #include <string.h>
35 #include <limits.h>
36 
37 #include "genC.h"
38 #include "linear.h"
39 
40 #include "misc.h"
41 #include "properties.h"
42 #include "pipsdbm.h"
43 
44 #include "ri.h"
45 #include "ri-util.h"
46 #include "workspace-util.h" // entity_minimal_name
47 
48 #include "text.h"
49 #include "text-util.h" // used
50 
51 #include "effects.h"
52 #include "effects-util.h" // used
53 #include "effects-generic.h" // used
54 #include "effects-simple.h" // used
55 
56 #include "prettyprint.h" // make_text_resource
57 //#include "preprocessor.h" // entity_minimal_name
58 #include "expressions.h" // stmt_to_fx
59 
60 #include "top-level.h" // PARALLEL_FORTRAN_EXT
61 
62 
63 /* returns a list of all entities which:
64  * - are concerned with cumulated effects (cfx) of the loop_body
65  * - and are member of loop_locals(lp)
66  * makes sure the loop index is in the list
67  */
68 static list real_loop_locals(loop lp, effects cfx)
69 {
70  list rll= NIL;
71 
72  MAPL(ce,
73  {
74  effect
75  eff = EFFECT(CAR(ce));
76  entity
78 
79  if (!entity_in_list_p(ent, rll)
80  && entity_in_list_p(ent,loop_locals(lp)) )
81  {
82  /* ent is a real loop local */
83  debug(7, "real_loop_locals", "real loop local: %s\n",
84  entity_local_name(ent));
85  rll = CONS(ENTITY, ent, rll);
86  }
87  }, effects_effects(cfx));
88 
89  if( !entity_in_list_p(loop_index(lp), rll) )
90  {
91  rll= CONS(ENTITY, loop_index(lp), rll);
92  }
93  return(rll);
94 }
95 
96 /*
97  * recursively concatenates all real loop locals of all enclosed loops.
98  * filters redondant entities
99  */
100 static list all_enclosed_scope_variables(statement stmt)
101 {
103  list ent_l= NIL;
104 
105  switch(instruction_tag(instr)) {
106  case is_instruction_block :
107  MAPL(stmt_l, {
108  statement st=STATEMENT(CAR(stmt_l));
109 
110  ent_l= concat_new_entities(ent_l, all_enclosed_scope_variables(st));
111  }, instruction_block(instr));
112  break;
113  case is_instruction_loop : {
114  loop lp= instruction_loop(instr);
115  statement lpb= loop_body(lp);
116  effects cfx = stmt_to_fx(lpb, get_rw_effects() );
117 
118  pips_assert("all_enclosed_scope_variables", cfx != effects_undefined);
119  ent_l= concat_new_entities(real_loop_locals(lp, cfx),
120  all_enclosed_scope_variables(lpb));
121  break;
122  }
123  case is_instruction_test : {
124  test tst= instruction_test(instr);
125  list l1, l2;
126 
127  l1= all_enclosed_scope_variables(test_true(tst));
128  l2= all_enclosed_scope_variables(test_false(tst));
129  ent_l= concat_new_entities(l1, l2);
130 
131  break;
132  }
133  case is_instruction_whileloop : {
134  whileloop lp= instruction_whileloop(instr);
135  ent_l= all_enclosed_scope_variables(whileloop_body(lp));
136  break;
137  }
139  list blocs = NIL;
140 
141  CONTROL_MAP(ctl, {
142  statement st = control_statement(ctl);
143 
144  ent_l= concat_new_entities(all_enclosed_scope_variables(st),
145  ent_l);
147 
148  gen_free_list(blocs);
149  break;
150  }
151  case is_instruction_call :
152  break;
153  case is_instruction_goto :
154  default :
155  pips_internal_error("Bad instruction tag");
156  }
157  return(ent_l);
158 }
159 
160 /* lp_stt must be a loop statement */
161 static text text_microtasked_loop(__attribute__((unused)) entity module,__attribute__((unused)) int margin, statement lp_stt)
162 {
163  text txt;
164  unformatted u;
165  effects fx;
166  list wordl;
167  int np = 0;
169  cons *lp_shared = NIL;
170  list ent_l= all_enclosed_scope_variables(lp_stt);
171 
172  /* initializations */
173  txt = make_text(NIL);
174 
175  wordl = CHAIN_SWORD(NIL, "DO ALL ");
176 
177  fx = stmt_to_fx(loop_body(lp), get_rw_effects());
178 
179  /* generate arguments for PRIVATE */
180  /* nb: ent_l should contain entities only ones. */
181  wordl = CHAIN_SWORD(wordl, "PRIVATE(");
182  np=0;
183  MAPL( el, {
184  entity ent = ENTITY(CAR(el));
185 
186  /* What about arrays? nothing special?? */
187  /* if (!ENDP(reference_indices(effect_any_reference(eff)))) */
188 
189  if (np>0)
190  wordl = CHAIN_SWORD(wordl, ",");
191  wordl = CHAIN_SWORD(wordl, entity_local_name(ent)) ;
192  np++;
193  }, ent_l);
194 
195  wordl = CHAIN_SWORD(wordl, ") ");
196 
197  ifdebug(6)
198  {
199  fprintf(stderr,
200  "[text_microtasked_loop] loop locals of %s: ",
202 
203  MAPL(ce,
204  {
205  fprintf(stderr, "%s ", entity_minimal_name(ENTITY(CAR(ce))));
206  },
207  loop_locals(lp));
208 
209  fprintf(stderr, "\nent_l content is: ");
210 
211  MAPL(ce,
212  {
213  fprintf(stderr, "%s ", entity_minimal_name(ENTITY(CAR(ce))));
214  },
215  ent_l);
216 
217  fprintf(stderr, "\n");
218  }
219 
220  /* generate arguments for SHARED */
221  wordl = CHAIN_SWORD(wordl, "SHARED(");
222  np=0;
223  MAPL(ce,
224  {
225  effect eff = EFFECT(CAR(ce));
227 
228 /* if(ENDP(ce)) user_log("ce is NIL !!\n");
229  if(ENDP(CDR(ce))) user_log("CDR(ce) is NIL\n");
230  else user_log("CDR(ce) is *not* NIL\n");
231  */
232  /* What about arrays? nothing special?? */
233  /* if (!ENDP(reference_indices(effect_any_reference(eff)))) */
234 
235  /*
236  * ent_l added, in order to use the newly computed << good >> effects,
237  * and to warrant the fact that no variables should be declared
238  * at the same time private and shared.
239  * same_entity_p added also, just in case.
240  *
241  * FC 28/09/93
242  */
243  if ((!entity_in_list_p(ent, loop_locals(lp))) &&
244  (!entity_in_list_p(ent, ent_l)) &&
245  (!same_entity_p(ent, loop_index(lp))) &&
246  (!entity_in_list_p(ent, lp_shared)))
247  {
248  /* ent is a new shared entity */
249  if (np>0)
250  wordl = CHAIN_SWORD(wordl, ",");
251  lp_shared = CONS(ENTITY, ent, lp_shared);
252  wordl = CHAIN_SWORD(wordl, entity_local_name(ent)) ;
253  np++;
254  }
255  /* What to do when no shared? */
256 
257  }, effects_effects(fx));
258 
259  wordl = CHAIN_SWORD(wordl, ") ");
260 
261  gen_free_list(lp_shared);
262  gen_free_list(ent_l);
263 
264  u = make_unformatted("CMIC$", 0, 0, wordl) ;
265 
266  /* format u */
267 
268 
270  return(txt);
271 }
272 
273 /* lp_stt must be a loop statement */
274 static text text_vectorized_loop(__attribute__((unused)) entity module,__attribute__((unused)) int margin,__attribute__((unused)) statement lp_stt)
275 {
276  text txt;
277  unformatted u;
278  list wordl;
279 
280  txt = make_text(NIL);
281 
282  wordl = CHAIN_SWORD(NIL, "IVDEP ");
283 
284  u = make_unformatted("CDIR$", 0, 0, wordl) ;
285 
287  return(txt);
288 }
289 
290 
291 static text text_cray(entity module, int margin, statement stat)
292 {
293  text txt = text_undefined;
294 
297  statement body = loop_body(lp);
298 
299  switch(execution_tag(loop_execution(lp))) {
301  txt = make_text(NIL);
302  break;
303  case (is_execution_parallel):
305  /* vector loop */
306  txt = text_vectorized_loop(module, margin, stat);
307  }
308  else {
309  /* assumes that all loops are CMIC$ !! */
310  txt = text_microtasked_loop(module, margin, stat);
311  }
312  break;
313  }
314  }
315  else {
316  txt = make_text(NIL);
317  }
318 
319  return(txt);
320 }
321 
322 
323 bool print_parallelizedcray_code(char *mod_name)
324 {
325  entity module = module_name_to_entity(mod_name);
327 
328  /* push prettyprint style */
331 
333  mod_stat = (statement)
334  db_get_memory_resource(DBR_PARALLELIZED_CODE, mod_name, true);
335 
336  /* We need to recompute proper effects and cumulated effects */
339 
340  init_rw_effects();
342 
343  debug_on("PRETTYPRINT_DEBUG_LEVEL");
344 
345  init_prettyprint(text_cray);
346 
347  make_text_resource(mod_name,
348  DBR_PARALLELPRINTED_FILE,
349  PARALLEL_FORTRAN_EXT,
351 
353 
354  /* free proper effects and cumulated effects
355  Je ne sais pas trop comment le free fonctionne avec statement_effects.
356  bc.*/
357  /* free_statement_effects( get_rw_effects() );
358  free_statement_effects( get_proper_rw_effects() ); */
359 
363 
365  free(pp);
366 
367  debug_off();
368 
369  return true;
370 }
371 
372 #endif // BUILDER_PRINT_PARALLELIZEDCRAY_CODE
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
unformatted make_unformatted(string a1, intptr_t a2, intptr_t a3, list a4)
Definition: text.c:149
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
text make_text(list a)
Definition: text.c:107
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void init_rw_effects(void)
void reset_proper_rw_effects(void)
void init_proper_rw_effects(void)
statement_effects get_rw_effects(void)
void reset_rw_effects(void)
void rproper_effects_of_statement(statement)
void rcumulated_effects_of_statement(statement)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define effects_undefined
Definition: effects.h:688
#define effects_effects(x)
Definition: effects.h:710
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
effects stmt_to_fx(statement, statement_effects)
returns proper effects associated to statement stmt
Definition: partial_eval.c:179
char * get_string_property(const char *)
void free(void *)
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
bool instruction_assign_p(instruction i)
Test if an instruction is an assignment.
Definition: instruction.c:164
#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 CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
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
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_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
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
const char * entity_minimal_name(entity e)
Do preserve scope informations.
Definition: naming.c:214
static char * module
Definition: pips.c:74
void close_prettyprint()
because some prettyprint functions may be used for debug, so the last hook set by somebody may have s...
Definition: misc.c:242
void init_prettyprint(text(*hook)(entity, int, statement))
checks that the prettyprint hook was actually reset...
Definition: misc.c:231
text text_module(entity, statement)
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
#define PRETTYPRINT_PARALLEL
void set_string_property(const char *, const char *)
#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)
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
bool entity_in_list_p(entity ent, list ent_l)
look for ent in ent_l
Definition: entity.c:2221
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
list concat_new_entities(list l1, list l2)
returns l1 after elements of l2 but not of l1 have been appended to l1.
Definition: entity.c:2236
#define execution_tag(x)
Definition: ri.h:1207
#define loop_body(x)
Definition: ri.h:1644
#define loop_execution(x)
Definition: ri.h:1648
#define instruction_loop_p(x)
Definition: ri.h:1518
#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 test_false(x)
Definition: ri.h:2837
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ 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 test_true(x)
Definition: ri.h:2835
#define loop_locals(x)
Definition: ri.h:1650
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
@ is_execution_parallel
Definition: ri.h:1190
@ is_execution_sequential
Definition: ri.h:1189
#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 loop_index(x)
Definition: ri.h:1640
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54
#define CHAIN_SWORD(l, s)
#define ADD_SENTENCE_TO_TEXT(t, p)
#define text_undefined
Definition: text.h:91
@ is_sentence_unformatted
Definition: text.h:58
bool print_parallelizedcray_code(char *)
prettyprintcray.c