OSDN Git Service

2010-04-06 Kai Tietz <kai.tietz@onevision.com>
[pf3gnuchains/gcc-fork.git] / gcc / bb-reorder.c
index a3fd3fe..5f7230f 100644 (file)
@@ -1,5 +1,5 @@
 /* Basic block reordering routines for the GNU compiler.
-   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
    Free Software Foundation, Inc.
 
    This file is part of GCC.
 #include "tree-pass.h"
 #include "df.h"
 
-#ifndef HAVE_conditional_execution
-#define HAVE_conditional_execution 0
-#endif
-
 /* The number of rounds.  In most cases there will only be 4 rounds, but
    when partitioning hot and cold basic blocks into separate sections of
    the .o file there will be an extra round.*/
@@ -278,7 +274,7 @@ find_traces (int *n_traces, struct trace *traces)
          basic_block bb;
          fprintf (dump_file, "Trace %d (round %d):  ", i + 1,
                   traces[i].round + 1);
-         for (bb = traces[i].first; bb != traces[i].last; bb = bb->aux)
+         for (bb = traces[i].first; bb != traces[i].last; bb = (basic_block) bb->aux)
            fprintf (dump_file, "%d [%d] ", bb->index, bb->frequency);
          fprintf (dump_file, "%d [%d]\n", bb->index, bb->frequency);
        }
@@ -358,7 +354,7 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
                }
            }
        }
-      bb = bb->aux;
+      bb = (basic_block) bb->aux;
     }
   while (bb != back_edge->dest);
 
@@ -368,7 +364,7 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
         the trace.  */
       if (back_edge->dest == trace->first)
        {
-         trace->first = best_bb->aux;
+         trace->first = (basic_block) best_bb->aux;
        }
       else
        {
@@ -376,7 +372,7 @@ rotate_loop (edge back_edge, struct trace *trace, int trace_n)
 
          for (prev_bb = trace->first;
               prev_bb->aux != back_edge->dest;
-              prev_bb = prev_bb->aux)
+              prev_bb = (basic_block) prev_bb->aux)
            ;
          prev_bb->aux = best_bb->aux;
 
@@ -442,7 +438,7 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
       fibheapkey_t key;
       edge_iterator ei;
 
-      bb = fibheap_extract_min (*heap);
+      bb = (basic_block) fibheap_extract_min (*heap);
       bbd[bb->index].heap = NULL;
       bbd[bb->index].node = NULL;
 
