Added dumping of interference graphs
authorSebastian Hack <hack@ipd.info.uni-karlsruhe.de>
Tue, 2 May 2006 12:01:59 +0000 (12:01 +0000)
committerSebastian Hack <hack@ipd.info.uni-karlsruhe.de>
Tue, 2 May 2006 12:01:59 +0000 (12:01 +0000)
ir/be/beifg.c
ir/be/beifg.h

index b43d260..e329de7 100644 (file)
@@ -21,6 +21,8 @@
 #include <alloca.h>
 #endif
 
+#include "bitset.h"
+
 #include "irnode_t.h"
 #include "irprintf.h"
 #include "beifg_t.h"
@@ -157,3 +159,52 @@ void be_ifg_check(const be_ifg_t *ifg)
                                ir_fprintf(stderr, "%+F is a neighbour of %+F but they are not connected!\n", n, m);
        }
 }
+
+void be_ifg_dump_dot(be_ifg_t *ifg, ir_graph *irg, FILE *file, const be_ifg_dump_dot_cb_t *cb, void *self)
+{
+       void *nodes_it  = be_ifg_nodes_iter_alloca(ifg);
+       void *neigh_it  = be_ifg_neighbours_iter_alloca(ifg);
+       bitset_t *nodes = bitset_malloc(get_irg_last_idx(irg));
+
+       ir_node *n, *m;
+
+       fprintf(file, "graph G {\n\tgraph [");
+       if(cb->graph_attr)
+               cb->graph_attr(file, self);
+       fprintf(file, "];\n");
+
+       if(cb->at_begin)
+               cb->at_begin(file, self);
+
+       be_ifg_foreach_node(ifg, nodes_it, n) {
+               if(cb->is_dump_node && cb->is_dump_node(self, n)) {
+                       int idx = get_irn_idx(n);
+                       bitset_set(nodes, idx);
+                       fprintf(file, "\tnode [");
+                       if(cb->node_attr)
+                               cb->node_attr(file, self, n);
+                       fprintf(file, "]; n%d;\n", idx);
+               }
+       }
+
+       /* Check, if all neighbours are indeed connected to the node. */
+       be_ifg_foreach_node(ifg, nodes_it, n) {
+               be_ifg_foreach_neighbour(ifg, neigh_it, n, m) {
+                       int n_idx = get_irn_idx(n);
+                       int m_idx = get_irn_idx(m);
+
+                       if(n_idx < m_idx && bitset_is_set(nodes, n_idx) && bitset_is_set(nodes, m_idx)) {
+                               fprintf(file, "\tn%d -- n%d [", n_idx, m_idx);
+                               if(cb->edge_attr)
+                                       cb->edge_attr(file, self, n, m);
+                               fprintf(file, "];\n");
+                       }
+               }
+       }
+
+       if(cb->at_end)
+               cb->at_end(file, self);
+
+       fprintf(file, "}\n");
+       bitset_free(nodes);
+}
index 7130a13..7844d15 100644 (file)
@@ -46,4 +46,24 @@ int      (be_ifg_degree)(const void *self, const ir_node *irn);
         *(count) != -1 ; \
         *(count) = be_ifg_cliques_next(self, iter))
 
+/*
+        ____                        _
+       |  _ \ _   _ _ __ ___  _ __ (_)_ __   __ _
+       | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
+       | |_| | |_| | | | | | | |_) | | | | | (_| |
+       |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
+                          |_|            |___/
+*/
+
+typedef struct _be_ifg_dump_dot_cb_t {
+       int  (*is_dump_node)(void *self, ir_node *irn);
+       void (*graph_attr)(FILE *f, void *self);
+       void (*node_attr)(FILE *f, void *self, ir_node *irn);
+       void (*edge_attr)(FILE *f, void *self, ir_node *from, ir_node *to);
+       void (*at_begin)(FILE *file, void *self);
+       void (*at_end)(FILE *file, void *self);
+} be_ifg_dump_dot_cb_t;
+
+void be_ifg_dump_dot(be_ifg_t *ifg, ir_graph *irg, FILE *file, const be_ifg_dump_dot_cb_t *cb, void *self);
+
 #endif /* _BEIFG_H */