OSDN Git Service

(do_include): Diagnose #import and #include_next if pedantic and if
[pf3gnuchains/gcc-fork.git] / gcc / sched.c
index 549148b..d7fe1ca 100644 (file)
@@ -1,5 +1,5 @@
 /* Instruction scheduling pass.
-   Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1992, 93-96, 1997 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
    Enhanced by, and currently maintained by, Jim Wilson (wilson@cygnus.com)
 
@@ -17,7 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* Instruction scheduling pass.
 
@@ -110,9 +111,11 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    reg_n_calls_crossed, and reg_live_length.  Also, basic_block_head,
    basic_block_end.
 
-   The information in the line number notes is carefully retained by this
-   pass.  All other NOTE insns are grouped in their same relative order at
-   the beginning of basic blocks that have been scheduled.  */
+   The information in the line number notes is carefully retained by
+   this pass.  Notes that refer to the starting and ending of
+   exception regions are also carefully retained by this pass.  All
+   other NOTE insns are grouped in their same relative order at the
+   beginning of basic blocks that have been scheduled.  */
 \f
 #include <stdio.h>
 #include "config.h"
@@ -312,10 +315,10 @@ static int insn_cost                      PROTO((rtx, rtx, rtx));
 static int priority                    PROTO((rtx));
 static void free_pending_lists         PROTO((void));
 static void add_insn_mem_dependence    PROTO((rtx *, rtx *, rtx, rtx));
-static void flush_pending_lists                PROTO((rtx));
+static void flush_pending_lists                PROTO((rtx, int));
 static void sched_analyze_1            PROTO((rtx, rtx));
 static void sched_analyze_2            PROTO((rtx, rtx));
-static void sched_analyze_insn         PROTO((rtx, rtx));
+static void sched_analyze_insn         PROTO((rtx, rtx, rtx));
 static int sched_analyze               PROTO((rtx, rtx));
 static void sched_note_set             PROTO((int, rtx, int));
 static int rank_for_schedule           PROTO((rtx *, rtx *));
@@ -332,6 +335,7 @@ static rtx unlink_notes                     PROTO((rtx, rtx));
 static int new_sometimes_live          PROTO((struct sometimes *, int, int,
                                               int));
 static void finish_sometimes_live      PROTO((struct sometimes *, int));
+static rtx reemit_notes                        PROTO((rtx, rtx));
 static void schedule_block             PROTO((int, FILE *));
 static rtx regno_use_in                        PROTO((int, rtx));
 static void split_hard_reg_notes       PROTO((rtx, rtx, rtx, rtx));
@@ -353,7 +357,7 @@ static rtx *reg_known_value;
 /* Vector recording for each reg_known_value whether it is due to a
    REG_EQUIV note.  Future passes (viz., reload) may replace the
    pseudo with the equivalent expression and so we account for the
-   dependences that would be introduced if that happens. */
+   dependences that would be introduced if that happens.  */
 /* ??? This is a problem only on the Convex.  The REG_EQUIV notes created in
    assign_parms mention the arg pointer, and there are explicit insns in the
    RTL that modify the arg pointer.  Thus we must ensure that such insns don't
@@ -370,9 +374,11 @@ static rtx
 canon_rtx (x)
      rtx x;
 {
+  /* Recursively look for equivalences.  */
   if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
       && REGNO (x) <= reg_known_value_size)
-    return reg_known_value[REGNO (x)];
+    return reg_known_value[REGNO (x)] == x
+      ? x : canon_rtx (reg_known_value[REGNO (x)]);
   else if (GET_CODE (x) == PLUS)
     {
       rtx x0 = canon_rtx (XEXP (x, 0));
@@ -389,6 +395,16 @@ canon_rtx (x)
          return gen_rtx (PLUS, GET_MODE (x), x0, x1);
        }
     }
+  /* This gives us much better alias analysis when called from
+     the loop optimizer.   Note we want to leave the original
+     MEM alone, but need to return the canonicalized MEM with
+     all the flags with their original values.  */
+  else if (GET_CODE (x) == MEM)
+    {
+      rtx copy = copy_rtx (x);
+      XEXP (copy, 0) = canon_rtx (XEXP (copy, 0));
+      x = copy;
+    }
   return x;
 }
 