@@ -648,7 +644,8 @@ find_traces_1_round (int branch_th, int exec_th, gcov_type count_th,
                          /* The loop has less than 4 iterations.  */
 
                          if (single_succ_p (bb)
-                             && copy_bb_p (best_edge->dest, !optimize_size))
+                             && copy_bb_p (best_edge->dest,
+                                           optimize_edge_for_speed_p (best_edge)))
                            {
                              bb = copy_bb (best_edge->dest, best_edge, bb,
                                            *n_traces);
@@ -780,7 +777,7 @@ copy_bb (basic_block old_bb, edge e, basic_block bb, int trace)
 
       new_size = MAX (last_basic_block, new_bb->index + 1);
       new_size = GET_ARRAY_SIZE (new_size);
-      bbd = xrealloc (bbd, new_size * sizeof (bbro_basic_block_data));
+      bbd = XRESIZEVEC (bbro_basic_block_data, bbd, new_size);
       for (i = array_size; i < new_size; i++)
        {
          bbd[i].start_of_trace = -1;
@@ -1102,7 +1099,7 @@ connect_traces (int n_traces, struct trace *traces)
                 edge is traversed frequently enough.  */
              if (try_copy
                  && copy_bb_p (best->dest,
-                               !optimize_size
+                               optimize_edge_for_speed_p (best)
                                && EDGE_FREQUENCY (best) >= freq_threshold
                                && best->count >= count_threshold))
                {
@@ -1143,7 +1140,7 @@ connect_traces (int n_traces, struct trace *traces)
       basic_block bb;
 
       fprintf (dump_file, "Final order:\n");
-      for (bb = traces[0].first; bb; bb = bb->aux)
+      for (bb = traces[0].first; bb; bb = (basic_block) bb->aux)
        fprintf (dump_file, "%d ", bb->index);
       fprintf (dump_file, "\n");
       fflush (dump_file);
@@ -1173,7 +1170,7 @@ copy_bb_p (const_basic_block bb, int code_may_grow)
   if (EDGE_COUNT (bb->succs) > 8)
     return false;
 
-  if (code_may_grow && maybe_hot_bb_p (bb))
+  if (code_may_grow && optimize_bb_for_speed_p (bb))
     max_size *= PARAM_VALUE (PARAM_MAX_GROW_COPY_BB_INSNS);
 
   FOR_BB_INSNS (bb, insn)
@@ -1251,8 +1248,7 @@ find_rarely_executed_basic_blocks_and_crossing_edges (edge **crossing_edges,
          if (i == *max_idx)
            {
              *max_idx *= 2;
-             *crossing_edges = xrealloc (*crossing_edges,
-                                        (*max_idx) * sizeof (edge));
+             *crossing_edges = XRESIZEVEC (edge, *crossing_edges, *max_idx);
            }
          (*crossing_edges)[i++] = e;
        }
@@ -1378,7 +1374,7 @@ fix_up_fall_thru_edges (void)
         edge_iterator ei;
 
         /* Find EDGE_CAN_FALLTHRU edge.  */
-        FOR_EACH_EDGE (e, ei, cur_bb->succs) 
+        FOR_EACH_EDGE (e, ei, cur_bb->succs)
           if (e->flags & EDGE_CAN_FALLTHRU)
           {
             fall_thru = e;
@@ -1420,7 +1416,7 @@ fix_up_fall_thru_edges (void)
 
                      fall_thru_label = block_label (fall_thru->dest);
 
-                     if (old_jump && fall_thru_label)
+                     if (old_jump && JUMP_P (old_jump) && fall_thru_label)
                        invert_worked = invert_jump (old_jump,
                                                     fall_thru_label,0);
                      if (invert_worked)
@@ -1442,7 +1438,7 @@ fix_up_fall_thru_edges (void)
                  /* This is the case where both edges out of the basic
                     block are crossing edges. Here we will fix up the
                     fall through edge. The jump edge will be taken care
-                    of later.  The EDGE_CROSSING flag of fall_thru edge 
+                    of later.  The EDGE_CROSSING flag of fall_thru edge
                      is unset before the call to force_nonfallthru
                      function because if a new basic-block is created
                      this edge remains in the current section boundary
@@ -1786,10 +1782,7 @@ add_reg_crossing_jump_notes (void)
     FOR_EACH_EDGE (e, ei, bb->succs)
       if ((e->flags & EDGE_CROSSING)
          && JUMP_P (BB_END (e->src)))
-       REG_NOTES (BB_END (e->src)) = gen_rtx_EXPR_LIST (REG_CROSSING_JUMP,
-                                                        NULL_RTX,
-                                                        REG_NOTES (BB_END
-                                                                 (e->src)));
+       add_reg_note (BB_END (e->src), REG_CROSSING_JUMP, NULL_RTX);
 }
 
 /* Hot and cold basic blocks are partitioned and put in separate
@@ -1988,7 +1981,9 @@ gate_duplicate_computed_gotos (void)
 {
   if (targetm.cannot_modify_jumps_p ())
     return false;
-  return (optimize > 0 && flag_expensive_optimizations && !optimize_size);
+  return (optimize > 0
+         && flag_expensive_optimizations
+         && ! optimize_function_for_size_p (cfun));
 }
 
 
@@ -2177,7 +2172,6 @@ struct rtl_opt_pass pass_duplicate_computed_gotos =
 static void
 partition_hot_cold_basic_blocks (void)
 {
-  basic_block cur_bb;
   edge *crossing_edges;
   int n_crossing_edges;
   int max_edges = 2 * last_basic_block;
@@ -2187,13 +2181,6 @@ partition_hot_cold_basic_blocks (void)
 
   crossing_edges = XCNEWVEC (edge, max_edges);
 
-  cfg_layout_initialize (0);
-
-  FOR_EACH_BB (cur_bb)
-    if (cur_bb->index >= NUM_FIXED_BLOCKS
-       && cur_bb->next_bb->index >= NUM_FIXED_BLOCKS)
-      cur_bb->aux = cur_bb->next_bb;
-
   find_rarely_executed_basic_blocks_and_crossing_edges (&crossing_edges,
                                                        &n_crossing_edges,
                                                        &max_edges);
@@ -2202,8 +2189,6 @@ partition_hot_cold_basic_blocks (void)
     fix_edges_for_rarely_executed_code (crossing_edges, n_crossing_edges);
 
   free (crossing_edges);
-
-  cfg_layout_finalize ();
 }
 \f
 static bool
@@ -2225,7 +2210,15 @@ rest_of_handle_reorder_blocks (void)
      splitting possibly introduced more crossjumping opportunities.  */
   cfg_layout_initialize (CLEANUP_EXPENSIVE);
 
-  if (flag_reorder_blocks || flag_reorder_blocks_and_partition)
+  if ((flag_reorder_blocks || flag_reorder_blocks_and_partition)
+      /* Don't reorder blocks when optimizing for size because extra jump insns may
+        be created; also barrier may create extra padding.
+
+        More correctly we should have a block reordering mode that tried to
+        minimize the combined size of all the jumps.  This would more or less
+        automatically remove extra jumps, but would also try to use more short
+        jumps instead of long jumps.  */
+      && optimize_function_for_speed_p (cfun))
     {
       reorder_basic_blocks ();
       cleanup_cfg (CLEANUP_EXPENSIVE);
@@ -2292,12 +2285,10 @@ struct rtl_opt_pass pass_partition_blocks =
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
   TV_REORDER_BLOCKS,                    /* tv_id */
-  0,                                    /* properties_required */
+  PROP_cfglayout,                       /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
   0,                                    /* todo_flags_start */
   TODO_dump_func | TODO_verify_rtl_sharing/* todo_flags_finish */
  }
 };
-
-