Implemented cf optimizations.
[libfirm] / ir / ir / irdump.c
index 0ebc0b0..d426237 100644 (file)
@@ -18,7 +18,7 @@
 # include "irdump.h"
 # include "panic.h"
 # include <string.h>
-# include "entity.h"
+# include "entity_t.h"
 # include <stdlib.h>
 # include "array.h"
 # include "irop_t.h"
@@ -27,6 +27,7 @@
 # include "irgwalk.h"
 # include "typewalk.h"
 # include "irouts.h"
+#include "irdom.h"
 
 /* Attributes of nodes */
 #define DEFAULT_NODE_ATTR ""
@@ -36,6 +37,7 @@
 #define BLOCK_EDGE_ATTR "class: 2 priority: 2 linestyle: dotted"
 #define CF_EDGE_ATTR    "color: red"
 #define MEM_EDGE_ATTR   "color: blue"
+#define DOMINATOR_EDGE_ATTR "color: red"
 
 /* Attributes of edges between Firm nodes and type/entity nodes */
 #define NODE2TYPE_EDGE_ATTR "class: 2 priority: 2 linestyle: dotted"
@@ -65,6 +67,9 @@
 #define PRINT_NODEID(X) fprintf(F, "%p", X)
 #endif
 
+/* A suffix to manipulate the file name. */
+char *dump_file_suffix = NULL;
+
 /* file to dump to */
 static FILE *F;
 
@@ -76,7 +81,7 @@ int const_entities = 1;
 int dump_keepalive = 0;
 /* A compiler option to dump the out edges in dump_ir_graph */
 int dump_out_edge_flag = 0;
-
+int dump_dominator_information_flag = 0;
 
 /* A global variable to record output of the Bad node. */
 int Bad_dumped;