@@ -793,11 +809,14 @@ memrefs_conflict_p (xsize, x, ysize, y, c)
    changed.  A volatile and non-volatile reference can be interchanged
    though. 
 
-   A MEM_IN_STRUCT reference at a non-QImode varying address can never
+   A MEM_IN_STRUCT reference at a non-QImode non-AND varying address can never
    conflict with a non-MEM_IN_STRUCT reference at a fixed address.   We must
    allow QImode aliasing because the ANSI C standard allows character
    pointers to alias anything.  We are assuming that characters are
-   always QImode here.  */
+   always QImode here.  We also must allow AND addresses, because they may
+   generate accesses outside the object being referenced.  This is used to
+   generate aligned addresses from unaligned addresses, for instance, the
+   alpha storeqi_unaligned pattern.  */
 
 /* Read dependence: X is read after read in MEM takes place.  There can
    only be a dependence here if both reads are volatile.  */
@@ -824,6 +843,8 @@ true_dependence (mem, x)
      both an unchanging read and an unchanging write.  This won't handle all
      cases optimally, but the possible performance loss should be
      negligible.  */
+  x = canon_rtx (x);
+  mem = canon_rtx (mem);
   if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem))
     return 0;
 
@@ -832,9 +853,11 @@ true_dependence (mem, x)
                                  SIZE_FOR_MODE (x), XEXP (x, 0), 0)
              && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
                    && GET_MODE (mem) != QImode
+                   && GET_CODE (XEXP (mem, 0)) != AND
                    && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
              && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
                    && GET_MODE (x) != QImode
+                   && GET_CODE (XEXP (x, 0)) != AND
                    && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
 }
 
@@ -847,7 +870,9 @@ anti_dependence (mem, x)
 {
   /* If MEM is an unchanging read, then it can't possibly conflict with
      the store to X, because there is at most one store to MEM, and it must
-     have occured somewhere before MEM.  */
+     have occurred somewhere before MEM.  */
+  x = canon_rtx (x);
+  mem = canon_rtx (mem);
   if (RTX_UNCHANGING_P (mem))
     return 0;
 
@@ -856,9 +881,11 @@ anti_dependence (mem, x)
                                  SIZE_FOR_MODE (x), XEXP (x, 0), 0)
              && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
                    && GET_MODE (mem) != QImode
+                   && GET_CODE (XEXP (mem, 0)) != AND
                    && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
              && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
                    && GET_MODE (x) != QImode
+                   && GET_CODE (XEXP (x, 0)) != AND
                    && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
 }
 
