OSDN Git Service

2007-04-06 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / bt-load.c
index 0fc47a0..bd17616 100644 (file)
@@ -1,5 +1,6 @@
 /* Perform branch target register load optimizations.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -15,8 +16,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"
@@ -34,6 +35,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "function.h"
 #include "except.h"
 #include "tm_p.h"
+#include "toplev.h"
+#include "tree-pass.h"
 
 /* Target register optimizations - these are performed after reload.  */
 
@@ -238,7 +241,7 @@ insn_sets_btr_p (rtx insn, int check_const, int *regno)
          && TEST_HARD_REG_BIT (all_btrs, REGNO (dest)))
        {
          gcc_assert (!btr_referenced_p (src, NULL));
-         
+
          if (!check_const || CONSTANT_P (src))
            {
              if (regno)
@@ -459,7 +462,7 @@ compute_defs_uses_and_gen (fibheap_t all_btr_defs, btr_def *def_array,
   defs_uses_info info;
 
   sbitmap_vector_zero (bb_gen, n_basic_blocks);
-  for (i = 0; i < n_basic_blocks; i++)
+  for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
     {
       basic_block bb = BASIC_BLOCK (i);
       int reg;
@@ -476,7 +479,7 @@ compute_defs_uses_and_gen (fibheap_t all_btr_defs, btr_def *def_array,
       CLEAR_HARD_REG_SET (info.btrs_written_in_block);
       for (reg = first_btr; reg <= last_btr; reg++)
        if (TEST_HARD_REG_BIT (all_btrs, reg)
-           && REGNO_REG_SET_P (bb->global_live_at_start, reg))
+           && REGNO_REG_SET_P (bb->il.rtl->global_live_at_start, reg))
          SET_HARD_REG_BIT (info.btrs_live_in_block, reg);
 
       for (insn = BB_HEAD (bb), last = NEXT_INSN (BB_END (bb));
@@ -506,6 +509,22 @@ compute_defs_uses_and_gen (fibheap_t all_btr_defs, btr_def *def_array,
                  SET_BIT (btr_defset[regno - first_btr], insn_uid);
                  note_other_use_this_block (regno, info.users_this_bb);
                }
+             /* Check for the blockage emitted by expand_nl_goto_receiver.  */
+             else if (current_function_has_nonlocal_label
+                      && GET_CODE (PATTERN (insn)) == ASM_INPUT)
+               {
+                 btr_user user;
+
+                 /* Do the equivalent of calling note_other_use_this_block
+                    for every target register.  */
+                 for (user = info.users_this_bb; user != NULL;
+                      user = user->next)
+                   if (user->use)
+                     user->other_use_this_block = 1;
+                 IOR_HARD_REG_SET (info.btrs_written_in_block, all_btrs);
+                 IOR_HARD_REG_SET (info.btrs_live_in_block, all_btrs);
+                 sbitmap_zero (info.bb_gen);
+               }
              else
                {
                  if (btr_referenced_p (PATTERN (insn), NULL))
@@ -561,7 +580,7 @@ compute_defs_uses_and_gen (fibheap_t all_btr_defs, btr_def *def_array,
       COPY_HARD_REG_SET (btrs_live[i], info.btrs_live_in_block);
       COPY_HARD_REG_SET (btrs_written[i], info.btrs_written_in_block);
 
-      REG_SET_TO_HARD_REG_SET (btrs_live_at_end[i], bb->global_live_at_end);
+      REG_SET_TO_HARD_REG_SET (btrs_live_at_end[i], bb->il.rtl->global_live_at_end);
       /* If this block ends in a jump insn, add any uses or even clobbers
         of branch target registers that it might have.  */
       for (insn = BB_END (bb); insn != BB_HEAD (bb) && ! INSN_P (insn); )
@@ -604,7 +623,7 @@ compute_kill (sbitmap *bb_kill, sbitmap *btr_defset,
   /* For each basic block, form the set BB_KILL - the set
      of definitions that the block kills.  */
   sbitmap_vector_zero (bb_kill, n_basic_blocks);
-  for (i = 0; i < n_basic_blocks; i++)
+  for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
     {
       for (regno = first_btr; regno <= last_btr; regno++)
        if (TEST_HARD_REG_BIT (all_btrs, regno)
@@ -627,14 +646,14 @@ compute_out (sbitmap *bb_out, sbitmap *bb_gen, sbitmap *bb_kill, int max_uid)
   int changed;
   sbitmap bb_in = sbitmap_alloc (max_uid);
 
-  for (i = 0; i < n_basic_blocks; i++)
+  for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
     sbitmap_copy (bb_out[i], bb_gen[i]);
 
   changed = 1;
   while (changed)
     {
       changed = 0;
-      for (i = 0; i < n_basic_blocks; i++)
+      for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
        {
          sbitmap_union_of_preds (bb_in, bb_out, i);
          changed |= sbitmap_union_of_diff_cg (bb_out[i], bb_gen[i],
@@ -653,7 +672,7 @@ link_btr_uses (btr_def *def_array, btr_user *use_array, sbitmap *bb_out,
 
   /* Link uses to the uses lists of all of their reaching defs.
      Count up the number of reaching defs of each use.  */
-  for (i = 0; i < n_basic_blocks; i++)
+  for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
     {
       basic_block bb = BASIC_BLOCK (i);
       rtx insn;
@@ -683,7 +702,8 @@ link_btr_uses (btr_def *def_array, btr_user *use_array, sbitmap *bb_out,
                {
                  /* Find all the reaching defs for this use.  */
                  sbitmap reaching_defs_of_reg = sbitmap_alloc(max_uid);
-                 int uid;
+                 unsigned int uid = 0;
+                 sbitmap_iterator sbi;
 
                  if (user->use)
                    sbitmap_a_and_b (
@@ -704,7 +724,7 @@ link_btr_uses (btr_def *def_array, btr_user *use_array, sbitmap *bb_out,
                            reaching_defs,
                            btr_defset[reg - first_btr]);
                    }
-                 EXECUTE_IF_SET_IN_SBITMAP (reaching_defs_of_reg, 0, uid,
+                 EXECUTE_IF_SET_IN_SBITMAP (reaching_defs_of_reg, 0, uid, sbi)
                    {
                      btr_def def = def_array[uid];
 
@@ -736,7 +756,7 @@ link_btr_uses (btr_def *def_array, btr_user *use_array, sbitmap *bb_out,
                        def->other_btr_uses_after_use = 1;
                      user->next = def->uses;
                      def->uses = user;
-                   });
+                   }
                  sbitmap_free (reaching_defs_of_reg);
                }
 
@@ -760,12 +780,12 @@ static void
 build_btr_def_use_webs (fibheap_t all_btr_defs)
 {
   const int max_uid = get_max_uid ();
-  btr_def  *def_array   = xcalloc (max_uid, sizeof (btr_def));
-  btr_user *use_array   = xcalloc (max_uid, sizeof (btr_user));
+  btr_def  *def_array   = XCNEWVEC (btr_def, max_uid);
+  btr_user *use_array   = XCNEWVEC (btr_user, max_uid);
   sbitmap *btr_defset   = sbitmap_vector_alloc (
                           (last_btr - first_btr) + 1, max_uid);
   sbitmap *bb_gen      = sbitmap_vector_alloc (n_basic_blocks, max_uid);
-  HARD_REG_SET *btrs_written = xcalloc (n_basic_blocks, sizeof (HARD_REG_SET));
+  HARD_REG_SET *btrs_written = XCNEWVEC (HARD_REG_SET, n_basic_blocks);
   sbitmap *bb_kill;
   sbitmap *bb_out;
 
@@ -884,7 +904,7 @@ augment_live_range (bitmap live_range, HARD_REG_SET *btrs_live_in_range,
 {
   basic_block *worklist, *tos;
 
-  tos = worklist = xmalloc (sizeof (basic_block) * (n_basic_blocks + 1));
+  tos = worklist = XNEWVEC (basic_block, n_basic_blocks + 1);
 
   if (dominated_by_p (CDI_DOMINATORS, new_bb, head_bb))
     {
@@ -892,6 +912,7 @@ augment_live_range (bitmap live_range, HARD_REG_SET *btrs_live_in_range,
        {
          if (full_range)
            IOR_HARD_REG_SET (*btrs_live_in_range, btrs_live[new_bb->index]);
+         free (tos);
          return;
        }
       *tos++ = new_bb;
@@ -903,12 +924,12 @@ augment_live_range (bitmap live_range, HARD_REG_SET *btrs_live_in_range,
       int new_block = new_bb->index;
 
       gcc_assert (dominated_by_p (CDI_DOMINATORS, head_bb, new_bb));
-  
+
       IOR_HARD_REG_SET (*btrs_live_in_range, btrs_live[head_bb->index]);
       bitmap_set_bit (live_range, new_block);
       /* A previous btr migration could have caused a register to be
-        live just at the end of new_block which we need in full, so
-        use trs_live_at_end even if full_range is set.  */
+       live just at the end of new_block which we need in full, so
+       use trs_live_at_end even if full_range is set.  */
       IOR_HARD_REG_SET (*btrs_live_in_range, btrs_live_at_end[new_block]);
       if (full_range)
        IOR_HARD_REG_SET (*btrs_live_in_range, btrs_live[new_block]);
@@ -1008,7 +1029,7 @@ btr_def_live_range (btr_def def, HARD_REG_SET *btrs_live_in_range)
                            def->bb, user->bb,
                            (flag_btr_bb_exclusive
                             || user->insn != BB_END (def->bb)
-                            || GET_CODE (user->insn) != JUMP_INSN));
+                            || !JUMP_P (user->insn)));
     }
   else
     {
@@ -1072,7 +1093,7 @@ combine_btr_defs (btr_def def, HARD_REG_SET *btrs_live_in_range)
                                def->bb, user->bb,
                                (flag_btr_bb_exclusive
                                 || user->insn != BB_END (def->bb)
-                                || GET_CODE (user->insn) != JUMP_INSN));
+                                || !JUMP_P (user->insn)));
 
          btr = choose_btr (combined_btrs_live);
          if (btr != -1)
@@ -1171,7 +1192,7 @@ move_btr_def (basic_block new_def_bb, int btr, btr_def def, bitmap live_range,
       insp = BB_END (b);
       for (insp = BB_END (b); ! INSN_P (insp); insp = PREV_INSN (insp))
        gcc_assert (insp != BB_HEAD (b));
-      
+
       if (JUMP_P (insp) || can_throw_internal (insp))
        insp = PREV_INSN (insp);
     }
@@ -1318,6 +1339,15 @@ migrate_btr_def (btr_def def, int min_cost)
       /* Try to move the instruction that sets the target register into
         basic block TRY.  */
       int try_freq = basic_block_freq (try);
+      edge_iterator ei;
+      edge e;
+
+      /* If TRY has abnormal edges, skip it.  */
+      FOR_EACH_EDGE (e, ei, try->succs)
+       if (e->flags & EDGE_COMPLEX)
+         break;
+      if (e)
+       continue;
 
       if (dump_file)
        fprintf (dump_file, "trying block %d ...", try->index);
@@ -1378,7 +1408,7 @@ migrate_btr_defs (enum reg_class btr_class, int allow_callee_save)
     {
       int i;
 
-      for (i = 0; i < n_basic_blocks; i++)
+      for (i = NUM_FIXED_BLOCKS; i < n_basic_blocks; i++)
        {
          basic_block bb = BASIC_BLOCK (i);
          fprintf(dump_file,
@@ -1448,7 +1478,7 @@ branch_target_load_optimize (bool after_prologue_epilogue_gen)
       cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0);
 #endif
 
-      life_analysis (NULL, 0);
+      life_analysis (0);
 
       /* Dominator info is also needed for migrate_btr_def.  */
       calculate_dominance_info (CDI_DOMINATORS);
@@ -1462,3 +1492,51 @@ branch_target_load_optimize (bool after_prologue_epilogue_gen)
                        PROP_DEATH_NOTES | PROP_REG_INFO);
     }
 }
+\f
+static bool
+gate_handle_branch_target_load_optimize (void)
+{
+  return (optimize > 0 && flag_branch_target_load_optimize2);
+}
+
+
+static unsigned int
+rest_of_handle_branch_target_load_optimize (void)
+{
+  static int warned = 0;
+
+  /* Leave this a warning for now so that it is possible to experiment
+     with running this pass twice.  In 3.6, we should either make this
+     an error, or use separate dump files.  */
+  if (flag_branch_target_load_optimize
+      && flag_branch_target_load_optimize2
+      && !warned)
+    {
+      warning (0, "branch target register load optimization is not intended "
+                 "to be run twice");
+
+      warned = 1;
+    }
+
+  branch_target_load_optimize (epilogue_completed);
+  return 0;
+}
+
+struct tree_opt_pass pass_branch_target_load_optimize =
+{
+  "btl",                               /* name */
+  gate_handle_branch_target_load_optimize,      /* gate */
+  rest_of_handle_branch_target_load_optimize,   /* execute */
+  NULL,                                 /* sub */
+  NULL,                                 /* next */
+  0,                                    /* static_pass_number */
+  0,                                   /* tv_id */
+  0,                                    /* properties_required */
+  0,                                    /* properties_provided */
+  0,                                    /* properties_destroyed */
+  0,                                    /* todo_flags_start */
+  TODO_dump_func |
+  TODO_ggc_collect,                     /* todo_flags_finish */
+  'd'                                   /* letter */
+};
+