OSDN Git Service

2008-04-30 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-sink.c
index b70d082..40a3640 100644 (file)
@@ -433,6 +433,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.  */
@@ -454,6 +455,7 @@ sink_code_in_bb (basic_block bb)
        {
          if (!bsi_end_p (bsi))
            bsi_prev (&bsi);
+         last = false;
          continue;
        }      
       if (dump_file)
@@ -472,6 +474,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);
       
@@ -553,8 +568,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 */
@@ -570,6 +587,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 */
+ }
 };