@@ -869,14 +896,18 @@ output_dependence (mem, x)
      rtx mem;
      rtx x;
 {
+  x = canon_rtx (x);
+  mem = canon_rtx (mem);
   return ((MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
          || (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
                                  SIZE_FOR_MODE (x), XEXP (x, 0), 0)
              && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
                    && GET_MODE (mem) != QImode
+                   && GET_CODE (XEXP (mem, 0)) != AND
                    && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
              && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
                    && GET_MODE (x) != QImode
+                   && GET_CODE (XEXP (x, 0)) != AND
                    && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
 }
 \f
@@ -911,7 +942,8 @@ add_dependence (insn, elem, dep_type)
     next = NEXT_INSN (next);
 #endif
 
-  if (next && SCHED_GROUP_P (next))
+  if (next && SCHED_GROUP_P (next)
+      && GET_CODE (next) != CODE_LABEL)
     {
       /* Notes will never intervene here though, so don't bother checking
         for them.  */
@@ -1607,15 +1639,17 @@ add_insn_mem_dependence (insn_list, mem_list, insn, mem)
 }
 \f
 /* Make a dependency between every memory reference on the pending lists
-   and INSN, thus flushing the pending lists.  */
+   and INSN, thus flushing the pending lists.  If ONLY_WRITE, don't flush
+   the read list.  */
 
 static void
-flush_pending_lists (insn)
+flush_pending_lists (insn, only_write)
      rtx insn;
+     int only_write;
 {
   rtx link;
 
-  while (pending_read_insns)
+  while (pending_read_insns && ! only_write)
     {
       add_dependence (insn, XEXP (pending_read_insns, 0), REG_DEP_ANTI);
 
@@ -1744,7 +1778,7 @@ sched_analyze_1 (x, insn)
             seems like a reasonable number.  When compiling GCC with itself,
             this flush occurs 8 times for sparc, and 10 times for m88k using
             the number 32.  */
-         flush_pending_lists (insn);
+         flush_pending_lists (insn, 0);
        }
       else
        {
@@ -1824,22 +1858,19 @@ sched_analyze_2 (x, insn)
       {
        rtx link, prev;
 
+       /* User of CC0 depends on immediately preceding insn.  */
+       SCHED_GROUP_P (insn) = 1;
+
        /* There may be a note before this insn now, but all notes will
           be removed before we actually try to schedule the insns, so
           it won't cause a problem later.  We must avoid it here though.  */
-
-       /* User of CC0 depends on immediately preceding insn.  */
-       SCHED_GROUP_P (insn) = 1;
+       prev = prev_nonnote_insn (insn);
 
        /* Make a copy of all dependencies on the immediately previous insn,
           and add to this insn.  This is so that all the dependencies will
           apply to the group.  Remove an explicit dependence on this insn
           as SCHED_GROUP_P now represents it.  */
 
-       prev = PREV_INSN (insn);
-       while (GET_CODE (prev) == NOTE)
-         prev = PREV_INSN (prev);
-
        if (find_insn_list (prev, LOG_LINKS (insn)))
          remove_dependence (insn, prev);
 
@@ -1966,7 +1997,7 @@ sched_analyze_2 (x, insn)
              }
            reg_pending_sets_all = 1;
 
-           flush_pending_lists (insn);
+           flush_pending_lists (insn, 0);
          }
 
        /* For all ASM_OPERANDS, we must traverse the vector of input operands.
@@ -2013,8 +2044,9 @@ sched_analyze_2 (x, insn)
 /* Analyze an INSN with pattern X to find all dependencies.  */
 
 static void
-sched_analyze_insn (x, insn)
+sched_analyze_insn (x, insn, loop_notes)
      rtx x, insn;
+     rtx loop_notes;
 {
   register RTX_CODE code = GET_CODE (x);
   rtx link;
@@ -2048,6 +2080,36 @@ sched_analyze_insn (x, insn)
          sched_analyze_2 (XEXP (link, 0), insn);
       }
 
+  /* If there is a {LOOP,EHREGION}_{BEG,END} note in the middle of a basic block, then
+     we must be sure that no instructions are scheduled across it.
+     Otherwise, the reg_n_refs info (which depends on loop_depth) would
+     become incorrect.  */
+
+  if (loop_notes)
+    {
+      int max_reg = max_reg_num ();
+      rtx link;
+
+      for (i = 0; i < max_reg; i++)
+       {
+         rtx u;
+         for (u = reg_last_uses[i]; u; u = XEXP (u, 1))
+           add_dependence (insn, XEXP (u, 0), REG_DEP_ANTI);
+         reg_last_uses[i] = 0;
+         if (reg_last_sets[i])
+           add_dependence (insn, reg_last_sets[i], 0);
+       }
+      reg_pending_sets_all = 1;
+
+      flush_pending_lists (insn, 0);
+
+      link = loop_notes;
+      while (XEXP (link, 1))
+       link = XEXP (link, 1);
+      XEXP (link, 1) = REG_NOTES (insn);
+      REG_NOTES (insn) = loop_notes;
+    }
+
   /* After reload, it is possible for an instruction to have a REG_DEAD note
      for a register that actually dies a few instructions earlier.  For
      example, this can happen with SECONDARY_MEMORY_NEEDED reloads.
@@ -2107,7 +2169,8 @@ sched_analyze_insn (x, insn)
       prev_dep_insn = insn;
       dep_insn = PREV_INSN (insn);
       while (GET_CODE (dep_insn) == INSN
-            && GET_CODE (PATTERN (dep_insn)) == USE)
+            && GET_CODE (PATTERN (dep_insn)) == USE
+            && GET_CODE (XEXP (PATTERN (dep_insn), 0)) == REG)
        {
          SCHED_GROUP_P (prev_dep_insn) = 1;
 
@@ -2135,6 +2198,7 @@ sched_analyze (head, tail)
   register int n_insns = 0;
   register rtx u;
   register int luid = 0;
+  rtx loop_notes = 0;
 
   for (insn = head; ; insn = NEXT_INSN (insn))
     {
@@ -2142,7 +2206,8 @@ sched_analyze (head, tail)
 
       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
        {
-         sched_analyze_insn (PATTERN (insn), insn);
+         sched_analyze_insn (PATTERN (insn), insn, loop_notes);
+         loop_notes = 0;
          n_insns += 1;
        }
       else if (GET_CODE (insn) == CALL_INSN)
@@ -2177,9 +2242,15 @@ sched_analyze (head, tail)
                }
              reg_pending_sets_all = 1;
 
-             /* Add a fake REG_NOTE which we will later convert
-                back into a NOTE_INSN_SETJMP note.  */
-             REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD, constm1_rtx,
+             /* Add a pair of fake REG_NOTEs which we will later
+                convert back into a NOTE_INSN_SETJMP note.  See
+                reemit_notes for why we use a pair of of NOTEs.  */
+
+             REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD,
+                                         GEN_INT (0),
+                                         REG_NOTES (insn));
+             REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD,
+                                         GEN_INT (NOTE_INSN_SETJMP),
                                          REG_NOTES (insn));
            }
          else