@@ -102,11 +107,12 @@ dump_node_opcode (ir_node *n)
   /* SymConst */
   } else if (n->op->code == iro_SymConst) {
     if (get_SymConst_kind(n) == linkage_ptr_info) {
-      xfprintf (F, "%I", get_SymConst_ptrinfo(n));
+      /* don't use get_SymConst_ptr_info as it mangles the name. */
+      xfprintf (F, "SymC %I", n->attr.i.tori.ptrinfo);
     } else {
       assert(get_kind(get_SymConst_type(n)) == k_type);
       assert(get_type_ident(get_SymConst_type(n)));
-      xfprintf (F, "%s ", id_to_str(get_type_ident(get_SymConst_type(n))));
+      xfprintf (F, "SymC %I ", get_type_ident(get_SymConst_type(n)));
       if (get_SymConst_kind == type_tag)
        xfprintf (F, "tag");
       else
@@ -157,7 +163,7 @@ dump_node_nodeattr (ir_node *n)
     break;
   case iro_Sel: {
     assert(get_kind(get_Sel_entity(n)) == k_entity);
-    xfprintf (F, "%s", id_to_str(get_entity_ident(get_Sel_entity(n))));
+    xfprintf (F, "%I", get_entity_ident(get_Sel_entity(n)));
     } break;
   default:
   } /* end switch */
@@ -344,7 +350,7 @@ dump_ir_node (ir_node *n)
   case iro_Sel:
     assert(get_kind(get_Sel_entity(n)) == k_entity);
     xfprintf (F, "\"%I ", get_irn_opident(n));
-    xfprintf (F, "%s", id_to_str(get_entity_ident(get_Sel_entity(n))));
+    xfprintf (F, "%I", get_entity_ident(get_Sel_entity(n)));
     xfprintf (F, DEFAULT_NODE_ATTR);
     break;
   case iro_SymConst:
@@ -634,7 +640,7 @@ dump_type_info (type_or_ent *tore, void *env) {
       switch (get_entity_visibility(ent)) {
        case local:              fprintf (F, "local\n");             break;
        case external_visible:   fprintf (F, "external_visible\n");  break;
-       case external_allocated: fprintf (F, "external_allocate\nd");break;
+       case external_allocated: fprintf (F, "external_allocate\n");break;
       }
       switch (get_entity_variability(ent)) {
        case uninitialized: fprintf (F, "uninitialized");break;
@@ -642,10 +648,13 @@ dump_type_info (type_or_ent *tore, void *env) {
        case part_constant: fprintf (F, "part_constant");break;
        case constant:      fprintf (F, "constant");     break;
       }
+      if (is_method_type(get_entity_type(ent)))
+       xfprintf (F, "\n irg = %p ", get_entity_irg(ent));
       xfprintf(F, "\"}\n");
       /* The Edges */
+      /* skip this to reduce graph.  Member edge of type is parallel to this edge. *
       xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
-                ENT_OWN_EDGE_ATTR "}\n", ent, get_entity_owner(ent));
+                ENT_OWN_EDGE_ATTR "}\n", ent, get_entity_owner(ent));*/
       xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
                 ENT_TYPE_EDGE_ATTR "}\n", ent, get_entity_type(ent));
       for(i = 0; i < get_entity_n_overwrites(ent); i++)
@@ -760,21 +769,18 @@ void vcg_open (ir_graph *irg, char *suffix) {
 
   /** open file for vcg graph */
   ent = get_irg_ent(irg);
-  id    = get_entity_ld_ident (ent);
+  id    = ent->ld_name ? ent->ld_name : ent->name;
+  /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
   len   = id_to_strlen (id);
   cp    = id_to_str (id);
-  fname = malloc (len + 5 + strlen(suffix));
+  if (dump_file_suffix)
+    fname = malloc (len + 5 + strlen(suffix) + strlen(dump_file_suffix));
+  else
+    fname = malloc (len + 5 + strlen(suffix));
   strncpy (fname, cp, len);      /* copy the filename */
   fname[len] = '\0';
+  if (dump_file_suffix) strcat (fname, dump_file_suffix);  /* append file suffix */
   strcat (fname, suffix);  /* append file suffix */
-
-  fname = malloc (len + 5 + strlen(suffix));
-  strncpy (fname, cp, len); /* copy the filename */
-  fname[len] = '\0';        /* ensure string termination */
-  /*strcpy (fname, cp);      * copy the filename *
-    this produces wrong, too long strings in conjuction with the
-    jocca frontend.  The \0 seems to be missing. */
-  strcat (fname, suffix);   /* append file suffix */
   strcat (fname, ".vcg");   /* append the .vcg suffix */
   F = fopen (fname, "w");   /* open file for writing */
   if (!F) {
@@ -902,6 +908,7 @@ dump_ir_graph (ir_graph *irg)
 /***********************************************************************/
 
 int node_floats(ir_node *n) {
+
   return ((get_op_pinned(get_irn_op(n)) == floats) &&
          (get_irg_pinned(current_ir_graph) == floats));
 }
@@ -1003,16 +1010,31 @@ dump_block_to_cfg (ir_node *block, void *env) {
 
   if (get_irn_opcode(block) == iro_Block) {
     /* This is a block. Dump a node for the block. */
-    xfprintf (F, "node: {title: \"%p\" label: \"%I\"}", block,
-             block->op->name);
+    xfprintf (F, "node: {title:\""); PRINT_NODEID(block);
+    xfprintf (F, "\" label: \"%I ", block->op->name); PRINT_NODEID(block);
+    xfprintf (F, "\" ");
+    if (dump_dominator_information_flag)
+      xfprintf(F, "info1:\"dom depth %d\"", get_Block_dom_depth(block));
+    xfprintf (F, "}\n");
     /* Dump the edges */
-    for ( i = 0; i < get_Block_n_cfgpreds(block); i++) {
-      pred = get_nodes_Block(skip_Proj(get_Block_cfgpred(block, i)));
+    for ( i = 0; i < get_Block_n_cfgpreds(block); i++)
+      if (get_irn_op(skip_Proj(get_Block_cfgpred(block, i))) != op_Bad) {
+       pred = get_nodes_Block(skip_Proj(get_Block_cfgpred(block, i)));
+       xfprintf (F, "edge: { sourcename: \"");
+       PRINT_NODEID(block);
+       fprintf (F, "\" targetname: \"");
+       PRINT_NODEID(pred);
+       fprintf (F, "\" }\n");
+      }
+
+    /* Dump dominator edge */
+    if (dump_dominator_information_flag && get_Block_idom(block)) {
+      pred = get_Block_idom(block);
       xfprintf (F, "edge: { sourcename: \"");
       PRINT_NODEID(block);
       fprintf (F, "\" targetname: \"");
       PRINT_NODEID(pred);
-      fprintf (F, "\" }\n");
+      fprintf (F, "\" " DOMINATOR_EDGE_ATTR "}\n");
     }
   }
 }
@@ -1020,11 +1042,16 @@ dump_block_to_cfg (ir_node *block, void *env) {
 void
 dump_cfg (ir_graph *irg)
 {
+  int rem = dump_dominator_information_flag;
   vcg_open (irg, "-cfg");
 
+  if (get_irg_dom_state(irg) != dom_consistent)
+    dump_dominator_information_flag = 0;
+
   /* walk over the blocks in the graph */
   irg_block_walk(irg->end, dump_block_to_cfg, NULL, NULL);
 
+  dump_dominator_information_flag = rem;
   vcg_close();
 }
 
@@ -1135,11 +1162,11 @@ void dump_all_ir_graphs (void dump_graph(ir_graph*)) {
 
 /* To turn off display of edge labels.  Edge labels offen cause xvcg to
    abort with a segmentation fault. */
-void turn_of_edge_labels() {
+void turn_off_edge_labels() {
   edge_label = 0;
 }
 
-void dump_constant_entity_values() {
+void turn_off_constant_entity_values() {
   const_entities = 0;
 }
 
@@ -1150,3 +1177,7 @@ void dump_keepalive_edges() {
 void dump_out_edges() {
   dump_out_edge_flag = 1;
 }
+
+void dump_dominator_information() {
+  dump_dominator_information_flag = 1;
+}