2 * Copyright (C) 1995-2008 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 Code for dumping backend datastructures (i.e. interference graphs)
23 * @author Matthias Braun
32 #include "becopyopt_t.h"
35 static void dump_ifg_nodes(FILE *F, const be_ifg_t *ifg)
37 nodes_iter_t ifg_iter;
39 be_ifg_foreach_node(ifg, &ifg_iter, node) {
44 static void dump_ifg_edges(FILE *F, const be_ifg_t *ifg)
46 nodes_iter_t ifg_iter;
49 be_ifg_foreach_node(ifg, &ifg_iter, node) {
50 neighbours_iter_t neigh_iter;
52 be_ifg_foreach_neighbour(ifg, &neigh_iter, node, neighbour) {
53 /* interference is bidirectional, but it's enough to dump 1
55 if (get_irn_node_nr(node) >= get_irn_node_nr(neighbour))
58 fprintf(F, "edge: {sourcename: ");
59 print_nodeid(F, node);
60 fprintf(F, " targetname: ");
61 print_nodeid(F, neighbour);
62 fprintf(F, " arrowstyle:none class:1}\n");
67 void be_dump_ifg(FILE *F, ir_graph *irg, const be_ifg_t *ifg)
70 "graph: { title: \"interference graph of %+F\"\n"
71 "layoutalgorithm: mindepth //$ \"circular\"\n"
72 "classname 1: \"interference\"\n"
74 dump_vcg_infonames(F);
75 dump_vcg_header_colors(F);
77 dump_ifg_nodes(F, ifg);
78 dump_ifg_edges(F, ifg);
83 static void dump_affinity_edges(FILE *F, const copy_opt_t *co,
84 bool dump_costs, bool dump_colors)
86 co_gs_foreach_aff_node(co, a) {
87 co_gs_foreach_neighb(a, n) {
88 /* edges are bidirection, dumping one direction is enough */
89 if (get_irn_node_nr(a->irn) >= get_irn_node_nr(n->irn))
92 fprintf(F, "edge: {sourcename: ");
93 print_nodeid(F, a->irn);
94 fprintf(F, " targetname: ");
95 print_nodeid(F, n->irn);
96 fprintf(F, " arrowstyle:none");
99 fprintf(F, " label:\"%d\"", n->costs);
101 const arch_register_t *ar = arch_get_irn_register(a->irn);
102 const arch_register_t *nr = arch_get_irn_register(n->irn);
103 const char *color = nr == ar ? "blue" : "red";
104 fprintf(F, " color:%s", color);
106 fprintf(F, " linestyle:dashed class:2");
112 void be_dump_ifg_co(FILE *F, const copy_opt_t *co, bool dump_costs,
115 ir_graph *irg = co->irg;
116 be_ifg_t *ifg = co->cenv->ifg;
119 "graph: { title: \"interference graph of %+F\"\n"
120 "layoutalgorithm: mindepth //$ \"circular\"\n"
121 "classname 1: \"interference\"\n"
122 "classname 2: \"affinity\"\n"
124 dump_vcg_infonames(F);
125 dump_vcg_header_colors(F);
127 dump_ifg_nodes(F, ifg);
128 dump_ifg_edges(F, ifg);
129 dump_affinity_edges(F, co, dump_costs, dump_colors);
134 static const char *lv_flags_to_str(unsigned flags)
136 static const char *states[] = {
147 return states[flags & 7];
150 void be_dump_liveness_block(be_lv_t *lv, FILE *F, const ir_node *bl)
152 be_lv_info_t *info = ir_nodehashmap_get(be_lv_info_t, &lv->map, bl);
154 fprintf(F, "liveness:\n");
156 unsigned n = info[0].head.n_members;
159 for (i = 0; i < n; ++i) {
160 be_lv_info_node_t *n = &info[i+1].node;
161 ir_fprintf(F, "%s %+F\n", lv_flags_to_str(n->flags), n->node);
166 typedef struct lv_walker_t {
171 static void lv_dump_block_walker(ir_node *irn, void *data)
173 lv_walker_t *w = (lv_walker_t*)data;
176 be_dump_liveness_block(w->lv, w->out, irn);
179 void be_liveness_dump(FILE *F, const be_lv_t *lv)
183 w.lv = (be_lv_t *) lv;
185 irg_block_walk_graph(lv->irg, lv_dump_block_walker, NULL, &w);