Added c_name for debugging
[libfirm] / ir / ana / irouts.c
index b48724d..d221e9f 100644 (file)
@@ -29,8 +29,7 @@
 
 #include "irouts.h"
 #include "irnode_t.h"
-#include "irgraph_t.h"     /* To access irg->outs field (which is private to this module)
-                  without public access routine */
+#include "irgraph_t.h"
 #include "irprog_t.h"
 #include "irgwalk.h"
 #include "string.h"
@@ -56,7 +55,7 @@ static void reset_outs (ir_node *node, void *unused)
 /* returns the number of successors of the node: */
 INLINE int get_irn_n_outs    (ir_node *node) {
 #ifdef DEBUG_libfirm
-  assert (node->out_valid);
+  /* assert (node->out_valid); */
 #endif /* defined DEBUG_libfirm */
   return (int)(node->out[0]);
 }
@@ -66,7 +65,7 @@ INLINE ir_node *get_irn_out      (ir_node *node, int pos) {
   assert(node);
   assert(pos >= 0 && pos < get_irn_n_outs(node));
 #ifdef DEBUG_libfirm
-  assert (node->out_valid);
+  /* assert (node->out_valid); */
 #endif /* defined DEBUG_libfirm */
   return node->out[pos+1];
 }
@@ -75,7 +74,7 @@ INLINE void set_irn_out      (ir_node *node, int pos, ir_node *out) {
   assert(node && out);
   assert(pos >= 0 && pos < get_irn_n_outs(node));
 #ifdef DEBUG_libfirm
-  assert (node->out_valid);
+  node->out_valid = 1;          /* assume that this function is used correctly */
 #endif /* defined DEBUG_libfirm */
   node->out[pos+1] = out;
 }
@@ -140,7 +139,7 @@ void irg_out_walk(ir_node *node,
             irg_walk_func *pre, irg_walk_func *post,
             void *env) {
   assert(node);
-  if (get_irg_outs_state(current_ir_graph) != no_outs) {
+  if (get_irg_outs_state(current_ir_graph) != outs_none) {
     inc_irg_visited (current_ir_graph);
     irg_out_walk_2(node, pre, post, env);
   }
@@ -267,13 +266,17 @@ static ir_node **set_out_edges(ir_node *n, ir_node **free) {
 }
 
 static INLINE void fix_start_proj(ir_graph *irg) {
-  ir_node *proj = NULL, *startbl;
+  ir_node *proj    = NULL;
+  ir_node *startbl = get_irg_start_block(irg);
   int i;
-  if (get_Block_n_cfg_outs(get_irg_start_block(irg))) {
-    startbl = get_irg_start_block(irg);
+
+  if (get_Block_n_cfg_outs(startbl)) {
     for (i = 0; i < get_irn_n_outs(startbl); i++)
-      if (get_irn_mode(get_irn_out(startbl, i)) == mode_X)
+      if (get_irn_mode(get_irn_out(startbl, i)) == mode_X) {
         proj = get_irn_out(startbl, i);
+        break;
+      }
+
     if (get_irn_out(proj, 0) == startbl) {
       assert(get_irn_n_outs(proj) == 2);
       set_irn_out(proj, 0, get_irn_out(proj, 1));
@@ -291,7 +294,7 @@ void compute_outs(ir_graph *irg) {
 
   /* Update graph state */
   assert(get_irg_phase_state(current_ir_graph) != phase_building);
-  if (current_ir_graph->outs_state != no_outs) free_outs(current_ir_graph);
+  if (current_ir_graph->outs_state != outs_none) free_outs(current_ir_graph);
   current_ir_graph->outs_state = outs_consistent;
 
   /* This first iteration counts the overall number of out edges and the
@@ -354,15 +357,16 @@ static void init_count(ir_node * node, void * env)
 
 static void node_arity_count(ir_node * node, void * env)
 {
-  int *anz = (int *) env, arity, i, start;
+  int *anz = (int *) env, arity, n_outs, i, start;
   ir_node *succ;
 
-  arity = 1 + get_irn_arity(node)
-            + ((is_Block(node)) ? 0 : 1);
-  *anz += arity;
-
+  arity = get_irn_arity(node);
   start = (is_Block(node)) ? 0 : -1;
-  for(i = start; i < get_irn_arity(node); i++) {
+
+  n_outs = 1 + arity + (-start);  // ((is_Block(node)) ? 0 : 1);   // Why + 1??
+  *anz += n_outs;
+
+  for(i = start; i < arity; i++) {
     succ = get_irn_n(node, i);
     succ->out = (ir_node **)((int)succ->out + 1);
   }
@@ -415,11 +419,11 @@ static void set_array_pointer(ir_node *node, void *env) {
    ------------------------------------------- */
 
 static void set_out_pointer(ir_node * node, void * env) {
-  int i;
+  int i, arity = get_irn_arity(node);
   ir_node *succ;
   int start = (!is_Block(node)) ? -1 : 0;
 
-  for(i = start; i < get_irn_arity(node); i++) {
+  for(i = start; i < arity; i++) {
     succ = get_irn_n(node, i);
     succ->out[get_irn_n_outs(succ)+1] = node;
     succ->out[0] = (ir_node *) (get_irn_n_outs(succ) + 1);
@@ -453,7 +457,7 @@ void compute_ip_outs(void) {
   assert(get_irp_ip_view_state() == ip_view_valid &&
      "Cannot construct outs for invalid ip view.");
 
-  if (irp->outs_state != no_outs) {
+  if (irp->outs_state != outs_none) {
     free_ip_outs();
   }
 
@@ -470,14 +474,14 @@ void free_ip_outs(void)
     free(out_edges);
     set_irp_ip_outedges(NULL);
   }
-  irp->outs_state = no_outs;
+  irp->outs_state = outs_none;
 }
 
 
 void free_outs(ir_graph *irg) {
 
-  /*   current_ir_graph->outs_state = no_outs; */
-  irg->outs_state = no_outs;
+  /*   current_ir_graph->outs_state = outs_none; */
+  irg->outs_state = outs_none;
 
   if (irg->outs) {
 #ifdef DEBUG_libfirm