remove strange function (christophs words) and duplicated comments
[libfirm] / ir / ana / ircfscc.c
index b112bd2..57a7ad4 100644 (file)
@@ -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.
  *
@@ -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);
 
@@ -86,7 +86,7 @@ static inline scc_info *new_scc_info(struct obstack *obst)
  */
 static inline void mark_irn_in_stack(ir_node *n)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        info->in_stack = 1;
 }
 
@@ -95,7 +95,7 @@ static inline void mark_irn_in_stack(ir_node *n)
  */
 static inline void mark_irn_not_in_stack(ir_node *n)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        info->in_stack = 0;
 }
 
@@ -104,7 +104,7 @@ static inline void mark_irn_not_in_stack(ir_node *n)
  */
 static inline int irn_is_in_stack(ir_node *n)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        return info->in_stack;
 }
 
@@ -113,7 +113,7 @@ static inline int irn_is_in_stack(ir_node *n)
  */
 static inline void set_irn_uplink(ir_node *n, int uplink)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        info->uplink = uplink;
 }
 
@@ -122,7 +122,7 @@ static inline void set_irn_uplink(ir_node *n, int uplink)
  */
 static inline int get_irn_uplink(ir_node *n)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        return info->uplink;
 }
 
@@ -131,7 +131,7 @@ static inline int get_irn_uplink(ir_node *n)
  */
 static inline void set_irn_dfn(ir_node *n, int dfn)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        info->dfn = dfn;
 }
 
@@ -140,7 +140,7 @@ static inline void set_irn_dfn(ir_node *n, int dfn)
  */
 static inline int get_irn_dfn(ir_node *n)
 {
-       scc_info *info = get_irn_link(n);
+       scc_info *info = (scc_info*) get_irn_link(n);
        return info->dfn;
 }
 
@@ -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;
 
@@ -288,7 +288,7 @@ static ir_loop *new_loop(void)
  */
 static inline void init_node(ir_node *n, void *env)
 {
-       struct obstack *obst = env;
+       struct obstack *obst = (struct obstack*) env;
        if (is_Block(n))
                set_irn_link(n, new_scc_info(obst));
        clear_backedges(n);
@@ -319,21 +319,6 @@ static inline void finish_scc(void)
        finish_stack();
 }
 
-#ifdef INTERPROCEDURAL_VIEW
-/**
- * Initializes the scc algorithm for the interprocedural case.
- */
-static inline void init_ip_scc(struct obstack *obst)
-{
-       init_scc_common();
-       cg_walk(init_node, NULL, obst);
-
-#if EXPERIMENTAL_CFLOOP_TREE
-       cg_walk(link_to_reg_end, NULL, NULL);
-#endif
-}
-#endif
-
 /**
  * Condition for breaking the recursion: n is the block
  * that gets the initial control flow from the Start node.
@@ -482,9 +467,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. */
@@ -493,16 +479,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;
                        }
@@ -511,15 +496,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. */
@@ -666,10 +651,6 @@ int construct_cf_backedges(ir_graph *irg)
        struct obstack temp;
        int i;
 
-#ifdef INTERPROCEDURAL_VIEW
-       assert(!get_interprocedural_view() &&
-               "use construct_ip_cf_backedges()");
-#endif
        max_loop_depth = 0;
 
        current_ir_graph   = irg;
@@ -711,151 +692,3 @@ void assure_cf_loop(ir_graph *irg)
        if (state != loopinfo_cf_consistent)
                construct_cf_backedges(irg);
 }