@@ -2207,17 +2278,14 @@ sched_analyze (head, tail)
            }
          LOG_LINKS (sched_before_next_call) = 0;
 
-         sched_analyze_insn (PATTERN (insn), insn);
+         sched_analyze_insn (PATTERN (insn), insn, loop_notes);
+         loop_notes = 0;
 
-         /* We don't need to flush memory for a function call which does
-            not involve memory.  */
-         if (! CONST_CALL_P (insn))
-           {
-             /* In the absence of interprocedural alias analysis,
-                we must flush all pending reads and writes, and
-                start new dependencies starting from here.  */
-             flush_pending_lists (insn);
-           }
+         /* In the absence of interprocedural alias analysis, we must flush
+            all pending reads and writes, and start new dependencies starting
+            from here.  But only flush writes for constant calls (which may
+            be passed a pointer to something we haven't written yet).  */
+         flush_pending_lists (insn, CONST_CALL_P (insn));
 
          /* Depend this function call (actually, the user of this
             function call) on all hard register clobberage.  */
@@ -2225,9 +2293,27 @@ sched_analyze (head, tail)
          n_insns += 1;
        }
 
+      /* See comments on reemit_notes as to why we do this.  */
+      else if (GET_CODE (insn) == NOTE
+              && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
+                  || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END
+                  || NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
+                  || NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
+                  || (NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP
+                      && GET_CODE (PREV_INSN (insn)) != CALL_INSN)))
+       {
+         loop_notes = gen_rtx (EXPR_LIST, REG_DEAD,
+                               GEN_INT (NOTE_BLOCK_NUMBER (insn)), loop_notes);
+         loop_notes = gen_rtx (EXPR_LIST, REG_DEAD,
+                               GEN_INT (NOTE_LINE_NUMBER (insn)), loop_notes);
+         CONST_CALL_P (loop_notes) = CONST_CALL_P (insn);
+       }
+
       if (insn == tail)
        return n_insns;
     }
+
+  abort ();
 }
 \f
 /* Called when we see a set of a register.  If death is true, then we are
@@ -2326,7 +2412,7 @@ sched_note_set (b, x, death)
 }
 \f
 /* Macros and functions for keeping the priority queue sorted, and
-   dealing with queueing and unqueueing of instructions.  */
+   dealing with queueing and dequeueing of instructions.  */
 
 #define SCHED_SORT(READY, NEW_READY, OLD_READY) \
   do { if ((NEW_READY) - (OLD_READY) == 1)                             \
@@ -2503,6 +2589,9 @@ adjust_priority (prev)
            }
          break;
        }
+#ifdef ADJUST_PRIORITY
+      ADJUST_PRIORITY (prev);
+#endif
     }
 }
 
