bedump.c 4.45 KB
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

/**
 * @file
 * @brief       Code for dumping backend datastructures (i.e. interference graphs)
 * @author      Matthias Braun
 */
#include "config.h"

#include "bedump.h"

#include "irdump_t.h"
30
#include "irgwalk.h"
Matthias Braun's avatar
Matthias Braun committed
31
32
#include "beifg.h"
#include "becopyopt_t.h"
33
#include "belive_t.h"
Matthias Braun's avatar
Matthias Braun committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

static void dump_ifg_nodes(FILE *F, const be_ifg_t *ifg)
{
	nodes_iter_t ifg_iter;
	ir_node     *node;
	be_ifg_foreach_node(ifg, &ifg_iter, node) {
		dump_node(F, node);
	}
}

static void dump_ifg_edges(FILE *F, const be_ifg_t *ifg)
{
	nodes_iter_t ifg_iter;
	ir_node     *node;

	be_ifg_foreach_node(ifg, &ifg_iter, node) {
		neighbours_iter_t neigh_iter;
		ir_node          *neighbour;

		be_ifg_foreach_neighbour(ifg, &neigh_iter, node, neighbour) {
			/* interference is bidirectional, but it's enough to dump 1
			 * direction */
			if (get_irn_node_nr(node) >= get_irn_node_nr(neighbour))
				continue;

59
60
61
62
63
			fprintf(F, "edge: {sourcename: ");
			print_nodeid(F, node);
			fprintf(F, " targetname: ");
			print_nodeid(F, neighbour);
			fprintf(F, " arrowstyle:none class:1}\n");
Matthias Braun's avatar
Matthias Braun committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
		}
	}
}

void be_dump_ifg(FILE *F, ir_graph *irg, const be_ifg_t *ifg)
{
	ir_fprintf(F,
		"graph: { title: \"interference graph of %+F\"\n"
		"layoutalgorithm: mindepth //$ \"circular\"\n"
		"classname 1: \"interference\"\n"
		, irg);
	dump_vcg_infonames(F);
	dump_vcg_header_colors(F);

	dump_ifg_nodes(F, ifg);
	dump_ifg_edges(F, ifg);

	fprintf(F, "}\n");
}

static void dump_affinity_edges(FILE *F, const copy_opt_t *co,
                                bool dump_costs, bool dump_colors)
{
	co_gs_foreach_aff_node(co, a) {
		co_gs_foreach_neighb(a, n) {
			/* edges are bidirection, dumping one direction is enough */
			if (get_irn_node_nr(a->irn) >= get_irn_node_nr(n->irn))
				continue;

93
94
95
96
97
			fprintf(F, "edge: {sourcename: ");
			print_nodeid(F, a->irn);
			fprintf(F, " targetname: ");
			print_nodeid(F, n->irn);
			fprintf(F, " arrowstyle:none");
Matthias Braun's avatar
Matthias Braun committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

			if (dump_costs)
				fprintf(F, " label:\"%d\"", n->costs);
			if (dump_colors) {
				const arch_register_t *ar = arch_get_irn_register(a->irn);
				const arch_register_t *nr = arch_get_irn_register(n->irn);
				const char *color = nr == ar ? "blue" : "red";
				fprintf(F, " color:%s", color);
			}
			fprintf(F, " linestyle:dashed class:2");
			fprintf(F, "}\n");
		}
	}
}

void be_dump_ifg_co(FILE *F, const copy_opt_t *co, bool dump_costs,
                    bool dump_colors)
{
	ir_graph *irg = co->irg;
	be_ifg_t *ifg = co->cenv->ifg;

	ir_fprintf(F,
		"graph: { title: \"interference graph of %+F\"\n"
		"layoutalgorithm: mindepth //$ \"circular\"\n"
		"classname 1: \"interference\"\n"
		"classname 2: \"affinity\"\n"
		, irg);
	dump_vcg_infonames(F);
	dump_vcg_header_colors(F);

	dump_ifg_nodes(F, ifg);
	dump_ifg_edges(F, ifg);
	dump_affinity_edges(F, co, dump_costs, dump_colors);

	fprintf(F, "}\n");
}
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

static const char *lv_flags_to_str(unsigned flags)
{
	static const char *states[] = {
		"---",
		"i--",
		"-e-",
		"ie-",
		"--o",
		"i-o",
		"-eo",
		"ieo"
	};

	return states[flags & 7];
}

Matthias Braun's avatar
Matthias Braun committed
151
void be_dump_liveness_block(be_lv_t *lv, FILE *F, const ir_node *bl)
152
{
Matthias Braun's avatar
Matthias Braun committed
153
154
155
156
157
158
159
160
161
162
	be_lv_info_t *info = ir_nodehashmap_get(be_lv_info_t, &lv->map, bl);

	fprintf(F, "liveness:\n");
	if (info != NULL) {
		unsigned n = info[0].head.n_members;
		unsigned i;

		for (i = 0; i < n; ++i) {
			be_lv_info_node_t *n = &info[i+1].node;
			ir_fprintf(F, "%s %+F\n", lv_flags_to_str(n->flags), n->node);
163
164
165
166
167
168
		}
	}
}

typedef struct lv_walker_t {
	be_lv_t *lv;
Matthias Braun's avatar
Matthias Braun committed
169
	FILE    *out;
170
171
172
173
174
175
176
} lv_walker_t;

static void lv_dump_block_walker(ir_node *irn, void *data)
{
	lv_walker_t *w = (lv_walker_t*)data;
	if (!is_Block(irn))
		return;
Matthias Braun's avatar
Matthias Braun committed
177
	be_dump_liveness_block(w->lv, w->out, irn);
178
179
180
181
182
183
}

void be_liveness_dump(FILE *F, const be_lv_t *lv)
{
	lv_walker_t w;

Matthias Braun's avatar
Matthias Braun committed
184
185
	w.lv  = (be_lv_t *) lv;
	w.out = F;
186
187
	irg_block_walk_graph(lv->irg, lv_dump_block_walker, NULL, &w);
}