OSDN Git Service

2008-06-15 Mark Shinwell <shinwell@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-sink.c
index 6dff7ff..ebf54e2 100644 (file)
@@ -1,12 +1,12 @@
 /* Code sinking for trees
-   Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
    Contributed by Daniel Berlin <dan@dberlin.org>
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GCC is distributed in the hope that it will be useful,
@@ -15,9 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License 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, 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -190,20 +189,7 @@ is_hidden_global_store (tree stmt)
 
        }
       else if (INDIRECT_REF_P (lhs))
-       {
-         tree ptr = TREE_OPERAND (lhs, 0);
-         struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
-         tree nmt = (pi) ? pi->name_mem_tag : NULL_TREE;
-         tree smt = symbol_mem_tag (SSA_NAME_VAR (ptr));
-
-         /* If either the name tag or the symbol tag for PTR is a
-            global variable, then the store is necessary.  */
-         if ((nmt && is_global_var (nmt))
-             || (smt && is_global_var (smt)))
-           {
-             return true;
-           }
-       }
+       return may_point_to_global_var (TREE_OPERAND (lhs, 0));
       else
        gcc_unreachable ();
     }
@@ -434,6 +420,7 @@ sink_code_in_bb (basic_block bb)
   block_stmt_iterator bsi;
   edge_iterator ei;
   edge e;
+  bool last = true;
   
   /* If this block doesn't dominate anything, there can't be any place to sink
      the statements to.  */
@@ -455,6 +442,7 @@ sink_code_in_bb (basic_block bb)
        {
          if (!bsi_end_p (bsi))
            bsi_prev (&bsi);
+         last = false;
          continue;
        }      
       if (dump_file)
@@ -473,6 +461,19 @@ sink_code_in_bb (basic_block bb)
        bsi_move_before (&bsi, &tobsi);
 
       sink_stats.sunk++;
+
+      /* If we've just removed the last statement of the BB, the
+        bsi_end_p() test below would fail, but bsi_prev() would have
+        succeeded, and we want it to succeed.  So we keep track of
+        whether we're at the last statement and pick up the new last
+        statement.  */
+      if (last)
+       {
+         bsi = bsi_last (bb);
+         continue;
+       }
+
+      last = false;
       if (!bsi_end_p (bsi))
        bsi_prev (&bsi);
       
@@ -532,8 +533,7 @@ execute_sink_code (void)
   calculate_dominance_info (CDI_DOMINATORS);
   calculate_dominance_info (CDI_POST_DOMINATORS);
   sink_code_in_bb (EXIT_BLOCK_PTR); 
-  if (dump_file && (dump_flags & TDF_STATS))
-    fprintf (dump_file, "Sunk statements:%d\n", sink_stats.sunk);
+  statistics_counter_event (cfun, "Sunk statements", sink_stats.sunk);
   free_dominance_info (CDI_POST_DOMINATORS);
   remove_fake_exit_edges ();
   loop_optimizer_finalize ();
@@ -554,8 +554,10 @@ gate_sink (void)
   return flag_tree_sink != 0;
 }
 
-struct tree_opt_pass pass_sink_code =
+struct gimple_opt_pass pass_sink_code =
 {
+ {
+  GIMPLE_PASS,
   "sink",                              /* name */
   gate_sink,                           /* gate */
   do_sink,                             /* execute */
@@ -571,6 +573,6 @@ struct tree_opt_pass pass_sink_code =
   TODO_update_ssa 
     | TODO_dump_func
     | TODO_ggc_collect
-    | TODO_verify_ssa,                 /* todo_flags_finish */
-  0                                    /* letter */
+    | TODO_verify_ssa                  /* todo_flags_finish */
+ }
 };