rework liveness dumper
authorMatthias Braun <matze@braunis.de>
Tue, 27 Nov 2012 13:53:54 +0000 (14:53 +0100)
committerMatthias Braun <matze@braunis.de>
Wed, 28 Nov 2012 10:27:12 +0000 (11:27 +0100)
- some code cleanup
- avoids the case where 2 dumpers are registered

ir/be/bedump.c
ir/be/bedump.h
ir/be/beinfo.c
ir/be/belive.c
ir/be/belive_t.h

index 486ca8a..9c216ed 100644 (file)
@@ -148,28 +148,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 +174,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);
 }
index 9326ff3..7b7775a 100644 (file)
@@ -52,6 +52,6 @@ void be_liveness_dump(FILE *F, const be_lv_t *lv);
 /**
  * node_info hook that dumps liveness for blocks
  */
-void be_dump_liveness_block(void *context, FILE *F, const ir_node *block);
+void be_dump_liveness_block(be_lv_t *lv, FILE *F, const ir_node *block);
 
 #endif
index 611d5c0..cada5c5 100644 (file)
 #include "bearch.h"
 #include "benode.h"
 #include "besched.h"
+#include "bedump.h"
+#include "belive_t.h"
 #include "irgwalk.h"
 #include "irnode_t.h"
 #include "irdump_t.h"
+#include "irhooks.h"
 #include "error.h"
 
 static copy_attr_func old_phi_copy_attr;
@@ -130,7 +133,26 @@ static void init_walker(ir_node *node, void *data)
        be_info_new_node(irg, node);
 }
 
-static bool initialized = false;
+static bool         initialized = false;
+static hook_entry_t hook_liveness_info;
+
+static void dump_liveness_info_hook(void *context, FILE *F, const ir_node *node)
+{
+       (void)context;
+       if (!is_Block(node))
+               return;
+       ir_graph *irg = get_irn_irg(node);
+       if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND))
+               return;
+
+       be_lv_t *lv = be_get_irg_liveness(irg);
+       if (lv == NULL)
+               return;
+       if (!lv->sets_valid)
+               return;
+
+       be_dump_liveness_block(lv, F, node);
+}
 
 void be_info_init(void)
 {
@@ -144,6 +166,9 @@ void be_info_init(void)
        /* phis have register and register requirements now which we want to dump */
        assert(op_Phi->ops.dump_node == NULL);
        op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
+
+       hook_liveness_info.hook._hook_node_info = dump_liveness_info_hook;
+       register_hook(hook_node_info, &hook_liveness_info);
 }
 
 /**
@@ -184,4 +209,6 @@ void be_info_free(void)
 
        assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
        op_Phi->ops.dump_node = NULL;
+
+       unregister_hook(hook_node_info, &hook_liveness_info);
 }
index 3ccd831..c1123a6 100644 (file)
@@ -42,7 +42,6 @@
 #include "belive_t.h"
 #include "besched.h"
 #include "bemodule.h"
-#include "bedump.h"
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
 
@@ -414,7 +413,6 @@ void be_liveness_compute_sets(be_lv_t *lv)
 
        DEL_ARR_F(nodes);
        free(re.visited);
-       register_hook(hook_node_info, &lv->hook_info);
 
        be_timer_pop(T_LIVE);
 
@@ -432,7 +430,6 @@ void be_liveness_invalidate_sets(be_lv_t *lv)
 {
        if (!lv->sets_valid)
                return;
-       unregister_hook(hook_node_info, &lv->hook_info);
        obstack_free(&lv->obst, NULL);
        ir_nodehashmap_destroy(&lv->map);
        lv->sets_valid = false;
@@ -453,8 +450,6 @@ be_lv_t *be_liveness_new(ir_graph *irg)
        be_lv_t *lv = XMALLOCZ(be_lv_t);
 
        lv->irg = irg;
-       lv->hook_info.context = lv;
-       lv->hook_info.hook._hook_node_info = be_dump_liveness_block;
 
        return lv;
 }
index 4e1d22f..15e58ed 100644 (file)
@@ -41,7 +41,6 @@ struct be_lv_t {
        struct obstack   obst;
        bool             sets_valid;
        ir_graph        *irg;
-       hook_entry_t     hook_info;
        lv_chk_t        *lvc;
 };