OSDN Git Service

* regclass.c (init_reg_autoinc): New function.
[pf3gnuchains/gcc-fork.git] / gcc / reorg.c
index b1c33f5..e3859a6 100644 (file)
@@ -122,6 +122,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "toplev.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -143,9 +145,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #ifdef DELAY_SLOTS
 
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
 #ifndef ANNUL_IFTRUE_SLOTS
 #define eligible_for_annul_true(INSN, SLOTS, TRIAL, FLAGS) 0
 #endif
@@ -511,7 +510,8 @@ emit_delay_sequence (insn, list, length)
 
            case REG_LABEL:
              /* Keep the label reference count up to date.  */
-             LABEL_NUSES (XEXP (note, 0)) ++;
+             if (GET_CODE (XEXP (note, 0)) == CODE_LABEL)
+               LABEL_NUSES (XEXP (note, 0)) ++;
              break;
 
            default:
@@ -616,7 +616,9 @@ delete_from_delay_slot (insn)
      annul flag.  */
   if (delay_list)
     trial = emit_delay_sequence (trial, delay_list, XVECLEN (seq, 0) - 2);
-  else
+  else if (GET_CODE (trial) == JUMP_INSN
+          || GET_CODE (trial) == CALL_INSN
+          || GET_CODE (trial) == INSN)
     INSN_ANNULLED_BRANCH_P (trial) = 0;
 
   INSN_FROM_TARGET_P (insn) = 0;
@@ -749,7 +751,8 @@ optimize_skip (insn)
       || GET_CODE (PATTERN (trial)) == SEQUENCE
       || recog_memoized (trial) < 0
       || (! eligible_for_annul_false (insn, 0, trial, flags)
-         && ! eligible_for_annul_true (insn, 0, trial, flags)))
+         && ! eligible_for_annul_true (insn, 0, trial, flags))
+      || can_throw_internal (trial))
     return 0;
 
   /* There are two cases where we are just executing one insn (we assume
@@ -927,7 +930,7 @@ rare_destination (insn)
    taken, return 1.  If the branch is slightly less likely to be taken,
    return 0 and if the branch is highly unlikely to be taken, return -1.
 
-   CONDITION, if non-zero, is the condition that JUMP_INSN is testing.  */
+   CONDITION, if nonzero, is the condition that JUMP_INSN is testing.  */
 
 static int
 mostly_true_jump (jump_insn, condition)
@@ -1085,14 +1088,19 @@ get_branch_condition (insn, target)
               || (GET_CODE (XEXP (src, 2)) == LABEL_REF
                   && XEXP (XEXP (src, 2), 0) == target))
           && XEXP (src, 1) == pc_rtx)
-    return gen_rtx_fmt_ee (reverse_condition (GET_CODE (XEXP (src, 0))),
-                          GET_MODE (XEXP (src, 0)),
-                          XEXP (XEXP (src, 0), 0), XEXP (XEXP (src, 0), 1));
+    {
+      enum rtx_code rev;
+      rev = reversed_comparison_code (XEXP (src, 0), insn);
+      if (rev != UNKNOWN)
+       return gen_rtx_fmt_ee (rev, GET_MODE (XEXP (src, 0)),
+                              XEXP (XEXP (src, 0), 0),
+                              XEXP (XEXP (src, 0), 1));
+    }
 
   return 0;
 }
 
-/* Return non-zero if CONDITION is more strict than the condition of
+/* Return nonzero if CONDITION is more strict than the condition of
    INSN, i.e., if INSN will always branch if CONDITION is true.  */
 
 static int
@@ -1120,7 +1128,7 @@ condition_dominates_p (condition, insn)
   return comparison_dominates_p (code, other_code);
 }
 
-/* Return non-zero if redirecting JUMP to NEWLABEL does not invalidate
+/* Return nonzero if redirecting JUMP to NEWLABEL does not invalidate
    any insns already in the delay slot of JUMP.  */
 
 static int
@@ -1132,7 +1140,7 @@ redirect_with_delay_slots_safe_p (jump, newlabel, seq)
 
   /* Make sure all the delay slots of this jump would still
      be valid after threading the jump.  If they are still
-     valid, then return non-zero.  */
+     valid, then return nonzero.  */
 
   flags = get_jump_flags (jump, newlabel);
   for (i = 1; i < XVECLEN (pat, 0); i++)
@@ -1155,7 +1163,7 @@ redirect_with_delay_slots_safe_p (jump, newlabel, seq)
   return (i == XVECLEN (pat, 0));
 }
 
-/* Return non-zero if redirecting JUMP to NEWLABEL does not invalidate
+/* Return nonzero if redirecting JUMP to NEWLABEL does not invalidate
    any insns we wish to place in the delay slot of JUMP.  */
 
 static int
@@ -1167,7 +1175,7 @@ redirect_with_delay_list_safe_p (jump, newlabel, delay_list)
 
   /* Make sure all the insns in DELAY_LIST would still be
      valid after threading the jump.  If they are still
-     valid, then return non-zero.  */
+     valid, then return nonzero.  */
 
   flags = get_jump_flags (jump, newlabel);
   for (li = delay_list, i = 0; li; li = XEXP (li, 1), i++)
