PIPS
prettyprint.c
Go to the documentation of this file.
1 /*
2 
3  $Id: prettyprint.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 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* Ansi includes */
28 #include <stdio.h>
29 #include <string.h>
30 
31 /* Newgen includes */
32 #include "genC.h"
33 
34 /* C3 includes */
35 #include "boolean.h"
36 #include "arithmetique.h"
37 #include "vecteur.h"
38 #include "contrainte.h"
39 #include "ray_dte.h"
40 #include "sommet.h"
41 #include "sg.h"
42 #include "sc.h"
43 #include "polyedre.h"
44 #include "union.h"
45 #include "matrix.h"
46 
47 /* Pips includes */
48 #include "boolean.h"
49 #include "ri.h"
50 #include "constants.h"
51 #include "ri-util.h"
52 #include "misc.h"
53 #include "complexity_ri.h"
54 #include "database.h"
55 #include "graph.h"
56 #include "dg.h"
57 #include "paf_ri.h"
58 #include "parser_private.h"
59 #include "property.h"
60 #include "properties.h"
61 #include "prettyprint.h"
62 #include "reduction.h"
63 #include "text.h"
64 #include "text-util.h"
65 #include "tiling.h"
66 #include "text-util.h"
67 #include "pipsdbm.h"
68 #include "resources.h"
69 #include "static_controlize.h"
70 #include "paf-util.h"
71 #include "pip.h"
72 #include "array_dfg.h"
73 #include "prgm_mapping.h"
74 #include "reindexing.h"
75 
76 #define CM_FORTRAN_EXT ".fcm"
77 #define CRAFT_FORTRAN_EXT ".craft"
78 
79 /* Local defines */
82 
83 extern list lparams;
86 
87 
88 /*=======================================================================*/
89 /* statement make_layout_statement(entity ae, int serial, news):
90  *
91  */
92 
94  entity ae;
95  int serial, news;
96 {
97  instruction ins;
98  list lstat = NIL;
99  char *comment;
100  statement stat;
101  int i;
102 
103  comment = (char*) malloc(64);
104  sprintf(comment,"CMF$ LAYOUT %s(", entity_local_name(ae));
105  for(i = 0; i < serial; i++) {
106  sprintf(comment, "%s:SERIAL", comment);
107  if((i < serial-1) || ((i == serial-1) && (news > 0)) )
108  sprintf(comment, "%s, ", comment);
109  }
110  for(i = 0; i < news; i++) {
111  sprintf(comment, "%s:NEWS", comment);
112  if(i < news-1)
113  sprintf(comment, "%s, ", comment);
114  }
115  sprintf(comment, "%s)\n", comment);
116 
117  stat = make_nop_statement();
119  lstat = CONS(STATEMENT, stat, lstat);
120 
121  /* put all the pieces of lstat in one statement */
122  stat = make_block_statement(lstat);
123 
124  if(get_debug_level() > 1)
125  fprintf(stderr,
126  "\nmake_layout_statement\n=====================\n%s\n",
127  comment);
128 
129  return(stat);
130 }
131 
132 
133 /*=======================================================================*/
134 /* statement make_shared_statement(entity ae, int serial, news):
135  *
136  */
137 
139  entity ae;
140  int serial, news;
141 {
142  instruction ins;
143  list lstat = NIL;
144  char *comment;
145  statement stat;
146  int i;
147 
148  comment = (char*) malloc(64);
149  sprintf(comment,"CDIR$ SHARED %s(", entity_local_name(ae));
150  for(i = 0; i < serial; i++) {
151  sprintf(comment, "%s:", comment);
152  if((i < serial-1) || ((i == serial-1) && (news > 0)) )
153  sprintf(comment, "%s, ", comment);
154  }
155  for(i = 0; i < news; i++) {
156  sprintf(comment, "%s:BLOCK", comment);
157  if(i < news-1)
158  sprintf(comment, "%s, ", comment);
159  }
160  sprintf(comment, "%s)\n", comment);
161 
162  stat = make_nop_statement();
164  lstat = CONS(STATEMENT, stat, lstat);
165 
166  /* put all the pieces of lstat in one statement */
167  stat = make_block_statement(lstat);
168 
169  if(get_debug_level() > 1)
170  fprintf(stderr,
171  "\nmake_shared_statement\n=====================\n%s\n",
172  comment);
173 
174  return(stat);
175 }
176 
177 
178 /*=======================================================================*/
179 /* void cmf_layout_align(statement mod_stat):
180  *
181  */
182 
185 {
186  list list_body, list_la, lae = NIL, li = NIL, lv;
187 
188  for(lv = graph_vertices(current_dfg); !ENDP(lv); POP(lv)) {
189  vertex cv;
190  int cn, bdim;
191  list bv, ciel;
192  string name;
193  char num[32];
194  entity array_ent;
195  static_control stco;
196 
197  cv = VERTEX(CAR(lv));
199 
200  if (cn == ENTRY_ORDER)
201  continue;
202  if (cn == EXIT_ORDER)
203  continue;
204 
205  /* Static control of the node */
207 
208  ciel = static_control_to_indices(stco);
209 
210  if(get_debug_level() > 0) {
211  fprintf(stderr, "\nIn cmf_layout_align, CIEL : ");
212  fprint_entity_list(stderr, ciel);
213  }
214 
215  /* We extract the bdt corresponding to this node. */
216  bv = extract_bdt(current_bdt, cn);
217 
218  /* We count the number of non constant dimension for each
219  domain. */
220  bdim = 0;
221  for (; !ENDP(bv); POP(bv)) {
222  int bcount = 0;
223  schedule sched = SCHEDULE(CAR(bv));
224  list lexp;
225 
226  for (lexp = schedule_dims(sched); !ENDP(lexp); POP(lexp)) {
229 
230  if(normalized_tag(nor) == is_normalized_linear) {
232 
233  if (vars_in_vect_p(vec, ciel))
234  bcount++;
235  }
236  else
237  user_error("cmf_layout_align",
238  "Rational case not treated yet !");
239  }
240 
241  if(bcount > bdim)
242  bdim = bcount;
243  }
244  li = CONS(INT, bdim, li);
245 
246  /* We get the array entity corresponding to this node. */
247  (void) sprintf(num, "%d", cn-BASE_NODE_NUMBER);
249  SAI, num, (string) NULL));
250  array_ent = gen_find_tabulated(name, entity_domain);
251  if(array_ent == entity_undefined)
252  user_error("make_array_bounds",
253  "\nOne ins (%d) has no array entity : %s\n",
254  cn-BASE_NODE_NUMBER, name);
255 
256  lae = CONS(ENTITY, array_ent, lae);
257  }
258 
259  /* Layout */
260  list_la = NIL;
261  for(; !ENDP(lae); POP(lae), POP(li)) {
262  entity ae;
263  int serial, nb_dims, news;
264 
265  ae = ENTITY(CAR(lae));
266  serial = INT(CAR(li));
267  nb_dims =
269  news = nb_dims - serial;
270 
271  list_la = CONS(STATEMENT, make_layout_statement(ae, serial, news),
272  list_la);
273  }
274 
275  /* We add these declarations to the statement of the module */
276  /* After reindexing, the first statement is in fact a sequence and
277  no longer an unstructured. Trust it to simplify the following: */
280  pips_user_error("Body is not a block\n");
281 
282  list_body = gen_nconc(list_la,
285  list_body;
286 }
287 
288 
289 /*=======================================================================*/
290 /* void craft_layout_align(statement mod_stat):
291  *
292  */
293 
294 void
296 {
297  list list_body, list_la, lae = NIL, li = NIL, lv;
298 
299  for(lv = graph_vertices(current_dfg); !ENDP(lv); POP(lv)) {
300  vertex cv;
301  int cn, bdim;
302  list bv, ciel;
303  string name;
304  char num[32];
305  entity array_ent;
306  static_control stco;
307 
308  cv = VERTEX(CAR(lv));
310 
311  if (cn == ENTRY_ORDER)
312  continue;
313  if (cn == EXIT_ORDER)
314  continue;
315 
316  /* Static control of the node */
318 
319  ciel = static_control_to_indices(stco);
320 
321  if(get_debug_level() > 0) {
322  fprintf(stderr, "\nIn craft_layout_align, CIEL : ");
323  fprint_entity_list(stderr, ciel);
324  }
325 
326  /* We extract the bdt corresponding to this node. */
327  bv = extract_bdt(current_bdt, cn);
328 
329  /* We count the number of non constant dimension for each
330  domain. */
331  bdim = 0;
332  for (; !ENDP(bv); POP(bv)) {
333  int bcount = 0;
334  schedule sched = SCHEDULE(CAR(bv));
335  list lexp;
336 
337  for (lexp = schedule_dims(sched); !ENDP(lexp); POP(lexp)) {
340 
341  if(normalized_tag(nor) == is_normalized_linear) {
343 
344  if (vars_in_vect_p(vec, ciel))
345  bcount++;
346  }
347  else
348  user_error("craft_layout_align",
349  "Rational case not treated yet !");
350  }
351 
352  if(bcount > bdim)
353  bdim = bcount;
354  }
355  li = CONS(INT, bdim, li);
356 
357  /* We get the array entity corresponding to this node. */
358  (void) sprintf(num, "%d", cn-BASE_NODE_NUMBER);
360  SAI, num, (string) NULL));
361  array_ent = gen_find_tabulated(name, entity_domain);
362  if(array_ent == entity_undefined)
363  user_error("craft_layout_align",
364  "\nOne ins (%d) has no array entity : %s\n",
365  cn-BASE_NODE_NUMBER, name);
366 
367  lae = CONS(ENTITY, array_ent, lae);
368  }
369 
370  /* Shared */
371  list_la = NIL;
372  for(; !ENDP(lae); POP(lae), POP(li)) {
373  entity ae;
374  int serial, nb_dims, news;
375 
376  ae = ENTITY(CAR(lae));
377  serial = INT(CAR(li));
378  nb_dims =
380  news = nb_dims - serial;
381 
382  list_la = CONS(STATEMENT, make_shared_statement(ae, serial, news),
383  list_la);
384  }
385 
386  /* We add these declarations to the statement of the module */
387  /* After reindexing, the first statement is in fact a sequence and
388  no longer an unstructured. Trust it to simplify the following: */
391  pips_user_error("Body is not a block\n");
392 
393  list_body = gen_nconc(list_la,
396  list_body;
397  }
398 
399 
400 /*=======================================================================*/
402 char *mod_name;
403 {
404  plc the_plc;
405 
406  text r = make_text(NIL);
407  entity module;
409  code c;
410  string s, pp;
411  static_control stco;
413  bool success;
414 
415  debug_on("PRETTYPRINT_DEBUG_LEVEL");
416 
421  }
422  c = entity_code(module);
423  s = code_decls_text(c);
424 
425  /* Static controlize code */
426  mod_stat = (statement) db_get_memory_resource(DBR_CODE, mod_name, true);
427  STS = (statement_mapping) db_get_memory_resource(DBR_STATIC_CONTROL,
428  mod_name, true);
431 
433  if (stco == static_control_undefined)
434  pips_internal_error("This is an undefined static control !");
435  if (!static_control_yes(stco))
436  pips_internal_error("This is not a static control program !");
437 
438  /* The DFG, the BDT and the PLC */
440  mod_name, true));
441  current_bdt = (bdt) db_get_memory_resource(DBR_BDT, mod_name, true);
442  the_plc = (plc) db_get_memory_resource(DBR_PLC, mod_name, true);
443  if (get_debug_level() > 0) {
444  fprint_dfg(stderr, current_dfg);
445  fprint_bdt(stderr, current_bdt);
446  fprint_plc(stderr, the_plc);
447  }
448 
451  set_bool_property("PRETTYPRINT_ALL_DECLARATIONS", true);
452 
454 
455  mod_stat = (statement)
456  db_get_memory_resource(DBR_REINDEXED_CODE, mod_name, true);
457 
458  insure_declaration_coherency_of_module(module, mod_stat);
459 
461 
463 
464  success = make_text_resource(mod_name,
465  DBR_PARALLELPRINTED_FILE,
467  r);
468 
472 
474 
475  debug_off();
476 
477  return(success);
478 }
479 
480 
481 /*=======================================================================*/
483 char *mod_name;
484 {
485  plc the_plc;
486 
487  text r = make_text(NIL);
488  entity module;
490  code c;
491  string s, pp;
492  static_control stco;
494  bool success;
495 
496  debug_on("PRETTYPRINT_DEBUG_LEVEL");
497 
502  }
503  c = entity_code(module);
504  s = code_decls_text(c);
505 
506  /* Static controlize code */
507  mod_stat = (statement) db_get_memory_resource(DBR_CODE, mod_name, true);
508  STS = (statement_mapping)db_get_memory_resource(DBR_STATIC_CONTROL,
509  mod_name, true);
512 
514  if (stco == static_control_undefined)
515  pips_internal_error("This is an undefined static control !");
516  if (!static_control_yes(stco))
517  pips_internal_error("This is not a static control program !");
518 
519  /* The DFG, the BDT and the PLC */
521  mod_name,
522  true));
523  current_bdt = (bdt) db_get_memory_resource(DBR_BDT, mod_name, true);
524  the_plc = (plc) db_get_memory_resource(DBR_PLC, mod_name, true);
525  if (get_debug_level() > 0) {
526  fprint_dfg(stderr, current_dfg);
527  fprint_bdt(stderr, current_bdt);
528  fprint_plc(stderr, the_plc);
529  }
530 
533  set_bool_property("PRETTYPRINT_ALL_DECLARATIONS", true);
534 
536 
537  mod_stat = (statement) db_get_memory_resource(DBR_REINDEXED_CODE,
538  mod_name, true);
539 
540  insure_declaration_coherency_of_module(module, mod_stat);
543 
544  success = make_text_resource(mod_name,
545  DBR_PARALLELPRINTED_FILE,
547  r);
548 
553  debug_off();
554 
555  return(success);
556 }
text make_text(list a)
Definition: text.c:107
graph adg_pure_dfg(graph in_gr)
======================================================================
Definition: adg_graph.c:56
void fprint_dfg(FILE *fp, graph obj)
===========================================================================
static hash_table STS
The "STS" global variable is the hash table that maps the static_control on the statements.
Definition: adg_read_paf.c:155
statement adg_number_to_statement(int in_nb)
======================================================================
Definition: adg_utils.c:461
static list lexp
#define EXIT_ORDER
#define ENTRY_ORDER
@ INT
Definition: atomic.c:48
static int num
Definition: bourdoncle.c:137
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
char * get_string_property(const char *)
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
void * malloc(YYSIZE_T)
void free(void *)
bool success
Definition: gpips-local.h:59
#define vertex_vertex_label(x)
Definition: graph.h:152
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
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
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
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
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
void insert_comments_to_statement(statement, const char *)
Insert a comment string (if non empty) at the beginning of the comments of a statement.
Definition: statement.c:1916
void fprint_entity_list(FILE *fp, list l)
void fprint_entity_list(FILE *fp,list l): prints a list of entities on file fp.
Definition: entity.c:3188
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_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define user_error(fn,...)
Definition: misc-local.h:265
#define pips_user_error
Definition: misc-local.h:147
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
#define MODULE_SEP_STRING
Definition: naming-local.h:30
hash_table statement_mapping
these macros are obsolete! newgen functions (->) should be used instead
Definition: newgen-local.h:42
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
char * string
STRING.
Definition: newgen_types.h:39
#define BASE_NODE_NUMBER
list static_control_to_indices(static_control)
package mapping : Alexis Platonoff, july 1993
Definition: utils.c:1037
void reset_current_stco_map(void)
========================================================================
Definition: utils.c:2423
static_control get_stco_from_current_map(statement)
========================================================================
Definition: utils.c:2429
void set_current_stco_map(statement_mapping)
========================================================================
Definition: utils.c:2408
void fprint_bdt(FILE *, bdt)
===========================================================================
Definition: print.c:352
struct _newgen_struct_bdt_ * bdt
Definition: paf_ri.h:72
#define SCHEDULE(x)
SCHEDULE.
Definition: paf_ri.h:682
#define static_control_params(x)
Definition: paf_ri.h:755
#define static_control_yes(x)
Definition: paf_ri.h:753
#define static_control_undefined
Definition: paf_ri.h:727
struct _newgen_struct_plc_ * plc
Definition: paf_ri.h:144
#define dfg_vertex_label_statement(x)
Definition: paf_ri.h:413
#define schedule_dims(x)
Definition: paf_ri.h:717
static char * module
Definition: pips.c:74
text empty_text(entity __attribute__((unused)) e, int __attribute__((unused)) m, statement __attribute__((unused)) s)
Definition: misc.c:219
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
void fprint_plc(FILE *fp, plc obj)
========================================================================
Definition: print.c:85
#define PRETTYPRINT_PARALLEL
void set_bool_property(const char *, bool)
void set_string_property(const char *, const char *)
#define SA_MODULE_NAME
#define SAI
static graph current_dfg
Definition: prettyprint.c:84
dfg_arc_label arc_label
Definition: prettyprint.c:81
static bdt current_bdt
Definition: prettyprint.c:85
bool print_parallelizedCMF_code(char *mod_name)
======================================================================
Definition: prettyprint.c:401
#define CM_FORTRAN_EXT
Ansi includes
Definition: prettyprint.c:76
dfg_vertex_label vertex_label
Local defines.
Definition: prettyprint.c:80
statement make_layout_statement(entity ae, int serial, int news)
======================================================================
Definition: prettyprint.c:93
list lparams
Array bounds.
Definition: reindexing.c:111
void cmf_layout_align(statement mod_stat)
======================================================================
Definition: prettyprint.c:183
bool print_parallelizedCRAFT_code(char *mod_name)
======================================================================
Definition: prettyprint.c:482
void craft_layout_align(statement mod_stat)
======================================================================
Definition: prettyprint.c:295
#define CRAFT_FORTRAN_EXT
Definition: prettyprint.c:77
statement make_shared_statement(entity ae, int serial, int news)
======================================================================
Definition: prettyprint.c:138
bool vars_in_vect_p(Pvecteur pv, list vars)
======================================================================
list extract_bdt(bdt b, int cn)
=======================================================================
#define make_nop_statement
An alias for make_empty_block_statement.
#define NORMALIZE_EXPRESSION(e)
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
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
code entity_code(entity e)
Definition: entity.c:1098
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define type_variable(x)
Definition: ri.h:2949
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined
Definition: ri.h:2761
@ is_instruction_sequence
Definition: ri.h:1469
#define instruction_tag(x)
Definition: ri.h:1511
#define normalized_tag(x)
Definition: ri.h:1778
#define expression_normalized(x)
Definition: ri.h:1249
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define variable_dimensions(x)
Definition: ri.h:3122
#define code_decls_text(x)
Definition: ri.h:786
#define statement_instruction(x)
Definition: ri.h:2458
#define entity_type(x)
Definition: ri.h:2792
#define normalized_linear(x)
Definition: ri.h:1781
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
@ is_normalized_linear
Definition: ri.h:1760
#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()
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define MERGE_TEXTS(r, t)
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207