localopt stuff for const-code irg
[libfirm] / ir / be / bedump.c
index 5e478c5..1e43f38 100644 (file)
 #include "bedump.h"
 
 #include "irdump_t.h"
+#include "irgwalk.h"
 #include "beifg.h"
 #include "becopyopt_t.h"
+#include "belive_t.h"
 
 static void dump_ifg_nodes(FILE *F, const be_ifg_t *ifg)
 {
@@ -54,11 +56,11 @@ static void dump_ifg_edges(FILE *F, const be_ifg_t *ifg)
                        if (get_irn_node_nr(node) >= get_irn_node_nr(neighbour))
                                continue;
 
-                       fprintf(F, "edge: {sourcename: \"");
-                       PRINT_NODEID(node);
-                       fprintf(F, "\" targetname: \"");
-                       PRINT_NODEID(neighbour);
-                       fprintf(F, "\" arrowstyle:none class:1}\n");
+                       fprintf(F, "edge: {sourcename: ");
+                       print_nodeid(F, node);
+                       fprintf(F, " targetname: ");
+                       print_nodeid(F, neighbour);
+                       fprintf(F, " arrowstyle:none class:1}\n");
                }
        }
 }
@@ -82,20 +84,17 @@ void be_dump_ifg(FILE *F, ir_graph *irg, const be_ifg_t *ifg)
 static void dump_affinity_edges(FILE *F, const copy_opt_t *co,
                                 bool dump_costs, bool dump_colors)
 {
-       affinity_node_t *a;
        co_gs_foreach_aff_node(co, a) {
-               neighb_t *n;
-
                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;
 
-                       fprintf(F, "edge: {sourcename: \"");
-                       PRINT_NODEID(a->irn);
-                       fprintf(F, "\" targetname: \"");
-                       PRINT_NODEID(n->irn);
-                       fprintf(F, "\" arrowstyle:none");
+                       fprintf(F, "edge: {sourcename: ");
+                       print_nodeid(F, a->irn);
+                       fprintf(F, " targetname: ");
+                       print_nodeid(F, n->irn);
+                       fprintf(F, " arrowstyle:none");
 
                        if (dump_costs)
                                fprintf(F, " label:\"%d\"", n->costs);
@@ -132,3 +131,60 @@ void be_dump_ifg_co(FILE *F, const copy_opt_t *co, bool dump_costs,
 
        fprintf(F, "}\n");
 }
+
+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];
+}
+
+void be_dump_liveness_block(void *context, 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), get_idx_irn(lv->irg, n->idx));
+                       }
+               }
+       }
+}
+
+typedef struct lv_walker_t {
+       be_lv_t *lv;
+       void *data;
+} 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;
+       be_dump_liveness_block(w->lv, (FILE*)w->data, 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;
+       irg_block_walk_graph(lv->irg, lv_dump_block_walker, NULL, &w);
+}