@@ -1227,9 +1235,9 @@ check_annul_list_true_false (annul_true_p, delay_list)
    insns in DELAY_LIST).  It is updated with the number that have been
    filled from the SEQUENCE, if any.
 
-   PANNUL_P points to a non-zero value if we already know that we need
+   PANNUL_P points to a nonzero value if we already know that we need
    to annul INSN.  If this routine determines that annulling is needed,
-   it may set that value non-zero.
+   it may set that value nonzero.
 
    PNEW_THREAD points to a location that is to receive the place at which
    execution should continue.  */
@@ -1850,9 +1858,9 @@ redundant_insn (insn, target, delay_list)
   return 0;
 }
 \f
-/* Return 1 if THREAD can only be executed in one way.  If LABEL is non-zero,
+/* Return 1 if THREAD can only be executed in one way.  If LABEL is nonzero,
    it is the target of the branch insn being scanned.  If ALLOW_FALLTHROUGH
-   is non-zero, we are allowed to fall into this thread; otherwise, we are
+   is nonzero, we are allowed to fall into this thread; otherwise, we are
    not.
 
    If LABEL is used more than one or we pass a label other than LABEL before
@@ -2034,7 +2042,7 @@ update_reg_unused_notes (insn, redundant_insn)
 /* Scan a function looking for insns that need a delay slot and find insns to
    put into the delay slot.
 
-   NON_JUMPS_P is non-zero if we are to only try to fill non-jump insns (such
+   NON_JUMPS_P is nonzero if we are to only try to fill non-jump insns (such
    as calls).  We do these first since we don't want jump insns (that are
    easier to fill) to get the only insns that could be used for non-jump insns.
    When it is zero, only try to fill JUMP_INSNs.
@@ -2121,7 +2129,8 @@ fill_simple_delay_slots (non_jumps_p)
          && GET_CODE (trial) == JUMP_INSN
          && simplejump_p (trial)
          && eligible_for_delay (insn, slots_filled, trial, flags)
-         && no_labels_between_p (insn, trial))
+         && no_labels_between_p (insn, trial)
+         && ! can_throw_internal (trial))
        {
          rtx *tmp;
          slots_filled++;
@@ -2191,7 +2200,7 @@ fill_simple_delay_slots (non_jumps_p)
                  /* Can't separate set of cc0 from its use.  */
                  && ! (reg_mentioned_p (cc0_rtx, pat) && ! sets_cc0_p (pat))
 #endif
