OSDN Git Service

2006-12-14 Andreas Tobler <a.tobler@schweiz.org>
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-loop-ivcanon.c
index 0ad2069..c26727a 100644 (file)
@@ -154,13 +154,12 @@ estimated_unrolled_size (unsigned HOST_WIDE_INT ninsns,
   return unr_insns;
 }
 
-/* Tries to unroll LOOP completely, i.e. NITER times.  LOOPS is the
-   loop tree.  UL determines which loops we are allowed to unroll. 
+/* Tries to unroll LOOP completely, i.e. NITER times.
+   UL determines which loops we are allowed to unroll. 
    EXIT is the exit of the loop that should be eliminated.  */
 
 static bool
-try_unroll_loop_completely (struct loops *loops ATTRIBUTE_UNUSED,
-                           struct loop *loop,
+try_unroll_loop_completely (struct loop *loop,
                            edge exit, tree niter,
                            enum unroll_level ul)
 {
@@ -237,7 +236,7 @@ try_unroll_loop_completely (struct loops *loops ATTRIBUTE_UNUSED,
       RESET_BIT (wont_exit, 0);
 
       if (!tree_duplicate_loop_to_header_edge (loop, loop_preheader_edge (loop),
-                                              loops, n_unroll, wont_exit,
+                                              n_unroll, wont_exit,
                                               exit, edges_to_remove,
                                               &n_to_remove,
                                               DLTHE_FLAG_UPDATE_FREQ
@@ -266,38 +265,32 @@ try_unroll_loop_completely (struct loops *loops ATTRIBUTE_UNUSED,
   return true;
 }
 
-/* Adds a canonical induction variable to LOOP if suitable.  LOOPS is the loops
-   tree.  CREATE_IV is true if we may create a new iv.  UL determines 
+/* Adds a canonical induction variable to LOOP if suitable.
+   CREATE_IV is true if we may create a new iv.  UL determines 
    which loops we are allowed to completely unroll.  If TRY_EVAL is true, we try
    to determine the number of iterations of a loop by direct evaluation. 
    Returns true if cfg is changed.  */
 
 static bool
-canonicalize_loop_induction_variables (struct loops *loops, struct loop *loop,
+canonicalize_loop_induction_variables (struct loop *loop,
                                       bool create_iv, enum unroll_level ul,
                                       bool try_eval)
 {
   edge exit = NULL;
   tree niter;
 
-  niter = number_of_iterations_in_loop (loop);
+  niter = number_of_latch_executions (loop);
   if (TREE_CODE (niter) == INTEGER_CST)
     {
-      exit = loop->single_exit;
+      exit = single_exit (loop);
       if (!just_once_each_iteration_p (loop, exit->src))
        return false;
-
-      /* The result of number_of_iterations_in_loop is by one higher than
-        we expect (i.e. it returns number of executions of the exit
-        condition, not of the loop latch edge).  */
-      niter = fold_build2 (MINUS_EXPR, TREE_TYPE (niter), niter,
-                          build_int_cst (TREE_TYPE (niter), 1));
     }
   else
     {
       /* If the loop has more than one exit, try checking all of them
         for # of iterations determinable through scev.  */
-      if (!loop->single_exit)
+      if (!single_exit (loop))
        niter = find_loop_niter (loop, &exit);
 
       /* Finally if everything else fails, try brute force evaluation.  */
@@ -318,7 +311,7 @@ canonicalize_loop_induction_variables (struct loops *loops, struct loop *loop,
       fprintf (dump_file, " times.\n");
     }
 
-  if (try_unroll_loop_completely (loops, loop, exit, niter, ul))
+  if (try_unroll_loop_completely (loop, exit, niter, ul))
     return true;
 
   if (create_iv)
@@ -328,23 +321,20 @@ canonicalize_loop_induction_variables (struct loops *loops, struct loop *loop,
 }
 
 /* The main entry point of the pass.  Adds canonical induction variables
-   to the suitable LOOPS.  */
+   to the suitable loops.  */
 
-void
-canonicalize_induction_variables (struct loops *loops)
+unsigned int
+canonicalize_induction_variables (void)
 {
-  unsigned i;
+  loop_iterator li;
   struct loop *loop;
   bool changed = false;
   
-  for (i = 1; i < loops->num; i++)
+  FOR_EACH_LOOP (li, loop, 0)
     {
-      loop = loops->parray[i];
-
-      if (loop)
-       changed |= canonicalize_loop_induction_variables (loops, loop,
-                                                         true, UL_SINGLE_ITER,
-                                                         true);
+      changed |= canonicalize_loop_induction_variables (loop,
+                                                       true, UL_SINGLE_ITER,
+                                                       true);
     }
 
   /* Clean up the information about numbers of iterations, since brute force
@@ -352,33 +342,29 @@ canonicalize_induction_variables (struct loops *loops)
   scev_reset ();
 
   if (changed)
-    cleanup_tree_cfg_loop ();
+    return TODO_cleanup_cfg;
+  return 0;
 }
 
 /* Unroll LOOPS completely if they iterate just few times.  Unless
    MAY_INCREASE_SIZE is true, perform the unrolling only if the
    size of the code does not increase.  */
 
-void
-tree_unroll_loops_completely (struct loops *loops, bool may_increase_size)
+unsigned int
+tree_unroll_loops_completely (bool may_increase_size)
 {
-  unsigned i;
+  loop_iterator li;
   struct loop *loop;
   bool changed = false;
   enum unroll_level ul;
 
-  for (i = 1; i < loops->num; i++)
+  FOR_EACH_LOOP (li, loop, 0)
     {
-      loop = loops->parray[i];
-
-      if (!loop)
-       continue;
-
       if (may_increase_size && maybe_hot_bb_p (loop->header))
        ul = UL_ALL;
       else
        ul = UL_NO_GROWTH;
-      changed |= canonicalize_loop_induction_variables (loops, loop,
+      changed |= canonicalize_loop_induction_variables (loop,
                                                        false, ul,
                                                        !flag_tree_loop_ivcanon);
     }
@@ -388,7 +374,8 @@ tree_unroll_loops_completely (struct loops *loops, bool may_increase_size)
   scev_reset ();
 
   if (changed)
-    cleanup_tree_cfg_loop ();
+    return TODO_cleanup_cfg;
+  return 0;
 }
 
 /* Checks whether LOOP is empty.  */
@@ -454,7 +441,7 @@ empty_loop_p (struct loop *loop)
          switch (TREE_CODE (stmt))
            {
            case RETURN_EXPR:
-           case MODIFY_EXPR:
+           case GIMPLE_MODIFY_STMT:
              stmt = get_call_expr_in (stmt);
              if (!stmt)
                break;
@@ -560,20 +547,21 @@ try_remove_empty_loop (struct loop *loop, bool *changed)
   return true;
 }
 
-/* Remove the empty LOOPS.  */
+/* Remove the empty loops.  */
 
-void
-remove_empty_loops (struct loops *loops)
+unsigned int
+remove_empty_loops (void)
 {
   bool changed = false;
   struct loop *loop;
 
-  for (loop = loops->tree_root->inner; loop; loop = loop->next)
+  for (loop = current_loops->tree_root->inner; loop; loop = loop->next)
     try_remove_empty_loop (loop, &changed);
 
   if (changed)
     {
       scev_reset ();
-      cleanup_tree_cfg_loop ();
+      return TODO_cleanup_cfg;
     }
+  return 0;
 }