X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Fircfscc.c;h=a5a53b70244c18baf94921cb64048e5be3b7aa70;hb=49bec3440763fcbac6bee60638cc8d699b12af11;hp=d4455417f333b4a67f3d583528d0e4e14fc714a8;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/ana/ircfscc.c b/ir/ana/ircfscc.c index d4455417f..a5a53b702 100644 --- a/ir/ana/ircfscc.c +++ b/ir/ana/ircfscc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -24,7 +24,6 @@ * [Trapp:99], Chapter 5.2.1.2. * @author Goetz Lindenmaier * @date 7.2002 - * @version $Id$ */ #include "config.h" @@ -38,6 +37,7 @@ #include "irgwalk.h" #include "irprog_t.h" #include "irdump.h" +#include "ircons_t.h" #define NO_CFLOOPS_WITHOUT_HEAD 1 @@ -53,7 +53,7 @@ static int loop_node_cnt = 0; /** Counter to generate depth first numbering of visited nodes. */ static int current_dfn = 1; -static int max_loop_depth = 0; +static unsigned max_loop_depth = 0; void link_to_reg_end(ir_node *n, void *env); @@ -151,7 +151,7 @@ static inline int get_irn_dfn(ir_node *n) /** An IR-node stack */ static ir_node **stack = NULL; /** The top (index) of the IR-node stack */ -static int tos = 0; +static size_t tos = 0; /** * Initializes the IR-node stack @@ -178,7 +178,7 @@ static void finish_stack(void) static inline void push(ir_node *n) { if (tos == ARR_LEN(stack)) { - int nlen = ARR_LEN(stack) * 2; + size_t nlen = ARR_LEN(stack) * 2; ARR_RESIZE(ir_node *, stack, nlen); } stack[tos++] = n; @@ -217,7 +217,7 @@ static inline void pop_scc_to_loop(ir_node *n) can't they have two loops as sons? Does it never get that far? ) */ static void close_loop(ir_loop *l) { - int last = get_loop_n_elements(l) - 1; + size_t last = get_loop_n_elements(l) - 1; loop_element lelement = get_loop_element(l, last); ir_loop *last_son = lelement.son; @@ -319,23 +319,6 @@ static inline void finish_scc(void) finish_stack(); } -/** - * Condition for breaking the recursion: n is the block - * that gets the initial control flow from the Start node. - */ -static int is_outermost_StartBlock(ir_node *n) -{ - /* Test whether this is the outermost Start node. If so - recursion must end. */ - assert(is_Block(n)); - if (get_Block_n_cfgpreds(n) == 1 && - is_Start(skip_Proj(get_Block_cfgpred(n, 0))) && - get_Block_cfgpred_block(n, 0) == n) { - return 1; - } - return 0; -} - /** Returns non-zero if n is a loop header, i.e., it is a Block node * and has predecessors within the cfloop and out of the cfloop. * @@ -350,21 +333,19 @@ static int is_head(ir_node *n, ir_node *root) assert(is_Block(n)); - if (!is_outermost_StartBlock(n)) { - arity = get_Block_n_cfgpreds(n); - for (i = 0; i < arity; i++) { - ir_node *pred = get_Block_cfgpred_block(n, i); - /* ignore Bad control flow: it cannot happen */ - if (is_Bad(pred)) - continue; - if (is_backedge(n, i)) - continue; - if (!irn_is_in_stack(pred)) { - some_outof_loop = 1; - } else { - assert(get_irn_uplink(pred) >= get_irn_uplink(root)); - some_in_loop = 1; - } + arity = get_Block_n_cfgpreds(n); + for (i = 0; i < arity; i++) { + ir_node *pred = get_Block_cfgpred_block(n, i); + /* ignore Bad control flow: it cannot happen */ + if (is_Bad(pred)) + continue; + if (is_backedge(n, i)) + continue; + if (!irn_is_in_stack(pred)) { + some_outof_loop = 1; + } else { + assert(get_irn_uplink(pred) >= get_irn_uplink(root)); + some_in_loop = 1; } } return some_outof_loop & some_in_loop; @@ -387,21 +368,19 @@ static int is_endless_head(ir_node *n, ir_node *root) assert(is_Block(n)); /* Test for legal loop header: Block, Phi, ... */ - if (!is_outermost_StartBlock(n)) { - arity = get_Block_n_cfgpreds(n); - for (i = 0; i < arity; i++) { - ir_node *pred = get_Block_cfgpred_block(n, i); - /* ignore Bad control flow: it cannot happen */ - if (is_Bad(pred)) - continue; - if (is_backedge(n, i)) - continue; - if (!irn_is_in_stack(pred)) { - none_outof_loop = 0; - } else { - assert(get_irn_uplink(pred) >= get_irn_uplink(root)); - some_in_loop = 1; - } + arity = get_Block_n_cfgpreds(n); + for (i = 0; i < arity; i++) { + ir_node *pred = get_Block_cfgpred_block(n, i); + /* ignore Bad control flow: it cannot happen */ + if (is_Bad(pred)) + continue; + if (is_backedge(n, i)) + continue; + if (!irn_is_in_stack(pred)) { + none_outof_loop = 0; + } else { + assert(get_irn_uplink(pred) >= get_irn_uplink(root)); + some_in_loop = 1; } } return none_outof_loop && some_in_loop; @@ -415,19 +394,17 @@ static int smallest_dfn_pred(ir_node *n, int limit) { int i, index = -2, min = -1; - if (!is_outermost_StartBlock(n)) { - int arity = get_Block_n_cfgpreds(n); - for (i = 0; i < arity; i++) { - ir_node *pred = get_Block_cfgpred_block(n, i); - /* ignore Bad control flow: it cannot happen */ - if (is_Bad(pred)) - continue; - if (is_backedge(n, i) || !irn_is_in_stack(pred)) - continue; - if (get_irn_dfn(pred) >= limit && (min == -1 || get_irn_dfn(pred) < min)) { - index = i; - min = get_irn_dfn(pred); - } + int arity = get_Block_n_cfgpreds(n); + for (i = 0; i < arity; i++) { + ir_node *pred = get_Block_cfgpred_block(n, i); + /* ignore Bad control flow: it cannot happen */ + if (is_Bad(pred)) + continue; + if (is_backedge(n, i) || !irn_is_in_stack(pred)) + continue; + if (get_irn_dfn(pred) >= limit && (min == -1 || get_irn_dfn(pred) < min)) { + index = i; + min = get_irn_dfn(pred); } } return index; @@ -440,19 +417,17 @@ static int largest_dfn_pred(ir_node *n) { int i, index = -2, max = -1; - if (!is_outermost_StartBlock(n)) { - int arity = get_Block_n_cfgpreds(n); - for (i = 0; i < arity; i++) { - ir_node *pred = get_Block_cfgpred_block(n, i); - /* ignore Bad control flow: it cannot happen */ - if (is_Bad(pred)) - continue; - if (is_backedge(n, i) || !irn_is_in_stack(pred)) - continue; - if (get_irn_dfn(pred) > max) { - index = i; - max = get_irn_dfn(pred); - } + int arity = get_Block_n_cfgpreds(n); + for (i = 0; i < arity; i++) { + ir_node *pred = get_Block_cfgpred_block(n, i); + /* ignore Bad control flow: it cannot happen */ + if (is_Bad(pred)) + continue; + if (is_backedge(n, i) || !irn_is_in_stack(pred)) + continue; + if (get_irn_dfn(pred) > max) { + index = i; + max = get_irn_dfn(pred); } } return index; @@ -467,9 +442,10 @@ static int largest_dfn_pred(ir_node *n) static ir_node *find_tail(ir_node *n) { ir_node *m; - int i, res_index = -2; + int res_index = -2; + size_t i; - m = stack[tos-1]; /* tos = top of stack */ + m = stack[tos - 1]; /* tos = top of stack */ if (is_head(m, n)) { res_index = smallest_dfn_pred(m, 0); if ((res_index == -2) && /* no smallest dfn pred found. */ @@ -478,16 +454,15 @@ static ir_node *find_tail(ir_node *n) } else { if (m == n) return NULL; - for (i = tos-2; i >= 0; --i) { - - m = stack[i]; + for (i = tos - 1; i != 0;) { + m = stack[--i]; if (is_head(m, n)) { res_index = smallest_dfn_pred(m, get_irn_dfn(m) + 1); if (res_index == -2) /* no smallest dfn pred found. */ res_index = largest_dfn_pred(m); if ((m == n) && (res_index == -2)) { - i = -1; + i = (size_t)-1; } break; } @@ -496,15 +471,15 @@ static ir_node *find_tail(ir_node *n) /* We should not walk past our selves on the stack: The upcoming nodes are not in this loop. We assume a loop not reachable from Start. */ if (m == n) { - i = -1; + i = (size_t)-1; break; } } - if (i < 0) { + if (i == (size_t)-1) { /* A dead loop not reachable from Start. */ - for (i = tos-2; i >= 0; --i) { - m = stack[i]; + for (i = tos - 1; i != 0;) { + m = stack[--i]; if (is_endless_head(m, n)) { res_index = smallest_dfn_pred (m, get_irn_dfn(m) + 1); if (res_index == -2) /* no smallest dfn pred found. */ @@ -519,7 +494,7 @@ static ir_node *find_tail(ir_node *n) assert(res_index > -2); set_backedge(m, res_index); - return is_outermost_StartBlock(n) ? NULL : get_Block_cfgpred_block(m, res_index); + return get_Block_cfgpred_block(m, res_index); } /** @@ -539,6 +514,7 @@ inline static int is_outermost_loop(ir_loop *l) */ static void cfscc(ir_node *n) { + int arity; int i; assert(is_Block(n)); @@ -552,26 +528,24 @@ static void cfscc(ir_node *n) ++current_dfn; push(n); - if (!is_outermost_StartBlock(n)) { - int arity = get_Block_n_cfgpreds(n); - - for (i = 0; i < arity; i++) { - ir_node *m; - - if (is_backedge(n, i)) - continue; - m = get_Block_cfgpred_block(n, i); - /* ignore Bad control flow: it cannot happen */ - if (is_Bad(m)) - continue; - - cfscc(m); - if (irn_is_in_stack(m)) { - /* Uplink of m is smaller if n->m is a backedge. - Propagate the uplink to mark the cfloop. */ - if (get_irn_uplink(m) < get_irn_uplink(n)) - set_irn_uplink(n, get_irn_uplink(m)); - } + arity = get_Block_n_cfgpreds(n); + + for (i = 0; i < arity; i++) { + ir_node *m; + + if (is_backedge(n, i)) + continue; + m = get_Block_cfgpred_block(n, i); + /* ignore Bad control flow: it cannot happen */ + if (is_Bad(m)) + continue; + + cfscc(m); + if (irn_is_in_stack(m)) { + /* Uplink of m is smaller if n->m is a backedge. + Propagate the uplink to mark the cfloop. */ + if (get_irn_uplink(m) < get_irn_uplink(n)) + set_irn_uplink(n, get_irn_uplink(m)); } } @@ -642,7 +616,6 @@ static void cfscc(ir_node *n) } } -/* Constructs control flow backedge information for irg. */ int construct_cf_backedges(ir_graph *irg) { ir_graph *rem = current_ir_graph; @@ -678,17 +651,15 @@ int construct_cf_backedges(ir_graph *irg) assert(head_rem == current_loop); mature_loops(current_loop, irg->obst); set_irg_loop(irg, current_loop); - set_irg_loopinfo_state(irg, loopinfo_cf_consistent); - assert(get_irg_loop(irg)->kind == k_ir_loop); + add_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO); current_ir_graph = rem; return max_loop_depth; } -void assure_cf_loop(ir_graph *irg) +void assure_loopinfo(ir_graph *irg) { - irg_loopinfo_state state = get_irg_loopinfo_state(irg); - - if (state != loopinfo_cf_consistent) - construct_cf_backedges(irg); + if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO)) + return; + construct_cf_backedges(irg); }