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 const char *get_mode_name_ex(const ir_mode *mode, int *bad)
301 return get_mode_name(mode);
307 #define CUSTOM_COLOR_BASE 100
308 static const char *color_names[ird_color_count];
309 static const char *color_rgb[ird_color_count];
310 static struct obstack color_obst;
312 /** define a custom color. */
313 static void custom_color(int num, const char *rgb_def)
315 assert(num < ird_color_count);
316 obstack_printf(&color_obst, "%d", CUSTOM_COLOR_BASE + num);
317 obstack_1grow(&color_obst, '\0');
319 color_rgb[num] = rgb_def;
320 color_names[num] = (const char*)obstack_finish(&color_obst);
323 /** Define a named color. */
324 static void named_color(int num, const char *name)
326 assert(num < ird_color_count);
327 color_rgb[num] = NULL;
328 color_names[num] = name;
331 /** Initializes the used colors. */
332 static void init_colors(void)
334 static bool initialized = 0;
338 obstack_init(&color_obst);
340 custom_color(ird_color_prog_background, "204 204 204");
341 custom_color(ird_color_block_background, "255 255 0");
342 custom_color(ird_color_dead_block_background, "190 150 150");
343 named_color(ird_color_block_inout, "lightblue");
344 named_color(ird_color_default_node, "white");
345 custom_color(ird_color_memory, "153 153 255");
346 custom_color(ird_color_controlflow, "255 153 153");
347 custom_color(ird_color_const, "204 255 255");
348 custom_color(ird_color_proj, "255 255 153");
349 custom_color(ird_color_uses_memory, "153 153 255");
350 custom_color(ird_color_phi, "105 255 105");
351 custom_color(ird_color_anchor, "100 100 255");
352 named_color(ird_color_error, "red");
353 custom_color(ird_color_entity, "204 204 255");
359 * Prints the VCG color to a file.
361 static void print_vcg_color(FILE *out, ird_color_t color)
363 assert(color < ird_color_count);
364 fprintf(out, "color:%s", color_names[color]);
367 void print_nodeid(FILE *F, const ir_node *node)
369 fprintf(F, "\"n%ld\"", get_irn_node_nr(node));
372 void print_irgid(FILE *F, const ir_graph *irg)
374 fprintf(F, "\"g%ld\"", get_irg_graph_nr(irg));
377 void print_typeid(FILE *F, const ir_type *type)
379 fprintf(F, "\"t%ld\"", get_type_nr(type));
382 void print_entityid(FILE *F, const ir_entity *entity)
384 fprintf(F, "\"e%ld\"", get_entity_nr(entity));
387 static void print_itemid(FILE *F, const ir_type *tp, size_t itemnr)
389 fprintf(F, "\"i%ldT%zu\"", get_type_nr(tp), itemnr);
393 * Prints the edge kind of a given IR node.
395 * Projs should be dumped near their predecessor, so they get "nearedge".
397 static void print_node_edge_kind(FILE *out, const ir_node *node)
400 fprintf(out, "nearedge: ");
402 fprintf(out, "edge: ");
407 * Prints the edge from a type S to a type T with additional info fmt, ...
410 static void print_type_type_edge(FILE *F, const ir_type *S, const ir_type *T, const char *fmt, ...)
415 fprintf(F, "edge: { sourcename: ");
417 fprintf(F, " targetname: ");
419 ir_vfprintf(F, fmt, ap);
425 * Prints the edge from a type tp to an entity ent with additional info fmt, ...
428 static void print_type_ent_edge(FILE *F, const ir_type *tp, const ir_entity *ent, const char *fmt, ...)
433 fprintf(F, "edge: { sourcename: ");
435 fprintf(F, " targetname: ");
436 print_entityid(F, ent);
437 ir_vfprintf(F, fmt, ap);
443 * Prints the edge from an entity ent1 to an entity ent2 with additional info fmt, ...
446 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, ...)
452 fprintf(F, "backedge: { sourcename: ");
454 fprintf(F, "edge: { sourcename: ");
455 print_entityid(F, ent1);
456 fprintf(F, " targetname: ");
457 print_entityid(F, ent2);
458 ir_vfprintf(F, fmt, ap);
460 if (color != ird_color_none)
461 print_vcg_color(F, color);
467 * Prints the edge from an entity ent to a type tp with additional info fmt, ...
470 static void print_ent_type_edge(FILE *F, const ir_entity *ent, const ir_type *tp, const char *fmt, ...)
475 fprintf(F, "edge: { sourcename: ");
476 print_entityid(F, ent);
477 fprintf(F, " targetname: ");
479 ir_vfprintf(F, fmt, ap);
485 * Prints the edge from a node irn to a type tp with additional info fmt, ...
488 static void print_node_type_edge(FILE *F, const ir_node *irn, ir_type *tp, const char *fmt, ...)
493 fprintf(F, "edge: { sourcename: ");
494 print_nodeid(F, irn);
495 fprintf(F, " targetname: ");
497 ir_vfprintf(F, fmt, ap);
503 * Prints the edge from a node irn to an entity ent with additional info fmt, ...
506 static void print_node_ent_edge(FILE *F, const ir_node *irn, const ir_entity *ent, const char *fmt, ...)
511 fprintf(F, "edge: { sourcename: ");
512 print_nodeid(F, irn);
513 fprintf(F, " targetname: ");
514 print_entityid(F, ent);
515 ir_vfprintf(F, fmt, ap);
521 * Prints the edge from a type tp to an enumeration item item with additional info fmt, ...
524 static void print_enum_item_edge(FILE *F, const ir_type *tp, size_t item, const char *fmt, ...)
529 fprintf(F, "edge: { sourcename: ");
531 fprintf(F, " targetname: ");
532 print_itemid(F, tp, item);
533 ir_vfprintf(F, fmt, ap);
538 /*-----------------------------------------------------------------*/
539 /* global and ahead declarations */
540 /*-----------------------------------------------------------------*/
542 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg);
544 /*-----------------------------------------------------------------*/
545 /* Helper functions. */
546 /*-----------------------------------------------------------------*/
549 * This map is used as a private link attr to be able to call dumper
550 * anywhere without destroying link fields.
552 static pmap *irdump_link_map = NULL;
554 /** NOT A STANDARD LIBFIRM INIT METHOD
556 * We do not want to integrate dumping into libfirm, i.e., if the dumpers
557 * are off, we want to have as few interferences as possible. Therefore the
558 * initialization is performed lazily and not called from within init_firm.
560 * Creates the link attribute map. */
561 static void init_irdump(void)
563 /* We need a new, empty map. */
564 if (irdump_link_map) pmap_destroy(irdump_link_map);
565 irdump_link_map = pmap_create();
566 if (!dump_file_filter_id)
567 dump_file_filter_id = new_id_from_str("");
571 * Returns the private link field.
573 static void *ird_get_irn_link(const ir_node *n)
575 if (irdump_link_map == NULL)
578 return pmap_get(void, irdump_link_map, n);
582 * Sets the private link field.
584 static void ird_set_irn_link(const ir_node *n, void *x)
586 if (irdump_link_map == NULL)
588 pmap_insert(irdump_link_map, n, x);
592 * Gets the private link field of an irg.
594 static void *ird_get_irg_link(const ir_graph *irg)
596 if (irdump_link_map == NULL)
599 return pmap_get(void, irdump_link_map, irg);
603 * Sets the private link field of an irg.
605 static void ird_set_irg_link(const ir_graph *irg, void *x)
607 if (irdump_link_map == NULL)
609 pmap_insert(irdump_link_map, irg, x);
613 * Walker, clears the private link field.
615 static void clear_link(ir_node *node, void *env)
618 ird_set_irn_link(node, NULL);
622 * If the entity has a ld_name, returns it if the dump_ld_name is set,
623 * else returns the name of the entity.
625 static const char *get_ent_dump_name_(const ir_entity *ent, bool dump_ld_name)
628 return "<NULL entity>";
630 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
631 if (ent->ld_name != NULL)
632 return get_id_str(ent->ld_name);
634 return get_id_str(ent->name);
637 const char *get_ent_dump_name(const ir_entity *ent)
639 return get_ent_dump_name_(ent, flags & ir_dump_flag_ld_names);
642 const char *get_irg_dump_name(const ir_graph *irg)
644 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
645 return get_ent_dump_name_(get_irg_entity(irg), true);
649 * Returns non-zero if a node is in floating state.
651 static int node_floats(const ir_node *n)
653 ir_graph *irg = get_irn_irg(n);
654 return ((get_irn_pinned(n) == op_pin_state_floats) &&
655 (get_irg_pinned(irg) == op_pin_state_floats));
659 * Walker that visits the anchors
661 static void ird_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
663 if ((flags & ir_dump_flag_all_anchors)
664 || ((flags & ir_dump_flag_iredges) && edges_activated(irg))) {
665 irg_walk_anchors(irg, pre, post, env);
667 irg_walk_graph(irg, pre, post, env);
672 * Walker, allocates an array for all blocks and puts their non-floating
673 * nodes into this array.
675 static void collect_node(ir_node *node, void *env)
680 || (get_op_flags(get_irn_op(node)) & irop_flag_dump_noblock)) {
681 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
682 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
683 ARR_APP1(ir_node *, arr, node);
684 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
686 ir_node * block = get_nodes_block(node);
689 /* this node is in a Bad block, so we must place it into the graph's list */
690 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
691 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
692 ARR_APP1(ir_node *, arr, node);
693 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
695 ird_set_irn_link(node, ird_get_irn_link(block));
696 ird_set_irn_link(block, node);
701 /** Construct lists to walk ir block-wise.
703 * Collects all blocks, nodes not op_pin_state_pinned,
704 * Bad, NoMem and Unknown into a flexible array in link field of
705 * irg they belong to. Sets the irg link field to NULL in all
706 * graphs not visited.
707 * Free the list with DEL_ARR_F().
709 static ir_node **construct_block_lists(ir_graph *irg)
712 int walk_flag = ir_resources_reserved(irg) & IR_RESOURCE_IRN_VISITED;
715 ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
718 for (i = get_irp_n_irgs(); i > 0;)
719 ird_set_irg_link(get_irp_irg(--i), NULL);
721 ird_walk_graph(irg, clear_link, collect_node, irg);
724 ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
727 return (ir_node**)ird_get_irg_link(irg);
730 void dump_node_opcode(FILE *F, const ir_node *n)
732 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
734 /* call the dump_node operation if available */
735 if (ops->dump_node) {
736 ops->dump_node(F, n, dump_node_opcode_txt);
740 /* implementation for default nodes */
741 switch (get_irn_opcode(n)) {
743 switch (get_SymConst_kind(n)) {
744 case symconst_addr_ent:
745 fprintf(F, "SymC &%s", get_entity_name(get_SymConst_entity(n)));
747 case symconst_ofs_ent:
748 fprintf(F, "SymC %s offset", get_entity_name(get_SymConst_entity(n)));
750 case symconst_type_size:
751 ir_fprintf(F, "SymC %+F size", get_SymConst_type(n));
753 case symconst_type_align:
754 ir_fprintf(F, "SymC %+F align", get_SymConst_type(n));
756 case symconst_enum_const:
757 fprintf(F, "SymC %s enum", get_enumeration_const_name(get_SymConst_enum(n)));
763 if (get_Load_unaligned(n) == align_non_aligned)
765 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Load_mode(n), NULL));
768 if (get_Store_unaligned(n) == align_non_aligned)
770 fprintf(F, "%s", get_irn_opname(n));
773 if (n == get_irg_start_block(get_irn_irg(n)))
775 if (n == get_irg_end_block(get_irn_irg(n)))
777 fprintf(F, "%s%s", get_irn_opname(n),
778 (flags & ir_dump_flag_show_marks) ? (get_Block_mark(n) ? "*" : "") : "");
781 fprintf(F, "%s", get_irn_opname(n));
782 if (get_Div_no_remainder(n))
784 fprintf(F, "[%s]", get_mode_name_ex(get_Div_resmode(n), NULL));
787 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Mod_resmode(n), NULL));
790 fprintf(F, "%s[%s]", get_irn_opname(n), get_builtin_kind_name(get_Builtin_kind(n)));
794 fprintf(F, "%s", get_irn_opname(n));
799 * Dump the mode of a node n to a file F.
800 * Ignore modes that are "always known".
802 static void dump_node_mode(FILE *F, const ir_node *n)
804 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
808 /* call the dump_node operation if available */
809 if (ops->dump_node) {
810 ops->dump_node(F, n, dump_node_mode_txt);
814 /* default implementation */
815 iro = get_irn_opcode(n);
827 mode = get_irn_mode(n);
829 if (mode != NULL && mode != mode_BB && mode != mode_ANY && mode != mode_BAD &&
830 (mode != mode_T || iro == iro_Proj))
831 fprintf(F, "%s", get_mode_name_ex(mode, NULL));
836 * Dump the type of a node n to a file F if it's known.
838 static int dump_node_typeinfo(FILE *F, const ir_node *n)
840 ir_graph *irg = get_irn_irg(n);
843 if (ir_get_dump_flags() & ir_dump_flag_analysed_types) {
844 if (get_irg_typeinfo_state(irg) == ir_typeinfo_consistent ||
845 get_irg_typeinfo_state(irg) == ir_typeinfo_inconsistent) {
846 ir_type *tp = get_irn_typeinfo_type(n);
847 if (tp != get_none_type()) {
848 ir_fprintf(F, "[%+F]", tp);
858 * Dump additional node attributes of some nodes to a file F.
860 static void dump_node_nodeattr(FILE *F, const ir_node *n)
865 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
867 /* call the dump_node operation if available */
868 if (ops->dump_node) {
869 ops->dump_node(F, n, dump_node_nodeattr_txt);
873 switch (get_irn_opcode(n)) {
875 ir_fprintf(F, "%T ", get_Const_tarval(n));
879 pred = get_Proj_pred(n);
880 proj_nr = get_Proj_proj(n);
881 code = get_irn_opcode(pred);
883 if (code == iro_Proj && get_irn_opcode(get_Proj_pred(pred)) == iro_Start) {
884 fprintf(F, "Arg %ld ", proj_nr);
886 unsigned i, j, f = 0;
888 for (i = 0; i < ARRAY_SIZE(proj_lut); ++i) {
889 if (code == proj_lut[i].code) {
890 for (j = 0; j < proj_lut[i].num_data; ++j) {
891 if (proj_nr == proj_lut[i].data[j].nr) {
892 fprintf(F, "%s ", proj_lut[i].data[j].name);
901 fprintf(F, "%ld ", proj_nr);
902 if (code == iro_Cond && get_Cond_jmp_pred(pred) != COND_JMP_PRED_NONE) {
903 if (proj_nr == pn_Cond_false && get_Cond_jmp_pred(pred) == COND_JMP_PRED_FALSE)
905 if (proj_nr == pn_Cond_true && get_Cond_jmp_pred(pred) == COND_JMP_PRED_TRUE)
911 fprintf(F, "%s ", get_ent_dump_name(get_Sel_entity(n)));
914 ir_fprintf(F, "(%+F)", get_Cast_type(n));
917 fprintf(F, "%s ", get_relation_string(get_Cmp_relation(n)));
920 fprintf(F, "%s ", get_relation_string(get_Confirm_relation(n)));
923 ir_fprintf(F, "(%+F)", get_CopyB_type(n));
931 void dump_node_label(FILE *F, const ir_node *n)
933 dump_node_opcode(F, n);
935 dump_node_mode(F, n);
937 dump_node_typeinfo(F, n);
938 dump_node_nodeattr(F, n);
939 if (flags & ir_dump_flag_number_label) {
940 fprintf(F, "%ld", get_irn_node_nr(n));
942 if (flags & ir_dump_flag_idx_label) {
943 fprintf(F, ":%u", get_irn_idx(n));
948 * Dumps the attributes of a node n into the file F.
949 * Currently this is only the color of a node.
951 static void dump_node_vcgattr(FILE *F, const ir_node *node, const ir_node *local, bool bad)
957 print_vcg_color(F, ird_color_error);
961 if (dump_node_vcgattr_hook != NULL) {
962 dump_node_vcgattr_hook(F, node, local);
966 n = local ? local : node;
968 if (overrule_nodecolor != ird_color_default_node) {
969 print_vcg_color(F, overrule_nodecolor);
973 mode = get_irn_mode(n);
974 if (mode == mode_M) {
975 print_vcg_color(F, ird_color_memory);
978 if (mode == mode_X) {
979 print_vcg_color(F, ird_color_controlflow);
983 switch (get_irn_opcode(n)) {
986 print_vcg_color(F, ird_color_anchor);
989 print_vcg_color(F, ird_color_error);
992 print_vcg_color(F, ird_color_block_background);
995 print_vcg_color(F, ird_color_phi);
998 print_vcg_color(F, ird_color_memory);
1002 print_vcg_color(F, ird_color_const);
1005 print_vcg_color(F, ird_color_proj);
1008 ir_op *op = get_irn_op(node);
1010 if (is_op_constlike(op)) {
1011 print_vcg_color(F, ird_color_const);
1012 } else if (is_op_uses_memory(op)) {
1013 print_vcg_color(F, ird_color_uses_memory);
1014 } else if (is_op_cfopcode(op) || is_op_forking(op)) {
1015 print_vcg_color(F, ird_color_controlflow);
1021 void *dump_add_node_info_callback(dump_node_info_cb_t *cb, void *data)
1023 hook_entry_t *info = XMALLOCZ(hook_entry_t);
1025 info->hook._hook_node_info = cb;
1026 info->context = data;
1027 register_hook(hook_node_info, info);
1032 void dump_remove_node_info_callback(void *handle)
1034 hook_entry_t *info = (hook_entry_t*)handle;
1035 unregister_hook(hook_node_info, info);
1040 * Dump the node information of a node n to a file F.
1042 static void dump_node_info(FILE *F, const ir_node *n)
1044 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
1046 fprintf(F, " info1: \"");
1047 dump_irnode_to_file(F, n);
1048 /* call the dump_node operation if available */
1050 ops->dump_node(F, n, dump_node_info_txt);
1052 /* allow additional info to be added */
1053 hook_node_info(F, n);
1057 static int is_constlike_node(const ir_node *node)
1059 const ir_op *op = get_irn_op(node);
1060 return is_op_constlike(op);
1063 static void print_constid(FILE *F, const ir_node *user, const ir_node *node)
1065 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(user), get_irn_node_nr(node));
1068 static void print_constblkid(FILE *F, const ir_node *node, const ir_node *block)
1070 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(node), get_irn_node_nr(block));
1074 /** outputs the predecessors of n, that are constants, local. I.e.,
1075 generates a copy of the constant predecessors for each node called with. */
1076 static void dump_const_node_local(FILE *F, const ir_node *n)
1078 ir_graph *irg = get_irn_irg(n);
1080 if (!get_opt_dump_const_local()) return;
1082 /* Use visited flag to avoid outputting nodes twice.
1083 initialize it first. */
1084 for (i = 0; i < get_irn_arity(n); i++) {
1085 ir_node *con = get_irn_n(n, i);
1086 if (is_constlike_node(con)) {
1087 set_irn_visited(con, get_irg_visited(irg) - 1);
1091 for (i = 0; i < get_irn_arity(n); i++) {
1092 ir_node *con = get_irn_n(n, i);
1093 if (is_constlike_node(con) && !irn_visited_else_mark(con)) {
1094 /* Generate a new name for the node by appending the names of
1096 fprintf(F, "node: {title: ");
1097 print_constid(F, n, con);
1098 fprintf(F, " label: \"");
1099 dump_node_label(F, con);
1101 dump_node_info(F, con);
1102 dump_node_vcgattr(F, n, con, 0);
1108 /** If the block of an edge is a const_like node, dump it local with an edge */
1109 static void dump_const_block_local(FILE *F, const ir_node *n)
1113 if (!get_opt_dump_const_local()) return;
1115 blk = get_nodes_block(n);
1116 if (is_constlike_node(blk)) {
1117 /* Generate a new name for the node by appending the names of
1119 fprintf(F, "node: {title: ");
1120 print_constblkid(F, n, blk);
1121 fprintf(F, " label: \"");
1122 dump_node_label(F, blk);
1124 dump_node_info(F, blk);
1125 dump_node_vcgattr(F, n, blk, 0);
1128 fprintf(F, "edge: { sourcename: ");
1130 fprintf(F, " targetname: ");
1131 print_constblkid(F, n, blk);
1134 if (dump_edge_vcgattr_hook != NULL
1135 && dump_edge_vcgattr_hook(F, n, -1)) {
1140 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1145 * prints the error message of a node to a file F as info2.
1147 static void print_node_error(FILE *F, const char *err_msg)
1152 fprintf(F, " info2: \"%s\"", err_msg);
1156 * prints debug messages of a node to file F as info3.
1158 static void print_dbg_info(FILE *F, dbg_info *dbg)
1162 ir_dbg_info_snprint(buf, sizeof(buf), dbg);
1164 fprintf(F, " info3: \"%s\"\n", buf);
1168 static void print_type_dbg_info(FILE *F, type_dbg_info *dbg)
1178 void dump_node(FILE *F, const ir_node *n)
1184 if (get_opt_dump_const_local() && is_constlike_node(n))
1187 /* dump this node */
1188 fputs("node: {title: ", F);
1191 fputs(" label: \"", F);
1192 irg = get_irn_irg(n);
1193 bad = ! irn_verify_irg_dump(n, irg, &p);
1194 dump_node_label(F, n);
1197 dump_node_info(F, n);
1198 print_node_error(F, p);
1199 print_dbg_info(F, get_irn_dbg_info(n));
1200 dump_node_vcgattr(F, n, NULL, bad);
1202 dump_const_node_local(F, n);
1206 /** dump the edge to the block this node belongs to */
1207 static void dump_ir_block_edge(FILE *F, const ir_node *n)
1209 if (get_opt_dump_const_local() && is_constlike_node(n)) return;
1211 ir_node *block = get_nodes_block(n);
1213 if (get_opt_dump_const_local() && is_constlike_node(block)) {
1214 dump_const_block_local(F, n);
1216 fprintf(F, "edge: { sourcename: ");
1218 fprintf(F, " targetname: ");
1219 print_nodeid(F, block);
1222 if (dump_edge_vcgattr_hook && dump_edge_vcgattr_hook(F, n, -1)) {
1227 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1232 static void print_data_edge_vcgattr(FILE *F, const ir_node *from, int to)
1235 * do not use get_nodes_block() here, will fail
1236 * if the irg is not pinned.
1238 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1239 fprintf(F, INTRA_DATA_EDGE_ATTR);
1241 fprintf(F, INTER_DATA_EDGE_ATTR);
1244 static void print_mem_edge_vcgattr(FILE *F, const ir_node *from, int to)
1247 * do not use get_nodes_block() here, will fail
1248 * if the irg is not pinned.
1250 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1251 fprintf(F, INTRA_MEM_EDGE_ATTR);
1253 fprintf(F, INTER_MEM_EDGE_ATTR);
1256 /** Print the vcg attributes for the edge from node "from" to its "to"th input */
1257 static void print_edge_vcgattr(FILE *F, const ir_node *from, int to)
1261 if (dump_edge_vcgattr_hook)
1262 if (dump_edge_vcgattr_hook(F, from, to))
1265 if ((flags & ir_dump_flag_back_edges) && is_backedge(from, to))
1266 fprintf(F, BACK_EDGE_ATTR);
1268 switch (get_irn_opcode(from)) {
1270 fprintf(F, CF_EDGE_ATTR);
1272 case iro_Start: break;
1275 if (get_irn_mode(get_End_keepalive(from, to)) == mode_BB)
1276 fprintf(F, KEEP_ALIVE_CF_EDGE_ATTR);
1278 fprintf(F, KEEP_ALIVE_DF_EDGE_ATTR);
1282 if (is_Proj(from)) {
1283 if (get_irn_mode(from) == mode_M)
1284 print_mem_edge_vcgattr(F, from, to);
1285 else if (get_irn_mode(from) == mode_X)
1286 fprintf(F, CF_EDGE_ATTR);
1288 print_data_edge_vcgattr(F, from, to);
1290 else if (get_irn_mode(get_irn_n(from, to)) == mode_M)
1291 print_mem_edge_vcgattr(F, from, to);
1292 else if (get_irn_mode(get_irn_n(from, to)) == mode_X)
1293 fprintf(F, CF_EDGE_ATTR);
1295 print_data_edge_vcgattr(F, from, to);
1299 /** dump edges to our inputs */
1300 static void dump_ir_data_edges(FILE *F, const ir_node *n)
1304 if (dump_node_edge_hook)
1305 dump_node_edge_hook(F, n);
1307 if (!(flags & ir_dump_flag_keepalive_edges) && is_End(n)) {
1308 /* the End node has only keep-alive edges */
1312 /* dump the dependency edges. */
1313 num = get_irn_deps(n);
1314 for (i = 0; i < num; ++i) {
1315 ir_node *dep = get_irn_dep(n, i);
1318 print_node_edge_kind(F, n);
1319 fprintf(F, "{sourcename: ");
1321 fprintf(F, " targetname: ");
1322 if ((get_opt_dump_const_local()) && is_constlike_node(dep)) {
1323 print_constid(F, n, dep);
1325 print_nodeid(F, dep);
1327 fprintf(F, " label: \"%d\" ", i);
1328 fprintf(F, " color: darkgreen}\n");
1332 num = get_irn_arity(n);
1333 for (i = 0; i < num; i++) {
1334 ir_node *pred = get_irn_n(n, i);
1337 if ((flags & ir_dump_flag_back_edges) && is_backedge(n, i)) {
1338 fprintf(F, "backedge: {sourcename: ");
1340 print_node_edge_kind(F, n);
1341 fprintf(F, "{sourcename: ");
1344 fprintf(F, " targetname: ");
1345 if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
1346 print_constid(F, n, pred);
1348 print_nodeid(F, pred);
1350 fprintf(F, " label: \"%d\" ", i);
1351 print_edge_vcgattr(F, n, i);
1359 static void dump_ir_edges(ir_node *node, void *env)
1362 FILE *F = (FILE*)env;
1364 foreach_out_edge(node, edge) {
1365 ir_node *succ = get_edge_src_irn(edge);
1367 print_node_edge_kind(F, succ);
1368 fprintf(F, "{sourcename: ");
1369 print_nodeid(F, node);
1370 fprintf(F, " targetname: ");
1371 print_nodeid(F, succ);
1373 fprintf(F, " label: \"%d\" ", i);
1374 fprintf(F, OUT_EDGE_ATTR);
1381 /** Dumps a node and its edges but not the block edge */
1382 static void dump_node_wo_blockedge(FILE *F, const ir_node *n)
1385 dump_ir_data_edges(F, n);
1388 /** Dumps a node and its edges. */
1389 static void dump_node_with_edges(ir_node *n, void *env)
1391 FILE *F = (FILE*)env;
1392 dump_node_wo_blockedge(F, n);
1393 if (!node_floats(n))
1394 dump_ir_block_edge(F, n);
1397 /** Dumps a const-like node. */
1398 static void dump_const_node(ir_node *n, void *env)
1400 FILE *F = (FILE*)env;
1401 if (is_Block(n)) return;
1402 dump_node_wo_blockedge(F, n);
1405 /***********************************************************************/
1406 /* the following routines dump the nodes/irgs bracketed to graphs. */
1407 /***********************************************************************/
1409 /** Dumps a constant expression as entity initializer, array bound ... */
1410 static void dump_const_expression(FILE *F, ir_node *value)
1412 ir_graph *irg = get_const_code_irg();
1413 ir_dump_flags_t old_flags = ir_get_dump_flags();
1414 ir_remove_dump_flags(ir_dump_flag_consts_local);
1416 irg_walk(value, dump_const_node, NULL, F);
1417 /* Decrease visited flag so that we walk with the same flag for the next
1418 expression. This guarantees that we don't dump the same node twice,
1419 as for const expressions cse is performed to save memory. */
1420 set_irg_visited(irg, get_irg_visited(irg) -1);
1422 ir_set_dump_flags(old_flags);
1425 /** Dump a block as graph containing its nodes.
1427 * Expects to find nodes belonging to the block as list in its
1429 * Dumps the edges of all nodes including itself. */
1430 static void dump_whole_block(FILE *F, const ir_node *block)
1434 assert(is_Block(block));
1436 fprintf(F, "graph: { title: ");
1437 print_nodeid(F, block);
1438 fprintf(F, " label: \"");
1439 dump_node_label(F, block);
1441 fprintf(F, "\" status:clustered ");
1442 /* colorize blocks */
1443 ird_color_t const color =
1444 !get_Block_matured(block) ? ird_color_error :
1445 ird_color_block_background;
1446 print_vcg_color(F, color);
1449 /* yComp can show attributes for blocks, XVCG parses but ignores them */
1450 dump_node_info(F, block);
1451 print_dbg_info(F, get_irn_dbg_info(block));
1453 /* dump the blocks edges */
1454 dump_ir_data_edges(F, block);
1456 if (dump_block_edge_hook)
1457 dump_block_edge_hook(F, block);
1459 /* dump the nodes that go into the block */
1460 for (node = (ir_node*)ird_get_irn_link(block); node; node = (ir_node*)ird_get_irn_link(node)) {
1462 dump_ir_data_edges(F, node);
1465 /* Close the vcg information for the block */
1467 dump_const_node_local(F, block);
1471 /** dumps a graph block-wise. Expects all blockless nodes in arr in irgs link.
1472 * The outermost nodes: blocks and nodes not op_pin_state_pinned, Bad, Unknown. */
1473 static void dump_block_graph(FILE *F, ir_graph *irg)
1476 ir_node **arr = (ir_node**)ird_get_irg_link(irg);
1478 for (i = 0, n = ARR_LEN(arr); i < n; ++i) {
1479 ir_node *node = arr[i];
1480 if (is_Block(node)) {
1481 /* Dumps the block and all the nodes in the block, which are to
1482 be found in Block->link. */
1483 dump_whole_block(F, node);
1485 /* Nodes that are not in a Block. */
1487 if (!node_floats(node) && is_Bad(get_nodes_block(node))) {
1488 dump_const_block_local(F, node);
1490 dump_ir_data_edges(F, node);
1492 if ((flags & ir_dump_flag_iredges) && edges_activated(irg))
1493 dump_ir_edges(node, F);
1496 if ((flags & ir_dump_flag_loops)
1497 && irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1498 dump_loop_nodes_into_graph(F, irg);
1502 * Dump the info for an irg.
1503 * Parsed by XVCG but not shown. use yComp.
1505 static void dump_graph_info(FILE *F, ir_graph *irg)
1507 fprintf(F, "info1: \"");
1508 dump_entity_to_file(F, get_irg_entity(irg));
1511 /* dump graph state */
1512 fprintf(F, "constraints:");
1513 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP))
1514 fprintf(F, " arch_dep");
1515 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_MODEB_LOWERED))
1516 fprintf(F, " modeb_lowered");
1517 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_NORMALISATION2))
1518 fprintf(F, " normalisation2");
1519 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE))
1520 fprintf(F, " optimize_unreachable_code");
1523 fprintf(F, "properties:");
1524 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES))
1525 fprintf(F, " no_critical_edges");
1526 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_BADS))
1527 fprintf(F, " no_bads");
1528 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE))
1529 fprintf(F, " no_unreachable_code");
1530 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_ONE_RETURN))
1531 fprintf(F, " one_return");
1532 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE))
1533 fprintf(F, " consistent_dominance");
1534 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE))
1535 fprintf(F, " consistent_postdominance");
1536 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES))
1537 fprintf(F, " consistent_out_edges");
1538 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))
1539 fprintf(F, " consistent_outs");
1540 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1541 fprintf(F, " consistent_loopinfo");
1542 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE))
1543 fprintf(F, " consistent_entity_usage");
1547 /** Dumps an irg as a graph clustered by block nodes.
1548 * If interprocedural view edges can point to nodes out of this graph.
1550 static void dump_graph_from_list(FILE *F, ir_graph *irg)
1552 ir_entity *ent = get_irg_entity(irg);
1554 fprintf(F, "graph: { title: ");
1555 print_irgid(F, irg);
1556 fprintf(F, " label: \"%s\" status:clustered color:%s\n",
1557 get_ent_dump_name(ent), color_names[ird_color_prog_background]);
1559 dump_graph_info(F, irg);
1560 print_dbg_info(F, get_entity_dbg_info(ent));
1562 dump_block_graph(F, irg);
1564 /* Close the vcg information for the irg */
1565 fprintf(F, "}\n\n");
1568 /*******************************************************************/
1569 /* Basic type and entity nodes and edges. */
1570 /*******************************************************************/
1572 /** dumps the edges between nodes and their type or entity attributes. */
1573 static void dump_node2type_edges(ir_node *n, void *env)
1575 FILE *F = (FILE*)env;
1578 switch (get_irn_opcode(n)) {
1580 /* @@@ some consts have an entity */
1583 if (SYMCONST_HAS_TYPE(get_SymConst_kind(n)))
1584 print_node_type_edge(F,n,get_SymConst_type(n),NODE2TYPE_EDGE_ATTR);
1587 print_node_ent_edge(F,n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
1590 print_node_type_edge(F,n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
1593 print_node_type_edge(F,n,get_Alloc_type(n),NODE2TYPE_EDGE_ATTR);
1596 print_node_type_edge(F,n,get_Free_type(n),NODE2TYPE_EDGE_ATTR);
1599 print_node_type_edge(F,n,get_Cast_type(n),NODE2TYPE_EDGE_ATTR);
1606 static void print_typespecific_vcgattr(FILE *F, ir_type *tp)
1608 switch (get_type_tpop_code(tp)) {
1610 fprintf(F, " " TYPE_CLASS_NODE_ATTR);
1613 fprintf(F, " " TYPE_METH_NODE_ATTR);
1621 case tpo_enumeration:
1632 void dump_type_node(FILE *F, ir_type *tp)
1634 fprintf(F, "node: {title: ");
1635 print_typeid(F, tp);
1636 fprintf(F, " label: \"");
1637 if (tp->dbi != NULL) {
1639 ir_print_type(buf, sizeof(buf), tp);
1640 fprintf(F, "%s '%s'", get_type_tpop_name(tp), buf);
1642 ir_fprintf(F, "%+F", tp);
1644 fputs("\" info1: \"", F);
1645 dump_type_to_file(F, tp);
1647 print_type_dbg_info(F, get_type_dbg_info(tp));
1648 print_typespecific_vcgattr(F, tp);
1652 static void dump_entity_node(FILE *F, ir_entity *ent)
1654 fprintf(F, "node: {title: ");
1655 print_entityid(F, ent);
1656 fprintf(F, " label: ");
1657 fprintf(F, "\"%s\" ", get_ent_dump_name(ent));
1659 print_vcg_color(F, ird_color_entity);
1660 fprintf(F, "\n info1: \"");
1662 dump_entity_to_file(F, ent);
1665 print_dbg_info(F, get_entity_dbg_info(ent));
1669 static void dump_enum_item(FILE *F, ir_type *tp, size_t pos)
1672 ir_enum_const *ec = get_enumeration_const(tp, pos);
1673 ident *id = get_enumeration_const_nameid(ec);
1674 ir_tarval *tv = get_enumeration_value(ec);
1677 tarval_snprintf(buf, sizeof(buf), tv);
1679 strncpy(buf, "<not set>", sizeof(buf));
1680 fprintf(F, "node: {title: ");
1681 print_itemid(F, tp, pos);
1682 fprintf(F, " label: ");
1683 fprintf(F, "\"enum item %s\" " ENUM_ITEM_NODE_ATTR, get_id_str(id));
1684 fprintf(F, "\n info1: \"value: %s\"}\n", buf);
1688 * Dumps a new style initializer.
1690 static void dump_entity_initializer(FILE *F, const ir_entity *ent)
1698 * type-walker: Dumps a type or entity and its edges.
1700 static void dump_type_info(type_or_ent tore, void *env)
1702 FILE *F = (FILE*)env;
1703 size_t i = 0; /* to shutup gcc */
1705 /* dump this type or entity */
1707 switch (get_kind(tore.ent)) {
1709 ir_entity *ent = tore.ent;
1711 dump_entity_node(F, ent);
1713 /* skip this to reduce graph. Member edge of type is parallel to this edge. *
1714 fprintf(F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
1715 ENT_OWN_EDGE_ATTR "}\n", ent, get_entity_owner(ent));*/
1716 print_ent_type_edge(F,ent, get_entity_type(ent), ENT_TYPE_EDGE_ATTR);
1717 if (is_Class_type(get_entity_owner(ent))) {
1718 for (i = get_entity_n_overwrites(ent); i > 0;)
1719 print_ent_ent_edge(F, ent, get_entity_overwrites(ent, --i), 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1721 /* attached subgraphs */
1722 if (! (flags & ir_dump_flag_no_entity_values)) {
1723 if (ent->initializer != NULL) {
1724 /* new style initializers */
1725 dump_entity_initializer(F, ent);
1731 ir_type *tp = tore.typ;
1732 dump_type_node(F, tp);
1733 /* and now the edges */
1734 switch (get_type_tpop_code(tp)) {
1736 for (i = get_class_n_supertypes(tp); i > 0;) {
1738 print_type_type_edge(F, tp, get_class_supertype(tp, i), TYPE_SUPER_EDGE_ATTR);
1740 for (i = get_class_n_members(tp); i > 0;) {
1742 print_type_ent_edge(F, tp, get_class_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1746 for (i = get_struct_n_members(tp); i > 0;) {
1748 print_type_ent_edge(F, tp, get_struct_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1752 for (i = get_method_n_params(tp); i > 0;) {
1754 print_type_type_edge(F, tp, get_method_param_type(tp, i), METH_PAR_EDGE_ATTR,i);
1756 for (i = get_method_n_ress(tp); i > 0;) {
1758 print_type_type_edge(F, tp, get_method_res_type(tp, i), METH_RES_EDGE_ATTR,i);
1762 for (i = get_union_n_members(tp); i > 0;) {
1764 print_type_ent_edge(F, tp, get_union_member(tp, i), UNION_EDGE_ATTR);
1768 print_type_type_edge(F, tp, get_array_element_type(tp), ARR_ELT_TYPE_EDGE_ATTR);
1769 print_type_ent_edge(F, tp, get_array_element_entity(tp), ARR_ENT_EDGE_ATTR);
1770 for (i = get_array_n_dimensions(tp); i > 0;) {
1771 ir_node *upper, *lower;
1774 upper = get_array_upper_bound(tp, i);
1775 lower = get_array_lower_bound(tp, i);
1776 print_node_type_edge(F, upper, tp, "label: \"upper %zu\"", get_array_order(tp, i));
1777 print_node_type_edge(F, lower, tp, "label: \"lower %zu\"", get_array_order(tp, i));
1778 dump_const_expression(F, upper);
1779 dump_const_expression(F, lower);
1782 case tpo_enumeration:
1783 for (i = get_enumeration_n_enums(tp); i > 0;) {
1785 dump_enum_item(F, tp, i);
1786 print_enum_item_edge(F, tp, i, "label: \"item %zu\"", i);
1790 print_type_type_edge(F, tp, get_pointer_points_to_type(tp), PTR_PTS_TO_EDGE_ATTR);
1794 case tpo_uninitialized:
1799 break; /* case k_type */
1802 printf(" *** irdump, dump_type_info(l.%i), faulty type.\n", __LINE__);
1806 /** For dumping class hierarchies.
1807 * Dumps a class type node and a superclass edge.
1809 static void dump_class_hierarchy_node(type_or_ent tore, void *ctx)
1811 FILE *F = (FILE*)ctx;
1812 size_t i = 0; /* to shutup gcc */
1814 /* dump this type or entity */
1815 switch (get_kind(tore.ent)) {
1817 ir_entity *ent = tore.ent;
1818 if (get_entity_owner(ent) == get_glob_type()) break;
1819 if (!is_Method_type(get_entity_type(ent)))
1821 if (flags & ir_dump_flag_entities_in_hierarchy
1822 && is_Class_type(get_entity_owner(ent))) {
1824 dump_entity_node(F, ent);
1826 print_type_ent_edge(F, get_entity_owner(ent), ent, TYPE_MEMBER_EDGE_ATTR);
1827 for (i = get_entity_n_overwrites(ent); i > 0;) {
1829 print_ent_ent_edge(F, get_entity_overwrites(ent, i), ent, 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1835 ir_type *tp = tore.typ;
1836 if (tp == get_glob_type())
1838 switch (get_type_tpop_code(tp)) {
1840 dump_type_node(F, tp);
1841 /* and now the edges */
1842 for (i = get_class_n_supertypes(tp); i > 0;) {
1844 print_type_type_edge(F,tp,get_class_supertype(tp, i),TYPE_SUPER_EDGE_ATTR);
1849 break; /* case k_type */
1852 printf(" *** irdump, dump_class_hierarchy_node(l.%i), faulty type.\n", __LINE__);
1856 /*******************************************************************/
1857 /* dump analysis information that is expressed in graph terms. */
1858 /*******************************************************************/
1860 /* dump out edges */
1861 static void dump_out_edge(ir_node *n, void *env)
1863 FILE *F = (FILE*)env;
1865 for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
1866 ir_node *succ = get_irn_out(n, i);
1868 print_node_edge_kind(F, succ);
1869 fprintf(F, "{sourcename: ");
1871 fprintf(F, " targetname: ");
1872 print_nodeid(F, succ);
1873 fprintf(F, " color: red linestyle: dashed");
1878 static void dump_loop_label(FILE *F, const ir_loop *loop)
1880 fprintf(F, "loop %u", get_loop_depth(loop));
1883 static void dump_loop_info(FILE *F, const ir_loop *loop)
1885 fprintf(F, " info1: \"");
1886 fprintf(F, " loop nr: %ld", get_loop_loop_nr(loop));
1887 #ifdef DEBUG_libfirm
1888 fprintf(F, "\n The loop was analyzed %ld times.", (long int) PTR_TO_INT(get_loop_link(loop)));
1893 void print_loopid(FILE *F, const ir_loop *loop)
1895 fprintf(F, "\"l%ld\"", get_loop_loop_nr(loop));
1898 static void dump_loop_node(FILE *F, const ir_loop *loop)
1900 fprintf(F, "node: {title: ");
1901 print_loopid(F, loop);
1902 fprintf(F, " label: \"");
1903 dump_loop_label(F, loop);
1905 dump_loop_info(F, loop);
1909 static void dump_loop_node_edge(FILE *F, const ir_loop *loop, size_t i)
1912 fprintf(F, "edge: {sourcename: ");
1913 print_loopid(F, loop);
1914 fprintf(F, " targetname: ");
1915 print_nodeid(F, get_loop_element(loop, i).node);
1916 fprintf(F, " color: green");
1920 static void dump_loop_son_edge(FILE *F, const ir_loop *loop, size_t i)
1923 fprintf(F, "edge: {sourcename: ");
1924 print_loopid(F, loop);
1925 fprintf(F, " targetname: ");
1926 print_loopid(F, get_loop_element(loop, i).son);
1927 ir_fprintf(F, " color: darkgreen label: \"%zu\"}\n", i);
1930 static void dump_loops(FILE *F, const ir_loop *loop)
1933 size_t n_elements = get_loop_n_elements(loop);
1934 /* dump this loop node */
1935 dump_loop_node(F, loop);
1937 /* dump edges to nodes in loop -- only if it is a real loop */
1938 if (get_loop_depth(loop) != 0) {
1939 for (i = n_elements; i > 0;) {
1940 loop_element element;
1942 element = get_loop_element(loop, i);
1943 if (*element.kind != k_ir_node)
1945 dump_loop_node_edge(F, loop, i);
1948 for (i = n_elements; i > 0;) {
1949 loop_element element;
1951 element = get_loop_element(loop, i);
1952 if (*element.kind != k_ir_loop)
1954 dump_loops(F, element.son);
1955 dump_loop_son_edge(F, loop, i);
1959 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg)
1961 ir_loop *loop = get_irg_loop(irg);
1963 dump_loops(F, loop);
1967 void dump_vcg_header_colors(FILE *F)
1971 for (i = 0; i < ird_color_count; ++i) {
1972 if (color_rgb[i] != NULL) {
1973 fprintf(F, "colorentry %s: %s\n", color_names[i], color_rgb[i]);
1978 void dump_vcg_infonames(FILE *F)
1981 "infoname 1: \"Attribute\"\n"
1982 "infoname 2: \"Verification errors\"\n"
1983 "infoname 3: \"Debug info\"\n", F);
1987 * dumps the VCG header
1989 void dump_vcg_header(FILE *F, const char *name, const char *layout, const char *orientation)
1992 = (flags & ir_dump_flag_disable_edge_labels) ? "no" : "yes";
1994 if (! layout) layout = "Compilergraph";
1995 if (!orientation) orientation = "bottom_to_top";
1999 "graph: { title: \"ir graph of %s\"\n"
2000 "display_edge_labels: %s\n"
2001 "layoutalgorithm: mindepth //$ \"%s\"\n"
2002 "manhattan_edges: yes\n"
2003 "port_sharing: no\n"
2005 "classname 1: \"intrablock Data\"\n"
2006 "classname 2: \"Block\"\n"
2007 "classname 3: \"Entity type\"\n"
2008 "classname 4: \"Entity owner\"\n"
2009 "classname 5: \"Method Param\"\n"
2010 "classname 6: \"Method Res\"\n"
2011 "classname 7: \"Super\"\n"
2012 "classname 8: \"Union\"\n"
2013 "classname 9: \"Points-to\"\n"
2014 "classname 10: \"Array Element Type\"\n"
2015 "classname 11: \"Overwrites\"\n"
2016 "classname 12: \"Member\"\n"
2017 "classname 13: \"Control Flow\"\n"
2018 "classname 14: \"intrablock Memory\"\n"
2019 "classname 15: \"Dominators\"\n"
2020 "classname 16: \"interblock Data\"\n"
2021 "classname 17: \"interblock Memory\"\n"
2022 "classname 18: \"Exception Control Flow for Interval Analysis\"\n"
2023 "classname 19: \"Postdominators\"\n"
2024 "classname 20: \"Keep Alive\"\n"
2025 "classname 21: \"Out Edges\"\n"
2026 "classname 22: \"Macro Block Edges\"\n",
2027 name, label, layout, orientation);
2028 dump_vcg_infonames(F);
2029 dump_vcg_header_colors(F);
2034 * Dumps the vcg file footer
2036 void dump_vcg_footer(FILE *F)
2043 static void dump_blocks_as_subgraphs(FILE *out, ir_graph *irg)
2047 construct_block_lists(irg);
2050 * If we are in the interprocedural view, we dump not
2051 * only the requested irg but also all irgs that can be reached
2054 for (i = get_irp_n_irgs(); i > 0;) {
2055 ir_graph *other_irg = get_irp_irg(--i);
2056 ir_node **arr = (ir_node**)ird_get_irg_link(other_irg);
2060 dump_graph_from_list(out, other_irg);
2065 void dump_ir_graph_file(FILE *out, ir_graph *irg)
2067 dump_vcg_header(out, get_irg_dump_name(irg), NULL, NULL);
2070 if (flags & ir_dump_flag_blocks_as_subgraphs) {
2071 dump_blocks_as_subgraphs(out, irg);
2073 /* dump_node_with_edges must be called in post visiting predecessors */
2074 ird_walk_graph(irg, NULL, dump_node_with_edges, out);
2077 /* dump type info */
2078 if (flags & ir_dump_flag_with_typegraph) {
2079 type_walk_irg(irg, dump_type_info, NULL, out);
2080 inc_irg_visited(get_const_code_irg());
2081 /* dump edges from graph to type info */
2082 irg_walk(get_irg_end(irg), dump_node2type_edges, NULL, out);
2085 /* dump iredges out edges */
2086 if ((flags & ir_dump_flag_iredges) && edges_activated(irg)) {
2087 irg_walk_edges(get_irg_start_block(irg), dump_ir_edges, NULL, out);
2090 /* dump the out edges in a separate walk */
2091 if ((flags & ir_dump_flag_out_edges)
2092 && (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))) {
2093 irg_out_walk(get_irg_start(irg), dump_out_edge, NULL, out);
2096 dump_vcg_footer(out);
2099 static void dump_block_to_cfg(ir_node *block, void *env)
2101 FILE *F = (FILE*)env;
2104 if (is_Bad(block) && get_irn_mode(block) == mode_X) {
2105 dump_node(F, block);
2108 if (is_Block(block)) {
2109 /* This is a block. Dump a node for the block. */
2110 fprintf(F, "node: {title: ");
2111 print_nodeid(F, block);
2112 fprintf(F, " label: \"");
2113 if (block == get_irg_start_block(get_irn_irg(block)))
2114 fprintf(F, "Start ");
2115 if (block == get_irg_end_block(get_irn_irg(block)))
2118 fprintf(F, "%s ", get_op_name(get_irn_op(block)));
2119 print_nodeid(F, block);
2121 fprintf(F, "info1:\"");
2123 /* the generic version. */
2124 dump_irnode_to_file(F, block);
2126 fprintf(F, "\""); /* closing quote of info */
2128 if ((block == get_irg_start_block(get_irn_irg(block))) ||
2129 (block == get_irg_end_block(get_irn_irg(block))) )
2130 fprintf(F, " color:blue ");
2134 /* Dump the edges */
2135 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
2136 ir_node *pred = get_Block_cfgpred(block, i);
2138 pred = get_nodes_block(pred);
2139 fprintf(F, "edge: { sourcename: ");
2140 print_nodeid(F, block);
2141 fprintf(F, " targetname: ");
2142 print_nodeid(F, pred);
2143 fprintf(F, "\"}\n");
2146 /* Dump dominator/postdominator edge */
2147 if (ir_get_dump_flags() & ir_dump_flag_dominance) {
2148 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE) && get_Block_idom(block)) {
2149 ir_node *pred = get_Block_idom(block);
2150 fprintf(F, "edge: { sourcename: ");
2151 print_nodeid(F, block);
2152 fprintf(F, " targetname: ");
2153 print_nodeid(F, pred);
2154 fprintf(F, " " DOMINATOR_EDGE_ATTR "}\n");
2156 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE) && get_Block_ipostdom(block)) {
2157 ir_node *pred = get_Block_ipostdom(block);
2158 fprintf(F, "edge: { sourcename: ");
2159 print_nodeid(F, block);
2160 fprintf(F, " targetname: ");
2161 print_nodeid(F, pred);
2162 fprintf(F, " " POSTDOMINATOR_EDGE_ATTR "}\n");
2168 void dump_cfg(FILE *F, ir_graph *irg)
2170 dump_vcg_header(F, get_irg_dump_name(irg), NULL, NULL);
2172 /* walk over the blocks in the graph */
2173 irg_walk_graph(irg, dump_block_to_cfg, NULL, F);
2178 void dump_callgraph(FILE *F)
2181 ir_dump_flags_t old_flags = ir_get_dump_flags();
2183 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2184 dump_vcg_header(F, "Callgraph", "Hierarchic", NULL);
2186 for (i = get_irp_n_irgs(); i > 0;) {
2187 ir_graph *irg = get_irp_irg(--i);
2188 ir_entity *ent = get_irg_entity(irg);
2189 size_t j, n_callees = get_irg_n_callees(irg);
2191 dump_entity_node(F, ent);
2192 for (j = 0; j < n_callees; ++j) {
2193 ir_entity *c = get_irg_entity(get_irg_callee(irg, j));
2194 int be = is_irg_callee_backedge(irg, j);
2195 const char *attr = be
2196 ? "label:\"recursion %zu\""
2197 : "label:\"calls %zu\"";
2198 print_ent_ent_edge(F, ent, c, be, ird_color_entity, attr,
2199 get_irg_callee_loop_depth(irg, j));
2203 ir_set_dump_flags(old_flags);
2207 void dump_typegraph(FILE *out)
2209 dump_vcg_header(out, "All_types", NULL, NULL);
2210 type_walk(dump_type_info, NULL, out);
2211 dump_vcg_footer(out);
2214 void dump_class_hierarchy(FILE *out)
2216 dump_vcg_header(out, "class_hierarchy", NULL, NULL);
2217 type_walk(dump_class_hierarchy_node, NULL, out);
2218 dump_vcg_footer(out);
2221 static void dump_loops_standalone(FILE *F, ir_loop *loop)
2224 bool loop_node_started = false;
2226 size_t son_number = 0;
2228 ir_loop *son = NULL;
2230 /* Dump a new loop node. */
2231 dump_loop_node(F, loop);
2233 /* Dump the loop elements. */
2234 for (i = 0; i < get_loop_n_elements(loop); i++) {
2235 le = get_loop_element(loop, i);
2237 if (get_kind(son) == k_ir_loop) {
2239 /* We are a loop son -> Recurse */
2241 if (loop_node_started) { /* Close the "firm-nodes" node first if we started one. */
2242 fprintf(F, "\" }\n");
2243 fprintf(F, "edge: {sourcename: ");
2244 print_loopid(F, loop);
2245 fprintf(F, " targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2246 get_loop_loop_nr(loop),
2247 (unsigned long) first,
2248 (unsigned long) first,
2249 (unsigned long) i-1);
2250 loop_node_started = false;
2252 dump_loop_son_edge(F, loop, son_number++);
2253 dump_loops_standalone(F, son);
2254 } else if (get_kind(son) == k_ir_node) {
2255 /* We are a loop node -> Collect firm nodes */
2257 ir_node *n = le.node;
2258 if (!loop_node_started) {
2259 /* Start a new node which contains all firm nodes of the current loop */
2260 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2261 get_loop_loop_nr(loop),
2263 loop_node_started = true;
2268 dump_node_label(F, n);
2269 if (has_backedges(n)) fprintf(F, "\t loop head!");
2270 } else { /* for callgraph loop tree */
2272 assert(get_kind(son) == k_ir_graph);
2274 /* We are a loop node -> Collect firm graphs */
2276 if (!loop_node_started) {
2277 /* Start a new node which contains all firm nodes of the current loop */
2278 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2279 get_loop_loop_nr(loop),
2281 loop_node_started = true;
2285 fprintf(F, " %s", get_irg_dump_name(n));
2286 /* fprintf(F, " %s (depth %d)", get_irg_dump_name(n), n->callgraph_weighted_loop_depth); */
2290 if (loop_node_started) {
2291 fprintf(F, "\" }\n");
2292 fprintf(F, "edge: {sourcename: \"");
2293 print_loopid(F, loop);
2294 fprintf(F, "\" targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2295 get_loop_loop_nr(loop),
2296 (unsigned long) first,
2297 (unsigned long) first,
2298 (unsigned long) i-1);
2302 void dump_loop_tree(FILE *out, ir_graph *irg)
2304 ir_dump_flags_t old_flags = ir_get_dump_flags();
2306 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2308 dump_vcg_header(out, get_irg_dump_name(irg), "Tree", "top_to_bottom");
2310 if (get_irg_loop(irg))
2311 dump_loops_standalone(out, get_irg_loop(irg));
2313 dump_vcg_footer(out);
2315 ir_set_dump_flags(old_flags);
2318 void dump_callgraph_loop_tree(FILE *out)
2320 dump_vcg_header(out, "callgraph looptree", "Tree", "top_to_bottom");
2321 dump_loops_standalone(out, irp->outermost_cg_loop);
2322 dump_vcg_footer(out);
2325 static void collect_nodeloop(FILE *F, ir_loop *loop, pset *loopnodes)
2329 int node_number = 0;
2331 if (flags & ir_dump_flag_loops)
2332 dump_loop_node(F, loop);
2334 for (i = 0; i < get_loop_n_elements(loop); i++) {
2335 loop_element le = get_loop_element(loop, i);
2336 if (*(le.kind) == k_ir_loop) {
2337 if (flags & ir_dump_flag_loops)
2338 dump_loop_son_edge(F, loop, son_number++);
2340 collect_nodeloop(F, le.son, loopnodes);
2342 if (flags & ir_dump_flag_loops)
2343 dump_loop_node_edge(F, loop, node_number++);
2344 pset_insert_ptr(loopnodes, le.node);
2349 static void collect_nodeloop_external_nodes(ir_loop *loop, pset *loopnodes,
2355 for (i = 0; i < get_loop_n_elements(loop); i++) {
2356 loop_element le = get_loop_element(loop, i);
2357 if (*(le.kind) == k_ir_loop) {
2359 collect_nodeloop_external_nodes(le.son, loopnodes, extnodes);
2361 if (is_Block(le.node)) start = 0; else start = -1;
2362 for (j = start; j < get_irn_arity(le.node); j++) {
2363 ir_node *pred = get_irn_n(le.node, j);
2364 if (!pset_find_ptr(loopnodes, pred)) {
2365 pset_insert_ptr(extnodes, pred);
2366 if (!is_Block(pred)) {
2367 pred = get_nodes_block(pred);
2368 if (!pset_find_ptr(loopnodes, pred))
2369 pset_insert_ptr(extnodes, pred);
2377 void dump_loop(FILE *F, ir_loop *l)
2379 pset *loopnodes = pset_new_ptr_default();
2380 pset *extnodes = pset_new_ptr_default();
2383 snprintf(name, sizeof(name), "loop_%ld", get_loop_loop_nr(l));
2384 dump_vcg_header(F, name, NULL, NULL);
2386 /* collect all nodes to dump */
2387 collect_nodeloop(F, l, loopnodes);
2388 collect_nodeloop_external_nodes(l, loopnodes, extnodes);
2390 /* build block lists */
2391 foreach_pset(loopnodes, ir_node, n) {
2392 set_irn_link(n, NULL);
2394 foreach_pset(extnodes, ir_node, n) {
2395 set_irn_link(n, NULL);
2397 foreach_pset(loopnodes, ir_node, n) {
2399 ir_node *const b = get_nodes_block(n);
2400 set_irn_link(n, get_irn_link(b));
2404 foreach_pset(extnodes, ir_node, n) {
2406 ir_node *const b = get_nodes_block(n);
2407 set_irn_link(n, get_irn_link(b));
2412 foreach_pset(loopnodes, ir_node, b) {
2414 fprintf(F, "graph: { title: ");
2416 fprintf(F, " label: \"");
2417 dump_node_opcode(F, b);
2418 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2419 fprintf(F, "\" status:clustered color:yellow\n");
2421 /* dump the blocks edges */
2422 dump_ir_data_edges(F, b);
2424 /* dump the nodes that go into the block */
2425 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2426 if (pset_find_ptr(extnodes, n))
2427 overrule_nodecolor = ird_color_block_inout;
2429 overrule_nodecolor = ird_color_default_node;
2430 if (!pset_find_ptr(extnodes, n)) dump_ir_data_edges(F, n);
2433 /* Close the vcg information for the block */
2435 dump_const_node_local(F, b);
2439 foreach_pset(extnodes, ir_node, b) {
2441 fprintf(F, "graph: { title: ");
2443 fprintf(F, " label: \"");
2444 dump_node_opcode(F, b);
2445 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2446 fprintf(F, "\" status:clustered color:lightblue\n");
2448 /* dump the nodes that go into the block */
2449 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2450 if (!pset_find_ptr(loopnodes, n))
2451 overrule_nodecolor = ird_color_block_inout;
2453 overrule_nodecolor = ird_color_default_node;
2454 if (pset_find_ptr(loopnodes, n)) dump_ir_data_edges(F, n);
2457 /* Close the vcg information for the block */
2459 dump_const_node_local(F, b);
2463 del_pset(loopnodes);
2469 static bool obstack_init;
2470 static struct obstack obst;
2471 static char *dump_path;
2473 void ir_set_dump_path(const char *path)
2476 dump_path = xstrdup(path);
2479 static void add_string_escaped(const char *string)
2482 for (p = string; *p != '\0'; ++p) {
2485 obstack_1grow(&obst, '@');
2486 obstack_1grow(&obst, '1');
2487 } else if (c == '@') {
2488 obstack_1grow(&obst, '@');
2489 obstack_1grow(&obst, '2');
2491 obstack_1grow(&obst, c);
2496 static void add_dump_path(void)
2498 if (!obstack_init) {
2499 obstack_init(&obst);
2500 obstack_init = true;
2503 if (dump_path != NULL) {
2504 size_t len = strlen(dump_path);
2505 obstack_grow(&obst, dump_path, len);
2506 if (len > 0 && dump_path[len-1] != '/')
2507 obstack_1grow(&obst, '/');
2511 void dump_ir_graph_ext(ir_graph_dump_func func, ir_graph *graph,
2514 const char *dump_name = get_irg_dump_name(graph);
2518 if (!ir_should_dump(dump_name))
2523 add_string_escaped(dump_name);
2524 obstack_printf(&obst, "-%02u", graph->dump_nr++);
2526 if (suffix != NULL) {
2527 if (suffix[0] != '.')
2528 obstack_1grow(&obst, '-');
2529 add_string_escaped(suffix);
2531 obstack_1grow(&obst, '\0');
2533 file_name = (char*)obstack_finish(&obst);
2534 /* xvcg expects only <LF> so we need "b"inary mode (for win32) */
2535 out = fopen(file_name, "wb");
2536 obstack_free(&obst, file_name);
2539 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2547 void dump_ir_prog_ext(ir_prog_dump_func func, const char *suffix)
2554 obstack_printf(&obst, "%02u", irp->dump_nr++);
2555 if (suffix != NULL) {
2556 if (suffix[0] != '.')
2557 obstack_1grow(&obst, '-');
2558 add_string_escaped(suffix);
2560 obstack_1grow(&obst, '\0');
2562 file_name = (char*)obstack_finish(&obst);
2563 out = fopen(file_name, "wb");
2564 obstack_free(&obst, file_name);
2567 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2574 void dump_ir_graph(ir_graph *graph, const char *suffix)
2578 snprintf(buf, sizeof(buf), "%s.vcg", suffix);
2579 dump_ir_graph_ext(dump_ir_graph_file, graph, buf);
2582 void dump_all_ir_graphs(const char *suffix)
2584 size_t i, n_irgs = get_irp_n_irgs();
2586 for (i = 0; i < n_irgs; ++i) {
2587 ir_graph *irg = get_irp_irg(i);
2588 dump_ir_graph(irg, suffix);
2592 typedef struct pass_t {
2593 ir_prog_pass_t pass;
2598 * Wrapper around dump_all_ir_graphs().
2600 static int dump_all_ir_graphs_wrapper(ir_prog *irp, void *context)
2602 pass_t *pass = (pass_t*)context;
2605 dump_all_ir_graphs(pass->suffix);
2609 ir_prog_pass_t *dump_all_ir_graph_pass(const char *name, const char *suffix)
2611 size_t len = strlen(suffix) + 1;
2612 pass_t *pass = XMALLOCF(pass_t, suffix, len);
2613 ir_prog_pass_t *res = def_prog_pass_constructor(
2614 &pass->pass, name ? name : "dump_all_graphs", dump_all_ir_graphs_wrapper);
2616 /* this pass does not change anything, so neither dump nor verify is needed. */
2617 res->dump_irprog = ir_prog_no_dump;
2618 res->verify_irprog = ir_prog_no_verify;
2620 memcpy(pass->suffix, suffix, len);