4 * @author Sebastian Hack
6 * Copyright (C) 2005 Universitaet Karlsruhe
7 * Released under the GPL
31 size_t (be_ifg_nodes_iter_size)(const void *self)
33 const be_ifg_t *ifg = self;
34 return ifg->impl->nodes_iter_size;
37 size_t (be_ifg_neighbours_iter_size)(const void *self)
39 const be_ifg_t *ifg = self;
40 return ifg->impl->neighbours_iter_size;
43 size_t (be_ifg_cliques_iter_size)(const void *self)
45 const be_ifg_t *ifg = self;
46 return ifg->impl->cliques_iter_size;
49 void (be_ifg_free)(void *self)
52 ifg->impl->free(self);
55 int (be_ifg_connected)(const void *self, const ir_node *a, const ir_node *b)
57 const be_ifg_t *ifg = self;
58 return ifg->impl->connected(self, a, b);
61 ir_node *(be_ifg_neighbours_begin)(const void *self, void *iter, const ir_node *irn)
63 const be_ifg_t *ifg = self;
64 return ifg->impl->neighbours_begin(self, iter, irn);
67 ir_node *(be_ifg_neighbours_next)(const void *self, void *iter)
69 const be_ifg_t *ifg = self;
70 return ifg->impl->neighbours_next(self, iter);
73 void (be_ifg_neighbours_break)(const void *self, void *iter)
75 const be_ifg_t *ifg = self;
76 ifg->impl->neighbours_break(self, iter);
79 ir_node *(be_ifg_nodes_begin)(const void *self, void *iter)
81 const be_ifg_t *ifg = self;
82 return ifg->impl->nodes_begin(self, iter);
85 ir_node *(be_ifg_nodes_next)(const void *self, void *iter)
87 const be_ifg_t *ifg = self;
88 return ifg->impl->nodes_next(self, iter);
91 void (be_ifg_nodes_break)(const void *self, void *iter)
93 const be_ifg_t *ifg = self;
94 ifg->impl->nodes_break(self, iter);
97 int (be_ifg_cliques_begin)(const void *self, void *iter, ir_node **buf)
99 const be_ifg_t *ifg = self;
100 return ifg->impl->cliques_begin(self, iter, buf);
103 int (be_ifg_cliques_next)(const void *self, void *iter)
105 const be_ifg_t *ifg = self;
106 return ifg->impl->cliques_next(self, iter);
109 void (be_ifg_cliques_break)(const void *self, void *iter)
111 const be_ifg_t *ifg = self;
112 ifg->impl->cliques_break(self, iter);
115 int (be_ifg_degree)(const void *self, const ir_node *irn)
117 const be_ifg_t *ifg = self;
118 return ifg->impl->degree(self, irn);
122 int be_ifg_is_simplicial(const be_ifg_t *ifg, const ir_node *irn)
124 int degree = be_ifg_degree(ifg, irn);
125 void *iter = be_ifg_neighbours_iter_alloca(ifg);
127 ir_node **neighbours = xmalloc(degree * sizeof(neighbours[0]));
133 be_ifg_foreach_neighbour(ifg, iter, irn, curr)
134 neighbours[i++] = curr;
136 for(i = 0; i < degree; ++i) {
137 for(j = 0; j < i; ++j)
138 if(!be_ifg_connected(ifg, neighbours[i], neighbours[j])) {
149 void be_ifg_check(const be_ifg_t *ifg)
151 void *iter1 = be_ifg_nodes_iter_alloca(ifg);
152 void *iter2 = be_ifg_neighbours_iter_alloca(ifg);
156 int neighbours_count = 0;
159 /* count all nodes */
160 ir_printf("\n\nFound the following nodes in the graph %+F:\n\n", current_ir_graph);
161 be_ifg_foreach_node(ifg,iter1,n)
164 degree = be_ifg_degree(ifg, n);
165 ir_printf("%d. %+F with degree: %d\n", node_count, n, degree);
168 ir_printf("\n\nNumber of nodes: %d\n\n", node_count);
170 /* Check, if all neighbours are indeed connected to the node. */
171 be_ifg_foreach_node(ifg, iter1, n)
173 ir_printf("\n%+F; ", n);
174 be_ifg_foreach_neighbour(ifg, iter2, n, m)
176 ir_printf("%+F; ", m);
178 if(!be_ifg_connected(ifg, n, m))
179 ir_fprintf(stderr, "%+F is a neighbour of %+F but they are not connected!\n", n, m);
182 ir_printf("\n\nFound %d nodes in the 'check neighbour section'\n", neighbours_count);
185 int be_ifg_check_get_node_count(const be_ifg_t *ifg)
187 void *iter = be_ifg_nodes_iter_alloca(ifg);
191 be_ifg_foreach_node(ifg, iter, n)
199 static int be_ifg_check_cmp_nodes(const void *a, const void *b)
201 const ir_node *node_a = *(ir_node **)a;
202 const ir_node *node_b = *(ir_node **)b;
204 int nr_a = node_a->node_nr;
205 int nr_b = node_b->node_nr;
207 return QSORT_CMP(nr_a, nr_b);
210 void be_ifg_check_sorted(const be_ifg_t *ifg, FILE *f)
212 void *iter1 = be_ifg_nodes_iter_alloca(ifg);
213 void *iter2 = be_ifg_neighbours_iter_alloca(ifg);
216 const int node_count = be_ifg_check_get_node_count(ifg);
217 int neighbours_count = 0;
220 ir_node **all_nodes = xmalloc(node_count * sizeof(all_nodes[0]));
222 be_ifg_foreach_node(ifg, iter1, n)
228 qsort(all_nodes, node_count, sizeof(all_nodes[0]), be_ifg_check_cmp_nodes);
230 for (i = 0; i < node_count; i++)
232 ir_node **neighbours = xmalloc(node_count * sizeof(neighbours[0]));
237 degree = be_ifg_degree(ifg, all_nodes[i]);
239 be_ifg_foreach_neighbour(ifg, iter2, all_nodes[i], m)
245 qsort(neighbours, j, sizeof(neighbours[0]), be_ifg_check_cmp_nodes);
247 ir_fprintf(f, "%d. %+F's neighbours(%d): ", i+1, all_nodes[i], degree);
249 for(k = 0; k < j; k++)
251 ir_fprintf(f, "%+F, ", neighbours[k]);
263 void be_ifg_dump_dot(be_ifg_t *ifg, ir_graph *irg, FILE *file, const be_ifg_dump_dot_cb_t *cb, void *self)
265 void *nodes_it = be_ifg_nodes_iter_alloca(ifg);
266 void *neigh_it = be_ifg_neighbours_iter_alloca(ifg);
267 bitset_t *nodes = bitset_malloc(get_irg_last_idx(irg));
271 fprintf(file, "graph G {\n\tgraph [");
273 cb->graph_attr(file, self);
274 fprintf(file, "];\n");
277 cb->at_begin(file, self);
279 be_ifg_foreach_node(ifg, nodes_it, n) {
280 if(cb->is_dump_node && cb->is_dump_node(self, n)) {
281 int idx = get_irn_idx(n);
282 bitset_set(nodes, idx);
283 fprintf(file, "\tnode [");
285 cb->node_attr(file, self, n);
286 fprintf(file, "]; n%d;\n", idx);
290 /* Check, if all neighbours are indeed connected to the node. */
291 be_ifg_foreach_node(ifg, nodes_it, n) {
292 be_ifg_foreach_neighbour(ifg, neigh_it, n, m) {
293 int n_idx = get_irn_idx(n);
294 int m_idx = get_irn_idx(m);
296 if(n_idx < m_idx && bitset_is_set(nodes, n_idx) && bitset_is_set(nodes, m_idx)) {
297 fprintf(file, "\tn%d -- n%d [", n_idx, m_idx);
299 cb->edge_attr(file, self, n, m);
300 fprintf(file, "];\n");
306 cb->at_end(file, self);
308 fprintf(file, "}\n");