@@ -2823,14 +2912,19 @@ attach_deaths (x, insn, set_p)
 #endif
                && regno != STACK_POINTER_REGNUM)
              {
-               if (! all_needed && ! dead_or_set_p (insn, x))
+               /* ??? It is perhaps a dead_or_set_p bug that it does
+                  not check for REG_UNUSED notes itself.  This is necessary
+                  for the case where the SET_DEST is a subreg of regno, as
+                  dead_or_set_p handles subregs specially.  */
+               if (! all_needed && ! dead_or_set_p (insn, x)
+                   && ! find_reg_note (insn, REG_UNUSED, x))
                  {
                    /* Check for the case where the register dying partially
                       overlaps the register set by this insn.  */
                    if (regno < FIRST_PSEUDO_REGISTER
                        && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1)
                      {
-                       int n = HARD_REGNO_NREGS (regno, GET_CODE (x));
+                       int n = HARD_REGNO_NREGS (regno, GET_MODE (x));
                        while (--n >= 0)
                          some_needed |= dead_or_set_regno_p (insn, regno + n);
                      }
@@ -2995,8 +3089,13 @@ unlink_notes (insn, tail)
 
       /* Don't save away NOTE_INSN_SETJMPs, because they must remain
         immediately after the call they follow.  We use a fake
-        (REG_DEAD (const_int -1)) note to remember them.  */
-      else if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_SETJMP)
+        (REG_DEAD (const_int -1)) note to remember them.
+        Likewise with NOTE_INSN_{LOOP,EHREGION}_{BEG, END}.  */
+      else if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_SETJMP
+              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_BEG
+              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_END
+              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_EH_REGION_BEG
+              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_EH_REGION_END)
        {
          /* Insert the note at the end of the notes list.  */
          PREV_INSN (insn) = note_list;
@@ -3059,6 +3158,45 @@ finish_sometimes_live (regs_sometimes_live, sometimes_max)
     }
 }
 
+/* Search INSN for fake REG_DEAD note pairs for NOTE_INSN_SETJMP,
+   NOTE_INSN_{LOOP,EHREGION}_{BEG,END}; and convert them back into
+   NOTEs.  The REG_DEAD note following first one is contains the saved
+   value for NOTE_BLOCK_NUMBER which is useful for
+   NOTE_INSN_EH_REGION_{BEG,END} NOTEs.  LAST is the last instruction
+   output by the instruction scheduler.  Return the new value of LAST.  */
+
+static rtx
+reemit_notes (insn, last)
+     rtx insn;
+     rtx last;
+{
+  rtx note;
+
+  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
+    {
+      if (REG_NOTE_KIND (note) == REG_DEAD
+         && GET_CODE (XEXP (note, 0)) == CONST_INT)
+       {
+         if (INTVAL (XEXP (note, 0)) == NOTE_INSN_SETJMP)
+           {
+             CONST_CALL_P (emit_note_after (INTVAL (XEXP (note, 0)), insn))
+               = CONST_CALL_P (note);
+             remove_note (insn, note);
+             note = XEXP (note, 1);
+           }
+         else
+           {
+             last = emit_note_before (INTVAL (XEXP (note, 0)), last);
+             remove_note (insn, note);
+             note = XEXP (note, 1);
+             NOTE_BLOCK_NUMBER (last) = INTVAL (XEXP (note, 0));
+           }
+         remove_note (insn, note);
+       }
+    }
+  return last;
+}
+
 /* Use modified list scheduling to rearrange insns in basic block
    B.  FILE, if nonzero, is where we dump interesting output about
    this pass.  */