-                 )
+                 && ! can_throw_internal (trial))
                {
                  trial = try_split (pat, trial, 1);
                  next_trial = prev_nonnote_insn (trial);
@@ -2267,7 +2276,7 @@ fill_simple_delay_slots (non_jumps_p)
 
             Presumably, we should also check to see if we could get
             back to this function via `setjmp'.  */
-         && !can_throw_internal (insn)
+         && ! can_throw_internal (insn)
          && (GET_CODE (insn) != JUMP_INSN
              || ((condjump_p (insn) || condjump_in_parallel_p (insn))
                  && ! simplejump_p (insn)
@@ -2334,7 +2343,8 @@ fill_simple_delay_slots (non_jumps_p)
 #endif
                    && ! (maybe_never && may_trap_p (pat))
                    && (trial = try_split (pat, trial, 0))
-                   && eligible_for_delay (insn, slots_filled, trial, flags))
+                   && eligible_for_delay (insn, slots_filled, trial, flags)
+                   && ! can_throw_internal(trial))
                  {
                    next_trial = next_nonnote_insn (trial);
                    delay_list = add_to_delay_list (trial, delay_list);
@@ -2386,7 +2396,8 @@ fill_simple_delay_slots (non_jumps_p)
 #endif
              && ! (maybe_never && may_trap_p (PATTERN (next_trial)))
              && (next_trial = try_split (PATTERN (next_trial), next_trial, 0))
-             && eligible_for_delay (insn, slots_filled, next_trial, flags))
+             && eligible_for_delay (insn, slots_filled, next_trial, flags)
+             && ! can_throw_internal (trial))
            {
              rtx new_label = next_active_insn (next_trial);
 
@@ -2490,7 +2501,7 @@ fill_simple_delay_slots (non_jumps_p)
          /* Don't want to mess with cc0 here.  */
          && ! reg_mentioned_p (cc0_rtx, pat)
 #endif
-         )
+         && ! can_throw_internal (trial))
        {
          trial = try_split (pat, trial, 1);
          if (ELIGIBLE_FOR_EPILOGUE_DELAY (trial, slots_filled))
@@ -2534,7 +2545,7 @@ fill_simple_delay_slots (non_jumps_p)
    OPPOSITE_THREAD is the thread in the opposite direction.  It is used
    to see if any potential delay slot insns set things needed there.
 
-   LIKELY is non-zero if it is extremely likely that the branch will be
+   LIKELY is nonzero if it is extremely likely that the branch will be
    taken and THREAD_IF_TRUE is set.  This is used for the branch at the
    end of a loop back up to the top.
 
@@ -2631,7 +2642,7 @@ fill_slots_from_thread (insn, condition, thread, opposite_thread, likely,
          && ! (reg_mentioned_p (cc0_rtx, pat)
                && (! own_thread || ! sets_cc0_p (pat)))
 #endif
-         )
+         && ! can_throw_internal (trial))
        {
          rtx prior_insn;
 
@@ -2732,12 +2743,13 @@ fill_slots_from_thread (insn, condition, thread, opposite_thread, likely,
                         temporarily increment the use count on any referenced
                         label lest it be deleted by delete_related_insns.  */
                      note = find_reg_note (trial, REG_LABEL, 0);
-                     if (note)
+                     /* REG_LABEL could be NOTE_INSN_DELETED_LABEL too.  */
+                     if (note && GET_CODE (XEXP (note, 0)) == CODE_LABEL)
                        LABEL_NUSES (XEXP (note, 0))++;
 
                      delete_related_insns (trial);
 
-                     if (note)
+                     if (note && GET_CODE (XEXP (note, 0)) == CODE_LABEL)
                        LABEL_NUSES (XEXP (note, 0))--;
                    }
                  else
@@ -2867,8 +2879,10 @@ fill_slots_from_thread (insn, condition, thread, opposite_thread, likely,
       trial = new_thread;
       pat = PATTERN (trial);
 
-      if (GET_CODE (trial) != INSN || GET_CODE (pat) != SET
-         || ! eligible_for_delay (insn, 0, trial, flags))
+      if (GET_CODE (trial) != INSN
+         || GET_CODE (pat) != SET
+         || ! eligible_for_delay (insn, 0, trial, flags)
+         || can_throw_internal (trial))
        return 0;
 
       dest = SET_DEST (pat), src = SET_SRC (pat);
@@ -3225,6 +3239,7 @@ relax_delay_slots (first)
          && GET_CODE (next) == JUMP_INSN
          && GET_CODE (PATTERN (next)) == RETURN)
        {
+         rtx after;
          int i;
 
          /* Delete the RETURN and just execute the delay list insns.
@@ -3241,7 +3256,15 @@ relax_delay_slots (first)
 
          trial = PREV_INSN (insn);
          delete_related_insns (insn);
-         emit_insn_after (pat, trial);
+         if (GET_CODE (pat) != SEQUENCE)
+           abort ();
+         after = trial;
+         for (i = 0; i < XVECLEN (pat, 0); i++)
+           {
+             rtx this_insn = XVECEXP (pat, 0, i);
+             add_insn_after (this_insn, after);
+             after = this_insn;
+           }
          delete_scheduled_jump (delay_insn);
          continue;
        }
@@ -3279,7 +3302,8 @@ relax_delay_slots (first)
             insn, redirect the jump to the following insn process again.  */
          trial = next_active_insn (target_label);
          if (trial && GET_CODE (PATTERN (trial)) != SEQUENCE
-             && redundant_insn (trial, insn, 0))
+             && redundant_insn (trial, insn, 0)
+             && ! can_throw_internal (trial))
            {
              rtx tmp;
 
@@ -3336,6 +3360,7 @@ relax_delay_slots (first)
 #endif
          )
        {
+         rtx after;
          int i;
 
          /* All this insn does is execute its delay list and jump to the
@@ -3354,7 +3379,15 @@ relax_delay_slots (first)
 
          trial = PREV_INSN (insn);
          delete_related_insns (insn);
-         emit_insn_after (pat, trial);
+         if (GET_CODE (pat) != SEQUENCE)
+           abort ();
+         after = trial;
+         for (i = 0; i < XVECLEN (pat, 0); i++)
+           {
+             rtx this_insn = XVECEXP (pat, 0, i);
+             add_insn_after (this_insn, after);
+             after = this_insn;
+           }
          delete_scheduled_jump (delay_insn);
          continue;
        }
@@ -3451,6 +3484,17 @@ make_return_insns (first)
   rtx real_return_label = end_of_function_label;
   int slots, i;
 
+#ifdef DELAY_SLOTS_FOR_EPILOGUE
+  /* If a previous pass filled delay slots in the epilogue, things get a
+     bit more complicated, as those filler insns would generally (without
+     data flow analysis) have to be executed after any existing branch
+     delay slot filler insns.  It is also unknown whether such a
+     transformation would actually be profitable.  Note that the existing
+     code only cares for branches with (some) filled delay slots.  */
+  if (current_function_epilogue_delay_list != NULL)
+    return;
+#endif
+
   /* See if there is a RETURN insn in the function other than the one we
      made for END_OF_FUNCTION_LABEL.  If so, set up anything we can't change
      into a RETURN to jump to it.  */
@@ -3684,10 +3728,6 @@ dbr_schedule (first, file)
   /* It is not clear why the line below is needed, but it does seem to be.  */
   unfilled_firstobj = (rtx *) obstack_alloc (&unfilled_slots_obstack, 0);
 
-  /* Reposition the prologue and epilogue notes in case we moved the
-     prologue/epilogue insns.  */
-  reposition_prologue_and_epilogue_notes (first);
-
   if (file)
     {
       int i, j, need_comma;