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