/*
- * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
#ifdef DEBUG_libfirm
assert(bl->out_valid);
#endif /* defined DEBUG_libfirm */
- for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i)
- if ((get_irn_mode(bl->out[i]) == mode_X) &&
- (get_irn_op(bl->out[i]) != op_End))
- ++n_cfg_outs;
+ for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i) {
+ ir_node *succ = bl->out[i];
+ if (get_irn_mode(succ) == mode_X && get_irn_op(succ) != op_End)
+ n_cfg_outs += PTR_TO_INT(succ->out[0]);
+ }
return n_cfg_outs;
}
#ifdef DEBUG_libfirm
assert(bl->out_valid);
#endif /* defined DEBUG_libfirm */
- for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i)
- 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_nodes_block(bl->out[i]) == bl)
- continue;
- else
- ++n_cfg_outs;
+ for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i) {
+ ir_node *succ = bl->out[i];
+ if (get_irn_mode(succ) == mode_X) {
+
+ if (get_irn_op(succ) == op_End) {
+ /* ignore End if we are in the Endblock */
+ if (get_irn_n(succ, -1) == bl)
+ continue;
+ else /* count Keep-alive as one */
+ n_cfg_outs += 1;
+ } else
+ n_cfg_outs += PTR_TO_INT(succ->out[0]);
}
+ }
return n_cfg_outs;
}
/* Access predecessor n, ignore keep-alives. */
ir_node *get_Block_cfg_out(ir_node *bl, int pos) {
- int i, out_pos = 0;
+ int i;
assert(bl && is_Block(bl));
#ifdef DEBUG_libfirm
assert (bl->out_valid);
#endif /* defined DEBUG_libfirm */
- for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i)
- if ((get_irn_mode(bl->out[i]) == mode_X) &&
- (get_irn_op(bl->out[i]) != op_End)) {
- if (out_pos == pos) {
- ir_node *cfop = bl->out[i];
- return cfop->out[1];
- } else
- ++out_pos;
+ for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i) {
+ ir_node *succ = bl->out[i];
+ if (get_irn_mode(succ) == mode_X && get_irn_op(succ) != op_End) {
+ int n_outs = PTR_TO_INT(succ->out[0]);
+ if (pos < n_outs)
+ return succ->out[pos + 1];
+ else
+ pos -= n_outs;
}
+ }
return NULL;
}
/* Access predecessor n, honor keep-alives. */
ir_node *get_Block_cfg_out_ka(ir_node *bl, int pos) {
- int i, out_pos = 0;
+ int i, n_outs;
assert(bl && is_Block(bl));
#ifdef DEBUG_libfirm
assert (bl->out_valid);
#endif /* defined DEBUG_libfirm */
- for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i)
- 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_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_nodes_block(cfop);
- return cfop->out[1];
- } else
- ++out_pos;
+ for (i = 1; i <= PTR_TO_INT(bl->out[0]); ++i) {
+ ir_node *succ = bl->out[i];
+ if (get_irn_mode(succ) == mode_X) {
+ if (get_irn_op(succ) == op_End) {
+ if (get_irn_n(succ, -1) == bl) {
+ /* ignore End if we are in the Endblock */
+ continue;
+ }
+ if (pos == 0) {
+ /* handle keep-alive here: return the Endblock instead of the End node */
+ return get_irn_n(succ, -1);
+ } else
+ --pos;
+ } else {
+ n_outs = PTR_TO_INT(succ->out[0]);
+ if (pos < n_outs)
+ return succ->out[pos + 1];
+ else
+ pos -= n_outs;
+ }
}
+ }
return NULL;
}
inc_irg_block_visited(current_ir_graph);
- if (get_irn_mode(node) == mode_X)
- node = node->out[1];
+ if (get_irn_mode(node) == mode_X) {
+ int i, n;
- irg_out_block_walk2(node, pre, post, env);
+ for (i = 0, n = get_irn_n_outs(node); i < n; ++i) {
+ ir_node *succ = get_irn_out(node, i);
+ if (get_irn_visited(succ) < get_irg_visited(current_ir_graph))
+ irg_out_walk_2(succ, pre, post, env);
+ }
+ }
+ else {
+ irg_out_block_walk2(node, pre, post, env);
+ }
}
/*--------------------------------------------------------------------*/
/** Returns the amount of out edges for not yet visited successors. */
static int _count_outs(ir_node *n) {
- int i, res, irn_arity;
+ int start, 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 + 1;
+ res = irn_arity - start + 1; /* --1 or --0; 1 for array size. */
- 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) {
+ for (i = start; 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 predecessors */
+ /* count outs for successors */
if (irn_not_visited(pred))
res += _count_outs(pred);
inc_irg_visited(irg);
res = _count_outs(get_irg_end(irg));
- /* now handle special nodes */
+ /* Now handle special nodes. We need the out count of those
+ even if they are not visible. */
n = get_irg_frame(irg);
- if (irn_not_visited(n)) {
+ if (! is_Bad(n) && irn_not_visited(n)) {
n->out = (ir_node **)1;
++res;
}
n = get_irg_args(irg);
- if (irn_not_visited(n)) {
+ if (! is_Bad(n) && irn_not_visited(n)) {
+ n->out = (ir_node **)1;
+ ++res;
+ }
+
+ n = get_irg_value_param_base(irg);
+ if (! is_Bad(n) && irn_not_visited(n)) {
n->out = (ir_node **)1;
++res;
}
* @return The next free address
*/
static ir_node **_set_out_edges(ir_node *n, ir_node **free) {
- int n_outs, i, irn_arity;
+ int n_outs, start, i, irn_arity;
ir_node *pred;
set_irn_visited(n, get_irg_visited(current_ir_graph));
edge. */
n->out[0] = (ir_node *)0;
- 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);
- }
-
+ start = is_Block(n) ? 0 : -1;
irn_arity = get_irn_arity(n);
- for (i = 0; i < irn_arity; ++i) {
+
+ for (i = start; i < irn_arity; ++i) {
pred = get_irn_n(n, i);
/* Recursion */
if (get_irn_visited(pred) < get_irg_visited(current_ir_graph))
* @return The next free address
*/
static ir_node **set_out_edges(ir_graph *irg, ir_node **free) {
- ir_node *n, *special[2];
+ ir_node *n, *special[3];
int i, n_outs;
inc_irg_visited(irg);
/* handle special nodes */
special[0] = get_irg_frame(irg);
special[1] = get_irg_args(irg);
+ special[2] = get_irg_value_param_base(irg);
- for (i = 1; i >= 0; --i) {
+ for (i = 2; i >= 0; --i) {
n = special[i];
+ if (is_Bad(n))
+ continue;
if (get_irn_visited(n) < get_irg_visited(current_ir_graph)) {
n_outs = PTR_TO_INT(n->out);
*------------------------------------------------------------*/
+#ifdef INTERPROCEDURAL_VIEW
/**
* Inits the number of outedges for each node
* before counting.
* which is saved in "env"
*/
static void node_arity_count(ir_node * node, void * env) {
- int *anz = (int *) env, arity, n_outs, i;
+ int *anz = (int *) env, arity, n_outs, i, start;
ir_node *succ;
arity = get_irn_arity(node);
- n_outs = 1 + arity;
-
- if (is_no_Block(node)) {
- succ = get_nodes_block(node);
- succ->out = (ir_node **)INT_TO_PTR(PTR_TO_INT(succ->out) + 1);
+ start = (is_Block(node)) ? 0 : -1;
- ++n_outs;
- }
+ n_outs = 1 + arity + (-start); // ((is_Block(node)) ? 0 : 1); // Why + 1??
*anz += n_outs;
- for (i = 0; i < arity; i++) {
+
+ for(i = start; i < arity; i++) {
succ = get_irn_n(node, i);
succ->out = (ir_node **)INT_TO_PTR(PTR_TO_INT(succ->out) + 1);
}
}
-
/*
* Inits all nodes for setting the outedges
* Returns the overall count of edges
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;
- 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) {
+ for (i = start; 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);
}
irp->outs_state = outs_none;
}
+#endif
void free_irg_outs(ir_graph *irg) {