introduce new mode for initializer
[libfirm] / ir / ana / ircfscc.c
index 26becd0..81a0bef 100644 (file)
@@ -1,18 +1,31 @@
 /*
- * Project:     libFIRM
- * File name:   ir/ana/irscc.c
- * Purpose:     Compute the strongly connected regions and build
- *              backedge/cfloop datastructures.
- *              A variation on the Tarjan algorithm. See also [Trapp:99],
- *              Chapter 5.2.1.2.
- * Author:      Goetz Lindenmaier
- * Modified by:
- * Created:     7.2002
- * CVS-ID:      $Id$
- * Copyright:   (c) 2002-2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2008 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.
  */
 
+/**
+ * @file
+ * @brief     Compute the strongly connected regions and build backedge/cfloop
+ *            datastructures. A variation on the Tarjan algorithm. See also
+ *            [Trapp:99], Chapter 5.2.1.2.
+ * @author    Goetz Lindenmaier
+ * @date      7.2002
+ * @version   $Id$
+ */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -59,7 +72,7 @@ void link_to_reg_end (ir_node *n, void *env);
  * construction.
  */
 typedef struct scc_info {
-  bool in_stack;         /**< Marks whether node is on the stack. */
+  int in_stack;          /**< Marks whether node is on the stack. */
   int dfn;               /**< Depth first search number. */
   int uplink;            /**< dfn number of ancestor. */
 } scc_info;
@@ -77,7 +90,7 @@ static INLINE scc_info *new_scc_info(void) {
 static INLINE void
 mark_irn_in_stack (ir_node *n) {
   scc_info *info = get_irn_link(n);
-  info->in_stack = true;
+  info->in_stack = 1;
 }
 
 /**
@@ -86,13 +99,13 @@ 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);
-  info->in_stack = false;
+  info->in_stack = 0;
 }
 
 /**
  * Returns whether node n is on the stack.
  */
-static INLINE bool
+static INLINE int
 irn_is_in_stack (ir_node *n) {
   scc_info *info = get_irn_link(n);
   return info->in_stack;
@@ -291,14 +304,16 @@ static ir_loop *new_loop (void) {
  * Called from a walker.
  */
 static INLINE void
-init_node (ir_node *n, void *env) {
+init_node (ir_node *n, void *env)
+{
+  (void) env;
   if (is_Block(n))
     set_irn_link (n, new_scc_info());
   clear_backedges(n);
 }
 
 /**
- * Initializes the common global settings for the scc algorthm
+ * Initializes the common global settings for the scc algorithm
  */
 static INLINE void
 init_scc_common (void) {
@@ -309,6 +324,7 @@ init_scc_common (void) {
 
 /**
  * Initializes the scc algorithm for the intraprocedural case.
+ * Add scc info to every block node.
  */
 static INLINE void
 init_scc (ir_graph *irg) {
@@ -316,6 +332,7 @@ init_scc (ir_graph *irg) {
   irg_walk_graph(irg, init_node, NULL, NULL);
 }
 
+#ifdef INTERPROCEDURAL_VIEW
 /**
  * Initializes the scc algorithm for the interprocedural case.
  */
@@ -328,29 +345,31 @@ init_ip_scc (void) {
   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.
  */
-static bool is_outermost_StartBlock(ir_node *n) {
+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)  &&
       (get_irn_op(skip_Proj(get_Block_cfgpred(n, 0))) == op_Start) &&
       (get_nodes_block(skip_Proj(get_Block_cfgpred(n, 0))) == n)) {
-    return true;
+    return 1;
   }
-  return false;
+  return 0;
 }
 
-/** Returns true if n is a loop header, i.e., it is a Block node
+/** 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.
  *
+ *  @param n     the block node to check
  *  @param root  only needed for assertion.
  */
-static bool
+static int
 is_head (ir_node *n, ir_node *root)
 {
   int i, arity;
@@ -364,13 +383,12 @@ is_head (ir_node *n, ir_node *root)
       ir_node *pred = get_nodes_block(skip_Proj(get_irn_n(n, i)));
       if (is_backedge(n, i)) continue;
       if (!irn_is_in_stack(pred)) {
-             some_outof_loop = 1;
+        some_outof_loop = 1;
       } else {
-             if (get_irn_uplink(pred) < get_irn_uplink(root))  {
-               DDMN(pred); DDMN(root);
-               assert(get_irn_uplink(pred) >= get_irn_uplink(root));
-             }
-             some_in_loop = 1;
+        if (get_irn_uplink(pred) < get_irn_uplink(root))  {
+          assert(get_irn_uplink(pred) >= get_irn_uplink(root));
+        }
+        some_in_loop = 1;
       }
     }
   }
@@ -379,12 +397,14 @@ is_head (ir_node *n, ir_node *root)
 
 
 /**
- * Returns true if n is possible loop head of an endless loop.
+ * Returns non-zero if n is possible loop head of an endless loop.
  * I.e., it is a Block, Phi or Filter node and has only predecessors
  * within the loop.
- * @arg root: only needed for assertion.
+ *
+ * @param n     the block node to check
+ * @param root  only needed for assertion.
  */
-static bool
+static int
 is_endless_head (ir_node *n, ir_node *root)
 {
   int i, arity;
@@ -402,7 +422,6 @@ is_endless_head (ir_node *n, ir_node *root)
              some_outof_loop = 1; //printf(" some out of loop ");
       } else {
              if(get_irn_uplink(pred) < get_irn_uplink(root)) {
-               DDMN(pred); DDMN(root);
                assert(get_irn_uplink(pred) >= get_irn_uplink(root));
              }
              some_in_loop = 1;
@@ -679,7 +698,7 @@ int construct_cf_backedges(ir_graph *irg) {
   return max_loop_depth;
 }
 
-
+#ifdef INTERPROCEDURAL_VIEW
 int construct_ip_cf_backedges (void) {
   ir_graph *rem = current_ir_graph;
   int rem_ipv = get_interprocedural_view();
@@ -693,7 +712,7 @@ int construct_ip_cf_backedges (void) {
 
   current_loop = NULL;
   new_loop();  /* sets current_loop */
-  set_interprocedural_view(true);
+  set_interprocedural_view(1);
 
   inc_max_irg_visited();
   for (i = 0; i < get_irp_n_irgs(); i++)
@@ -751,20 +770,27 @@ int construct_ip_cf_backedges (void) {
   set_interprocedural_view(rem_ipv);
   return max_loop_depth;
 }
+#endif
 
 /**
  * Clear the intra- and the interprocedural
  * backedge information pf a block.
  */
 static void reset_backedges(ir_node *block) {
-  int rem = get_interprocedural_view();
+  int rem;
 
   assert(is_Block(block));
-  set_interprocedural_view(true);
+#ifdef INTERPROCEDURAL_VIEW
+  rem = get_interprocedural_view();
+  set_interprocedural_view(1);
   clear_backedges(block);
-  set_interprocedural_view(false);
+  set_interprocedural_view(0);
   clear_backedges(block);
   set_interprocedural_view(rem);
+#else
+  (void) rem;
+  clear_backedges(block);
+#endif
 }
 
 /**
@@ -788,17 +814,21 @@ void free_cfloop_information(ir_graph *irg) {
   if (get_irg_loop(irg))
     loop_reset_backedges(get_irg_loop(irg));
   set_irg_loop(irg, NULL);
-  set_irg_loopinfo_state(current_ir_graph, loopinfo_none);
+  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(true);  /* To visit all filter nodes */
-  for (i = 0; i < get_irp_n_irgs(); i++) {
+  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
 }