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
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 * Dump routines for the ir graph and all type information.
19 * @author Martin Trapp, Christian Schaefer
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.
28 * Most routines use the name of the passed entity as the name of the
41 * Names of the 32 supported colors
44 ird_color_default = -1,
50 ird_color_magenta = 5,
52 ird_color_darkgray = 7,
53 ird_color_darkblue = 8,
54 ird_color_darkred = 9,
55 ird_color_darkgreen = 10,
56 ird_color_darkyellow = 11,
57 ird_color_darkmagenta = 12,
58 ird_color_darkcyan = 13,
60 ird_color_lightgray = 15,
61 ird_color_lightblue = 16,
62 ird_color_lightred = 17,
63 ird_color_lightgreen = 18,
64 ird_color_lightyellow = 19,
65 ird_color_lightmagenta = 20,
66 ird_color_lightcyan = 21,
68 ird_color_turquoise = 23,
69 ird_color_aquamarine = 24,
71 ird_color_purple = 26,
72 ird_color_yellowgreen = 27,
74 ird_color_orange = 29,
75 ird_color_orchid = 30,
83 data_edge = 0x01, /**< a data edge between two basic blocks */
84 block_edge = 0x02, /**< an edge from a node to its basic block */
85 cf_edge = 0x03, /**< regularly control flow edge */
86 exc_cf_edge = 0x04, /**< exceptional control flow edge */
87 mem_edge = 0x05, /**< memory edge */
88 dominator_edge = 0x06, /**< dominator edge */
89 node2type_edge = 0x07, /**< an edge from an IR node to a type */
91 ent_type_edge = 0x11, /**< an edge from an entity to its type */
92 ent_own_edge = 0x12, /**< an edge from an entity to its owner type */
93 ent_overwrites_edge = 0x13, /**< an edge from an entity to the entity it overwrites */
94 ent_value_edge = 0x14, /**< an edge from an entity to its value entity */
95 ent_corr_edge = 0x15, /**< an edge from an entity to the member entity its initializes */
97 meth_par_edge = 0x21, /**< an edge from a method type to one of its parameter types */
98 meth_res_edge = 0x22, /**< an edge from a method type to one of its result types */
99 type_super_edge = 0x23, /**< an edge from a class type to its super/basis type */
100 union_edge = 0x24, /**< an edge from a union type to its member types */
101 ptr_pts_to_edge = 0x25, /**< an edge from a pointer type to its points-to type */
102 arr_elt_type_edge = 0x26, /**< an edge from an array type to its element type */
103 arr_ent_edge = 0x27, /**< an edge from a array type to its element entity */
104 type_member_edge = 0x28, /**< an edge from a compound type to its member entities */
106 /* additional flags */
107 intra_edge = 0, /**< intra edge flag: edge do not cross basic block boundaries */
108 inter_edge = 0x40, /**< inter edge flag: edge cross basic block boundaries */
109 back_edge = 0x80 /**< backwards edge flag */
112 /* **************************************************************************** */
114 /* **************************************************************************** */
117 * This hook is called to insert some special nodes into dumped graph
119 typedef int (*DUMP_IR_GRAPH_FUNC)(FILE *F, ir_graph *irg);
121 * This hook is called to dump the vcg attributes of a node to a file.
122 * If this function returns zero, the default attributes are added, else
125 typedef int (*DUMP_NODE_VCGATTR_FUNC)(FILE *F, ir_node *node, ir_node *local);
127 * This hook is called to dump the vcg attributes of an edge to a file.
128 * If this function returns zero, the default attributes are added, else
131 typedef int (*DUMP_EDGE_VCGATTR_FUNC)(FILE *F, ir_node *node, int to);
133 /** Set the ir graph dump hook. */
134 void set_dump_ir_graph_hook(DUMP_IR_GRAPH_FUNC hook);
135 /** Set the node_vcgattr hook. */
136 void set_dump_node_vcgattr_hook(DUMP_NODE_VCGATTR_FUNC hook);
137 /** Set the edge_vcgattr hook. */
138 void set_dump_edge_vcgattr_hook(DUMP_EDGE_VCGATTR_FUNC hook);
140 typedef int (*DUMP_NODE_EDGE_FUNC)(FILE *f, ir_node *node);
143 * Set the hook to be called to dump additional edges to a node.
144 * @param func The hook to be called.
146 void set_dump_node_edge_hook(DUMP_NODE_EDGE_FUNC func);
149 * Get the additional edge dump hook.
150 * @return The current additional edge dump hook.]
152 DUMP_NODE_EDGE_FUNC get_dump_node_edge_hook(void);
154 /** Dump a firm graph.
156 * @param irg The firm graph to be dumped.
157 * @param suffix A suffix for the file name.
160 * A file containing the firm graph in vcg format.
162 * Dumps all Firm nodes of a single graph for a single procedure in
163 * standard xvcg format. Dumps the graph to a file. The file name
164 * is constructed from the name of the entity describing the
165 * procedure (irg->entity) and the ending -pure<-ip>.vcg. Eventually
166 * overwrites existing files. Visits all nodes in
167 * interprocedural_view.
169 * @see turn_off_edge_labels()
171 void dump_ir_graph (ir_graph *irg, const char *suffix);
173 /** Dump a firm graph without explicit block nodes.
175 * @param irg The firm graph to be dumped.
176 * @param suffix A suffix for the file name.
179 * A file containing the firm graph in vcg format.
181 * Dumps all Firm nodes of a single graph for a single procedure in
182 * extended xvcg format.
183 * Dumps the graph to a file. The file name is constructed from the
184 * name of the entity describing the procedure (irg->entity) and the
185 * ending <-ip>.vcg. Eventually overwrites existing files. Dumps several
186 * procedures in boxes if interprocedural_view.
188 * @see turn_off_edge_labels()
190 void dump_ir_block_graph (ir_graph *irg, const char *suffix);
192 /** Dump a firm graph without explicit block nodes but grouped in extended blocks.
194 * @param irg The firm graph to be dumped.
197 * A file containing the firm graph in vcg format.
199 * Dumps all Firm nodes of a single graph for a single procedure in
200 * extended xvcg format.
201 * Dumps the graph to a file. The file name is constructed from the
202 * name of the entity describing the procedure (irg->entity) and the
203 * ending <-ip>.vcg. Eventually overwrites existing files. Dumps several
204 * procedures in boxes if interprocedural_view.
206 * @see turn_off_edge_labels()
208 void dump_ir_extblock_graph (ir_graph *irg, const char *suffix);
210 /** Dumps all graphs in interprocedural view to a file named All_graphs<suffix>.vcg.
212 * @param suffix A suffix for the file name.
214 void dump_all_cg_block_graph(const char *suffix);
216 /** Dumps a firm graph and all the type information needed for Calls,
217 * Sels, ... in this graph.
219 * @param irg The firm graph to be dumped with its type information.
220 * @param suffix A suffix for the file name.
223 * A file containing the firm graph and the type information of the firm graph in vcg format.
225 * Dumps the graph to a file. The file name is constructed from the
226 * name of the entity describing the procedure (irg->entity) and the
227 * ending -all.vcg. Eventually overwrites existing files.
229 * @see turn_off_edge_labels()
231 void dump_ir_graph_w_types (ir_graph *irg, const char *suffix);
233 /** Dumps a firm graph and all the type information needed for Calls,
234 * Sels, ... in this graph.
236 * @param irg The firm graph to be dumped with its type information.
237 * @param suffix A suffix for the file name.
240 * A file containing the firm graph and the type information of the firm graph in vcg format.
242 * The graph is in blocked format.
243 * Dumps the 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 -all.vcg. Eventually overwrites existing files.
247 * @see turn_off_edge_labels()
249 void dump_ir_block_graph_w_types (ir_graph *irg, const char *suffix);
251 /** The type of a dump function that is called for each graph.
253 * @param irg current visited graph
254 * @param suffix A suffix for the file name.
256 typedef void dump_graph_func(ir_graph *irg, const char *suffix);
259 * A walker that calls a dumper for each graph.
261 * @param dump_graph The dumper to be used for dumping.
262 * @param suffix A suffix for the file name.
265 * Whatever the dumper creates.
267 * Walks over all firm graphs and calls a dumper for each graph.
268 * The following dumpers can be passed as arguments:
270 * - dump_ir_block_graph()
272 * - dump_type_graph()
273 * - dump_ir_graph_w_types()
275 * @see turn_off_edge_labels()
277 void dump_all_ir_graphs (dump_graph_func *dump_graph, const char *suffix);
281 * Dump the control flow graph of a procedure.
283 * @param irg The firm graph whose CFG shall be dumped.
284 * @param suffix A suffix for the file name.
287 * A file containing the CFG in vcg format.
289 * Dumps the control flow graph of a procedure in standard xvcg format.
290 * Dumps the graph to a file. The file name is constructed from the
291 * name of the entity describing the procedure (irg->entity) and the
292 * ending -cfg.vcg. Eventually overwrites existing files.
294 * @see turn_off_edge_labels()
296 void dump_cfg (ir_graph *irg, const char *suffix);
299 * Dump a node and its predecessors forming a subgraph to a vcg file.
301 * @param root The node serving as root for the subgraph.
302 * @param depth Dump nodes on paths starting at root with length depth.
303 * @param suffix A suffix for the file name.
305 * Dumps the graph to a file. The file name is constructed from the
306 * name of the entity describing the procedure the passed node is
307 * in, suffix and the ending -subg_<nr>.vcg. nr is a unique number
308 * for each graph dumped. Eventually overwrites existing files.
311 * A file containing the subgraph in vcg format.
313 void dump_subgraph (ir_node *root, int depth, const char *suffix);
315 /* **************************************************************************** */
316 /* CALLGRAPH DUMPERS */
317 /* **************************************************************************** */
320 /** Dump the call graph.
322 * Dumps the callgraph to a file "Callgraph"<suffix>".vcg".
324 * @param suffix A suffix for the file name.
326 * @see dump_callgraph_loop_tree(const char *suffix)
328 void dump_callgraph(const char *suffix);
330 /* **************************************************************************** */
331 /* TYPEGRAPH DUMPERS */
332 /* **************************************************************************** */
335 * Dumps all the type information needed for Calls, Sels, ... in this graph.
336 * Does not dump the graph!
338 * @param irg The firm graph whose type information is to be dumped.
339 * @param suffix A suffix for the file name.
342 * A file containing the type information of the firm graph in vcg format.
344 * Dumps this graph to a file. The file name is constructed from the
345 * name of the entity describing the procedure (irg->entity) and the
346 * ending -type.vcg. Eventually overwrites existing files.
348 * @see turn_off_edge_labels()
350 void dump_type_graph (ir_graph *irg, const char *suffix);
353 * Dumps all type information.
355 * @param suffix A suffix for the file name.
358 * A file containing all type information for the program in standard
361 * Dumps all type information that is somehow reachable in standard vcg
363 * Dumps the graph to a file named All_types.vcg.
365 * @see turn_off_edge_labels()
367 void dump_all_types (const char *suffix);
370 * Dumps the class hierarchy with or without entities.
372 * @param entities Flag whether to dump the entities.
373 * @param suffix A suffix for the file name.
376 * A file containing the class hierarchy tree for the program in standard
379 * Does not dump the global type.
380 * Dumps a node for all classes and the sub/supertype relations. If
381 * entities is set to true also dumps the entities of classes, but without
382 * any additional information as the entities type. The overwrites relation
383 * is dumped along with the entities.
384 * Dumps to a file class_hierarchy.vcg
386 void dump_class_hierarchy (int entities, const char *suffix);
388 /* **************************************************************************** */
389 /* LOOPTREE DUMPERS */
390 /* **************************************************************************** */
393 * Dump a standalone loop tree, which contains the loop nodes and the firm nodes
394 * belonging to one loop packed together in one subgraph. Dumps to file
395 * <name of irg><suffix>-looptree.vcg
396 * Turns on edge labels by default.
398 * Implementing this dumper was stimulated by Florian Liekwegs similar dumper.
400 * @param irg Dump the loop tree for this graph.
401 * @param suffix A suffix for the file name.
403 void dump_loop_tree(ir_graph *irg, const char *suffix);
405 /** Dumps the firm nodes in the sub-loop-tree of loop to a graph.
407 * Dumps the loop nodes if dump_loop_information() is set.
408 * The name of the file is loop_<loop_nr><suffix>.vcg.
410 * @param l Dump the loop tree for this loop.
411 * @param suffix A suffix for the file name.
413 void dump_loop (ir_loop *l, const char *suffix);
415 /** Dumps the loop tree over the call graph.
417 * See for yourself what you can use this for.
418 * The filename is "Callgraph_looptree<suffix>.vcg".
420 * @param suffix A suffix for the file name.
422 void dump_callgraph_loop_tree(const char *suffix);
425 /* **************************************************************************** */
427 /* **************************************************************************** */
430 /** Write the irnode and all its attributes to the file passed.
432 int dump_irnode_to_file (FILE *f, ir_node *n);
434 /** Write the irnode and all its attributes to stdout.
436 void dump_irnode (ir_node *n);
438 /** Write the graph and all its attributes to the file passed.
439 * Does not write the nodes.
441 void dump_graph_to_file(FILE *F, ir_graph *irg);
443 /** Write the graph and all its attributes to stdout.
444 * Does not write the nodes.
446 void dump_graph(ir_graph *g);
449 /** Dump graph information as text.
451 * Often graphs are unhandy in their vcg representation. The text
452 * dumper represents the information for the firm nodes more compact,
453 * but the relations between the nodes only implicitly.
455 * The file name is the graph name (get_entity_name()), appended by
458 void dump_graph_as_text(ir_graph *irg, const char *suffix);
461 /** Verbosity for text dumpers */
463 dump_verbosity_onlynames = 0x00000001, /**< only dump names. turns off all other
464 flags up to 0x00010000. */
465 dump_verbosity_fields = 0x00000002, /**< dump types and fields (like a type declaration) */
466 dump_verbosity_methods = 0x00000004, /**< dump types and methods (like a type declaration) */
467 dump_verbosity_nostatic = 0x00000040, /**< dump types and dynamic allocated fields (like a
468 type declaration). This excludes methods and
469 static, polymorphic fields. */
470 dump_verbosity_typeattrs = 0x00000008, /**< dump all type attributes */
471 dump_verbosity_entattrs = 0x00000010, /**< dump all entity attributes */
472 dump_verbosity_entconsts = 0x00000020, /**< dump entity constants */
474 dump_verbosity_accessStats = 0x00000100, /**< dump entity access statistics */
475 dump_verbosity_csv = 0x00000200, /**< dump access statistics as comma separated list */
477 dump_verbosity_noClassTypes = 0x00001000, /**< dump no class types */
478 dump_verbosity_noStructTypes = 0x00002000, /**< dump no struct types */
479 dump_verbosity_noUnionTypes = 0x00004000, /**< dump no union types */
480 dump_verbosity_noArrayTypes = 0x00008000, /**< dump no array types */
481 dump_verbosity_noPointerTypes = 0x00010000, /**< dump no pointer types */
482 dump_verbosity_noMethodTypes = 0x00020000, /**< dump no method types */
483 dump_verbosity_noPrimitiveTypes = 0x00040000, /**< dump no primitive types */
484 dump_verbosity_noEnumerationTypes= 0x00080000, /**< dump no enumeration types */
486 dump_verbosity_onlyClassTypes = 0x000FE000, /**< dump only class types */
487 dump_verbosity_onlyStructTypes = 0x000FD000, /**< dump only struct types */
488 dump_verbosity_onlyUnionTypes = 0x000FB000, /**< dump only union types */
489 dump_verbosity_onlyArrayTypes = 0x000F7000, /**< dump only array types */
490 dump_verbosity_onlyPointerTypes = 0x000EF000, /**< dump only pointer types */
491 dump_verbosity_onlyMethodTypes = 0x000DF000, /**< dump only method types */
492 dump_verbosity_onlyPrimitiveTypes = 0x000BF000, /**< dump only primitive types */
493 dump_verbosity_onlyEnumerationTypes=0x0007F000, /**< dump only enumeration types */
495 dump_verbosity_max = 0x4FF00FBE /**< turn on all verbosity.
496 Do not turn on negative flags!
497 @@@ Because of a bug in gcc 3.2 we can not set the
502 /** Write the entity and all its attributes to the passed file.
504 void dump_entity_to_file (FILE *F, entity *ent, unsigned verbosity);
506 /** Write the entity and all its attributes to the stdout.
508 * Calls dump_entity_to_file(). */
509 void dump_entity (entity *ent);
511 /** Write the type and all its attributes to the file passed.
513 void dump_type_to_file (FILE *f, ir_type *tp, dump_verbosity verbosity);
515 /** Write the type and all its attributes to stdout.
517 void dump_type (ir_type *tp);
520 /** Dump type information as text.
522 * Often type graphs are unhandy in their vcg representation. The text
523 * dumper represents the information for a single type more compact, but
524 * the relations between the types only implicitly.
525 * Dumps only 'real' types, i.e., those in the type list. Does not dump
526 * the global type nor frame types or the like.
528 * The file name is the program name (get_irp_name()), or 'TextTypes'
529 * if the program name is not set, appended by <suffix>-types.txt.
530 * For verbosity see the documentation of the verbosity flags above.
532 void dump_types_as_text(unsigned verbosity, const char *suffix);
534 /** Dumps all global variables as text.
536 * @param suffix A suffix for the file name.
538 * Dumps a text representation of the entities in the global type.
540 * The file name is the program name (get_irp_name()), or 'TextTypes'
541 * if the program name is not set, appended by <suffix>-globals.txt.
542 * For verbosity see the documentation of the verbosity flags above.
544 void dump_globals_as_text(unsigned verbosity, const char *suffix);
546 /* **************************************************************************** */
548 /* **************************************************************************** */
550 /** Output a selected graph.
552 * All graph dumpers check this name. If the name is != "" and
553 * not a prefix of the graph to be dumped, the dumper does not
556 * @param name The prefix of the name (not the ld_name) of the method
557 * entity to be dumped.
559 void only_dump_method_with_name(ident *name);
561 /** Returns the name set with only_dump_method_with_name(). */
562 ident *get_dump_file_filter_ident(void);
564 /** Returns true if dump file filter is not set, or if it is a
566 int is_filtered_dump_name(ident *name);
568 /** Sets the vcg flag "display_edge_labels" to no.
570 * This is necessary as xvcg and aisee both fail to display graphs
571 * with self-edges if these edges have labels.
573 void turn_off_edge_labels(void);
576 * If set to non-zero constants will be replicated for every use. In non
577 * blocked view edges from constant to block are skipped. Vcg then
578 * layouts the graphs more compact, this makes them better readable.
579 * The flag is automatically and temporarily set to false if other
580 * edges are dumped, as outs, loop, ...
581 * Default setting: false.
583 void dump_consts_local(int flag);
586 * Returns 0 if dump_out_edge_flag or dump_loop_information_flag
587 * are set, else returns dump_const_local_flag.
589 int get_opt_dump_const_local(void);
591 /** Turns off dumping the values of constant entities. Makes type graphs
594 void dump_constant_entity_values(int flag);
596 /** Turns on dumping the edges from the End node to nodes to be kept
599 void dump_keepalive_edges(int flag);
600 int get_opt_dump_keepalive_edges(void);
602 /** Turns on dumping the out edges starting from the Start block in
605 * To test the consistency of the out data structure.
607 void dump_out_edges(int flag);
609 /** If this flag is set the dumper dumps edges to immediate dominator in cfg.
611 void dump_dominator_information(int flag);
613 /** If this flag is set the dumper dumps loop nodes and edges from
614 * these nodes to the contained ir nodes.
616 * If the loops are interprocedural nodes can be missing.
618 void dump_loop_information(int flag);
620 /** If set and backedge info is computed, backedges are dumped dashed
621 * and as vcg 'backedge' construct.
625 void dump_backedge_information(int flag);
627 /** Dump the information of type field specified in ana/irtypeinfo.h.
629 * If the flag is set, the type name is output in [] in the node label,
630 * else it is output as info.
632 void set_opt_dump_analysed_type_info(int flag);
634 /** Write the address of a node into the vcg info.
636 * This is off per default for automatic comparisons of
637 * vcg graphs -- these will differ in the pointer values!
639 void dump_pointer_values_to_info(int flag);
641 /** Dumps ld_names of entities instead of there names.
643 * This option is on per default.
645 void dump_ld_names(int flag);
647 # endif /* _IRDUMP_H_ */