beloopana: Remove duplicate comments.
[libfirm] / ir / ana / ircfscc.c
index e069082..5b89447 100644 (file)
@@ -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.
  */
 
 /**
@@ -37,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;
@@ -52,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.                      **/
 /**********************************************************************/
@@ -267,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;
 }
@@ -326,14 +302,11 @@ static inline void finish_scc(void)
  */
 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));
-
-       arity = get_Block_n_cfgpreds(n);
-       for (i = 0; i < arity; i++) {
+       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))
@@ -361,14 +334,12 @@ 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, ... */
-       arity = get_Block_n_cfgpreds(n);
-       for (i = 0; i < arity; i++) {
+       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))
@@ -567,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
@@ -586,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);
 
@@ -603,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.
@@ -615,17 +576,13 @@ static void cfscc(ir_node *n)
        }
 }
 
-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);
@@ -648,17 +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_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO);
-
-       current_ir_graph = rem;
-       return max_loop_depth;
+       add_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
 }
 
 void assure_loopinfo(ir_graph *irg)
 {
-       if (is_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO))
+       if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
                return;
        construct_cf_backedges(irg);
 }