PIPS
trace.c
Go to the documentation of this file.
1 /*
2 
3  $Id: trace.c 23480 2018-08-22 07:33:48Z ancourt $
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 #include "local.h"
28 #include "transformations.h"
29 
30 #define ADD_ELEMENT_TO_LIST( _list, _type, _element) \
31  (_list = gen_nconc( _list, CONS( _type, _element, NIL)))
32 
33 /* get vertex in a list by the vertex's label
34  */
35 vertex get_vertex_in_list(list in_l, string in_s)
36 {
37  MAP(VERTEX, ver, {
38  string s = (string)vertex_vertex_label(ver);
39  if (same_string_p(in_s, s)) return ver;
40  }, in_l);
41  return vertex_undefined;
42 }
43 
44 /* print a graph to text format
45  */
46 void prettyprint_graph_text(FILE * out_f, list l_of_vers)
47 {
48  FOREACH (VERTEX, ver, l_of_vers) {
49  FOREACH (SUCCESSOR, succ, vertex_successors(ver)) {
50  fputs((string) vertex_vertex_label (ver), out_f);
51  fprintf(out_f, " ");
52  fputs((string) vertex_vertex_label (successor_vertex(succ)), out_f);
53  fprintf(out_f, " ");
54  fputs((string) successor_arc_label (succ), out_f);
55  fprintf(out_f, "\n");
56  }
57  }
58 }
59 
60 /* print a graph to daVinci format, each label of successor is represented by
61  * a circular node, each vertex is represented by a square node
62  */
63 void prettyprint_graph_daVinci(FILE * out_f, list l_of_vers) {
64  /* To match the call to the free() at the end: */
65  string gr_buffer = strdup("");
66  bool first_node_parent = true;
67  fprintf(out_f, "[\n");
68 
69  MAP(VERTEX, ver, {
70  string node_name_parent = (string)vertex_vertex_label(ver);
71  bool first_node_child = true;
72  if (first_node_parent)
73  first_node_parent = false;
74  else
75  fprintf(out_f, ",\n");
76  fprintf(out_f,"l(\"%s\",n(\"\",[a(\"OBJECT\",\"%s\")],[\n", node_name_parent, node_name_parent);
77 
78  MAP(SUCCESSOR, succ, {
79  string node_name_child = (string)vertex_vertex_label(successor_vertex(succ));
80  if (first_node_child)
81  first_node_child = false;
82  else
83  fprintf(out_f, ",\n");
84  if (strlen((string)successor_arc_label(succ)) == 0) {
85  fprintf(out_f, " l(\"\",e(\"\",[],r(\"%s\")))", node_name_child);
86  } else {
87  string temp_buffer = strdup(concatenate(gr_buffer, ",\nl(\"", node_name_parent, "-", node_name_child, "\",n(\"\",[a(\"OBJECT\",\"", (string)successor_arc_label(succ), "\"),a(\"_GO\",\"ellipse\")],[\n l(\"\",e(\"\",[],r(\"", node_name_child, "\")))]))", NULL));
88  free(gr_buffer);
89  gr_buffer = temp_buffer;
90  fprintf(out_f, " l(\"\",e(\"\",[],r(\"%s-%s\")))", node_name_parent, node_name_child);
91  }
92  }, vertex_successors(ver));
93  fprintf(out_f, "]))");
94  }, l_of_vers);
95 
96  fprintf(out_f, "%s", gr_buffer);
97  fprintf(out_f, "\n]");
98  free(gr_buffer);
99 }
100 
102 {
103  list verlist = NIL;
104  list vars_ent_list = get_list_of_variable_to_filter();
105 
107  int dl = -1;
108 
110  /* for computing the line numbers of statements */
113  }
114 
115  MAP(VERTEX, v1, {
117 
118  MAP(SUCCESSOR, su, {
119  vertex v2 = successor_vertex(su);
122 
123  MAP(CONFLICT, c, {
126  if (gen_in_list_p(conflict_var, vars_ent_list) || vars_ent_list == NIL) {
127  string succ_label = (string)malloc(sizeof(string)*30);
128  int l1 = dl + apply_persistant_statement_to_int(s_to_l, s1);
129  int l2 = dl + apply_persistant_statement_to_int(s_to_l, s2);
130 
131  vertex vertex_parent = NULL;
132  vertex vertex_child = NULL;
133  char statement_action_parent = action_read_p(effect_action(conflict_source(c))) ? 'R' : 'W';
134  char statement_action_child = action_read_p(effect_action(conflict_sink(c))) ? 'R' : 'W';
137  string node_name_parent = (string)malloc(sizeof(string)*strlen(variable_name_parent) + 30);
138  string node_name_child = (string)malloc(sizeof(string)*strlen(variable_name_child) + 30);
139 
140  successor succ = NULL;
141  memset(node_name_parent, 0, sizeof(string)*strlen(variable_name_parent) + 30);
142  memset(node_name_child, 0, sizeof(string)*strlen(variable_name_child) + 30);
143  sprintf(node_name_parent, "%d-<%s>-%c", l1, variable_name_parent, statement_action_parent);
144  sprintf(node_name_child, "%d-<%s>-%c", l2, variable_name_child, statement_action_child);
145 
146  /* Additional information for EDF prettyprint.
147  Instruction calls are given with statement numbers
148  */
149  if (get_bool_property("PRETTYPRINT_WITH_COMMON_NAMES")) {
151  sprintf(node_name_parent + strlen(node_name_parent), " %td-%s", statement_number(s1),
153  else sprintf(node_name_parent + strlen(node_name_parent), " %td", statement_number(s1));
155  sprintf(node_name_child + strlen(node_name_child), " %td-%s", statement_number(s2),
157  else sprintf(node_name_child + strlen(node_name_child), " %td", statement_number(s2));
158  }
159 
160  memset(succ_label, 0, strlen(succ_label));
161  if (conflict_cone(c) != cone_undefined) {
163  strcat(succ_label, "levels(");
164  MAPL(pl, {
165  sprintf(succ_label + strlen(succ_label),
166  pl == cone_levels(conflict_cone(c)) ? "%td" : ",%td", INT(CAR(pl)));
167  }, cone_levels(conflict_cone(c)));
168  strcat(succ_label, ")");
169  }
170  }
171 
172  vertex_parent = get_vertex_in_list(verlist, node_name_parent);
173  if (vertex_undefined_p(vertex_parent)) {
174  vertex_parent = make_vertex((vertex_label)node_name_parent, NIL);
175  ADD_ELEMENT_TO_LIST(verlist, VERTEX, vertex_parent);
176  }
177 
178  vertex_child = get_vertex_in_list(verlist, node_name_child);
179  if (vertex_undefined_p(vertex_child)) {
180  vertex_child = make_vertex((vertex_label)node_name_child, NIL);
181  ADD_ELEMENT_TO_LIST(verlist, VERTEX, vertex_child);
182  }
183 
184  succ = make_successor((dg_arc_label)succ_label, vertex_child);
185  ADD_ELEMENT_TO_LIST(vertex_successors(vertex_parent), SUCCESSOR, succ);
186  }
187  }
188  }, dg_arc_label_conflicts(dal));
189 
190  }, vertex_successors(v1));
191 
192  }, graph_vertices(mod_graph));
193 
194  gen_free_list(vars_ent_list);
195 
198 
199  return verlist;
200 }
201 
202 bool print_filtered_dg_or_dvdg(string mod_name, bool is_dv)
203 {
204  string dg_name = NULL;
205  string local_dg_name = NULL;
206  FILE *fp;
207  graph dg;
209  list flt_graph;
210 
213  db_get_memory_resource(DBR_CODE, mod_name, true) );
216 
217  dg = (graph) db_get_memory_resource(DBR_DG, mod_name, true);
218 
219  flt_graph = make_filtered_dg_or_dvdg(mod_stat, dg);
220 
221  local_dg_name = db_build_file_resource_name(DBR_DG, mod_name, is_dv ? ".dvdg" : ".dg");
223  "/", local_dg_name, NULL));
224  fp = safe_fopen(dg_name, "w");
225 
226  debug_on("RICEDG_DEBUG_LEVEL");
227 
228  if (is_dv) {
229  prettyprint_graph_daVinci(fp, flt_graph);
230  } else {
231  prettyprint_graph_text(fp, flt_graph);
232  }
233 
234  debug_off();
235 
236  safe_fclose(fp, dg_name);
237  free(dg_name);
238 
239  DB_PUT_FILE_RESOURCE(is_dv ? DBR_DVDG_FILE : DBR_DG_FILE, strdup(mod_name), local_dg_name);
240 
241  gen_free_list(flt_graph);
242 
246 
247  return true;
248 }
249 
250 static bool statement_in_loopnest_p = false;
253 {
256 }
257 
258 static void print_cone_vecteur(FILE * fd,Pvecteur v, Ptsg gs, int type)
259 {
260  Pbase b=gs->base;
261  Pvecteur coord;
262  if(vect_in_basis_p(v, b)) {
263  fprintf(fd, (type==1) ? "Vertex":"Ray");
264  for(coord = b; !VECTEUR_NUL_P(coord) ; coord = coord->succ) {
265  fprint_string_Value(fd, " \t",vect_coeff(vecteur_var(coord), v));
266  }
267  fprintf(fd, " \n");
268  }
269 }
270 
271 
272 extern entity selected_label;
273 
275 {
277  graph dg = (graph) db_get_memory_resource(DBR_DG, module_name, true);
278  FILE *fp;
279  string dc_name,local_dc_name;
280  statement loopnest_st;
281  bool first=true;
284  db_get_memory_resource(DBR_CODE, module_name, true) );
287  local_dc_name = db_build_file_resource_name(DBR_DC_FILE, module_name, ".dc");
288  dc_name = strdup(concatenate(db_get_current_workspace_directory(), "/", local_dc_name, NULL));
289  fp = safe_fopen(dc_name, "w");
290 
291  debug_on("RICEDG_DEBUG_LEVEL");
292 
293  /* Get the loop label from the user */
294  const char* lp_label = get_string_property("LOOP_LABEL");
295  if( string_undefined_p( lp_label))
296  pips_user_warning("No loop label", "Please precise the loop label\n");
297 
298  if(lp_label)
299  {
302  pips_user_warning("loop label does not exist\n", "Please give a valid label (%s not valid)\n",lp_label);
303  }
304  }
306  fprintf(fp,"Label: %s ",lp_label);
310  // Verify s is a statement in the loop nest
314 
317 
318  vertex v2 = successor_vertex(su);
319  statement s2 = vertex_to_statement( v2 );
320  // Verify s2 is a statement in the loop nest
324 
325  if(statement_in_loopnest_p) { // s and s2 are in the loop nest
326 
328 
329  if ( conflict_cone(c) != cone_undefined ) {
331  if( !SG_UNDEFINED_P(gs)) {
332  if (first) {
333  fprintf(fp,"- Dependence Cone Basis :");
335  first=false;
336  }
337  if( sg_nbre_rayons(gs) > 0) {
338  for (Pray_dte e = sg_rayons(gs); e != NULL; e = e->succ) {
339  print_cone_vecteur(fp,e->vecteur, gs,2);
340  }
341  }
342  if( sg_nbre_droites(gs) > 0) {
343  for (Pray_dte e = sg_droites(gs); e != NULL; e = e->succ) {
344  Pvecteur v=vect_copy(e->vecteur);
345  print_cone_vecteur(fp,e->vecteur, gs,2);
346  vect_chg_sgn(v);
347  print_cone_vecteur(fp,e->vecteur, gs,2);
348  vect_rm(v);
349  }
350  }
351  if( sg_nbre_sommets(gs) > 0) {
352  for (Psommet e = sg_sommets(gs); e != NULL; e = e->succ) {
353  print_cone_vecteur(fp,e->vecteur, gs,1);
354  }
355  }
356  }
357  }
358  }
359  }
360  }
361  }
362  }
363  if (first) fprintf(fp,"- No Dependencies");
364  }
365 
366  debug_off();
367 
368  safe_fclose(fp, dc_name);
369  free(dc_name);
370 
371  DB_PUT_FILE_RESOURCE( DBR_DC_FILE, strdup(module_name), local_dc_name);
372 
376 
377  return true;
378 }
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389 
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
404 
405 
406 
407 
408 
409 
410 
411 
412 
413 
414 
415 
416 
417 
successor make_successor(arc_label a1, vertex a2)
Definition: graph.c:98
vertex make_vertex(vertex_label a1, list a2)
Definition: graph.c:140
intptr_t apply_persistant_statement_to_int(persistant_statement_to_int f, statement k)
Definition: ri.c:1654
void free_persistant_statement_to_int(persistant_statement_to_int p)
Definition: ri.c:1618
void fprint_string_Value(FILE *, char *, Value)
Definition: io.c:47
@ INT
Definition: atomic.c:48
bool vect_in_basis_p(Pvecteur v, Pbase b)
Pvecteur vect_in_basis_p(Pvecteur v, Pbase b): check that all coordinates in v are in b,...
Definition: base.c:342
static graph dg
dg is the dependency graph ; FIXME : should not be static global ?
Definition: chains.c:124
#define cone_generating_system(x)
Definition: dg.h:130
struct _newgen_struct_dg_arc_label_ * dg_arc_label
Definition: dg.h:60
#define conflict_sink(x)
Definition: dg.h:167
#define cone_levels(x)
Definition: dg.h:128
#define CONFLICT(x)
CONFLICT.
Definition: dg.h:134
#define dg_arc_label_conflicts(x)
Definition: dg.h:201
#define conflict_source(x)
Definition: dg.h:165
#define cone_undefined
Definition: dg.h:104
#define conflict_cone(x)
Definition: dg.h:169
list get_list_of_variable_to_filter(void)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
list effect_words_reference(reference)
prettyprint.c
Definition: prettyprint.c:68
#define effect_action(x)
Definition: effects.h:642
#define action_read_p(x)
Definition: effects.h:311
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
char * get_string_property(const char *)
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
void * malloc(YYSIZE_T)
void free(void *)
#define successor_vertex(x)
Definition: graph.h:118
#define vertex_undefined
Definition: graph.h:128
#define successor_arc_label(x)
Definition: graph.h:116
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
#define vertex_vertex_label(x)
Definition: graph.h:152
#define vertex_successors(x)
Definition: graph.h:154
#define vertex_undefined_p(x)
Definition: graph.h:129
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
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
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734
#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
#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
#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
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_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
persistant_statement_to_int statement_to_line_number(statement)
Definition: statement.c:2460
static list verlist
of vertex
Definition: icfg_scan.c:107
statement vertex_to_statement(vertex v)
Vertex_to_statement looks for the statement that is pointed to by vertex v.
Definition: util.c:45
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
void base_fprint(FILE *f, Pbase b, get_variable_name_t variable_name)
void base_fprint(FILE * f, Pbase b, char * (*variable_name)()): impression d'une base sur le fichier ...
Definition: io.c:342
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
void * memset(void *str, int c, size_t len)
memset.c – set an area of memory to a given value Copyright (C) 1991, 2003, 2009-2011 Free Software F...
Definition: memset.c:23
#define debug_on(env)
Definition: misc-local.h:157
#define pips_user_warning
Definition: misc-local.h:146
#define debug_off()
Definition: misc-local.h:160
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define same_string_p(s1, s2)
char * string
STRING.
Definition: newgen_types.h:39
#define string_undefined_p(s)
Definition: newgen_types.h:41
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
static hash_table pl
properties are stored in this hash table (string -> property) for fast accesses.
Definition: properties.c:783
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
string safe_entity_name(entity e)
predicates and functions for entities
Definition: entity.c:433
int module_to_declaration_length(entity func)
Number of user declaration lines for a module.
Definition: module.c:352
entity find_label_entity(const char *, const char *)
util.c
Definition: util.c:43
#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 entity_undefined_p(x)
Definition: ri.h:2762
#define instruction_call_p(x)
Definition: ri.h:1527
#define statement_instruction(x)
Definition: ri.h:2458
#define persistant_statement_to_int_undefined
Definition: ri.h:1915
#define instruction_call(x)
Definition: ri.h:1529
#define statement_undefined_p(x)
Definition: ri.h:2420
#define statement_number(x)
Definition: ri.h:2452
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
s1
Definition: set.c:247
#define sg_sommets(sg)
vieilles definitions des fonctions d'impression void sg_fprint(); #define print_sg(sg) sg_fprint(stdo...
Definition: sg-local.h:85
#define sg_rayons(sg)
acces au premier rayon de la liste des rayons d'un systeme generateur defini par un pointeur: sg_rayo...
Definition: sg-local.h:89
struct type_sg * Ptsg
Representation d'un systeme generateur par trois ensembles de sommets de rayons et de droites.
#define sg_nbre_sommets(sg)
nombre de sommets: int sg_nbre_sommets(Ptsg)
Definition: sg-local.h:96
#define SG_UNDEFINED_P(sg)
Definition: sg-local.h:74
#define sg_nbre_droites(sg)
nombre de droites: int sg_nbre_droites(Ptsg)
Definition: sg-local.h:102
#define sg_nbre_rayons(sg)
nombre de rayons: int sg_nbre_rayons(Ptsg)
Definition: sg-local.h:99
#define sg_droites(sg)
acces a la premiere droite de la liste des droites d'un systeme generateur defini par un pointeur: sg...
Definition: sg-local.h:93
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
struct Svecteur * succ
Definition: vecteur-local.h:92
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
structure de donnees Sommet
Definition: sommet-local.h:64
Representation d'un systeme generateur par trois ensembles de sommets de rayons et de droites.
Definition: sg-local.h:66
Pbase base
Definition: sg-local.h:70
string words_to_string(cons *lw)
Definition: print.c:211
static void statement_in_loopnest(statement s)
Definition: trace.c:252
static void print_cone_vecteur(FILE *fd, Pvecteur v, Ptsg gs, int type)
Definition: trace.c:258
entity selected_label
Interface with pipsmake for interactive loop transformations: loop interchange, hyperplane method,...
void prettyprint_graph_daVinci(FILE *out_f, list l_of_vers)
print a graph to daVinci format, each label of successor is represented by a circular node,...
Definition: trace.c:63
static statement test_statement_of_reference
Definition: trace.c:251
list make_filtered_dg_or_dvdg(statement mod_stat, graph mod_graph)
Definition: trace.c:101
bool print_filtered_dg_or_dvdg(string mod_name, bool is_dv)
Definition: trace.c:202
#define ADD_ELEMENT_TO_LIST(_list, _type, _element)
Definition: trace.c:30
void prettyprint_graph_text(FILE *out_f, list l_of_vers)
print a graph to text format
Definition: trace.c:46
vertex get_vertex_in_list(list in_l, string in_s)
get vertex in a list by the vertex's label
Definition: trace.c:35
static bool statement_in_loopnest_p
Definition: trace.c:250
bool print_loopnest_dependence_cone(const char *module_name)
Definition: trace.c:274
statement find_loop_from_label(statement, entity)
Definition: util.c:218
#define vecteur_var(v)
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
#define VECTEUR_NUL_P(v)
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228