OSDN Git Service

* loop-invariant.c (move_loop_invariants): Add missing hunk from
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-loop.c
index cb5d561..34126b1 100644 (file)
@@ -1,5 +1,5 @@
 /* Loop optimizations over tree-ssa.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    
 This file is part of GCC.
    
@@ -15,8 +15,8 @@ for more details.
    
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -40,7 +40,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 /* The loop tree currently optimized.  */
 
-struct loops *current_loops;
+struct loops *current_loops = NULL;
 
 /* Initializes the loop structures.  DUMP is the file to that the details
    about the analysis should be dumped.  */
@@ -53,17 +53,7 @@ tree_loop_optimizer_init (FILE *dump)
   if (!loops)
     return NULL;
 
-  /* Creation of preheaders may create redundant phi nodes if the loop is
-     entered by more than one edge, but the initial value of the induction
-     variable is the same on all of them.  */
-  kill_redundant_phi_nodes ();
-  rewrite_into_ssa (false);
-  bitmap_clear (vars_to_rename);
-
-  rewrite_into_loop_closed_ssa (NULL);
-#ifdef ENABLE_CHECKING
-  verify_loop_closed_ssa ();
-#endif
+  rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
 
   return loops;
 }
@@ -71,15 +61,15 @@ tree_loop_optimizer_init (FILE *dump)
 /* The loop superpass.  */
 
 static bool
-gate_loop (void)
+gate_tree_loop (void)
 {
   return flag_tree_loop_optimize != 0;
 }
 
-struct tree_opt_pass pass_loop = 
+struct tree_opt_pass pass_tree_loop = 
 {
   "loop",                              /* name */
-  gate_loop,                           /* gate */
+  gate_tree_loop,                      /* gate */
   NULL,                                        /* execute */
   NULL,                                        /* sub */
   NULL,                                        /* next */
@@ -108,7 +98,7 @@ tree_ssa_loop_init (void)
   scev_initialize (current_loops);
 }
   
-struct tree_opt_pass pass_loop_init = 
+struct tree_opt_pass pass_tree_loop_init = 
 {
   "loopinit",                          /* name */
   NULL,                                        /* gate */
@@ -121,7 +111,7 @@ struct tree_opt_pass pass_loop_init =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -155,7 +145,7 @@ struct tree_opt_pass pass_lim =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -176,7 +166,7 @@ gate_tree_ssa_loop_unswitch (void)
   return flag_unswitch_loops != 0;
 }
 
-struct tree_opt_pass pass_unswitch = 
+struct tree_opt_pass pass_tree_unswitch = 
 {
   "unswitch",                          /* name */
   gate_tree_ssa_loop_unswitch,         /* gate */
@@ -189,7 +179,7 @@ struct tree_opt_pass pass_unswitch =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -198,17 +188,13 @@ struct tree_opt_pass pass_unswitch =
 static void
 tree_vectorize (void)
 {
-  if (!current_loops)
-    return;
-
-  bitmap_clear (vars_to_rename);
   vectorize_loops (current_loops);
 }
 
 static bool
 gate_tree_vectorize (void)
 {
-  return flag_tree_vectorize != 0;
+  return flag_tree_vectorize && current_loops;
 }
 
 struct tree_opt_pass pass_vectorize =
@@ -223,12 +209,11 @@ struct tree_opt_pass pass_vectorize =
   PROP_cfg | PROP_ssa,                  /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
-  0,                                    /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_verify_loops,                   /* todo_flags_start */
+  TODO_dump_func | TODO_update_ssa,    /* todo_flags_finish */
   0                                    /* letter */
 };
 
-
 /* Loop nest optimizations.  */
 
 static void
@@ -259,7 +244,7 @@ struct tree_opt_pass pass_linear_transform =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */    
 };
 
@@ -293,7 +278,61 @@ struct tree_opt_pass pass_iv_canon =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
+  0                                    /* letter */
+};
+
+/* Propagation of constants using scev.  */
+
+static bool
+gate_scev_const_prop (void)
+{
+  return true;
+}
+
+struct tree_opt_pass pass_scev_cprop =
+{
+  "sccp",                              /* name */
+  gate_scev_const_prop,                        /* gate */
+  scev_const_prop,                     /* execute */
+  NULL,                                        /* sub */
+  NULL,                                        /* next */
+  0,                                   /* static_pass_number */
+  TV_SCEV_CONST,                       /* tv_id */
+  PROP_cfg | PROP_ssa,                 /* properties_required */
+  0,                                   /* properties_provided */
+  0,                                   /* properties_destroyed */
+  0,                                   /* todo_flags_start */
+  TODO_dump_func | TODO_update_ssa_only_virtuals,
+                                       /* todo_flags_finish */
+  0                                    /* letter */
+};
+
+/* Remove empty loops.  */
+
+static void
+tree_ssa_empty_loop (void)
+{
+  if (!current_loops)
+    return;
+
+  remove_empty_loops (current_loops);
+}
+
+struct tree_opt_pass pass_empty_loop =
+{
+  "empty",                             /* name */
+  NULL,                                        /* gate */
+  tree_ssa_empty_loop,                 /* execute */
+  NULL,                                        /* sub */
+  NULL,                                        /* next */
+  0,                                   /* static_pass_number */
+  TV_COMPLETE_UNROLL,                  /* tv_id */
+  PROP_cfg | PROP_ssa,                 /* properties_required */
+  0,                                   /* properties_provided */
+  0,                                   /* properties_destroyed */
+  0,                                   /* todo_flags_start */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -334,13 +373,16 @@ tree_complete_unroll (void)
   if (!current_loops)
     return;
 
-  tree_unroll_loops_completely (current_loops);
+  tree_unroll_loops_completely (current_loops,
+                               flag_unroll_loops
+                               || flag_peel_loops
+                               || optimize >= 3);
 }
 
 static bool
 gate_tree_complete_unroll (void)
 {
-  return flag_unroll_loops != 0;
+  return true;
 }
 
 struct tree_opt_pass pass_complete_unroll =
@@ -356,7 +398,7 @@ struct tree_opt_pass pass_complete_unroll =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -390,7 +432,7 @@ struct tree_opt_pass pass_iv_optimize =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func,                      /* todo_flags_finish */
+  TODO_dump_func | TODO_verify_loops,  /* todo_flags_finish */
   0                                    /* letter */
 };
 
@@ -402,10 +444,6 @@ tree_ssa_loop_done (void)
   if (!current_loops)
     return;
 
-#ifdef ENABLE_CHECKING
-  verify_loop_closed_ssa ();
-#endif
-
   free_numbers_of_iterations_estimates (current_loops);
   scev_finalize ();
   loop_optimizer_finalize (current_loops,
@@ -413,7 +451,7 @@ tree_ssa_loop_done (void)
   current_loops = NULL;
 }
   
-struct tree_opt_pass pass_loop_done = 
+struct tree_opt_pass pass_tree_loop_done = 
 {
   "loopdone",                          /* name */
   NULL,                                        /* gate */
@@ -429,4 +467,3 @@ struct tree_opt_pass pass_loop_done =
   TODO_cleanup_cfg | TODO_dump_func,   /* todo_flags_finish */
   0                                    /* letter */
 };
-