beifg: Factorise code to count interference components.
[libfirm] / ir / be / bedump.c
index 486ca8a..ce7421f 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * 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.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
 
 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) {
+       be_ifg_foreach_node(ifg, 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) {
+       be_ifg_foreach_node(ifg, 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
@@ -148,28 +128,25 @@ static const char *lv_flags_to_str(unsigned flags)
        return states[flags & 7];
 }
 
-void be_dump_liveness_block(void *context, FILE *F, const ir_node *bl)
+void be_dump_liveness_block(be_lv_t *lv, FILE *F, const ir_node *bl)
 {
-       if (is_Block(bl)) {
-               be_lv_t *lv = (be_lv_t*)context;
-               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);
-                       }
+       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);
                }
        }
 }
 
 typedef struct lv_walker_t {
        be_lv_t *lv;
-       void *data;
+       FILE    *out;
 } lv_walker_t;
 
 static void lv_dump_block_walker(ir_node *irn, void *data)
@@ -177,14 +154,14 @@ static void lv_dump_block_walker(ir_node *irn, void *data)
        lv_walker_t *w = (lv_walker_t*)data;
        if (!is_Block(irn))
                return;
-       be_dump_liveness_block(w->lv, (FILE*)w->data, irn);
+       be_dump_liveness_block(w->lv, w->out, irn);
 }
 
 void be_liveness_dump(FILE *F, const be_lv_t *lv)
 {
        lv_walker_t w;
 
-       w.lv   = (be_lv_t *) lv;
-       w.data = F;
+       w.lv  = (be_lv_t *) lv;
+       w.out = F;
        irg_block_walk_graph(lv->irg, lv_dump_block_walker, NULL, &w);
 }