Replaced set_irn_n(*, -1, *) and get_irn_n(*, -1) by new get_nodes_block()/set_nodes_...
[libfirm] / ir / ana / irouts.c
index fb5f029..6f00283 100644 (file)
@@ -111,7 +111,7 @@ int get_Block_n_cfg_outs_ka(ir_node *bl) {
                if (get_irn_mode(bl->out[i]) == mode_X) {
                        /* ignore End if we are in the Endblock */
                        if (get_irn_op(bl->out[i]) == op_End &&
-                           get_irn_n(bl->out[i], -1) == bl)
+                           get_nodes_block(bl->out[i]) == bl)
                                continue;
                        else
                                ++n_cfg_outs;
@@ -149,13 +149,13 @@ ir_node *get_Block_cfg_out_ka(ir_node *bl, int pos) {
                if (get_irn_mode(bl->out[i]) == mode_X) {
                        /* ignore End if we are in the Endblock */
                        if (get_irn_op(bl->out[i]) == op_End &&
-                               get_irn_n(bl->out[i], -1) == bl)
+                               get_nodes_block(bl->out[i]) == bl)
                                continue;
                        if (out_pos == pos) {
                                ir_node *cfop = bl->out[i];
                                /* handle keep-alive here */
                                if (get_irn_op(cfop) == op_End)
-                                       return get_irn_n(cfop, -1);
+                                       return get_nodes_block(cfop);
                                return cfop->out[1];
                        } else
                                ++out_pos;
@@ -237,7 +237,7 @@ void irg_out_block_walk(ir_node *node,
 }
 
 /*--------------------------------------------------------------------*/
-/** Building and Removing the out datasturcture                      **/
+/** Building and Removing the out datastructure                      **/
 /**                                                                  **/
 /** The outs of a graph are allocated in a single, large array.      **/
 /** This allows to allocate and deallocate the memory for the outs   **/
@@ -258,21 +258,31 @@ void irg_out_block_walk(ir_node *node,
 
 /** Returns the amount of out edges for not yet visited successors. */
 static int _count_outs(ir_node *n) {
-       int start, i, res, irn_arity;
+       int i, res, irn_arity;
 
        mark_irn_visited(n);
        n->out = (ir_node **) 1;     /* Space for array size. */
 
-       start = is_Block(n) ? 0 : -1;
        irn_arity = get_irn_arity(n);
-       res = irn_arity - start + 1;  /* --1 or --0; 1 for array size. */
+       res = irn_arity + 1;
 
-       for (i = start; i < irn_arity; ++i) {
+       if (is_no_Block(n)) {
+               ir_node *pred = get_nodes_block(n);
+
+               /* count outs for predecessors */
+               if (irn_not_visited(pred))
+                       res += _count_outs(pred);
+
+               /* Count my outs */
+               pred->out = (ir_node **)INT_TO_PTR(PTR_TO_INT(pred->out) + 1);
+               ++res;
+       }
+       for (i = 0; i < irn_arity; ++i) {
                /* Optimize Tuples.  They annoy if walking the cfg. */
                ir_node *pred = skip_Tuple(get_irn_n(n, i));
                set_irn_n(n, i, pred);
 
-               /* count outs for successors */
+               /* count outs for predecessors */
                if (irn_not_visited(pred))
                        res += _count_outs(pred);
 
@@ -318,7 +328,7 @@ static int count_outs(ir_graph *irg) {
  * @return The next free address
  */
 static ir_node **_set_out_edges(ir_node *n, ir_node **free) {
-       int n_outs, start, i, irn_arity;
+       int n_outs, i, irn_arity;
        ir_node *pred;
 
        set_irn_visited(n, get_irg_visited(current_ir_graph));
@@ -335,10 +345,18 @@ static ir_node **_set_out_edges(ir_node *n, ir_node **free) {
           edge. */
        n->out[0] = (ir_node *)0;
 
-       start = is_Block(n) ? 0 : -1;
-       irn_arity = get_irn_arity(n);
+       if (is_no_Block(n)) {
+               pred = get_nodes_block(n);
+               /* Recursion */
+               if (get_irn_visited(pred) < get_irg_visited(current_ir_graph))
+                       free = _set_out_edges(pred, free);
+               /* Remember our back edge */
+               pred->out[get_irn_n_outs(pred)+1] = n;
+               pred->out[0] = INT_TO_PTR(get_irn_n_outs(pred) + 1);
+       }
 
-       for (i = start; i < irn_arity; ++i) {
+       irn_arity = get_irn_arity(n);
+       for (i = 0; i < irn_arity; ++i) {
                pred = get_irn_n(n, i);
                /* Recursion */
                if (get_irn_visited(pred) < get_irg_visited(current_ir_graph))
@@ -494,16 +512,20 @@ static void init_count(ir_node * node, void *env) {
  * which is saved in "env"
  */
 static void node_arity_count(ir_node * node, void * env) {
-       int *anz = (int *) env, arity, n_outs, i, start;
+       int *anz = (int *) env, arity, n_outs, i;
        ir_node *succ;
 
        arity = get_irn_arity(node);
-       start = (is_Block(node)) ? 0 : -1;
+       n_outs = 1 + arity;
 
-       n_outs = 1 + arity + (-start);  // ((is_Block(node)) ? 0 : 1);   // Why + 1??
-       *anz += n_outs;
+       if (is_no_Block(node)) {
+               succ = get_nodes_block(node);
+               succ->out = (ir_node **)INT_TO_PTR(PTR_TO_INT(succ->out) + 1);
 
-       for(i = start; i < arity; i++) {
+               ++n_outs;
+       }
+       *anz += n_outs;
+       for (i = 0; i < arity; i++) {
                succ = get_irn_n(node, i);
                succ->out = (ir_node **)INT_TO_PTR(PTR_TO_INT(succ->out) + 1);
        }
@@ -553,10 +575,15 @@ static void set_array_pointer(ir_node *node, void *env) {
 static void set_out_pointer(ir_node * node, void *env) {
        int i, arity = get_irn_arity(node);
        ir_node *succ;
-       int start = (!is_Block(node)) ? -1 : 0;
        (void) env;
 
-       for (i = start; i < arity; ++i) {
+       if (is_no_Block(node)) {
+               succ = get_nodes_block(node);
+               succ->out[get_irn_n_outs(succ)+1] = node;
+               succ->out[0] = INT_TO_PTR(get_irn_n_outs(succ) + 1);
+
+       }
+       for (i = 0; i < arity; ++i) {
                succ = get_irn_n(node, i);
                succ->out[get_irn_n_outs(succ)+1] = node;
                succ->out[0] = INT_TO_PTR(get_irn_n_outs(succ) + 1);