Let dfs() discover only memory nodes
[libfirm] / ir / ir / irdump.c
index 9b1904a..5a1ce28 100644 (file)
@@ -50,6 +50,7 @@
 #include "irgwalk.h"
 #include "tv_t.h"
 #include "irouts.h"
+#include "iredges.h"
 #include "irdom.h"
 #include "irloop_t.h"
 #include "callgraph.h"
@@ -93,6 +94,8 @@ static int edge_label = 1;
 static int const_entities = 1;
 /** An option to dump the keep alive edges */
 static int dump_keepalive = 0;
+/** An option to dump the new out edges */
+static int dump_new_edges_flag = 0;
 /** An option to dump ld_names instead of names. */
 static int dump_ld_name = 1;
 /** Compiler options to dump analysis information in dump_ir_graph */
@@ -160,10 +163,9 @@ void set_dump_edge_vcgattr_hook(DUMP_EDGE_VCGATTR_FUNC hook) {
  * are set, else returns dump_const_local_flag.
  */
 int get_opt_dump_const_local(void) {
-       if (!dump_out_edge_flag && !dump_loop_information_flag)
-               return dump_const_local;
-       else
+       if (dump_out_edge_flag || dump_loop_information_flag || (dump_new_edges_flag && edges_activated(current_ir_graph)))
                return 0;
+       return dump_const_local;
 }
 
 /* Set a prefix filter for output functions. */
@@ -204,6 +206,10 @@ void dump_keepalive_edges(int flag) {
        dump_keepalive = flag;
 }
 
+void dump_new_edges(int flag) {
+       dump_new_edges_flag = flag;
+}
+
 int get_opt_dump_keepalive_edges(void) {
        return dump_keepalive;
 }
@@ -541,7 +547,7 @@ static int node_floats(ir_node *n) {
  *  Walker that visits the anchors
  */
 static void ird_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
-       if (dump_anchors) {
+       if (dump_anchors || (dump_new_edges_flag && edges_activated(irg))) {
                irg_walk_anchors(irg, pre, post, env);
        } else {
                irg_walk_graph(irg, pre, post, env);
@@ -588,7 +594,9 @@ static void collect_node(ir_node * node, void *env) {
  */
 static ir_node **construct_block_lists(ir_graph *irg) {
        int      i;
+#ifdef INTERPROCEDURAL_VIEW
        int      rem_view  = get_interprocedural_view();
+#endif
        int      walk_flag = using_visited(irg);
        ir_graph *rem      = current_ir_graph;
 
@@ -602,15 +610,19 @@ static ir_node **construct_block_lists(ir_graph *irg) {
 
        ird_walk_graph(current_ir_graph, clear_link, collect_node, current_ir_graph);
 
+#ifdef INTERPROCEDURAL_VIEW
        /* Collect also EndReg and EndExcept. We do not want to change the walker. */
        set_interprocedural_view(0);
+#endif
 
        set_irg_visited(current_ir_graph, get_irg_visited(current_ir_graph)-1);
        irg_walk(get_irg_end_reg(current_ir_graph), clear_link, collect_node, current_ir_graph);
        set_irg_visited(current_ir_graph, get_irg_visited(current_ir_graph)-1);
        irg_walk(get_irg_end_except(current_ir_graph), clear_link, collect_node, current_ir_graph);
 
+#ifdef INTERPROCEDURAL_VIEW
        set_interprocedural_view(rem_view);
+#endif
 
        if(walk_flag)
                set_using_visited(current_ir_graph);
@@ -1116,13 +1128,17 @@ handle_lut:
 #include "execution_frequency.h"
 
 static void dump_node_ana_vals(FILE *F, ir_node *n) {
+       (void) F;
+       (void) n;
        return;
+#ifdef INTERPROCEDURAL_VIEW
        fprintf(F, " %lf*(%2.0lf + %2.0lf) = %2.0lf ",
                get_irn_exec_freq(n),
                get_irg_method_execution_frequency(get_irn_irg(n)),
                pow(5, get_irg_recursion_depth(get_irn_irg(n))),
                get_irn_exec_freq(n) * (get_irg_method_execution_frequency(get_irn_irg(n)) + pow(5, get_irg_recursion_depth(get_irn_irg(n))))
        );
+#endif
 }
 
 
@@ -1500,7 +1516,7 @@ static void dump_ir_data_edges(FILE *F, ir_node *n)  {
        for (i = 0; i < get_irn_deps(n); ++i) {
                ir_node *dep = get_irn_dep(n, i);
 
-               if(dep) {
+               if (dep) {
                        fprintf(F, "edge: {sourcename: \"");
                        PRINT_NODEID(n);
                        fprintf(F, "\" targetname: ");
@@ -1540,9 +1556,34 @@ static void dump_ir_data_edges(FILE *F, ir_node *n)  {
        }
 }
 
+/**
+ * Dump the ir_edges
+ */
+static void
+dump_ir_edges(FILE *F, ir_node *n) {
+       const ir_edge_t *edge;
+       int i = 0;
+
+       foreach_out_edge(n, edge) {
+               ir_node *succ = get_edge_src_irn(edge);
+
+               fprintf(F, "edge: {sourcename: \"");
+               PRINT_NODEID(n);
+               fprintf(F, "\" targetname: \"");
+               PRINT_NODEID(succ);
+               fprintf(F, "\"");
+
+               fprintf(F, " label: \"%d\" ", i);
+               fprintf(F, OUT_EDGE_ATTR);
+               fprintf(F, "}\n");
+               ++i;
+       }
+}
+
+
 /** Dumps a node and its edges but not the block edge
  */
-static INLINE void
+static void
 dump_node_wo_blockedge(ir_node *n, void *env) {
        FILE *F = env;
        dump_node(F, n);
@@ -1555,7 +1596,10 @@ static void
 dump_whole_node(ir_node *n, void *env) {
        FILE *F = env;
        dump_node_wo_blockedge(n, env);
-       if (!node_floats(n)) dump_ir_block_edge(F, n);
+       if (!node_floats(n))
+               dump_ir_block_edge(F, n);
+       if (dump_new_edges_flag && edges_activated(current_ir_graph))
+               dump_ir_edges(F, n);
 }
 
 static void
@@ -1663,6 +1707,8 @@ dump_block_graph(FILE *F, ir_graph *irg) {
                        }
                        dump_ir_data_edges(F, node);
                }
+               if (dump_new_edges_flag && edges_activated(irg))
+                       dump_ir_edges(F, node);
        }
 
        if (dump_loop_information_flag && (get_irg_loopinfo_state(irg) & loopinfo_valid))
@@ -2218,12 +2264,13 @@ void dump_vcg_header(FILE *F, const char *name, const char *orientation) {
                "classname 18: \"Exception Control Flow for Interval Analysis\"\n"
                "classname 19: \"Postdominators\"\n"
                "classname 20: \"Keep Alive\"\n"
+               "classname 21: \"Out Edges\"\n"
                "infoname 1: \"Attribute\"\n"
                "infoname 2: \"Verification errors\"\n"
                "infoname 3: \"Debug info\"\n",
                name, label, orientation);
 
-       /* don't use all, the range is too whith/black. */
+       /* don't use all, the range is too wide. */
        n_colors   = 18;
        base_color = 105;
        fprintf(F,
@@ -2442,9 +2489,10 @@ void dump_ir_block_graph(ir_graph *irg, const char *suffix)
                 * from irg.
                 */
                for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-                       ir_node **arr = ird_get_irg_link(get_irp_irg(i));
+                       ir_graph *g = get_irp_irg(i);
+                       ir_node **arr = ird_get_irg_link(g);
                        if (arr) {
-                               dump_graph_from_list(f, get_irp_irg(i));
+                               dump_graph_from_list(f, g);
                                DEL_ARR_F(arr);
                        }
                }
@@ -2690,21 +2738,27 @@ dump_cfg(ir_graph *irg, const char *suffix)
        f = vcg_open(irg, suffix, "-cfg");
        if (f != NULL) {
                ir_graph *rem = current_ir_graph;
+#ifdef INTERPROCEDURAL_VIEW
                int ipv = get_interprocedural_view();
+#endif
 
                current_ir_graph = irg;
                dump_vcg_header(f, get_irg_dump_name(irg), NULL);
 
+#ifdef INTERPROCEDURAL_VIEW
                if (ipv) {
                        printf("Warning: dumping cfg not in interprocedural view!\n");
                        set_interprocedural_view(0);
                }
+#endif
 
                /* walk over the blocks in the graph */
                irg_block_walk(get_irg_end(irg), dump_block_to_cfg, NULL, f);
                dump_node(f, get_irg_bad(irg));
 
+#ifdef INTERPROCEDURAL_VIEW
                set_interprocedural_view(ipv);
+#endif
                vcg_close(f);
                current_ir_graph = rem;
        }
@@ -2744,7 +2798,7 @@ void dump_subgraph(ir_node *root, int depth, const char *suffix) {
        }
 }
 
-
+#if 0
 static int weight_overall(int rec, int loop) {
        return 2*rec + loop;
 }
@@ -2790,24 +2844,29 @@ static int get_entity_color(ir_entity *ent) {
                return my_overall_color;
        }
 }
+#endif
 
+#ifdef INTERPROCEDURAL_VIEW
 void dump_callgraph(const char *suffix) {
        FILE *F = vcg_open_name("Callgraph", suffix);
 
        if (F != NULL) {
-               int i, rem = edge_label, colorize;
+               int i, rem = edge_label;
+               //int colorize;
                edge_label = 1;
                dump_vcg_header(F, "Callgraph", NULL);
 
-               colorize = get_irp_callgraph_state() == irp_callgraph_and_calltree_consistent;
+               //colorize = get_irp_callgraph_state() == irp_callgraph_and_calltree_consistent;
 
                for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
                        ir_graph *irg = get_irp_irg(i);
                        ir_entity *ent = get_irg_entity(irg);
-                       int j, n_callees = get_irg_n_callees(irg);
+                       int j;
+                       //int n_callees = get_irg_n_callees(irg);
                        int color;
 
-                       color = colorize ? get_entity_color(ent) : ird_color_green;
+                       //color = colorize ? get_entity_color(ent) : ird_color_green;
+                       color = ird_color_green;
                        dump_entity_node(F, ent, color);
                        for (j = 0; j < n_callees; ++j) {
                                ir_entity *c = get_irg_entity(get_irg_callee(irg, j));
@@ -2855,6 +2914,7 @@ void dump_all_cg_block_graph(const char *suffix) {
                set_interprocedural_view(rem_view);
        }
 }
+#endif
 
 /*---------------------------------------------------------------------*/
 /* the following routines dumps type information without any ir nodes. */