@@ -3070,7 +3208,7 @@ schedule_block (b, file)
 {
   rtx insn, last;
   rtx *ready, link;
-  int i, j, n_ready = 0, new_ready, n_insns = 0;
+  int i, j, n_ready = 0, new_ready, n_insns;
   int sched_n_insns = 0;
   int clock;
 #define NEED_NOTHING   0
@@ -3187,7 +3325,7 @@ schedule_block (b, file)
 
   LOG_LINKS (sched_before_next_call) = 0;
 
-  n_insns += sched_analyze (head, tail);
+  n_insns = sched_analyze (head, tail);
   if (n_insns == 0)
     {
       free_pending_lists ();
@@ -3281,9 +3419,7 @@ schedule_block (b, file)
            {
              while (SCHED_GROUP_P (insn))
                {
-                 insn = PREV_INSN (insn);
-                 while (GET_CODE (insn) == NOTE)
-                   insn = PREV_INSN (insn);
+                 insn = prev_nonnote_insn (insn);
                  priority (insn);
                }
              continue;
@@ -3378,11 +3514,31 @@ schedule_block (b, file)
                        sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 0);
                  }
 
+               /* Each call clobbers (makes live) all call-clobbered regs
+                  that are not global or fixed.  Note that the function-value
+                  reg is a call_clobbered reg.  */
+
+               if (GET_CODE (insn) == CALL_INSN)
+                 {
+                   int j;
+                   for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
+                     if (call_used_regs[j] && ! global_regs[j]
+                         && ! fixed_regs[j])
+                       {
+                         register int offset = j / REGSET_ELT_BITS;
+                         register REGSET_ELT_TYPE bit
+                           = (REGSET_ELT_TYPE) 1 << (j % REGSET_ELT_BITS);
+
+                         bb_live_regs[offset] |= bit;
+                         bb_dead_regs[offset] &= ~bit;
+                       }
+                 }
+
                for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
                  {
                    if ((REG_NOTE_KIND (link) == REG_DEAD
                         || REG_NOTE_KIND (link) == REG_UNUSED)
-                       /* Verify that the REG_NOTE has a legal value.  */
+                       /* Verify that the REG_NOTE has a valid value.  */
                        && GET_CODE (XEXP (link, 0)) == REG)
                      {
                        register int regno = REGNO (XEXP (link, 0));
@@ -3479,13 +3635,33 @@ schedule_block (b, file)
                  sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 0);
            }
 
+         /* Each call clobbers (makes live) all call-clobbered regs that are
+            not global or fixed.  Note that the function-value reg is a
+            call_clobbered reg.  */
+
+         if (GET_CODE (insn) == CALL_INSN)
+           {
+             int j;
+             for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
+               if (call_used_regs[j] && ! global_regs[j]
+                   && ! fixed_regs[j])
+                 {
+                   register int offset = j / REGSET_ELT_BITS;
+                   register REGSET_ELT_TYPE bit
+                     = (REGSET_ELT_TYPE) 1 << (j % REGSET_ELT_BITS);
+
+                   bb_live_regs[offset] |= bit;
+                   bb_dead_regs[offset] &= ~bit;
+                 }
+           }
+
          /* Need to know what registers this insn kills.  */
          for (prev = 0, link = REG_NOTES (insn); link; link = next)
            {
              next = XEXP (link, 1);
              if ((REG_NOTE_KIND (link) == REG_DEAD
                   || REG_NOTE_KIND (link) == REG_UNUSED)
-                 /* Verify that the REG_NOTE has a legal value.  */
+                 /* Verify that the REG_NOTE has a valid value.  */
                  && GET_CODE (XEXP (link, 0)) == REG)
                {
                  register int regno = REGNO (XEXP (link, 0));
@@ -3718,11 +3894,12 @@ schedule_block (b, file)
                {
                  register struct sometimes *p;
 
-                 /* A call kills all call used and global registers, except
-                    for those mentioned in the call pattern which will be
-                    made live again later.  */
+                 /* A call kills all call used registers that are not
+                    global or fixed, except for those mentioned in the call
+                    pattern which will be made live again later.  */
                  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-                   if (call_used_regs[i] || global_regs[i])
+                   if (call_used_regs[i] && ! global_regs[i]
+                       && ! fixed_regs[i])
                      {
                        register int offset = i / REGSET_ELT_BITS;
                        register REGSET_ELT_TYPE bit
@@ -3811,19 +3988,6 @@ schedule_block (b, file)
       sched_n_insns += 1;
       NEXT_INSN (insn) = last;
       PREV_INSN (last) = insn;
-      last = insn;
-
-      /* Check to see if we need to re-emit a NOTE_INSN_SETJMP here.  */
-      if (GET_CODE (insn) == CALL_INSN)
-       {
-         rtx note = find_reg_note (insn, REG_DEAD, constm1_rtx);
-
-         if (note)
-           {
-             emit_note_after (NOTE_INSN_SETJMP, insn);
-             remove_note (insn, note);
-           }
-       }
 
       /* Everything that precedes INSN now either becomes "ready", if
         it can execute immediately before INSN, or "pending", if
@@ -3838,7 +4002,8 @@ schedule_block (b, file)
       /* Schedule all prior insns that must not be moved.  */
       if (SCHED_GROUP_P (insn))
        {
-         /* Disable these insns from being launched.  */
+         /* Disable these insns from being launched, in case one of the
+            insns in the group has a dependency on an earlier one.  */
          link = insn;
          while (SCHED_GROUP_P (link))
            {
@@ -3847,19 +4012,44 @@ schedule_block (b, file)
              INSN_REF_COUNT (link) = 0;
            }
 
-         /* None of these insns can move forward into delay slots.  */
-         while (SCHED_GROUP_P (insn))
+         /* Now handle each group insn like the main insn was handled
+            above.  */
+         link = insn;
+         while (SCHED_GROUP_P (link))
            {
-             insn = PREV_INSN (insn);
-             new_ready = schedule_insn (insn, ready, new_ready, clock);
-             INSN_PRIORITY (insn) = DONE_PRIORITY;
+             link = PREV_INSN (link);
 
              sched_n_insns += 1;
-             NEXT_INSN (insn) = last;
-             PREV_INSN (last) = insn;
-             last = insn;
+
+             /* ??? Why don't we set LAUNCH_PRIORITY here?  */
+             new_ready = schedule_insn (link, ready, new_ready, clock);
+             INSN_PRIORITY (link) = DONE_PRIORITY;
            }
        }
+
+      /* Put back NOTE_INSN_SETJMP,
+         NOTE_INSN_{LOOP,EHREGION}_{BEGIN,END} notes.  */
+
+      /* To prime the loop.  We need to handle INSN and all the insns in the
+         sched group.  */
+      last = NEXT_INSN (insn);
+      do
+       {
+         insn = PREV_INSN (last);
+
+         /* Maintain a valid chain so emit_note_before works.
+            This is necessary because PREV_INSN (insn) isn't valid
+            (if ! SCHED_GROUP_P) and if it points to an insn already
+            scheduled, a circularity will result.  */
+         if (! SCHED_GROUP_P (insn))
+           {
+             NEXT_INSN (prev_head) = insn;
+             PREV_INSN (insn) = prev_head;
+           }
+
+         last = reemit_notes (insn, insn);
+       }
+      while (SCHED_GROUP_P (insn));
     }
   if (q_size != 0)
     abort ();
@@ -3870,7 +4060,7 @@ schedule_block (b, file)
   /* HEAD is now the first insn in the chain of insns that
      been scheduled by the loop above.
      TAIL is the last of those insns.  */
-  head = insn;
+  head = last;
 
   /* NOTE_LIST is the end of a chain of notes previously found
      among the insns.  Insert them at the beginning of the insns.  */
@@ -3943,7 +4133,7 @@ schedule_block (b, file)
            prev = PREV_INSN (insn);
            if (LINE_NOTE (note))
              {
-               /* Re-use the original line-number note. */
+               /* Re-use the original line-number note.  */
                LINE_NOTE (note) = 0;
                PREV_INSN (note) = prev;
                NEXT_INSN (prev) = note;
@@ -3955,6 +4145,7 @@ schedule_block (b, file)
                notes++;
                new = emit_note_after (NOTE_LINE_NUMBER (note), prev);
                NOTE_SOURCE_FILE (new) = NOTE_SOURCE_FILE (note);
+               RTX_INTEGRATED_P (new) = RTX_INTEGRATED_P (note);
              }
          }
       if (file && notes)
@@ -4261,6 +4452,15 @@ update_flow_info (notes, first, last, orig_insn)
                 pattern, so we can safely ignore it.  */
              if (insn == first)
                {
+                 /* After reload, REG_DEAD notes come sometimes an
+                    instruction after the register actually dies.  */
+                 if (reload_completed && REG_NOTE_KIND (note) == REG_DEAD)
+                   {
+                     XEXP (note, 1) = REG_NOTES (insn);
+                     REG_NOTES (insn) = note;
+                     break;
+                   }
+                       
                  if (REG_NOTE_KIND (note) != REG_UNUSED)
                    abort ();
 
@@ -4289,6 +4489,15 @@ update_flow_info (notes, first, last, orig_insn)
                     uses it.  */
                  break;
                }
+             /* If this note refers to a multiple word hard
+                register, it may have been split into several smaller
+                hard register references.  We could split the notes,
+                but simply dropping them is good enough.  */
+             if (GET_CODE (orig_dest) == REG
+                 && REGNO (orig_dest) < FIRST_PSEUDO_REGISTER
+                 && HARD_REGNO_NREGS (REGNO (orig_dest),
+                                      GET_MODE (orig_dest)) > 1)
+                   break;
              /* It must be set somewhere, fail if we couldn't find where it
                 was set.  */
              if (insn == last)
@@ -4325,7 +4534,22 @@ update_flow_info (notes, first, last, orig_insn)
              /* The original dest must still be set someplace.  Abort if we
                 couldn't find it.  */
              if (insn == first)
-               abort ();
+               {
+                 /* However, if this note refers to a multiple word hard
+                    register, it may have been split into several smaller
+                    hard register references.  We could split the notes,
+                    but simply dropping them is good enough.  */
+                 if (GET_CODE (orig_dest) == REG
+                     && REGNO (orig_dest) < FIRST_PSEUDO_REGISTER
+                     && HARD_REGNO_NREGS (REGNO (orig_dest),
+                                          GET_MODE (orig_dest)) > 1)
+                   break;
+                 /* Likewise for multi-word memory references.  */
+                 if (GET_CODE (orig_dest) == MEM
+                     && SIZE_FOR_MODE (orig_dest) > MOVE_MAX)
+                   break;
+                 abort ();
+               }
            }
          break;
 
@@ -4341,6 +4565,12 @@ update_flow_info (notes, first, last, orig_insn)
            XEXP (note, 0) = first;
          break;
 
+       case REG_EXEC_COUNT:
+         /* Move a REG_EXEC_COUNT note to the first insn created.  */
+         XEXP (note, 1) = REG_NOTES (first);
+         REG_NOTES (first) = note;
+         break;
+
        case REG_RETVAL:
          /* Move a REG_RETVAL note to the last insn created, and update
             the corresponding REG_LIBCALL note.  */
@@ -4354,6 +4584,7 @@ update_flow_info (notes, first, last, orig_insn)
          break;
 
        case REG_NONNEG:
+       case REG_BR_PROB:
          /* This should be moved to whichever instruction is a JUMP_INSN.  */
 
          for (insn = last; ; insn = PREV_INSN (insn))
@@ -4372,6 +4603,9 @@ update_flow_info (notes, first, last, orig_insn)
          break;
 
        case REG_INC:
+         /* reload sometimes leaves obsolete REG_INC notes around.  */
+         if (reload_completed)
+           break;
          /* This should be moved to whichever instruction now has the
             increment operation.  */
          abort ();
@@ -4438,6 +4672,10 @@ update_flow_info (notes, first, last, orig_insn)
        dest = XEXP (dest, 0);
 
       if (GET_CODE (dest) == REG
+         /* Global registers are always live, so the code below does not
+            apply to them.  */
+         && (REGNO (dest) >= FIRST_PSEUDO_REGISTER
+             || ! global_regs[REGNO (dest)])
          && ! reg_overlap_mentioned_p (dest, SET_SRC (set)))
        {
          for (insn = PREV_INSN (last); ; insn = PREV_INSN (insn))
@@ -4690,6 +4928,8 @@ schedule_insns (dump_file)
 
   /* ??? Add a NOTE after the last insn of the last basic block.  It is not
      known why this is done.  */
+  /* ??? Perhaps it's done to ensure NEXT_TAIL in schedule_block is a
+     valid insn.  */
 
   insn = basic_block_end[n_basic_blocks-1];
   if (NEXT_INSN (insn) == 0
@@ -4748,7 +4988,10 @@ schedule_insns (dump_file)
 
          /* Split insns here to get max fine-grain parallelism.  */
          prev = PREV_INSN (insn);
-         if (reload_completed == 0)
+         /* It is probably not worthwhile to try to split again in the
+            second pass.  However, if flag_schedule_insns is not set,
+            the first and only (if any) scheduling pass is after reload.  */
+         if (reload_completed == 0 || ! flag_schedule_insns)
            {
              rtx last, first = PREV_INSN (insn);
              rtx notes = REG_NOTES (insn);