2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Write vcg representation of firm to file.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Hubert Schmidt,
38 #include "irgraph_t.h"
52 #include "callgraph.h"
54 #include "dbginfo_t.h"
68 * Symbolic names for the different dumping colors.
70 typedef enum ird_color_t {
72 ird_color_prog_background,
73 ird_color_block_background,
74 ird_color_dead_block_background,
75 ird_color_block_inout,
76 ird_color_default_node,
79 ird_color_controlflow,
83 ird_color_uses_memory,
93 data_edge = 0x01, /**< A data edge between two basic blocks. */
94 block_edge = 0x02, /**< An edge from a node to its basic block. */
95 cf_edge = 0x03, /**< A regularly control flow edge. */
96 exc_cf_edge = 0x04, /**< An exceptional control flow edge. */
97 mem_edge = 0x05, /**< A memory edge. */
98 dominator_edge = 0x06, /**< A dominator edge from a block to its immediate dominator. */
99 node2type_edge = 0x07, /**< An edge from an IR node to a type. */
101 ent_type_edge = 0x11, /**< An edge from an entity to its type. */
102 ent_own_edge = 0x12, /**< An edge from an entity to its owner type. */
103 ent_overwrites_edge = 0x13, /**< An edge from an entity to the entity it overwrites. */
104 ent_value_edge = 0x14, /**< An edge from an entity to its value entity. */
105 ent_corr_edge = 0x15, /**< An edge from an entity to the member entity its initializes. */
107 meth_par_edge = 0x21, /**< An edge from a method type to one of its parameter types. */
108 meth_res_edge = 0x22, /**< An edge from a method type to one of its result types. */
109 type_super_edge = 0x23, /**< An edge from a class type to its super/basis type. */
110 union_edge = 0x24, /**< An edge from a union type to its member types. */
111 ptr_pts_to_edge = 0x25, /**< An edge from a pointer type to its points-to type. */
112 arr_elt_type_edge = 0x26, /**< An edge from an array type to its element type. */
113 arr_ent_edge = 0x27, /**< An edge from a array type to its element entity. */
114 type_member_edge = 0x28, /**< An edge from a compound type to its member entities. */
116 /* additional flags */
117 intra_edge = 0, /**< Intra edge flag: edge do not cross basic block boundaries */
118 inter_edge = 0x40, /**< Inter edge flag: edge cross basic block boundaries */
119 back_edge = 0x80 /**< Backwards edge flag. */
122 /* Attributes of nodes */
123 #define PRINT_DEFAULT_NODE_ATTR
124 #define DEFAULT_NODE_ATTR " "
125 #define DEFAULT_TYPE_ATTRIBUTE " "
126 #define DEFAULT_ENUM_ITEM_ATTRIBUTE " "
128 /* Attributes of edges between Firm nodes */
129 #define INTRA_DATA_EDGE_ATTR "class:1 priority:50"
130 #define INTER_DATA_EDGE_ATTR "class:16 priority:10"
131 #define BLOCK_EDGE_ATTR "class:2 priority:50 linestyle:dotted"
132 #define CF_EDGE_ATTR "class:13 priority:60 color:red"
133 #define EXC_CF_EDGE_ATTR "class:18 priority:60 color:blue"
134 #define INTRA_MEM_EDGE_ATTR "class:14 priority:50 color:blue"
135 #define INTER_MEM_EDGE_ATTR "class:17 priority:10 color:blue"
136 #define DOMINATOR_EDGE_ATTR "class:15 color:red"
137 #define POSTDOMINATOR_EDGE_ATTR "class:19 color:red linestyle:dotted"
138 #define KEEP_ALIVE_EDGE_ATTR "class:20 priority:10 color:purple"
139 #define KEEP_ALIVE_CF_EDGE_ATTR "class:20 priority:60 color:purple"
140 #define KEEP_ALIVE_DF_EDGE_ATTR "class:20 priority:10 color:purple"
141 #define ANCHOR_EDGE_ATTR "class:20 priority:60 color:purple linestyle:dotted"
142 #define OUT_EDGE_ATTR "class:21 priority:10 color:gold linestyle:dashed"
144 #define BACK_EDGE_ATTR "linestyle:dashed "
146 /* Attributes of edges between Firm nodes and type/entity nodes */
147 #define NODE2TYPE_EDGE_ATTR "class:2 priority:2 linestyle:dotted"
149 /* Attributes of edges in type/entity graphs. */
150 #define TYPE_METH_NODE_ATTR "color: lightyellow"
151 #define TYPE_CLASS_NODE_ATTR "color: green"
152 #define TYPE_DESCRIPTION_NODE_ATTR "color: lightgreen"
153 #define ENTITY_NODE_ATTR "color: yellow"
154 #define ENUM_ITEM_NODE_ATTR "color: green"
155 #define ENT_TYPE_EDGE_ATTR "class: 3 label: \"type\" color: red"
156 #define ENT_OWN_EDGE_ATTR "class: 4 label: \"owner\" color: black"
157 #define METH_PAR_EDGE_ATTR "class: 5 label: \"param %zu\" color: green"
158 #define METH_RES_EDGE_ATTR "class: 6 label: \"res %zu\" color: green"
159 #define TYPE_SUPER_EDGE_ATTR "class: 7 label: \"supertype\" color: red"
160 #define UNION_EDGE_ATTR "class: 8 label: \"component\" color: blue"
161 #define PTR_PTS_TO_EDGE_ATTR "class: 9 label: \"points to\" color:green"
162 #define ARR_ELT_TYPE_EDGE_ATTR "class: 10 label: \"arr elt tp\" color:green"
163 #define ARR_ENT_EDGE_ATTR "class: 10 label: \"arr ent\" color: green"
164 #define ENT_OVERWRITES_EDGE_ATTR "class: 11 label: \"overwrites\" color:red"
165 #define ENT_VALUE_EDGE_ATTR "label: \"value %d\""
166 #define ENT_CORR_EDGE_ATTR "label: \"value %zu corresponds to \" "
167 #define TYPE_MEMBER_EDGE_ATTR "class: 12 label: \"member\" color:blue"
168 /* #define CALLGRAPH_EDGE_ATTR "calls" */
170 typedef struct pns_lookup {
171 long nr; /**< the proj number */
172 const char *name; /**< the name of the Proj */
175 typedef struct proj_lookup {
176 unsigned code; /**< the opcode of the Proj predecessor */
177 unsigned num_data; /**< number of data entries */
178 const pns_lookup_t *data; /**< the data */
181 #include "gen_irdump.c.inl"
183 /** Dump only irgs with names that start with this prefix. */
184 static ident *dump_file_filter_id = NULL;
186 static ir_dump_flags_t flags =
187 ir_dump_flag_blocks_as_subgraphs |
188 ir_dump_flag_keepalive_edges |
189 ir_dump_flag_ld_names |
190 ir_dump_flag_back_edges |
191 ir_dump_flag_consts_local |
192 ir_dump_flag_analysed_types |
193 ir_dump_flag_entities_in_hierarchy |
194 ir_dump_flag_number_label;
196 static ird_color_t overrule_nodecolor = ird_color_default_node;
198 /** The vcg node attribute hook. */
199 static dump_node_vcgattr_func dump_node_vcgattr_hook = NULL;
200 /** The vcg edge attribute hook. */
201 static dump_edge_vcgattr_func dump_edge_vcgattr_hook = NULL;
202 /** The vcg dump block edge hook */
203 static dump_node_edge_func dump_block_edge_hook = NULL;
204 /** The vcg dump node edge hook. */
205 static dump_node_edge_func dump_node_edge_hook = NULL;
207 void set_dump_node_edge_hook(dump_node_edge_func func)
209 dump_node_edge_hook = func;
212 dump_node_edge_func get_dump_node_edge_hook(void)
214 return dump_node_edge_hook;
217 void set_dump_block_edge_hook(dump_node_edge_func func)
219 dump_block_edge_hook = func;
222 dump_node_edge_func get_dump_block_edge_hook(void)
224 return dump_node_edge_hook;
227 void set_dump_node_vcgattr_hook(dump_node_vcgattr_func hook)
229 dump_node_vcgattr_hook = hook;
232 void set_dump_edge_vcgattr_hook(dump_edge_vcgattr_func hook)
234 dump_edge_vcgattr_hook = hook;
237 void ir_set_dump_flags(ir_dump_flags_t new_flags)
242 void ir_add_dump_flags(ir_dump_flags_t new_flags)
247 void ir_remove_dump_flags(ir_dump_flags_t to_remove)
252 ir_dump_flags_t ir_get_dump_flags(void)
257 /** Returns 0 if dump_out_edge_flag or dump_loop_information_flag
258 * are set, else returns dump_const_local_flag.
260 static bool get_opt_dump_const_local(void)
262 return (flags & ir_dump_flag_out_edges)
263 || (flags & ir_dump_flag_loops)
264 || (flags & ir_dump_flag_consts_local)
265 || (flags & ir_dump_flag_iredges);
268 static char *dump_filter;
270 void ir_set_dump_filter(const char *new_filter)
273 dump_filter = xstrdup(new_filter);
276 const char *ir_get_dump_filter(void)
281 int ir_should_dump(const char *name)
285 if (dump_filter == NULL || dump_filter[0] == '\0')
288 for (n = name, f = dump_filter; *f != '\0' && *n != '\0';
296 /* -------------- some extended helper functions ----------------- */
298 char const *get_mode_name_ex(ir_mode const *const mode)
301 return get_mode_name(mode);
305 #define CUSTOM_COLOR_BASE 100
306 static const char *color_names[ird_color_count];
307 static const char *color_rgb[ird_color_count];
308 static struct obstack color_obst;
310 /** define a custom color. */
311 static void custom_color(int num, const char *rgb_def)
313 assert(num < ird_color_count);
314 obstack_printf(&color_obst, "%d", CUSTOM_COLOR_BASE + num);
315 obstack_1grow(&color_obst, '\0');
317 color_rgb[num] = rgb_def;
318 color_names[num] = (const char*)obstack_finish(&color_obst);
321 /** Define a named color. */
322 static void named_color(int num, const char *name)
324 assert(num < ird_color_count);
325 color_rgb[num] = NULL;
326 color_names[num] = name;
329 /** Initializes the used colors. */
330 static void init_colors(void)
332 static bool initialized = 0;
336 obstack_init(&color_obst);
338 custom_color(ird_color_prog_background, "204 204 204");
339 custom_color(ird_color_block_background, "255 255 0");
340 custom_color(ird_color_dead_block_background, "190 150 150");
341 named_color(ird_color_block_inout, "lightblue");
342 named_color(ird_color_default_node, "white");
343 custom_color(ird_color_memory, "153 153 255");
344 custom_color(ird_color_controlflow, "255 153 153");
345 custom_color(ird_color_const, "204 255 255");
346 custom_color(ird_color_proj, "255 255 153");
347 custom_color(ird_color_uses_memory, "153 153 255");
348 custom_color(ird_color_phi, "105 255 105");
349 custom_color(ird_color_anchor, "100 100 255");
350 named_color(ird_color_error, "red");
351 custom_color(ird_color_entity, "204 204 255");
357 * Prints the VCG color to a file.
359 static void print_vcg_color(FILE *out, ird_color_t color)
361 assert(color < ird_color_count);
362 fprintf(out, "color:%s", color_names[color]);
365 void print_nodeid(FILE *F, const ir_node *node)
367 fprintf(F, "\"n%ld\"", get_irn_node_nr(node));
370 void print_irgid(FILE *F, const ir_graph *irg)
372 fprintf(F, "\"g%ld\"", get_irg_graph_nr(irg));
375 void print_typeid(FILE *F, const ir_type *type)
377 fprintf(F, "\"t%ld\"", get_type_nr(type));
380 void print_entityid(FILE *F, const ir_entity *entity)
382 fprintf(F, "\"e%ld\"", get_entity_nr(entity));
385 static void print_itemid(FILE *F, const ir_type *tp, size_t itemnr)
387 fprintf(F, "\"i%ldT%zu\"", get_type_nr(tp), itemnr);
391 * Prints the edge kind of a given IR node.
393 * Projs should be dumped near their predecessor, so they get "nearedge".
395 static void print_node_edge_kind(FILE *out, const ir_node *node)
398 fprintf(out, "nearedge: ");
400 fprintf(out, "edge: ");
405 * Prints the edge from a type S to a type T with additional info fmt, ...
408 static void print_type_type_edge(FILE *F, const ir_type *S, const ir_type *T, const char *fmt, ...)
413 fprintf(F, "edge: { sourcename: ");
415 fprintf(F, " targetname: ");
417 ir_vfprintf(F, fmt, ap);
423 * Prints the edge from a type tp to an entity ent with additional info fmt, ...
426 static void print_type_ent_edge(FILE *F, const ir_type *tp, const ir_entity *ent, const char *fmt, ...)
431 fprintf(F, "edge: { sourcename: ");
433 fprintf(F, " targetname: ");
434 print_entityid(F, ent);
435 ir_vfprintf(F, fmt, ap);
441 * Prints the edge from an entity ent1 to an entity ent2 with additional info fmt, ...
444 static void print_ent_ent_edge(FILE *F, const ir_entity *ent1, const ir_entity *ent2, int backedge, ird_color_t color, const char *fmt, ...)
450 fprintf(F, "backedge: { sourcename: ");
452 fprintf(F, "edge: { sourcename: ");
453 print_entityid(F, ent1);
454 fprintf(F, " targetname: ");
455 print_entityid(F, ent2);
456 ir_vfprintf(F, fmt, ap);
458 if (color != ird_color_none)
459 print_vcg_color(F, color);
465 * Prints the edge from an entity ent to a type tp with additional info fmt, ...
468 static void print_ent_type_edge(FILE *F, const ir_entity *ent, const ir_type *tp, const char *fmt, ...)
473 fprintf(F, "edge: { sourcename: ");
474 print_entityid(F, ent);
475 fprintf(F, " targetname: ");
477 ir_vfprintf(F, fmt, ap);
483 * Prints the edge from a node irn to a type tp with additional info fmt, ...
486 static void print_node_type_edge(FILE *F, const ir_node *irn, ir_type *tp, const char *fmt, ...)
491 fprintf(F, "edge: { sourcename: ");
492 print_nodeid(F, irn);
493 fprintf(F, " targetname: ");
495 ir_vfprintf(F, fmt, ap);
501 * Prints the edge from a node irn to an entity ent with additional info fmt, ...
504 static void print_node_ent_edge(FILE *F, const ir_node *irn, const ir_entity *ent, const char *fmt, ...)
509 fprintf(F, "edge: { sourcename: ");
510 print_nodeid(F, irn);
511 fprintf(F, " targetname: ");
512 print_entityid(F, ent);
513 ir_vfprintf(F, fmt, ap);
519 * Prints the edge from a type tp to an enumeration item item with additional info fmt, ...
522 static void print_enum_item_edge(FILE *F, const ir_type *tp, size_t item, const char *fmt, ...)
527 fprintf(F, "edge: { sourcename: ");
529 fprintf(F, " targetname: ");
530 print_itemid(F, tp, item);
531 ir_vfprintf(F, fmt, ap);
536 /*-----------------------------------------------------------------*/
537 /* global and ahead declarations */
538 /*-----------------------------------------------------------------*/
540 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg);
542 /*-----------------------------------------------------------------*/
543 /* Helper functions. */
544 /*-----------------------------------------------------------------*/
547 * This map is used as a private link attr to be able to call dumper
548 * anywhere without destroying link fields.
550 static pmap *irdump_link_map = NULL;
552 /** NOT A STANDARD LIBFIRM INIT METHOD
554 * We do not want to integrate dumping into libfirm, i.e., if the dumpers
555 * are off, we want to have as few interferences as possible. Therefore the
556 * initialization is performed lazily and not called from within init_firm.
558 * Creates the link attribute map. */
559 static void init_irdump(void)
561 /* We need a new, empty map. */
562 if (irdump_link_map) pmap_destroy(irdump_link_map);
563 irdump_link_map = pmap_create();
564 if (!dump_file_filter_id)
565 dump_file_filter_id = new_id_from_str("");
569 * Returns the private link field.
571 static void *ird_get_irn_link(const ir_node *n)
573 if (irdump_link_map == NULL)
576 return pmap_get(void, irdump_link_map, n);
580 * Sets the private link field.
582 static void ird_set_irn_link(const ir_node *n, void *x)
584 if (irdump_link_map == NULL)
586 pmap_insert(irdump_link_map, n, x);
590 * Gets the private link field of an irg.
592 static void *ird_get_irg_link(const ir_graph *irg)
594 if (irdump_link_map == NULL)
597 return pmap_get(void, irdump_link_map, irg);
601 * Sets the private link field of an irg.
603 static void ird_set_irg_link(const ir_graph *irg, void *x)
605 if (irdump_link_map == NULL)
607 pmap_insert(irdump_link_map, irg, x);
611 * Walker, clears the private link field.
613 static void clear_link(ir_node *node, void *env)
616 ird_set_irn_link(node, NULL);
620 * If the entity has a ld_name, returns it if the dump_ld_name is set,
621 * else returns the name of the entity.
623 static const char *get_ent_dump_name_(const ir_entity *ent, bool dump_ld_name)
626 return "<NULL entity>";
628 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
629 if (ent->ld_name != NULL)
630 return get_id_str(ent->ld_name);
632 return get_id_str(ent->name);
635 const char *get_ent_dump_name(const ir_entity *ent)
637 return get_ent_dump_name_(ent, flags & ir_dump_flag_ld_names);
640 const char *get_irg_dump_name(const ir_graph *irg)
642 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
643 return get_ent_dump_name_(get_irg_entity(irg), true);
647 * Returns non-zero if a node is in floating state.
649 static int node_floats(const ir_node *n)
651 ir_graph *irg = get_irn_irg(n);
652 return ((get_irn_pinned(n) == op_pin_state_floats) &&
653 (get_irg_pinned(irg) == op_pin_state_floats));
657 * Walker that visits the anchors
659 static void ird_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
661 if ((flags & ir_dump_flag_all_anchors)
662 || ((flags & ir_dump_flag_iredges) && edges_activated(irg))) {
663 irg_walk_anchors(irg, pre, post, env);
665 irg_walk_graph(irg, pre, post, env);
670 * Walker, allocates an array for all blocks and puts their non-floating
671 * nodes into this array.
673 static void collect_node(ir_node *node, void *env)
678 || (get_op_flags(get_irn_op(node)) & irop_flag_dump_noblock)) {
679 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
680 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
681 ARR_APP1(ir_node *, arr, node);
682 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
684 ir_node * block = get_nodes_block(node);
687 /* this node is in a Bad block, so we must place it into the graph's list */
688 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
689 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
690 ARR_APP1(ir_node *, arr, node);
691 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
693 ird_set_irn_link(node, ird_get_irn_link(block));
694 ird_set_irn_link(block, node);
699 /** Construct lists to walk ir block-wise.
701 * Collects all blocks, nodes not op_pin_state_pinned,
702 * Bad, NoMem and Unknown into a flexible array in link field of
703 * irg they belong to. Sets the irg link field to NULL in all
704 * graphs not visited.
705 * Free the list with DEL_ARR_F().
707 static ir_node **construct_block_lists(ir_graph *irg)
710 int walk_flag = ir_resources_reserved(irg) & IR_RESOURCE_IRN_VISITED;
713 ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
716 for (i = get_irp_n_irgs(); i > 0;)
717 ird_set_irg_link(get_irp_irg(--i), NULL);
719 ird_walk_graph(irg, clear_link, collect_node, irg);
722 ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
725 return (ir_node**)ird_get_irg_link(irg);
728 void dump_node_opcode(FILE *F, const ir_node *n)
730 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
732 /* call the dump_node operation if available */
733 if (ops->dump_node) {
734 ops->dump_node(F, n, dump_node_opcode_txt);
738 /* implementation for default nodes */
739 switch (get_irn_opcode(n)) {
741 switch (get_SymConst_kind(n)) {
742 case symconst_addr_ent:
743 fprintf(F, "SymC &%s", get_entity_name(get_SymConst_entity(n)));
745 case symconst_ofs_ent:
746 fprintf(F, "SymC %s offset", get_entity_name(get_SymConst_entity(n)));
748 case symconst_type_size:
749 ir_fprintf(F, "SymC %+F size", get_SymConst_type(n));
751 case symconst_type_align:
752 ir_fprintf(F, "SymC %+F align", get_SymConst_type(n));
754 case symconst_enum_const:
755 fprintf(F, "SymC %s enum", get_enumeration_const_name(get_SymConst_enum(n)));
761 if (get_Load_unaligned(n) == align_non_aligned)
763 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Load_mode(n)));
766 if (get_Store_unaligned(n) == align_non_aligned)
768 fprintf(F, "%s", get_irn_opname(n));
771 if (n == get_irg_start_block(get_irn_irg(n)))
773 if (n == get_irg_end_block(get_irn_irg(n)))
775 fprintf(F, "%s%s", get_irn_opname(n),
776 (flags & ir_dump_flag_show_marks) ? (get_Block_mark(n) ? "*" : "") : "");
779 fprintf(F, "%s", get_irn_opname(n));
780 if (get_Div_no_remainder(n))
782 fprintf(F, "[%s]", get_mode_name_ex(get_Div_resmode(n)));
785 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Mod_resmode(n)));
788 fprintf(F, "%s[%s]", get_irn_opname(n), get_builtin_kind_name(get_Builtin_kind(n)));
792 fprintf(F, "%s", get_irn_opname(n));
797 * Dump the mode of a node n to a file F.
798 * Ignore modes that are "always known".
800 static void dump_node_mode(FILE *F, const ir_node *n)
802 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
806 /* call the dump_node operation if available */
807 if (ops->dump_node) {
808 ops->dump_node(F, n, dump_node_mode_txt);
812 /* default implementation */
813 iro = get_irn_opcode(n);
825 mode = get_irn_mode(n);
827 if (mode != NULL && mode != mode_BB && mode != mode_ANY && mode != mode_BAD &&
828 (mode != mode_T || iro == iro_Proj))
829 fprintf(F, "%s", get_mode_name_ex(mode));
834 * Dump the type of a node n to a file F if it's known.
836 static int dump_node_typeinfo(FILE *F, const ir_node *n)
838 ir_graph *irg = get_irn_irg(n);
841 if (ir_get_dump_flags() & ir_dump_flag_analysed_types) {
842 if (get_irg_typeinfo_state(irg) == ir_typeinfo_consistent ||
843 get_irg_typeinfo_state(irg) == ir_typeinfo_inconsistent) {
844 ir_type *tp = get_irn_typeinfo_type(n);
845 if (tp != get_none_type()) {
846 ir_fprintf(F, "[%+F]", tp);
856 * Dump additional node attributes of some nodes to a file F.
858 static void dump_node_nodeattr(FILE *F, const ir_node *n)
863 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
865 /* call the dump_node operation if available */
866 if (ops->dump_node) {
867 ops->dump_node(F, n, dump_node_nodeattr_txt);
871 switch (get_irn_opcode(n)) {
873 ir_fprintf(F, "%T ", get_Const_tarval(n));
877 pred = get_Proj_pred(n);
878 proj_nr = get_Proj_proj(n);
879 code = get_irn_opcode(pred);
881 if (code == iro_Proj && get_irn_opcode(get_Proj_pred(pred)) == iro_Start) {
882 fprintf(F, "Arg %ld ", proj_nr);
884 unsigned i, j, f = 0;
886 for (i = 0; i < ARRAY_SIZE(proj_lut); ++i) {
887 if (code == proj_lut[i].code) {
888 for (j = 0; j < proj_lut[i].num_data; ++j) {
889 if (proj_nr == proj_lut[i].data[j].nr) {
890 fprintf(F, "%s ", proj_lut[i].data[j].name);
899 fprintf(F, "%ld ", proj_nr);
900 if (code == iro_Cond && get_Cond_jmp_pred(pred) != COND_JMP_PRED_NONE) {
901 if (proj_nr == pn_Cond_false && get_Cond_jmp_pred(pred) == COND_JMP_PRED_FALSE)
903 if (proj_nr == pn_Cond_true && get_Cond_jmp_pred(pred) == COND_JMP_PRED_TRUE)
909 fprintf(F, "%s ", get_ent_dump_name(get_Sel_entity(n)));
912 fprintf(F, "%s ", get_relation_string(get_Cmp_relation(n)));
915 fprintf(F, "%s ", get_relation_string(get_Confirm_relation(n)));
918 ir_fprintf(F, "(%+F)", get_CopyB_type(n));
926 void dump_node_label(FILE *F, const ir_node *n)
928 dump_node_opcode(F, n);
930 dump_node_mode(F, n);
932 dump_node_typeinfo(F, n);
933 dump_node_nodeattr(F, n);
934 if (flags & ir_dump_flag_number_label) {
935 fprintf(F, "%ld", get_irn_node_nr(n));
937 if (flags & ir_dump_flag_idx_label) {
938 fprintf(F, ":%u", get_irn_idx(n));
943 * Dumps the attributes of a node n into the file F.
944 * Currently this is only the color of a node.
946 static void dump_node_vcgattr(FILE *F, const ir_node *node, const ir_node *local, bool bad)
952 print_vcg_color(F, ird_color_error);
956 if (dump_node_vcgattr_hook != NULL) {
957 dump_node_vcgattr_hook(F, node, local);
961 n = local ? local : node;
963 if (overrule_nodecolor != ird_color_default_node) {
964 print_vcg_color(F, overrule_nodecolor);
968 mode = get_irn_mode(n);
969 if (mode == mode_M) {
970 print_vcg_color(F, ird_color_memory);
973 if (mode == mode_X) {
974 print_vcg_color(F, ird_color_controlflow);
978 switch (get_irn_opcode(n)) {
981 print_vcg_color(F, ird_color_anchor);
984 print_vcg_color(F, ird_color_error);
987 print_vcg_color(F, ird_color_block_background);
990 print_vcg_color(F, ird_color_phi);
993 print_vcg_color(F, ird_color_memory);
997 print_vcg_color(F, ird_color_const);
1000 print_vcg_color(F, ird_color_proj);
1003 ir_op *op = get_irn_op(node);
1005 if (is_op_constlike(op)) {
1006 print_vcg_color(F, ird_color_const);
1007 } else if (is_op_uses_memory(op)) {
1008 print_vcg_color(F, ird_color_uses_memory);
1009 } else if (is_op_cfopcode(op) || is_op_forking(op)) {
1010 print_vcg_color(F, ird_color_controlflow);
1016 void *dump_add_node_info_callback(dump_node_info_cb_t *cb, void *data)
1018 hook_entry_t *info = XMALLOCZ(hook_entry_t);
1020 info->hook._hook_node_info = cb;
1021 info->context = data;
1022 register_hook(hook_node_info, info);
1027 void dump_remove_node_info_callback(void *handle)
1029 hook_entry_t *info = (hook_entry_t*)handle;
1030 unregister_hook(hook_node_info, info);
1035 * Dump the node information of a node n to a file F.
1037 static void dump_node_info(FILE *F, const ir_node *n)
1039 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
1041 fprintf(F, " info1: \"");
1042 dump_irnode_to_file(F, n);
1043 /* call the dump_node operation if available */
1045 ops->dump_node(F, n, dump_node_info_txt);
1047 /* allow additional info to be added */
1048 hook_node_info(F, n);
1052 static int is_constlike_node(const ir_node *node)
1054 const ir_op *op = get_irn_op(node);
1055 return is_op_constlike(op);
1058 static void print_constid(FILE *F, const ir_node *user, const ir_node *node)
1060 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(user), get_irn_node_nr(node));
1063 static void print_constblkid(FILE *F, const ir_node *node, const ir_node *block)
1065 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(node), get_irn_node_nr(block));
1069 /** outputs the predecessors of n, that are constants, local. I.e.,
1070 generates a copy of the constant predecessors for each node called with. */
1071 static void dump_const_node_local(FILE *F, const ir_node *n)
1073 ir_graph *irg = get_irn_irg(n);
1075 if (!get_opt_dump_const_local()) return;
1077 /* Use visited flag to avoid outputting nodes twice.
1078 initialize it first. */
1079 for (i = 0; i < get_irn_arity(n); i++) {
1080 ir_node *con = get_irn_n(n, i);
1081 if (is_constlike_node(con)) {
1082 set_irn_visited(con, get_irg_visited(irg) - 1);
1086 for (i = 0; i < get_irn_arity(n); i++) {
1087 ir_node *con = get_irn_n(n, i);
1088 if (is_constlike_node(con) && !irn_visited_else_mark(con)) {
1089 /* Generate a new name for the node by appending the names of
1091 fprintf(F, "node: {title: ");
1092 print_constid(F, n, con);
1093 fprintf(F, " label: \"");
1094 dump_node_label(F, con);
1096 dump_node_info(F, con);
1097 dump_node_vcgattr(F, n, con, 0);
1103 /** If the block of an edge is a const_like node, dump it local with an edge */
1104 static void dump_const_block_local(FILE *F, const ir_node *n)
1108 if (!get_opt_dump_const_local()) return;
1110 blk = get_nodes_block(n);
1111 if (is_constlike_node(blk)) {
1112 /* Generate a new name for the node by appending the names of
1114 fprintf(F, "node: {title: ");
1115 print_constblkid(F, n, blk);
1116 fprintf(F, " label: \"");
1117 dump_node_label(F, blk);
1119 dump_node_info(F, blk);
1120 dump_node_vcgattr(F, n, blk, 0);
1123 fprintf(F, "edge: { sourcename: ");
1125 fprintf(F, " targetname: ");
1126 print_constblkid(F, n, blk);
1129 if (dump_edge_vcgattr_hook != NULL
1130 && dump_edge_vcgattr_hook(F, n, -1)) {
1135 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1140 * prints the error message of a node to a file F as info2.
1142 static void print_node_error(FILE *F, const char *err_msg)
1147 fprintf(F, " info2: \"%s\"", err_msg);
1151 * prints debug messages of a node to file F as info3.
1153 static void print_dbg_info(FILE *F, dbg_info *dbg)
1157 ir_dbg_info_snprint(buf, sizeof(buf), dbg);
1159 fprintf(F, " info3: \"%s\"\n", buf);
1163 static void print_type_dbg_info(FILE *F, type_dbg_info *dbg)
1173 void dump_node(FILE *F, const ir_node *n)
1179 if (get_opt_dump_const_local() && is_constlike_node(n))
1182 /* dump this node */
1183 fputs("node: {title: ", F);
1186 fputs(" label: \"", F);
1187 irg = get_irn_irg(n);
1188 bad = ! irn_verify_irg_dump(n, irg, &p);
1189 dump_node_label(F, n);
1192 dump_node_info(F, n);
1193 print_node_error(F, p);
1194 print_dbg_info(F, get_irn_dbg_info(n));
1195 dump_node_vcgattr(F, n, NULL, bad);
1197 dump_const_node_local(F, n);
1201 /** dump the edge to the block this node belongs to */
1202 static void dump_ir_block_edge(FILE *F, const ir_node *n)
1204 if (get_opt_dump_const_local() && is_constlike_node(n)) return;
1206 ir_node *block = get_nodes_block(n);
1208 if (get_opt_dump_const_local() && is_constlike_node(block)) {
1209 dump_const_block_local(F, n);
1211 fprintf(F, "edge: { sourcename: ");
1213 fprintf(F, " targetname: ");
1214 print_nodeid(F, block);
1217 if (dump_edge_vcgattr_hook && dump_edge_vcgattr_hook(F, n, -1)) {
1222 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1227 static void print_data_edge_vcgattr(FILE *F, const ir_node *from, int to)
1230 * do not use get_nodes_block() here, will fail
1231 * if the irg is not pinned.
1233 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1234 fprintf(F, INTRA_DATA_EDGE_ATTR);
1236 fprintf(F, INTER_DATA_EDGE_ATTR);
1239 static void print_mem_edge_vcgattr(FILE *F, const ir_node *from, int to)
1242 * do not use get_nodes_block() here, will fail
1243 * if the irg is not pinned.
1245 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1246 fprintf(F, INTRA_MEM_EDGE_ATTR);
1248 fprintf(F, INTER_MEM_EDGE_ATTR);
1251 /** Print the vcg attributes for the edge from node "from" to its "to"th input */
1252 static void print_edge_vcgattr(FILE *F, const ir_node *from, int to)
1256 if (dump_edge_vcgattr_hook)
1257 if (dump_edge_vcgattr_hook(F, from, to))
1260 if ((flags & ir_dump_flag_back_edges) && is_backedge(from, to))
1261 fprintf(F, BACK_EDGE_ATTR);
1263 switch (get_irn_opcode(from)) {
1265 fprintf(F, CF_EDGE_ATTR);
1267 case iro_Start: break;
1270 if (get_irn_mode(get_End_keepalive(from, to)) == mode_BB)
1271 fprintf(F, KEEP_ALIVE_CF_EDGE_ATTR);
1273 fprintf(F, KEEP_ALIVE_DF_EDGE_ATTR);
1277 if (is_Proj(from)) {
1278 if (get_irn_mode(from) == mode_M)
1279 print_mem_edge_vcgattr(F, from, to);
1280 else if (get_irn_mode(from) == mode_X)
1281 fprintf(F, CF_EDGE_ATTR);
1283 print_data_edge_vcgattr(F, from, to);
1285 else if (get_irn_mode(get_irn_n(from, to)) == mode_M)
1286 print_mem_edge_vcgattr(F, from, to);
1287 else if (get_irn_mode(get_irn_n(from, to)) == mode_X)
1288 fprintf(F, CF_EDGE_ATTR);
1290 print_data_edge_vcgattr(F, from, to);
1294 /** dump edges to our inputs */
1295 static void dump_ir_data_edges(FILE *F, const ir_node *n)
1299 if (dump_node_edge_hook)
1300 dump_node_edge_hook(F, n);
1302 if (!(flags & ir_dump_flag_keepalive_edges) && is_End(n)) {
1303 /* the End node has only keep-alive edges */
1307 /* dump the dependency edges. */
1308 num = get_irn_deps(n);
1309 for (i = 0; i < num; ++i) {
1310 ir_node *dep = get_irn_dep(n, i);
1313 print_node_edge_kind(F, n);
1314 fprintf(F, "{sourcename: ");
1316 fprintf(F, " targetname: ");
1317 if ((get_opt_dump_const_local()) && is_constlike_node(dep)) {
1318 print_constid(F, n, dep);
1320 print_nodeid(F, dep);
1322 fprintf(F, " label: \"%d\" ", i);
1323 fprintf(F, " color: darkgreen}\n");
1327 num = get_irn_arity(n);
1328 for (i = 0; i < num; i++) {
1329 ir_node *pred = get_irn_n(n, i);
1332 if ((flags & ir_dump_flag_back_edges) && is_backedge(n, i)) {
1333 fprintf(F, "backedge: {sourcename: ");
1335 print_node_edge_kind(F, n);
1336 fprintf(F, "{sourcename: ");
1339 fprintf(F, " targetname: ");
1340 if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
1341 print_constid(F, n, pred);
1343 print_nodeid(F, pred);
1345 fprintf(F, " label: \"%d\" ", i);
1346 print_edge_vcgattr(F, n, i);
1354 static void dump_ir_edges(ir_node *node, void *env)
1357 FILE *F = (FILE*)env;
1359 foreach_out_edge(node, edge) {
1360 ir_node *succ = get_edge_src_irn(edge);
1362 print_node_edge_kind(F, succ);
1363 fprintf(F, "{sourcename: ");
1364 print_nodeid(F, node);
1365 fprintf(F, " targetname: ");
1366 print_nodeid(F, succ);
1368 fprintf(F, " label: \"%d\" ", i);
1369 fprintf(F, OUT_EDGE_ATTR);
1376 /** Dumps a node and its edges but not the block edge */
1377 static void dump_node_wo_blockedge(FILE *F, const ir_node *n)
1380 dump_ir_data_edges(F, n);
1383 /** Dumps a node and its edges. */
1384 static void dump_node_with_edges(ir_node *n, void *env)
1386 FILE *F = (FILE*)env;
1387 dump_node_wo_blockedge(F, n);
1388 if (!node_floats(n))
1389 dump_ir_block_edge(F, n);
1392 /** Dumps a const-like node. */
1393 static void dump_const_node(ir_node *n, void *env)
1395 FILE *F = (FILE*)env;
1396 if (is_Block(n)) return;
1397 dump_node_wo_blockedge(F, n);
1400 /***********************************************************************/
1401 /* the following routines dump the nodes/irgs bracketed to graphs. */
1402 /***********************************************************************/
1404 /** Dumps a constant expression as entity initializer, array bound ... */
1405 static void dump_const_expression(FILE *F, ir_node *value)
1407 ir_graph *irg = get_const_code_irg();
1408 ir_dump_flags_t old_flags = ir_get_dump_flags();
1409 ir_remove_dump_flags(ir_dump_flag_consts_local);
1411 irg_walk(value, dump_const_node, NULL, F);
1412 /* Decrease visited flag so that we walk with the same flag for the next
1413 expression. This guarantees that we don't dump the same node twice,
1414 as for const expressions cse is performed to save memory. */
1415 set_irg_visited(irg, get_irg_visited(irg) -1);
1417 ir_set_dump_flags(old_flags);
1420 /** Dump a block as graph containing its nodes.
1422 * Expects to find nodes belonging to the block as list in its
1424 * Dumps the edges of all nodes including itself. */
1425 static void dump_whole_block(FILE *F, const ir_node *block)
1429 assert(is_Block(block));
1431 fprintf(F, "graph: { title: ");
1432 print_nodeid(F, block);
1433 fprintf(F, " label: \"");
1434 dump_node_label(F, block);
1436 fprintf(F, "\" status:clustered ");
1437 /* colorize blocks */
1438 ird_color_t const color =
1439 !get_Block_matured(block) ? ird_color_error :
1440 ird_color_block_background;
1441 print_vcg_color(F, color);
1444 /* yComp can show attributes for blocks, XVCG parses but ignores them */
1445 dump_node_info(F, block);
1446 print_dbg_info(F, get_irn_dbg_info(block));
1448 /* dump the blocks edges */
1449 dump_ir_data_edges(F, block);
1451 if (dump_block_edge_hook)
1452 dump_block_edge_hook(F, block);
1454 /* dump the nodes that go into the block */
1455 for (node = (ir_node*)ird_get_irn_link(block); node; node = (ir_node*)ird_get_irn_link(node)) {
1457 dump_ir_data_edges(F, node);
1460 /* Close the vcg information for the block */
1462 dump_const_node_local(F, block);
1466 /** dumps a graph block-wise. Expects all blockless nodes in arr in irgs link.
1467 * The outermost nodes: blocks and nodes not op_pin_state_pinned, Bad, Unknown. */
1468 static void dump_block_graph(FILE *F, ir_graph *irg)
1471 ir_node **arr = (ir_node**)ird_get_irg_link(irg);
1473 for (i = 0, n = ARR_LEN(arr); i < n; ++i) {
1474 ir_node *node = arr[i];
1475 if (is_Block(node)) {
1476 /* Dumps the block and all the nodes in the block, which are to
1477 be found in Block->link. */
1478 dump_whole_block(F, node);
1480 /* Nodes that are not in a Block. */
1482 if (!node_floats(node) && is_Bad(get_nodes_block(node))) {
1483 dump_const_block_local(F, node);
1485 dump_ir_data_edges(F, node);
1487 if ((flags & ir_dump_flag_iredges) && edges_activated(irg))
1488 dump_ir_edges(node, F);
1491 if ((flags & ir_dump_flag_loops)
1492 && irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1493 dump_loop_nodes_into_graph(F, irg);
1497 * Dump the info for an irg.
1498 * Parsed by XVCG but not shown. use yComp.
1500 static void dump_graph_info(FILE *F, ir_graph *irg)
1502 fprintf(F, "info1: \"");
1503 dump_entity_to_file(F, get_irg_entity(irg));
1506 /* dump graph state */
1507 fprintf(F, "constraints:");
1508 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP))
1509 fprintf(F, " arch_dep");
1510 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_MODEB_LOWERED))
1511 fprintf(F, " modeb_lowered");
1512 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_NORMALISATION2))
1513 fprintf(F, " normalisation2");
1514 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE))
1515 fprintf(F, " optimize_unreachable_code");
1518 fprintf(F, "properties:");
1519 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES))
1520 fprintf(F, " no_critical_edges");
1521 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_BADS))
1522 fprintf(F, " no_bads");
1523 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE))
1524 fprintf(F, " no_unreachable_code");
1525 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_ONE_RETURN))
1526 fprintf(F, " one_return");
1527 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE))
1528 fprintf(F, " consistent_dominance");
1529 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE))
1530 fprintf(F, " consistent_postdominance");
1531 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES))
1532 fprintf(F, " consistent_out_edges");
1533 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))
1534 fprintf(F, " consistent_outs");
1535 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1536 fprintf(F, " consistent_loopinfo");
1537 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE))
1538 fprintf(F, " consistent_entity_usage");
1542 /** Dumps an irg as a graph clustered by block nodes.
1543 * If interprocedural view edges can point to nodes out of this graph.
1545 static void dump_graph_from_list(FILE *F, ir_graph *irg)
1547 ir_entity *ent = get_irg_entity(irg);
1549 fprintf(F, "graph: { title: ");
1550 print_irgid(F, irg);
1551 fprintf(F, " label: \"%s\" status:clustered color:%s\n",
1552 get_ent_dump_name(ent), color_names[ird_color_prog_background]);
1554 dump_graph_info(F, irg);
1555 print_dbg_info(F, get_entity_dbg_info(ent));
1557 dump_block_graph(F, irg);
1559 /* Close the vcg information for the irg */
1560 fprintf(F, "}\n\n");
1563 /*******************************************************************/
1564 /* Basic type and entity nodes and edges. */
1565 /*******************************************************************/
1567 /** dumps the edges between nodes and their type or entity attributes. */
1568 static void dump_node2type_edges(ir_node *n, void *env)
1570 FILE *F = (FILE*)env;
1573 switch (get_irn_opcode(n)) {
1575 /* @@@ some consts have an entity */
1578 if (SYMCONST_HAS_TYPE(get_SymConst_kind(n)))
1579 print_node_type_edge(F,n,get_SymConst_type(n),NODE2TYPE_EDGE_ATTR);
1582 print_node_ent_edge(F,n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
1585 print_node_type_edge(F,n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
1588 print_node_type_edge(F,n,get_Alloc_type(n),NODE2TYPE_EDGE_ATTR);
1591 print_node_type_edge(F,n,get_Free_type(n),NODE2TYPE_EDGE_ATTR);
1598 static void print_typespecific_vcgattr(FILE *F, ir_type *tp)
1600 switch (get_type_tpop_code(tp)) {
1602 fprintf(F, " " TYPE_CLASS_NODE_ATTR);
1605 fprintf(F, " " TYPE_METH_NODE_ATTR);
1613 case tpo_enumeration:
1624 void dump_type_node(FILE *F, ir_type *tp)
1626 fprintf(F, "node: {title: ");
1627 print_typeid(F, tp);
1628 fprintf(F, " label: \"");
1629 if (tp->dbi != NULL) {
1631 ir_print_type(buf, sizeof(buf), tp);
1632 fprintf(F, "%s '%s'", get_type_tpop_name(tp), buf);
1634 ir_fprintf(F, "%+F", tp);
1636 fputs("\" info1: \"", F);
1637 dump_type_to_file(F, tp);
1639 print_type_dbg_info(F, get_type_dbg_info(tp));
1640 print_typespecific_vcgattr(F, tp);
1644 static void dump_entity_node(FILE *F, ir_entity *ent)
1646 fprintf(F, "node: {title: ");
1647 print_entityid(F, ent);
1648 fprintf(F, " label: ");
1649 fprintf(F, "\"%s\" ", get_ent_dump_name(ent));
1651 print_vcg_color(F, ird_color_entity);
1652 fprintf(F, "\n info1: \"");
1654 dump_entity_to_file(F, ent);
1657 print_dbg_info(F, get_entity_dbg_info(ent));
1661 static void dump_enum_item(FILE *F, ir_type *tp, size_t pos)
1664 ir_enum_const *ec = get_enumeration_const(tp, pos);
1665 ident *id = get_enumeration_const_nameid(ec);
1666 ir_tarval *tv = get_enumeration_value(ec);
1669 tarval_snprintf(buf, sizeof(buf), tv);
1671 strncpy(buf, "<not set>", sizeof(buf));
1672 fprintf(F, "node: {title: ");
1673 print_itemid(F, tp, pos);
1674 fprintf(F, " label: ");
1675 fprintf(F, "\"enum item %s\" " ENUM_ITEM_NODE_ATTR, get_id_str(id));
1676 fprintf(F, "\n info1: \"value: %s\"}\n", buf);
1680 * Dumps a new style initializer.
1682 static void dump_entity_initializer(FILE *F, const ir_entity *ent)
1690 * type-walker: Dumps a type or entity and its edges.
1692 static void dump_type_info(type_or_ent tore, void *env)
1694 FILE *F = (FILE*)env;
1695 size_t i = 0; /* to shutup gcc */
1697 /* dump this type or entity */
1699 switch (get_kind(tore.ent)) {
1701 ir_entity *ent = tore.ent;
1703 dump_entity_node(F, ent);
1705 /* skip this to reduce graph. Member edge of type is parallel to this edge. *
1706 fprintf(F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
1707 ENT_OWN_EDGE_ATTR "}\n", ent, get_entity_owner(ent));*/
1708 print_ent_type_edge(F,ent, get_entity_type(ent), ENT_TYPE_EDGE_ATTR);
1709 if (is_Class_type(get_entity_owner(ent))) {
1710 for (i = get_entity_n_overwrites(ent); i > 0;)
1711 print_ent_ent_edge(F, ent, get_entity_overwrites(ent, --i), 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1713 /* attached subgraphs */
1714 if (! (flags & ir_dump_flag_no_entity_values)) {
1715 if (ent->initializer != NULL) {
1716 /* new style initializers */
1717 dump_entity_initializer(F, ent);
1723 ir_type *tp = tore.typ;
1724 dump_type_node(F, tp);
1725 /* and now the edges */
1726 switch (get_type_tpop_code(tp)) {
1728 for (i = get_class_n_supertypes(tp); i > 0;) {
1730 print_type_type_edge(F, tp, get_class_supertype(tp, i), TYPE_SUPER_EDGE_ATTR);
1732 for (i = get_class_n_members(tp); i > 0;) {
1734 print_type_ent_edge(F, tp, get_class_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1738 for (i = get_struct_n_members(tp); i > 0;) {
1740 print_type_ent_edge(F, tp, get_struct_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1744 for (i = get_method_n_params(tp); i > 0;) {
1746 print_type_type_edge(F, tp, get_method_param_type(tp, i), METH_PAR_EDGE_ATTR,i);
1748 for (i = get_method_n_ress(tp); i > 0;) {
1750 print_type_type_edge(F, tp, get_method_res_type(tp, i), METH_RES_EDGE_ATTR,i);
1754 for (i = get_union_n_members(tp); i > 0;) {
1756 print_type_ent_edge(F, tp, get_union_member(tp, i), UNION_EDGE_ATTR);
1760 print_type_type_edge(F, tp, get_array_element_type(tp), ARR_ELT_TYPE_EDGE_ATTR);
1761 print_type_ent_edge(F, tp, get_array_element_entity(tp), ARR_ENT_EDGE_ATTR);
1762 for (i = get_array_n_dimensions(tp); i > 0;) {
1763 ir_node *upper, *lower;
1766 upper = get_array_upper_bound(tp, i);
1767 lower = get_array_lower_bound(tp, i);
1768 print_node_type_edge(F, upper, tp, "label: \"upper %zu\"", get_array_order(tp, i));
1769 print_node_type_edge(F, lower, tp, "label: \"lower %zu\"", get_array_order(tp, i));
1770 dump_const_expression(F, upper);
1771 dump_const_expression(F, lower);
1774 case tpo_enumeration:
1775 for (i = get_enumeration_n_enums(tp); i > 0;) {
1777 dump_enum_item(F, tp, i);
1778 print_enum_item_edge(F, tp, i, "label: \"item %zu\"", i);
1782 print_type_type_edge(F, tp, get_pointer_points_to_type(tp), PTR_PTS_TO_EDGE_ATTR);
1786 case tpo_uninitialized:
1791 break; /* case k_type */
1794 printf(" *** irdump, dump_type_info(l.%i), faulty type.\n", __LINE__);
1798 /** For dumping class hierarchies.
1799 * Dumps a class type node and a superclass edge.
1801 static void dump_class_hierarchy_node(type_or_ent tore, void *ctx)
1803 FILE *F = (FILE*)ctx;
1804 size_t i = 0; /* to shutup gcc */
1806 /* dump this type or entity */
1807 switch (get_kind(tore.ent)) {
1809 ir_entity *ent = tore.ent;
1810 if (get_entity_owner(ent) == get_glob_type()) break;
1811 if (!is_Method_type(get_entity_type(ent)))
1813 if (flags & ir_dump_flag_entities_in_hierarchy
1814 && is_Class_type(get_entity_owner(ent))) {
1816 dump_entity_node(F, ent);
1818 print_type_ent_edge(F, get_entity_owner(ent), ent, TYPE_MEMBER_EDGE_ATTR);
1819 for (i = get_entity_n_overwrites(ent); i > 0;) {
1821 print_ent_ent_edge(F, get_entity_overwrites(ent, i), ent, 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1827 ir_type *tp = tore.typ;
1828 if (tp == get_glob_type())
1830 switch (get_type_tpop_code(tp)) {
1832 dump_type_node(F, tp);
1833 /* and now the edges */
1834 for (i = get_class_n_supertypes(tp); i > 0;) {
1836 print_type_type_edge(F,tp,get_class_supertype(tp, i),TYPE_SUPER_EDGE_ATTR);
1841 break; /* case k_type */
1844 printf(" *** irdump, dump_class_hierarchy_node(l.%i), faulty type.\n", __LINE__);
1848 /*******************************************************************/
1849 /* dump analysis information that is expressed in graph terms. */
1850 /*******************************************************************/
1852 /* dump out edges */
1853 static void dump_out_edge(ir_node *n, void *env)
1855 FILE *F = (FILE*)env;
1857 for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
1858 ir_node *succ = get_irn_out(n, i);
1860 print_node_edge_kind(F, succ);
1861 fprintf(F, "{sourcename: ");
1863 fprintf(F, " targetname: ");
1864 print_nodeid(F, succ);
1865 fprintf(F, " color: red linestyle: dashed");
1870 static void dump_loop_label(FILE *F, const ir_loop *loop)
1872 fprintf(F, "loop %u", get_loop_depth(loop));
1875 static void dump_loop_info(FILE *F, const ir_loop *loop)
1877 fprintf(F, " info1: \"");
1878 fprintf(F, " loop nr: %ld", get_loop_loop_nr(loop));
1879 #ifdef DEBUG_libfirm
1880 fprintf(F, "\n The loop was analyzed %ld times.", (long int) PTR_TO_INT(get_loop_link(loop)));
1885 void print_loopid(FILE *F, const ir_loop *loop)
1887 fprintf(F, "\"l%ld\"", get_loop_loop_nr(loop));
1890 static void dump_loop_node(FILE *F, const ir_loop *loop)
1892 fprintf(F, "node: {title: ");
1893 print_loopid(F, loop);
1894 fprintf(F, " label: \"");
1895 dump_loop_label(F, loop);
1897 dump_loop_info(F, loop);
1901 static void dump_loop_node_edge(FILE *F, const ir_loop *loop, size_t i)
1904 fprintf(F, "edge: {sourcename: ");
1905 print_loopid(F, loop);
1906 fprintf(F, " targetname: ");
1907 print_nodeid(F, get_loop_element(loop, i).node);
1908 fprintf(F, " color: green");
1912 static void dump_loop_son_edge(FILE *F, const ir_loop *loop, size_t i)
1915 fprintf(F, "edge: {sourcename: ");
1916 print_loopid(F, loop);
1917 fprintf(F, " targetname: ");
1918 print_loopid(F, get_loop_element(loop, i).son);
1919 ir_fprintf(F, " color: darkgreen label: \"%zu\"}\n", i);
1922 static void dump_loops(FILE *F, const ir_loop *loop)
1925 size_t n_elements = get_loop_n_elements(loop);
1926 /* dump this loop node */
1927 dump_loop_node(F, loop);
1929 /* dump edges to nodes in loop -- only if it is a real loop */
1930 if (get_loop_depth(loop) != 0) {
1931 for (i = n_elements; i > 0;) {
1932 loop_element element;
1934 element = get_loop_element(loop, i);
1935 if (*element.kind != k_ir_node)
1937 dump_loop_node_edge(F, loop, i);
1940 for (i = n_elements; i > 0;) {
1941 loop_element element;
1943 element = get_loop_element(loop, i);
1944 if (*element.kind != k_ir_loop)
1946 dump_loops(F, element.son);
1947 dump_loop_son_edge(F, loop, i);
1951 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg)
1953 ir_loop *loop = get_irg_loop(irg);
1955 dump_loops(F, loop);
1959 void dump_vcg_header_colors(FILE *F)
1963 for (i = 0; i < ird_color_count; ++i) {
1964 if (color_rgb[i] != NULL) {
1965 fprintf(F, "colorentry %s: %s\n", color_names[i], color_rgb[i]);
1970 void dump_vcg_infonames(FILE *F)
1973 "infoname 1: \"Attribute\"\n"
1974 "infoname 2: \"Verification errors\"\n"
1975 "infoname 3: \"Debug info\"\n", F);
1979 * dumps the VCG header
1981 void dump_vcg_header(FILE *F, const char *name, const char *layout, const char *orientation)
1984 = (flags & ir_dump_flag_disable_edge_labels) ? "no" : "yes";
1986 if (! layout) layout = "Compilergraph";
1987 if (!orientation) orientation = "bottom_to_top";
1991 "graph: { title: \"ir graph of %s\"\n"
1992 "display_edge_labels: %s\n"
1993 "layoutalgorithm: mindepth //$ \"%s\"\n"
1994 "manhattan_edges: yes\n"
1995 "port_sharing: no\n"
1997 "classname 1: \"intrablock Data\"\n"
1998 "classname 2: \"Block\"\n"
1999 "classname 3: \"Entity type\"\n"
2000 "classname 4: \"Entity owner\"\n"
2001 "classname 5: \"Method Param\"\n"
2002 "classname 6: \"Method Res\"\n"
2003 "classname 7: \"Super\"\n"
2004 "classname 8: \"Union\"\n"
2005 "classname 9: \"Points-to\"\n"
2006 "classname 10: \"Array Element Type\"\n"
2007 "classname 11: \"Overwrites\"\n"
2008 "classname 12: \"Member\"\n"
2009 "classname 13: \"Control Flow\"\n"
2010 "classname 14: \"intrablock Memory\"\n"
2011 "classname 15: \"Dominators\"\n"
2012 "classname 16: \"interblock Data\"\n"
2013 "classname 17: \"interblock Memory\"\n"
2014 "classname 18: \"Exception Control Flow for Interval Analysis\"\n"
2015 "classname 19: \"Postdominators\"\n"
2016 "classname 20: \"Keep Alive\"\n"
2017 "classname 21: \"Out Edges\"\n"
2018 "classname 22: \"Macro Block Edges\"\n",
2019 name, label, layout, orientation);
2020 dump_vcg_infonames(F);
2021 dump_vcg_header_colors(F);
2026 * Dumps the vcg file footer
2028 void dump_vcg_footer(FILE *F)
2035 static void dump_blocks_as_subgraphs(FILE *out, ir_graph *irg)
2039 construct_block_lists(irg);
2042 * If we are in the interprocedural view, we dump not
2043 * only the requested irg but also all irgs that can be reached
2046 for (i = get_irp_n_irgs(); i > 0;) {
2047 ir_graph *other_irg = get_irp_irg(--i);
2048 ir_node **arr = (ir_node**)ird_get_irg_link(other_irg);
2052 dump_graph_from_list(out, other_irg);
2057 void dump_ir_graph_file(FILE *out, ir_graph *irg)
2059 dump_vcg_header(out, get_irg_dump_name(irg), NULL, NULL);
2062 if (flags & ir_dump_flag_blocks_as_subgraphs) {
2063 dump_blocks_as_subgraphs(out, irg);
2065 /* dump_node_with_edges must be called in post visiting predecessors */
2066 ird_walk_graph(irg, NULL, dump_node_with_edges, out);
2069 /* dump type info */
2070 if (flags & ir_dump_flag_with_typegraph) {
2071 type_walk_irg(irg, dump_type_info, NULL, out);
2072 inc_irg_visited(get_const_code_irg());
2073 /* dump edges from graph to type info */
2074 irg_walk(get_irg_end(irg), dump_node2type_edges, NULL, out);
2077 /* dump iredges out edges */
2078 if ((flags & ir_dump_flag_iredges) && edges_activated(irg)) {
2079 irg_walk_edges(get_irg_start_block(irg), dump_ir_edges, NULL, out);
2082 /* dump the out edges in a separate walk */
2083 if ((flags & ir_dump_flag_out_edges)
2084 && (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))) {
2085 irg_out_walk(get_irg_start(irg), dump_out_edge, NULL, out);
2088 dump_vcg_footer(out);
2091 static void dump_block_to_cfg(ir_node *block, void *env)
2093 FILE *F = (FILE*)env;
2096 if (is_Bad(block) && get_irn_mode(block) == mode_X) {
2097 dump_node(F, block);
2100 if (is_Block(block)) {
2101 /* This is a block. Dump a node for the block. */
2102 fprintf(F, "node: {title: ");
2103 print_nodeid(F, block);
2104 fprintf(F, " label: \"");
2105 if (block == get_irg_start_block(get_irn_irg(block)))
2106 fprintf(F, "Start ");
2107 if (block == get_irg_end_block(get_irn_irg(block)))
2110 fprintf(F, "%s ", get_op_name(get_irn_op(block)));
2111 print_nodeid(F, block);
2113 fprintf(F, "info1:\"");
2115 /* the generic version. */
2116 dump_irnode_to_file(F, block);
2118 fprintf(F, "\""); /* closing quote of info */
2120 if ((block == get_irg_start_block(get_irn_irg(block))) ||
2121 (block == get_irg_end_block(get_irn_irg(block))) )
2122 fprintf(F, " color:blue ");
2126 /* Dump the edges */
2127 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
2128 ir_node *pred = get_Block_cfgpred(block, i);
2130 pred = get_nodes_block(pred);
2131 fprintf(F, "edge: { sourcename: ");
2132 print_nodeid(F, block);
2133 fprintf(F, " targetname: ");
2134 print_nodeid(F, pred);
2135 fprintf(F, "\"}\n");
2138 /* Dump dominator/postdominator edge */
2139 if (ir_get_dump_flags() & ir_dump_flag_dominance) {
2140 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE) && get_Block_idom(block)) {
2141 ir_node *pred = get_Block_idom(block);
2142 fprintf(F, "edge: { sourcename: ");
2143 print_nodeid(F, block);
2144 fprintf(F, " targetname: ");
2145 print_nodeid(F, pred);
2146 fprintf(F, " " DOMINATOR_EDGE_ATTR "}\n");
2148 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE) && get_Block_ipostdom(block)) {
2149 ir_node *pred = get_Block_ipostdom(block);
2150 fprintf(F, "edge: { sourcename: ");
2151 print_nodeid(F, block);
2152 fprintf(F, " targetname: ");
2153 print_nodeid(F, pred);
2154 fprintf(F, " " POSTDOMINATOR_EDGE_ATTR "}\n");
2160 void dump_cfg(FILE *F, ir_graph *irg)
2162 dump_vcg_header(F, get_irg_dump_name(irg), NULL, NULL);
2164 /* walk over the blocks in the graph */
2165 irg_walk_graph(irg, dump_block_to_cfg, NULL, F);
2170 void dump_callgraph(FILE *F)
2173 ir_dump_flags_t old_flags = ir_get_dump_flags();
2175 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2176 dump_vcg_header(F, "Callgraph", "Hierarchic", NULL);
2178 for (i = get_irp_n_irgs(); i > 0;) {
2179 ir_graph *irg = get_irp_irg(--i);
2180 ir_entity *ent = get_irg_entity(irg);
2181 size_t j, n_callees = get_irg_n_callees(irg);
2183 dump_entity_node(F, ent);
2184 for (j = 0; j < n_callees; ++j) {
2185 ir_entity *c = get_irg_entity(get_irg_callee(irg, j));
2186 int be = is_irg_callee_backedge(irg, j);
2187 const char *attr = be
2188 ? "label:\"recursion %zu\""
2189 : "label:\"calls %zu\"";
2190 print_ent_ent_edge(F, ent, c, be, ird_color_entity, attr,
2191 get_irg_callee_loop_depth(irg, j));
2195 ir_set_dump_flags(old_flags);
2199 void dump_typegraph(FILE *out)
2201 dump_vcg_header(out, "All_types", NULL, NULL);
2202 type_walk(dump_type_info, NULL, out);
2203 dump_vcg_footer(out);
2206 void dump_class_hierarchy(FILE *out)
2208 dump_vcg_header(out, "class_hierarchy", NULL, NULL);
2209 type_walk(dump_class_hierarchy_node, NULL, out);
2210 dump_vcg_footer(out);
2213 static void dump_loops_standalone(FILE *F, ir_loop *loop)
2216 bool loop_node_started = false;
2218 size_t son_number = 0;
2220 ir_loop *son = NULL;
2222 /* Dump a new loop node. */
2223 dump_loop_node(F, loop);
2225 /* Dump the loop elements. */
2226 for (i = 0; i < get_loop_n_elements(loop); i++) {
2227 le = get_loop_element(loop, i);
2229 if (get_kind(son) == k_ir_loop) {
2231 /* We are a loop son -> Recurse */
2233 if (loop_node_started) { /* Close the "firm-nodes" node first if we started one. */
2234 fprintf(F, "\" }\n");
2235 fprintf(F, "edge: {sourcename: ");
2236 print_loopid(F, loop);
2237 fprintf(F, " targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2238 get_loop_loop_nr(loop),
2239 (unsigned long) first,
2240 (unsigned long) first,
2241 (unsigned long) i-1);
2242 loop_node_started = false;
2244 dump_loop_son_edge(F, loop, son_number++);
2245 dump_loops_standalone(F, son);
2246 } else if (get_kind(son) == k_ir_node) {
2247 /* We are a loop node -> Collect firm nodes */
2249 ir_node *n = le.node;
2250 if (!loop_node_started) {
2251 /* Start a new node which contains all firm nodes of the current loop */
2252 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2253 get_loop_loop_nr(loop),
2255 loop_node_started = true;
2260 dump_node_label(F, n);
2261 if (has_backedges(n)) fprintf(F, "\t loop head!");
2262 } else { /* for callgraph loop tree */
2264 assert(get_kind(son) == k_ir_graph);
2266 /* We are a loop node -> Collect firm graphs */
2268 if (!loop_node_started) {
2269 /* Start a new node which contains all firm nodes of the current loop */
2270 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2271 get_loop_loop_nr(loop),
2273 loop_node_started = true;
2277 fprintf(F, " %s", get_irg_dump_name(n));
2278 /* fprintf(F, " %s (depth %d)", get_irg_dump_name(n), n->callgraph_weighted_loop_depth); */
2282 if (loop_node_started) {
2283 fprintf(F, "\" }\n");
2284 fprintf(F, "edge: {sourcename: \"");
2285 print_loopid(F, loop);
2286 fprintf(F, "\" targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2287 get_loop_loop_nr(loop),
2288 (unsigned long) first,
2289 (unsigned long) first,
2290 (unsigned long) i-1);
2294 void dump_loop_tree(FILE *out, ir_graph *irg)
2296 ir_dump_flags_t old_flags = ir_get_dump_flags();
2298 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2300 dump_vcg_header(out, get_irg_dump_name(irg), "Tree", "top_to_bottom");
2302 if (get_irg_loop(irg))
2303 dump_loops_standalone(out, get_irg_loop(irg));
2305 dump_vcg_footer(out);
2307 ir_set_dump_flags(old_flags);
2310 void dump_callgraph_loop_tree(FILE *out)
2312 dump_vcg_header(out, "callgraph looptree", "Tree", "top_to_bottom");
2313 dump_loops_standalone(out, irp->outermost_cg_loop);
2314 dump_vcg_footer(out);
2317 static void collect_nodeloop(FILE *F, ir_loop *loop, pset *loopnodes)
2321 int node_number = 0;
2323 if (flags & ir_dump_flag_loops)
2324 dump_loop_node(F, loop);
2326 for (i = 0; i < get_loop_n_elements(loop); i++) {
2327 loop_element le = get_loop_element(loop, i);
2328 if (*(le.kind) == k_ir_loop) {
2329 if (flags & ir_dump_flag_loops)
2330 dump_loop_son_edge(F, loop, son_number++);
2332 collect_nodeloop(F, le.son, loopnodes);
2334 if (flags & ir_dump_flag_loops)
2335 dump_loop_node_edge(F, loop, node_number++);
2336 pset_insert_ptr(loopnodes, le.node);
2341 static void collect_nodeloop_external_nodes(ir_loop *loop, pset *loopnodes,
2347 for (i = 0; i < get_loop_n_elements(loop); i++) {
2348 loop_element le = get_loop_element(loop, i);
2349 if (*(le.kind) == k_ir_loop) {
2351 collect_nodeloop_external_nodes(le.son, loopnodes, extnodes);
2353 if (is_Block(le.node)) start = 0; else start = -1;
2354 for (j = start; j < get_irn_arity(le.node); j++) {
2355 ir_node *pred = get_irn_n(le.node, j);
2356 if (!pset_find_ptr(loopnodes, pred)) {
2357 pset_insert_ptr(extnodes, pred);
2358 if (!is_Block(pred)) {
2359 pred = get_nodes_block(pred);
2360 if (!pset_find_ptr(loopnodes, pred))
2361 pset_insert_ptr(extnodes, pred);
2369 void dump_loop(FILE *F, ir_loop *l)
2371 pset *loopnodes = pset_new_ptr_default();
2372 pset *extnodes = pset_new_ptr_default();
2375 snprintf(name, sizeof(name), "loop_%ld", get_loop_loop_nr(l));
2376 dump_vcg_header(F, name, NULL, NULL);
2378 /* collect all nodes to dump */
2379 collect_nodeloop(F, l, loopnodes);
2380 collect_nodeloop_external_nodes(l, loopnodes, extnodes);
2382 /* build block lists */
2383 foreach_pset(loopnodes, ir_node, n) {
2384 set_irn_link(n, NULL);
2386 foreach_pset(extnodes, ir_node, n) {
2387 set_irn_link(n, NULL);
2389 foreach_pset(loopnodes, ir_node, n) {
2391 ir_node *const b = get_nodes_block(n);
2392 set_irn_link(n, get_irn_link(b));
2396 foreach_pset(extnodes, ir_node, n) {
2398 ir_node *const b = get_nodes_block(n);
2399 set_irn_link(n, get_irn_link(b));
2404 foreach_pset(loopnodes, ir_node, b) {
2406 fprintf(F, "graph: { title: ");
2408 fprintf(F, " label: \"");
2409 dump_node_opcode(F, b);
2410 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2411 fprintf(F, "\" status:clustered color:yellow\n");
2413 /* dump the blocks edges */
2414 dump_ir_data_edges(F, b);
2416 /* dump the nodes that go into the block */
2417 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2418 if (pset_find_ptr(extnodes, n))
2419 overrule_nodecolor = ird_color_block_inout;
2421 overrule_nodecolor = ird_color_default_node;
2422 if (!pset_find_ptr(extnodes, n)) dump_ir_data_edges(F, n);
2425 /* Close the vcg information for the block */
2427 dump_const_node_local(F, b);
2431 foreach_pset(extnodes, ir_node, b) {
2433 fprintf(F, "graph: { title: ");
2435 fprintf(F, " label: \"");
2436 dump_node_opcode(F, b);
2437 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2438 fprintf(F, "\" status:clustered color:lightblue\n");
2440 /* dump the nodes that go into the block */
2441 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2442 if (!pset_find_ptr(loopnodes, n))
2443 overrule_nodecolor = ird_color_block_inout;
2445 overrule_nodecolor = ird_color_default_node;
2446 if (pset_find_ptr(loopnodes, n)) dump_ir_data_edges(F, n);
2449 /* Close the vcg information for the block */
2451 dump_const_node_local(F, b);
2455 del_pset(loopnodes);
2461 static bool obstack_init;
2462 static struct obstack obst;
2463 static char *dump_path;
2465 void ir_set_dump_path(const char *path)
2468 dump_path = xstrdup(path);
2471 static void add_string_escaped(const char *string)
2474 for (p = string; *p != '\0'; ++p) {
2477 obstack_1grow(&obst, '@');
2478 obstack_1grow(&obst, '1');
2479 } else if (c == '@') {
2480 obstack_1grow(&obst, '@');
2481 obstack_1grow(&obst, '2');
2483 obstack_1grow(&obst, c);
2488 static void add_dump_path(void)
2490 if (!obstack_init) {
2491 obstack_init(&obst);
2492 obstack_init = true;
2495 if (dump_path != NULL) {
2496 size_t len = strlen(dump_path);
2497 obstack_grow(&obst, dump_path, len);
2498 if (len > 0 && dump_path[len-1] != '/')
2499 obstack_1grow(&obst, '/');
2503 void dump_ir_graph_ext(ir_graph_dump_func func, ir_graph *graph,
2506 const char *dump_name = get_irg_dump_name(graph);
2510 if (!ir_should_dump(dump_name))
2515 add_string_escaped(dump_name);
2516 obstack_printf(&obst, "-%02u", graph->dump_nr++);
2518 if (suffix != NULL) {
2519 if (suffix[0] != '.')
2520 obstack_1grow(&obst, '-');
2521 add_string_escaped(suffix);
2523 obstack_1grow(&obst, '\0');
2525 file_name = (char*)obstack_finish(&obst);
2526 /* xvcg expects only <LF> so we need "b"inary mode (for win32) */
2527 out = fopen(file_name, "wb");
2528 obstack_free(&obst, file_name);
2531 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2539 void dump_ir_prog_ext(ir_prog_dump_func func, const char *suffix)
2546 obstack_printf(&obst, "%02u", irp->dump_nr++);
2547 if (suffix != NULL) {
2548 if (suffix[0] != '.')
2549 obstack_1grow(&obst, '-');
2550 add_string_escaped(suffix);
2552 obstack_1grow(&obst, '\0');
2554 file_name = (char*)obstack_finish(&obst);
2555 out = fopen(file_name, "wb");
2556 obstack_free(&obst, file_name);
2559 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2566 void dump_ir_graph(ir_graph *graph, const char *suffix)
2570 snprintf(buf, sizeof(buf), "%s.vcg", suffix);
2571 dump_ir_graph_ext(dump_ir_graph_file, graph, buf);
2574 void dump_all_ir_graphs(const char *suffix)
2576 size_t i, n_irgs = get_irp_n_irgs();
2578 for (i = 0; i < n_irgs; ++i) {
2579 ir_graph *irg = get_irp_irg(i);
2580 dump_ir_graph(irg, suffix);
2584 typedef struct pass_t {
2585 ir_prog_pass_t pass;
2590 * Wrapper around dump_all_ir_graphs().
2592 static int dump_all_ir_graphs_wrapper(ir_prog *irp, void *context)
2594 pass_t *pass = (pass_t*)context;
2597 dump_all_ir_graphs(pass->suffix);
2601 ir_prog_pass_t *dump_all_ir_graph_pass(const char *name, const char *suffix)
2603 size_t len = strlen(suffix) + 1;
2604 pass_t *pass = XMALLOCF(pass_t, suffix, len);
2605 ir_prog_pass_t *res = def_prog_pass_constructor(
2606 &pass->pass, name ? name : "dump_all_graphs", dump_all_ir_graphs_wrapper);
2608 /* this pass does not change anything, so neither dump nor verify is needed. */
2609 res->dump_irprog = ir_prog_no_dump;
2610 res->verify_irprog = ir_prog_no_verify;
2612 memcpy(pass->suffix, suffix, len);