added function for convertion jump prediction into human readable names
[libfirm] / ir / ir / irdump.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irdump.h
4  * Purpose:     Write vcg representation of firm to file.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Hubert Schmidt
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irdump.h
16  *
17  * Dump routines for the ir graph and all type information.
18  *
19  * @author Martin Trapp, Christian Schaefer
20  *
21  * The dump format of most functions is vcg.  This is a text based graph
22  * representation. Some use the original format,
23  * but most generate an extended format that is only read by some special
24  * versions of xvcg or by the comercialized version now calles aiSee.
25  * A test version of aiSee is available at
26  * http://www.absint.de/aisee/download/index.htm.
27  *
28  * Most routines use the name of the passed entity as the name of the
29  * file dumped to.
30  */
31
32
33 # ifndef _IRDUMP_H_
34 # define _IRDUMP_H_
35
36 # include "irnode.h"
37 # include "irgraph.h"
38 # include "irloop.h"
39
40
41 /* **************************************************************************** */
42 /*                                 GRAPH DUMPERS                                */
43 /* **************************************************************************** */
44
45 /**
46  * This hook is called to dump the vcg attributes of a node to a file.
47  * If this function returns zero, the default attributes are added, else
48  * removed.
49  */
50 typedef int (*DUMP_NODE_VCGATTR_FUNC)(FILE *F, ir_node *node, ir_node *local);
51
52 /** Set the node_vcgattr hook. */
53 void set_dump_node_vcgattr_hook(DUMP_NODE_VCGATTR_FUNC hook);
54
55 typedef int (*DUMP_NODE_EDGE_FUNC)(FILE *f, ir_node *node);
56
57 /**
58  * Set the hook to be called to dump additional edges to a node.
59  * @param func The hook to be called.
60  */
61 void set_dump_node_edge_hook(DUMP_NODE_EDGE_FUNC func);
62
63 /**
64  * Get the additional edge dump hook.
65  * @return The current additional edge dump hook.]
66  */
67 DUMP_NODE_EDGE_FUNC get_dump_node_edge_hook(void);
68
69 /** Dump a firm graph.
70  *
71  *  @param irg  The firm graph to be dumped.
72  *
73  *  @return
74  *     A file containing the firm graph in vcg format.
75  *
76  *  Dumps all Firm nodes of a single graph for a single procedure in
77  *  standard xvcg format.  Dumps the graph to a file.  The file name
78  *  is constructed from the name of the entity describing the
79  *  procedure (irg->entity) and the ending -pure<-ip>.vcg.  Eventually
80  *  overwrites existing files.  Visits all nodes in
81  *  interprocedural_view.
82  *
83  * @see turn_off_edge_labels()
84  */
85 void dump_ir_graph (ir_graph *irg, const char *suffix);
86
87 /** Dump a firm graph without explicit block nodes.
88  *
89  *  @param irg   The firm graph to be dumped.
90  *
91  *  @return
92  *     A file containing the firm graph in vcg format.
93  *
94  *  Dumps all Firm nodes of a single graph for a single procedure in
95  *  extended xvcg format.
96  *  Dumps the graph to a file.  The file name is constructed from the
97  *  name of the entity describing the procedure (irg->entity) and the
98  *  ending <-ip>.vcg.  Eventually overwrites existing files.  Dumps several
99  *  procedures in boxes if interprocedural_view.
100  *
101  * @see turn_off_edge_labels()
102  */
103 void dump_ir_block_graph (ir_graph *irg, const char *suffix);
104
105 /** Dump a firm graph without explicit block nodes but grouped in extended blocks.
106  *
107  *  @param irg   The firm graph to be dumped.
108  *
109  *  @return
110  *     A file containing the firm graph in vcg format.
111  *
112  *  Dumps all Firm nodes of a single graph for a single procedure in
113  *  extended xvcg format.
114  *  Dumps the graph to a file.  The file name is constructed from the
115  *  name of the entity describing the procedure (irg->entity) and the
116  *  ending <-ip>.vcg.  Eventually overwrites existing files.  Dumps several
117  *  procedures in boxes if interprocedural_view.
118  *
119  * @see turn_off_edge_labels()
120  */
121 void dump_ir_extblock_graph (ir_graph *irg, const char *suffix);
122
123 /** Dumps all graphs in interprocedural view to a file named All_graphs.vcg.
124  */
125 void dump_all_cg_block_graph(const char *suffix);
126
127 /** Dumps a firm graph and  all the type information needed for Calls,
128  *  Sels, ... in this graph.
129  *
130  *  @param irg   The firm graph to be dumped with its type information.
131  *
132  *  @return
133  *      A file containing the firm graph and the type information of the firm graph in vcg format.
134  *
135  *  Dumps the graph to a file.  The file name is constructed from the
136  *  name of the entity describing the procedure (irg->entity) and the
137  *  ending -all.vcg.  Eventually overwrites existing files.
138  *
139  * @see turn_off_edge_labels()
140  */
141 void dump_ir_graph_w_types (ir_graph *irg, const char *suffix);
142
143 /** Dumps a firm graph and  all the type information needed for Calls,
144  *  Sels, ... in this graph.
145  *
146  *  @param irg   The firm graph to be dumped with its type information.
147  *
148  *  @return
149  *      A file containing the firm graph and the type information of the firm graph in vcg format.
150  *
151  *  The graph is in blocked format.
152  *  Dumps the graph to a file.  The file name is constructed from the
153  *  name of the entity describing the procedure (irg->entity) and the
154  *  ending -all.vcg.  Eventually overwrites existing files.
155  *
156  * @see turn_off_edge_labels()
157  */
158 void dump_ir_block_graph_w_types (ir_graph *irg, const char *suffix);
159
160 /** The type of a walker function that is called for each graph.
161  *
162  *  @param irg   current visited graph
163  */
164 typedef void dump_graph_func(ir_graph *irg, const char *suffix);
165
166 /**  A walker that calls a dumper for each graph.
167  *
168  *   @param dump_graph    The dumper to be used for dumping.
169  *
170  *   @return
171  *      Whatever the dumper creates.
172  *
173  *   Walks over all firm graphs and  calls a dumper for each graph.
174  *   The following dumpers can be passed as arguments:
175  *   - dump_ir_graph()
176  *   - dump_ir_block_graph()
177  *   - dump_cfg()
178  *   - dump_type_graph()
179  *   - dump_ir_graph_w_types()
180  *
181  * @see turn_off_edge_labels()
182  */
183 void dump_all_ir_graphs (dump_graph_func *dump_graph, const char *suffix);
184
185
186 /**  Dump the control flow graph of a procedure.
187  *
188  *   @param irg  The firm graph whose CFG shall be dumped.
189  *
190  *   @return
191  *      A file containing the CFG in vcg format.
192  *
193  *   Dumps the control flow graph of a procedure in standard xvcg format.
194  *   Dumps the graph to a file.  The file name is constructed from the
195  *   name of the entity describing the procedure (irg->entity) and the
196  *   ending -cfg.vcg.  Eventually overwrites existing files.
197  *
198  * @see turn_off_edge_labels()
199  */
200 void dump_cfg (ir_graph *irg, const char *suffix);
201
202 /**  Dump a node and its predecessors forming a subgraph to a vcg file.
203  *
204  *   @param root   The node serving as root for the subgraph.
205  *   @param depth  Dump nodes on paths starting at root with length depth.
206  *   @param suffix A suffix for the file name.
207  *
208  *   Dumps the graph to a file.  The file name is constructed from the
209  *   name of the entity describing the procedure the passed node is
210  *   in, suffix and the ending -subg_<nr>.vcg.  nr is a unique number
211  *   for each graph dumped. Eventually overwrites existing files.
212  *
213  *   @return
214  *      A file containing the subgraph in vcg format.
215  */
216 void dump_subgraph (ir_node *root, int depth, const char *suffix);
217
218 /* **************************************************************************** */
219 /*                              CALLGRAPH DUMPERS                               */
220 /* **************************************************************************** */
221
222
223 /** Dump the call graph.
224  *
225  * Dumps the callgraph to a file "Callgraph"<suffix>".vcg".
226  *
227  * @see dump_callgraph_loop_tree(const char *suffix)
228  */
229 void dump_callgraph(const char *suffix);
230
231 /* **************************************************************************** */
232 /*                              TYPEGRAPH DUMPERS                               */
233 /* **************************************************************************** */
234
235 /**
236  *  Dumps all the type information needed for Calls, Sels, ... in this graph.
237  *  Does not dump the graph!
238  *
239  *  @param irg   The firm graph whose type information is to be dumped.
240  *  @return
241  *      A file containing the type information of the firm graph in vcg format.
242  *
243  *  Dumps this graph to a file.  The file name is constructed from the
244  *  name of the entity describing the procedure (irg->entity) and the
245  *  ending -type.vcg.  Eventually overwrites existing files.
246  *
247  * @see turn_off_edge_labels()
248  */
249 void dump_type_graph (ir_graph *irg, const char *suffix);
250
251 /**  Dumps all type information.
252  *
253  *   @return
254  *      A file containing all type information for the program in standard
255  *      vcg format.
256  *
257  *   Dumps all type information that is somehow reachable in standard vcg
258  *   format.
259  *   Dumps the graph to a file named All_types.vcg.
260  *
261  * @see turn_off_edge_labels()
262  */
263 void dump_all_types (const char *suffix);
264
265 /**  Dumps the class hierarchy with or without entities.
266  *
267  *   @param entities    Flag whether to dump the entities.
268  *
269  *   @return
270  *      A file containing the class hierarchy tree for the program in standard
271  *      vcg format.
272  *
273  *   Does not dump the global type.
274  *   Dumps a node for all classes and the sub/supertype relations.  If
275  *   entities is set to true also dumps the entities of classes, but without
276  *   any additional information as the entities type.  The overwrites relation
277  *   is dumped along with the entities.
278  *   Dumps to a file class_hierarchy.vcg
279  */
280 void dump_class_hierarchy (bool entities, const char *suffix);
281
282 /* **************************************************************************** */
283 /*                              LOOPTREE DUMPERS                                */
284 /* **************************************************************************** */
285
286 /**
287  * Dump a standalone loop tree, which contains the loop nodes and the firm nodes
288  * belonging to one loop packed together in one subgraph.  Dumps to file
289  * <name of irg><suffix>-looptree.vcg
290  * Turns on edge labels by default.
291  *
292  * Implementing this dumper was stimulated by Florian Liekwegs similar dumper.
293  *
294  * @arg irg     Dump the loop tree for this graph.
295  * @arg suffix  Suffix to filename.
296  */
297 void dump_loop_tree(ir_graph *irg, const char *suffix);
298
299 /** Dumps the firm nodes in the sub-loop-tree of loop to a graph.
300  *
301  *  Dumps the loop nodes if dump_loop_information() is set.
302  *  The name of the file is loop_<loop_nr><suffix>.vcg.
303  *
304  *  @arg loop    Dump the loop tree for this loop.
305  *  @arg suffix  Suffix to filename.
306  */
307 void dump_loop (ir_loop *l, const char *suffix);
308
309 /** Dumps the loop tree over the call graph.
310  *
311  *  See for yourself what you can use this for.
312  *  The filename is "Callgraph_looptree<suffix>.vcg".
313  *
314  *  @arg suffix  Suffix to filename.
315  */
316 void dump_callgraph_loop_tree(const char *suffix);
317
318
319 /* **************************************************************************** */
320 /*                                TEXT DUMPERS                                  */
321 /* **************************************************************************** */
322
323
324 /** Write the irnode and all its attributes to the file passed.
325  * */
326 int dump_irnode_to_file (FILE *f, ir_node *n);
327
328 /** Write the irnode and all its attributes to stdout.
329  *  */
330 void dump_irnode (ir_node *n);
331
332 /** Write the graph and all its attributes to the file passed.
333  *  Does not write the nodes.
334  * */
335 void dump_graph_to_file(FILE *F, ir_graph *irg);
336
337 /** Write the graph and all its attributes to stdout.
338  *  Does not write the nodes.
339  *  */
340 void dump_graph(ir_graph *g);
341
342
343 /** Dump graph information as text.
344  *
345  *  Often graphs are unhandy in their vcg representation.  The text
346  *  dumper represents the information for the firm nodes more compact,
347  *  but the relations between the nodes only implicitly.
348  *
349  *  The file name is the graph name (get_entity_name()), appended by
350  *  <suffix>.txt.
351  */
352 void dump_graph_as_text(ir_graph *irg, const char *suffix);
353
354
355 /** Verbosity for text dumpers */
356 typedef enum {
357   dump_verbosity_onlynames         = 0x00000001,   /**< only dump names. turns off all other
358                                                       flags up to 0x00010000. */
359   dump_verbosity_fields            = 0x00000002,   /**< dump types and fields (like a type declaration) */
360   dump_verbosity_methods           = 0x00000004,   /**< dump types and methods (like a type declaration) */
361   dump_verbosity_nostatic          = 0x00000040,   /**< dump types and dynamic allocated fields (like a
362                                                         type declaration). This excludes methods and
363                                                         static, polymorphic fields. */
364   dump_verbosity_typeattrs         = 0x00000008,   /**< dump all type attributes */
365   dump_verbosity_entattrs          = 0x00000010,   /**< dump all entity attributes */
366   dump_verbosity_entconsts         = 0x00000020,   /**< dump entity constants */
367
368   dump_verbosity_accessStats       = 0x00000100,   /**< dump entity access statistics */
369   dump_verbosity_csv               = 0x00000200,   /**< dump access statistics as comma separated list */
370
371   dump_verbosity_noClassTypes      = 0x00001000,   /**< dump no class       types */
372   dump_verbosity_noStructTypes     = 0x00002000,   /**< dump no struct      types */
373   dump_verbosity_noUnionTypes      = 0x00004000,   /**< dump no union       types */
374   dump_verbosity_noArrayTypes      = 0x00008000,   /**< dump no array       types */
375   dump_verbosity_noPointerTypes    = 0x00010000,   /**< dump no pointer     types */
376   dump_verbosity_noMethodTypes     = 0x00020000,   /**< dump no method      types */
377   dump_verbosity_noPrimitiveTypes  = 0x00040000,   /**< dump no primitive   types */
378   dump_verbosity_noEnumerationTypes= 0x00080000,   /**< dump no enumeration types */
379
380   dump_verbosity_onlyClassTypes     = 0x000FE000,  /**< dump only class     types */
381   dump_verbosity_onlyStructTypes    = 0x000FD000,  /**< dump only struct    types */
382   dump_verbosity_onlyUnionTypes     = 0x000FB000,  /**< dump only union     types */
383   dump_verbosity_onlyArrayTypes     = 0x000F7000,  /**< dump only array     types */
384   dump_verbosity_onlyPointerTypes   = 0x000EF000,  /**< dump only pointer   types */
385   dump_verbosity_onlyMethodTypes    = 0x000DF000,  /**< dump only method    types */
386   dump_verbosity_onlyPrimitiveTypes = 0x000BF000,  /**< dump only primitive types */
387   dump_verbosity_onlyEnumerationTypes=0x0007F000,  /**< dump only enumeration types */
388
389   dump_verbosity_max                = 0x4FF00FBE   /**< turn on all verbosity.
390                                                         Do not turn on negative flags!
391                                                         @@@ Because of a bug in gcc 3.2 we can not set the
392                                                         first two bits. */
393 } dump_verbosity;
394
395
396 /** Write the entity and all its attributes to the passed file.
397  *  */
398 void    dump_entity_to_file (FILE *F, entity *ent, unsigned verbosity);
399
400 /** Write the entity and all its attributes to the stdout.
401  *
402  *  Calls dump_entity_to_file().  */
403 void    dump_entity (entity *ent);
404
405 /** Write the type and all its attributes to the file passed.
406  * */
407 void    dump_type_to_file (FILE *f, type *tp, dump_verbosity verbosity);
408
409 /** Write the type and all its attributes to stdout.
410  *  */
411 void    dump_type (type *tp);
412
413
414 /** Dump type information as text.
415  *
416  *  Often type graphs are unhandy in their vcg representation.  The text
417  *  dumper represents the information for a single type more compact, but
418  *  the relations between the types only implicitly.
419  *  Dumps only 'real' types, i.e., those in the type list.  Does not dump
420  *  the global type nor frame types or the like.
421  *
422  *  The file name is the program name (get_irp_name()), or 'TextTypes'
423  *  if the program name is not set, appended by <suffix>-types.txt.
424  *  For verbosity see the documentation of the verbosity flags above.
425  */
426 void dump_types_as_text(unsigned verbosity, const char *suffix);
427
428 /** Dumps all global variables as text.
429  *
430  *  Dumps a text representation of the entities in the global type.
431  *
432  *  The file name is the program name (get_irp_name()), or 'TextTypes'
433  *  if the program name is not set, appended by <suffix>-globals.txt.
434  *  For verbosity see the documentation of the verbosity flags above.
435  */
436 void dump_globals_as_text(unsigned verbosity, const char *suffix);
437
438 /* **************************************************************************** */
439 /*                                    FLAGS                                     */
440 /* **************************************************************************** */
441
442 /** Output a selected graph.
443  *
444  *  All graph dumpers check this name.  If the name is != "" and
445  *  not a prefix of the graph to be dumped, the dumper does not
446  *  dump the graph.
447  *
448  *  @param name The prefix of the name (not the ld_name) of the method
449  *              entity to be dumped.
450  */
451 void   only_dump_method_with_name(ident *name);
452
453 /** Returns the name set with only_dump_method_with_name(). */
454 ident *get_dump_file_filter_ident(void);
455
456 /** Returns true if dump file filter is not set, or if it is a
457  *  prefix of name. */
458 int is_filtered_dump_name(ident *name);
459
460 /**  Sets the vcg flag "display_edge_labels" to no.
461  *
462  *   This is necessary as xvcg and aisee both fail to display graphs
463  *   with self-edges if these edges have labels.
464  */
465 void turn_off_edge_labels(void);
466
467 /**
468  *  If set to true constants will be replicated for every use. In non
469  *  blocked view edges from constant to block are skipped.  Vcg then
470  *  layouts the graphs more compact, this makes them better readable.
471  *  The flag is automatically and temporarily set to false if other
472  *  edges are dumped, as outs, loop, ...
473  *  Default setting: false.
474  */
475 void dump_consts_local(bool b);
476
477 /**
478  * Returns false if dump_out_edge_flag or dump_loop_information_flag
479  * are set, else returns dump_const_local_flag.
480  */
481 bool get_opt_dump_const_local(void);
482
483 /**  Turns off dumping the values of constant entities. Makes type graphs
484  *   better readable.
485  */
486 void dump_constant_entity_values(bool b);
487
488 /**  Turns on dumping the edges from the End node to nodes to be kept
489  *   alive.
490  */
491 void dump_keepalive_edges(bool b);
492 bool get_opt_dump_keepalive_edges(void);
493
494 /** Turns on dumping the out edges starting from the Start block in
495  *  dump_ir_graph.
496  *
497  *  To test the consistency of the out data structure.
498  */
499 void dump_out_edges(bool b);
500
501 /** If this flag is set the dumper dumps edges to immediate dominator in cfg.
502  */
503 void dump_dominator_information(bool b);
504
505 /** If this flag is set the dumper dumps loop nodes and edges from
506  *  these nodes to the contained ir nodes.
507  *
508  *  If the loops are interprocedural nodes can be missing.
509  */
510 void dump_loop_information(bool b);
511
512 /** If set and backedge info is computed, backedges are dumped dashed
513  *  and as vcg 'backedge' construct.
514  *
515  *  Default: set.
516  */
517 void dump_backedge_information(bool b);
518
519 /** Dump the information of type field specified in ana/irtypeinfo.h.
520  *
521  *  If the flag is set, the type name is output in [] in the node label,
522  *  else it is output as info.
523  */
524 void set_opt_dump_analysed_type_info(bool b);
525
526 /** Write the address of a node into the vcg info.
527  *
528  *  This is off per default for automatic comparisons of
529  *  vcg graphs -- these will differ in the pointer values!
530  */
531 void dump_pointer_values_to_info(bool b);
532
533 /** Dumps ld_names of entities instead of there names.
534  *
535  * This option is on per default.
536  */
537 void dump_ld_names(bool b);
538
539 # endif /* _IRDUMP_H_ */