X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=ir%2Fana%2Fircfscc.c;h=5b89447e9f3ad2c78349eed7abffb91bba19225c;hb=b1ac8fe5c7b3b462f66a99e6c780be9826414b7d;hp=57a7ad46a7e806aebb1b1ce17550ebaeb1179127;hpb=1a3b7d363474ab544c13093a2f0b578718d37c7a;p=libfirm diff --git a/ir/ana/ircfscc.c b/ir/ana/ircfscc.c index 57a7ad46a..5b89447e9 100644 --- a/ir/ana/ircfscc.c +++ b/ir/ana/ircfscc.c @@ -1,20 +1,6 @@ /* - * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** @@ -24,7 +10,6 @@ * [Trapp:99], Chapter 5.2.1.2. * @author Goetz Lindenmaier * @date 7.2002 - * @version $Id$ */ #include "config.h" @@ -38,8 +23,7 @@ #include "irgwalk.h" #include "irprog_t.h" #include "irdump.h" - -#define NO_CFLOOPS_WITHOUT_HEAD 1 +#include "ircons_t.h" /** The outermost graph the scc is computed for */ static ir_graph *outermost_ir_graph; @@ -53,14 +37,6 @@ static int loop_node_cnt = 0; /** Counter to generate depth first numbering of visited nodes. */ static int current_dfn = 1; -static unsigned max_loop_depth = 0; - -void link_to_reg_end(ir_node *n, void *env); - -/**********************************************************************/ -/* Node attributes **/ -/**********************************************************************/ - /**********************************************************************/ /* Node attributes needed for the construction. **/ /**********************************************************************/ @@ -268,9 +244,8 @@ static inline void pop_scc_unmark_visit(ir_node *n) static ir_loop *new_loop(void) { ir_loop *father = current_loop; - ir_loop *son = alloc_loop(father, outermost_ir_graph->obst); + ir_loop *son = alloc_loop(father, get_irg_obstack(outermost_ir_graph)); - if (son->depth > max_loop_depth) max_loop_depth = son->depth; current_loop = son; return father; } @@ -319,23 +294,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. * @@ -344,27 +302,22 @@ static int is_outermost_StartBlock(ir_node *n) */ static int is_head(ir_node *n, ir_node *root) { - int i, arity; int some_outof_loop = 0, some_in_loop = 0; (void) 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; - } + int const arity = get_Block_n_cfgpreds(n); + for (int 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; @@ -381,27 +334,23 @@ static int is_head(ir_node *n, ir_node *root) */ static int is_endless_head(ir_node *n, ir_node *root) { - int i, arity; int none_outof_loop = 1, some_in_loop = 0; (void) 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; - } + int const arity = get_Block_n_cfgpreds(n); + for (int 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 +364,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 +387,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; @@ -519,7 +464,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 +484,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 +498,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)); } } @@ -594,8 +538,6 @@ static void cfscc(ir_node *n) Next actions: Open a new cfloop on the cfloop tree and try to find inner cfloops */ -#if NO_CFLOOPS_WITHOUT_HEAD - /* This is an adaption of the algorithm from fiasco / optscc to * avoid cfloops without Block or Phi as first node. This should * severely reduce the number of evaluations of nodes to detect @@ -613,12 +555,6 @@ static void cfscc(ir_node *n) close = 0; } -#else - - ir_loop *l = new_loop(); - -#endif - /* Remove the cfloop from the stack ... */ pop_scc_unmark_visit(n); @@ -630,9 +566,7 @@ static void cfscc(ir_node *n) cfscc(tail); assert(irn_visited(n)); -#if NO_CFLOOPS_WITHOUT_HEAD if (close) -#endif close_loop(l); } else { /* AS: No cfloop head was found, that is we have straight line code. @@ -642,18 +576,13 @@ static void cfscc(ir_node *n) } } -/* Constructs control flow backedge information for irg. */ -int construct_cf_backedges(ir_graph *irg) +void construct_cf_backedges(ir_graph *irg) { - ir_graph *rem = current_ir_graph; ir_loop *head_rem; ir_node *end = get_irg_end(irg); struct obstack temp; int i; - max_loop_depth = 0; - - current_ir_graph = irg; outermost_ir_graph = irg; obstack_init(&temp); @@ -676,19 +605,14 @@ int construct_cf_backedges(ir_graph *irg) obstack_free(&temp, NULL); assert(head_rem == current_loop); - mature_loops(current_loop, irg->obst); + mature_loops(current_loop, get_irg_obstack(irg)); set_irg_loop(irg, current_loop); - set_irg_loopinfo_state(irg, loopinfo_cf_consistent); - assert(get_irg_loop(irg)->kind == k_ir_loop); - - current_ir_graph = rem; - return max_loop_depth; + add_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO); } -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); }