-
-#ifdef INTERPROCEDURAL_VIEW
-int construct_ip_cf_backedges (void)
-{
-       ir_graph *rem = current_ir_graph;
-       int rem_ipv = get_interprocedural_view();
-       struct obstack temp;
-       int i;
-
-       assert(get_irp_ip_view_state() == ip_view_valid);
-       max_loop_depth = 0;
-       outermost_ir_graph = get_irp_main_irg();
-
-       obstack_init(&temp);
-       init_ip_scc(&temp);
-
-       current_loop = NULL;
-       new_loop();  /* sets current_loop */
-       set_interprocedural_view(1);
-
-       inc_max_irg_visited();
-       for (i = 0; i < get_irp_n_irgs(); i++)
-         set_irg_visited(get_irp_irg(i), get_max_irg_visited());
-
-       /** We have to start the walk at the same nodes as cg_walk. **/
-       /* Walk starting at unreachable procedures. Only these
-        * have End blocks visible in interprocedural view. */
-       for (i = 0; i < get_irp_n_irgs(); i++) {
-               ir_node *sb;
-               current_ir_graph = get_irp_irg(i);
-
-               sb = get_irg_start_block(current_ir_graph);
-
-               if ((get_Block_n_cfgpreds(sb) > 1) ||
-                       (get_nodes_block(get_Block_cfgpred(sb, 0)) != sb)) continue;
-
-               cfscc(get_irg_end_block(current_ir_graph));
-       }
-
-       /* Check whether we walked all procedures: there could be procedures
-          with cyclic calls but no call from the outside. */
-       for (i = 0; i < get_irp_n_irgs(); i++) {
-               ir_node *sb;
-               current_ir_graph = get_irp_irg(i);
-
-               /* Test start block: if inner procedure end and end block are not
-                * visible and therefore not marked. */
-               sb = get_irg_start_block(current_ir_graph);
-               if (get_irn_visited(sb) < get_irg_visited(current_ir_graph)) cfscc(sb);
-       }
-
-       /* Walk all endless cfloops in inner procedures.
-        * We recognize an inner procedure if the End node is not visited. */
-       for (i = 0; i < get_irp_n_irgs(); i++) {
-               ir_node *e;
-               current_ir_graph = get_irp_irg(i);
-
-               e = get_irg_end(current_ir_graph);
-               if (get_irn_visited(e) < get_irg_visited(current_ir_graph)) {
-                       int j;
-                       /* Don't visit the End node. */
-                       for (j = 0; j < get_End_n_keepalives(e); j++) {
-                               ir_node *el = get_End_keepalive(e, j);
-                               if (is_Block(el)) cfscc(el);
-                       }
-               }
-       }
-
-       set_irg_loop(outermost_ir_graph, current_loop);
-       set_irg_loopinfo_state(current_ir_graph, loopinfo_cf_ip_consistent);
-       assert(get_irg_loop(outermost_ir_graph)->kind == k_ir_loop);
-
-       obstack_free(&temp, NULL);
-       current_ir_graph = rem;
-       set_interprocedural_view(rem_ipv);
-       return max_loop_depth;
-}
-#endif
-
-#if 0
-/**
- * Clear the intra- and the interprocedural
- * backedge information pf a block.
- */
-static void reset_backedges(ir_node *block)
-{
-       int rem;
-
-       assert(is_Block(block));
-#ifdef INTERPROCEDURAL_VIEW
-       rem = get_interprocedural_view();
-       set_interprocedural_view(1);
-       clear_backedges(block);
-       set_interprocedural_view(0);
-       clear_backedges(block);
-       set_interprocedural_view(rem);
-#else
-       (void) rem;
-       clear_backedges(block);
-#endif
-}
-
-/**
- * Reset all backedges of the first block of
- * a loop as well as all loop info for all nodes of this loop.
- * Recurse into all nested loops.
- */
-static void loop_reset_backedges(ir_loop *l)
-{
-       int i;
-       reset_backedges(get_loop_node(l, 0));
-       for (i = 0; i < get_loop_n_nodes(l); ++i)
-               set_irn_loop(get_loop_node(l, i), NULL);
-       for (i = 0; i < get_loop_n_sons(l); ++i) {
-               loop_reset_backedges(get_loop_son(l, i));
-       }
-}
-
-/* Removes all cfloop information.
-   Resets all backedges */
-static void free_cfloop_information(ir_graph *irg)
-{
-       ir_loop *loop = get_irg_loop(irg);
-       if (loop != NULL) {
-               loop_reset_backedges(loop);
-               set_irg_loop(irg, NULL);
-       }
-       set_irg_loopinfo_state(irg, loopinfo_none);
-       /* We cannot free the cfloop nodes, they are on the obstack. */
-}
-
-
-void free_all_cfloop_information(void)
-{
-       int i;
-#ifdef INTERPROCEDURAL_VIEW
-       int rem = get_interprocedural_view();
-       set_interprocedural_view(1);  /* To visit all filter nodes */
-#endif
-       for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-               free_cfloop_information(get_irp_irg(i));
-       }
-#ifdef INTERPROCEDURAL_VIEW
-       set_interprocedural_view(rem);
-#endif
-}
-
-#endif