OSDN Git Service

* sched-rgn.c (schedule_insns): Fix comment.
[pf3gnuchains/gcc-fork.git] / gcc / sched-rgn.c
index 76fb198..9e5020b 100644 (file)
@@ -1,24 +1,24 @@
 /* Instruction scheduling pass.
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000 Free Software Foundation, Inc.
+   1999, 2000, 2001 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
    and currently maintained by, Jim Wilson (wilson@cygnus.com)
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
 
-GNU CC is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the 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
-the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+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.  */
 
 /* This pass implements list scheduling within basic blocks.  It is
@@ -62,6 +62,18 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "recog.h"
 #include "sched-int.h"
 
+/* Define when we want to do count REG_DEAD notes before and after scheduling
+   for sanity checking.  We can't do that when conditional execution is used,
+   as REG_DEAD exist only for unconditional deaths.  */
+
+#if !defined (HAVE_conditional_execution) && defined (ENABLE_CHECKING)
+#define CHECK_DEAD_NOTES 1
+#else
+#define CHECK_DEAD_NOTES 0
+#endif
+
+
+#ifdef INSN_SCHEDULING
 /* Some accessor macros for h_i_d members only used within this file.  */
 #define INSN_REF_COUNT(INSN)   (h_i_d[INSN_UID (INSN)].ref_count)
 #define FED_BY_SPEC_LOAD(insn) (h_i_d[INSN_UID (insn)].fed_by_spec_load)
@@ -151,10 +163,6 @@ static int current_blocks;
 /* The mapping from bb to block.  */
 #define BB_TO_BLOCK(bb) (rgn_bb_table[current_blocks + (bb)])
 
-/* Bit vectors and bitset operations are needed for computations on
-   the control flow graph.  */
-
-typedef unsigned HOST_WIDE_INT *bitset;
 typedef struct
 {
   int *first_member;           /* Pointer to the list start in bitlst_table.  */
@@ -166,8 +174,7 @@ static int bitlst_table_last;
 static int bitlst_table_size;
 static int *bitlst_table;
 
-static char bitset_member PARAMS ((bitset, int, int));
-static void extract_bitlst PARAMS ((bitset, int, int, bitlst *));
+static void extract_bitlst PARAMS ((sbitmap, bitlst *));
 
 /* Target info declarations.
 
@@ -213,22 +220,16 @@ static void compute_trg_info PARAMS ((int));
 void debug_candidate PARAMS ((int));
 void debug_candidates PARAMS ((int));
 
-/* Bit-set of bbs, where bit 'i' stands for bb 'i'.  */
-typedef bitset bbset;
-
-/* Number of words of the bbset.  */
-static int bbset_size;
-
-/* Dominators array: dom[i] contains the bbset of dominators of
+/* Dominators array: dom[i] contains the sbitmap of dominators of
    bb i in the region.  */
-static bbset *dom;
+static sbitmap *dom;
 
 /* bb 0 is the only region entry.  */
 #define IS_RGN_ENTRY(bb) (!bb)
 
 /* Is bb_src dominated by bb_trg.  */
 #define IS_DOMINATED(bb_src, bb_trg)                                 \
-( bitset_member (dom[bb_src], bb_trg, bbset_size) )
+( TEST_BIT (dom[bb_src], bb_trg) )
 
 /* Probability: Prob[i] is a float in [0, 1] which is the probability
    of bb i relative to the region entry.  */
@@ -241,7 +242,7 @@ static float *prob;
                                                      prob[bb_trg])))
 
 /* Bit-set of edges, where bit i stands for edge i.  */
-typedef bitset edgeset;
+typedef sbitmap edgeset;
 
 /* Number of edges in the region.  */
 static int rgn_nr_edges;
@@ -249,11 +250,6 @@ static int rgn_nr_edges;
 /* Array of size rgn_nr_edges.  */
 static int *rgn_edges;
 
-/* Number of words in an edgeset.  */
-static int edgeset_size;
-
-/* Number of bits in an edgeset.  */
-static int edgeset_bitsize;
 
 /* Mapping from each edge in the graph to its number in the rgn.  */
 static int *edge_to_bit;
@@ -303,7 +299,7 @@ void debug_dependencies PARAMS ((void));
 
 static void init_regions PARAMS ((void));
 static void schedule_region PARAMS ((int));
-static void propagate_deps PARAMS ((int, struct deps *, int));
+static void propagate_deps PARAMS ((int, struct deps *));
 static void free_pending_lists PARAMS ((void));
 
 /* Functions for construction of the control flow graph.  */
@@ -348,13 +344,15 @@ is_cfg_nonregular ()
     for (insn = BLOCK_HEAD (b);; insn = NEXT_INSN (insn))
       {
        code = GET_CODE (insn);
-       if (GET_RTX_CLASS (code) == 'i')
+       if (GET_RTX_CLASS (code) == 'i' && code != JUMP_INSN)
          {
-           rtx note;
+           rtx note = find_reg_note (insn, REG_LABEL, NULL_RTX);
 
-           for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
-             if (REG_NOTE_KIND (note) == REG_LABEL)
-               return 1;
+           if (note
+               && ! (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
+                     && find_reg_note (NEXT_INSN (insn), REG_LABEL,
+                                       XEXP (note, 0))))
+             return 1;
          }
 
        if (insn == BLOCK_END (b))
@@ -479,80 +477,14 @@ new_edge (source, target)
     }
 }
 
-/* BITSET macros for operations on the control flow graph.  */
-
-/* Compute bitwise union of two bitsets.  */
-#define BITSET_UNION(set1, set2, len)                                \
-do { register bitset tp = set1, sp = set2;                           \
-     register int i;                                                 \
-     for (i = 0; i < len; i++)                                       \
-       *(tp++) |= *(sp++); } while (0)
-
-/* Compute bitwise intersection of two bitsets.  */
-#define BITSET_INTER(set1, set2, len)                                \
-do { register bitset tp = set1, sp = set2;                           \
-     register int i;                                                 \
-     for (i = 0; i < len; i++)                                       \
-       *(tp++) &= *(sp++); } while (0)
-
-/* Compute bitwise difference of two bitsets.  */
-#define BITSET_DIFFER(set1, set2, len)                               \
-do { register bitset tp = set1, sp = set2;                           \
-     register int i;                                                 \
-     for (i = 0; i < len; i++)                                       \
-       *(tp++) &= ~*(sp++); } while (0)
-
-/* Inverts every bit of bitset 'set'.  */
-#define BITSET_INVERT(set, len)                                      \
-do { register bitset tmpset = set;                                   \
-     register int i;                                                 \
-     for (i = 0; i < len; i++, tmpset++)                             \
-       *tmpset = ~*tmpset; } while (0)
-
-/* Turn on the index'th bit in bitset set.  */
-#define BITSET_ADD(set, index, len)                                  \
-{                                                                    \
-  if (index >= HOST_BITS_PER_WIDE_INT * len)                         \
-    abort ();                                                        \
-  else                                                               \
-    set[index/HOST_BITS_PER_WIDE_INT] |=                            \
-      1 << (index % HOST_BITS_PER_WIDE_INT);                         \
-}
-
-/* Turn off the index'th bit in set.  */
-#define BITSET_REMOVE(set, index, len)                               \
-{                                                                    \
-  if (index >= HOST_BITS_PER_WIDE_INT * len)                         \
-    abort ();                                                        \
-  else                                                               \
-    set[index/HOST_BITS_PER_WIDE_INT] &=                            \
-      ~(1 << (index%HOST_BITS_PER_WIDE_INT));                        \
-}
-
-/* Check if the index'th bit in bitset set is on.  */
-
-static char
-bitset_member (set, index, len)
-     bitset set;
-     int index, len;
-{
-  if (index >= HOST_BITS_PER_WIDE_INT * len)
-    abort ();
-  return (set[index / HOST_BITS_PER_WIDE_INT] &
-         1 << (index % HOST_BITS_PER_WIDE_INT)) ? 1 : 0;
-}
-
 /* Translate a bit-set SET to a list BL of the bit-set members.  */
 
 static void
-extract_bitlst (set, len, bitlen, bl)
-     bitset set;
-     int len;
-     int bitlen;
+extract_bitlst (set, bl)
+     sbitmap set;
      bitlst *bl;
 {
-  int i, j, offset;
-  unsigned HOST_WIDE_INT word;
+  int i;
 
   /* bblst table space is reused in each call to extract_bitlst.  */
   bitlst_table_last = 0;
@@ -561,24 +493,11 @@ extract_bitlst (set, len, bitlen, bl)
   bl->nr_members = 0;
 
   /* Iterate over each word in the bitset.  */
-  for (i = 0; i < len; i++)
-    {
-      word = set[i];
-      offset = i * HOST_BITS_PER_WIDE_INT;
-
-      /* Iterate over each bit in the word, but do not
-        go beyond the end of the defined bits.  */
-      for (j = 0; offset < bitlen && word; j++)
-       {
-         if (word & 1)
-           {
-             bitlst_table[bitlst_table_last++] = offset;
-             (bl->nr_members)++;
-           }
-         word >>= 1;
-         ++offset;
-       }
-    }
+  EXECUTE_IF_SET_IN_SBITMAP (set, 0, i,
+  {
+    bitlst_table[bitlst_table_last++] = i;
+    (bl->nr_members)++;
+  });
 
 }
 
@@ -1130,7 +1049,7 @@ compute_dom_prob_ps (bb)
   prob[bb] = 0.0;
   if (IS_RGN_ENTRY (bb))
     {
-      BITSET_ADD (dom[bb], 0, bbset_size);
+      SET_BIT (dom[bb], 0);
       prob[bb] = 1.0;
       return;
     }
@@ -1138,26 +1057,24 @@ compute_dom_prob_ps (bb)
   fst_in_edge = nxt_in_edge = IN_EDGES (BB_TO_BLOCK (bb));
 
   /* Intialize dom[bb] to '111..1'.  */
-  BITSET_INVERT (dom[bb], bbset_size);
+  sbitmap_ones (dom[bb]);
 
   do
     {
       pred = FROM_BLOCK (nxt_in_edge);
-      BITSET_INTER (dom[bb], dom[BLOCK_TO_BB (pred)], bbset_size);
-
-      BITSET_UNION (ancestor_edges[bb], ancestor_edges[BLOCK_TO_BB (pred)],
-                   edgeset_size);
+      sbitmap_a_and_b (dom[bb], dom[bb], dom[BLOCK_TO_BB (pred)]);
+      sbitmap_a_or_b (ancestor_edges[bb], ancestor_edges[bb], ancestor_edges[BLOCK_TO_BB (pred)]);
 
-      BITSET_ADD (ancestor_edges[bb], EDGE_TO_BIT (nxt_in_edge), edgeset_size);
+      SET_BIT (ancestor_edges[bb], EDGE_TO_BIT (nxt_in_edge));
 
       nr_out_edges = 1;
       nr_rgn_out_edges = 0;
       fst_out_edge = OUT_EDGES (pred);
       nxt_out_edge = NEXT_OUT (fst_out_edge);
-      BITSET_UNION (pot_split[bb], pot_split[BLOCK_TO_BB (pred)],
-                   edgeset_size);
 
-      BITSET_ADD (pot_split[bb], EDGE_TO_BIT (fst_out_edge), edgeset_size);
+      sbitmap_a_or_b (pot_split[bb], pot_split[bb], pot_split[BLOCK_TO_BB (pred)]);
+
+      SET_BIT (pot_split[bb], EDGE_TO_BIT (fst_out_edge));
 
       /* The successor doesn't belong in the region?  */
       if (CONTAINING_RGN (TO_BLOCK (fst_out_edge)) !=
@@ -1171,7 +1088,7 @@ compute_dom_prob_ps (bb)
          if (CONTAINING_RGN (TO_BLOCK (nxt_out_edge)) !=
              CONTAINING_RGN (BB_TO_BLOCK (bb)))
            ++nr_rgn_out_edges;
-         BITSET_ADD (pot_split[bb], EDGE_TO_BIT (nxt_out_edge), edgeset_size);
+        SET_BIT (pot_split[bb], EDGE_TO_BIT (nxt_out_edge));
          nxt_out_edge = NEXT_OUT (nxt_out_edge);
 
        }
@@ -1188,8 +1105,8 @@ compute_dom_prob_ps (bb)
     }
   while (fst_in_edge != nxt_in_edge);
 
-  BITSET_ADD (dom[bb], bb, bbset_size);
-  BITSET_DIFFER (pot_split[bb], ancestor_edges[bb], edgeset_size);
+  SET_BIT (dom[bb], bb);
+  sbitmap_difference (pot_split[bb], pot_split[bb], ancestor_edges[bb]);
 
   if (sched_verbose >= 2)
     fprintf (sched_dump, ";;  bb_prob(%d, %d) = %3d\n", bb, BB_TO_BLOCK (bb),
@@ -1207,14 +1124,12 @@ split_edges (bb_src, bb_trg, bl)
      int bb_trg;
      edgelst *bl;
 {
-  int es = edgeset_size;
-  edgeset src = (edgeset) xcalloc (es, sizeof (HOST_WIDE_INT));
-
-  while (es--)
-    src[es] = (pot_split[bb_src])[es];
-  BITSET_DIFFER (src, pot_split[bb_trg], edgeset_size);
-  extract_bitlst (src, edgeset_size, edgeset_bitsize, bl);
-  free (src);
+  sbitmap src = (edgeset) sbitmap_alloc (pot_split[bb_src]->n_bits);
+  sbitmap_copy (src, pot_split[bb_src]);
+
+  sbitmap_difference (src, src, pot_split[bb_trg]);
+  extract_bitlst (src, bl);
+  sbitmap_free (src);
 }
 
 /* Find the valid candidate-source-blocks for the target block TRG, compute
@@ -1225,7 +1140,7 @@ static void
 compute_trg_info (trg)
      int trg;
 {
-  register candidate *sp;
+  candidate *sp;
   edgelst el;
   int check_block, update_idx;
   int i, j, k, fst_edge, nxt_edge;
@@ -1380,9 +1295,9 @@ check_live_1 (src, x)
      int src;
      rtx x;
 {
-  register int i;
-  register int regno;
-  register rtx reg = SET_DEST (x);
+  int i;
+  int regno;
+  rtx reg = SET_DEST (x);
 
   if (reg == 0)
     return 1;
@@ -1392,13 +1307,15 @@ check_live_1 (src, x)
         || GET_CODE (reg) == STRICT_LOW_PART)
     reg = XEXP (reg, 0);
 
-  if (GET_CODE (reg) == PARALLEL
-      && GET_MODE (reg) == BLKmode)
+  if (GET_CODE (reg) == PARALLEL)
     {
-      register int i;
+      int i;
+
       for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
-       if (check_live_1 (src, XVECEXP (reg, 0, i)))
-         return 1;
+       if (XEXP (XVECEXP (reg, 0, i), 0) != 0)
+         if (check_live_1 (src, XEXP (XVECEXP (reg, 0, i), 0)))
+           return 1;
+
       return 0;
     }
 
@@ -1458,9 +1375,9 @@ update_live_1 (src, x)
      int src;
      rtx x;
 {
-  register int i;
-  register int regno;
-  register rtx reg = SET_DEST (x);
+  int i;
+  int regno;
+  rtx reg = SET_DEST (x);
 
   if (reg == 0)
     return;
@@ -1470,12 +1387,14 @@ update_live_1 (src, x)
         || GET_CODE (reg) == STRICT_LOW_PART)
     reg = XEXP (reg, 0);
 
-  if (GET_CODE (reg) == PARALLEL
-      && GET_MODE (reg) == BLKmode)
+  if (GET_CODE (reg) == PARALLEL)
     {
-      register int i;
+      int i;
+
       for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
-       update_live_1 (src, XVECEXP (reg, 0, i));
+       if (XEXP (XVECEXP (reg, 0, i), 0) != 0)
+         update_live_1 (src, XEXP (XVECEXP (reg, 0, i), 0));
+
       return;
     }
 
@@ -1639,9 +1558,8 @@ enum INSN_TRAP_CLASS
 #define IS_REACHABLE(bb_from, bb_to)                                   \
 (bb_from == bb_to                                                       \
    || IS_RGN_ENTRY (bb_from)                                           \
-   || (bitset_member (ancestor_edges[bb_to],                           \
-                     EDGE_TO_BIT (IN_EDGES (BB_TO_BLOCK (bb_from))),   \
-                     edgeset_size)))
+   || (TEST_BIT (ancestor_edges[bb_to],                               \
+                    EDGE_TO_BIT (IN_EDGES (BB_TO_BLOCK (bb_from))))))
 
 /* Non-zero iff the address is comprised from at most 1 register.  */
 #define CONST_BASED_ADDRESS_P(x)                       \
@@ -1762,7 +1680,7 @@ is_pfree (load_insn, bb_src, bb_trg)
      int bb_src, bb_trg;
 {
   rtx back_link;
-  register candidate *candp = candidate_table + bb_src;
+  candidate *candp = candidate_table + bb_src;
 
   if (candp->split_bbs.nr_members != 1)
     /* Must have exactly one escape block.  */
@@ -1911,15 +1829,17 @@ haifa_classify_insn (insn)
              if (tmp_class == TRAP_RISKY)
                break;
              /* Test if it is a load.  */
-             tmp_class =
-               WORST_CLASS (tmp_class,
-                            may_trap_exp (SET_SRC (XVECEXP (pat, 0, i)), 0));
+             tmp_class
+               = WORST_CLASS (tmp_class,
+                              may_trap_exp (SET_SRC (XVECEXP (pat, 0, i)),
+                                            0));
              break;
            case COND_EXEC:
            case TRAP_IF:
              tmp_class = TRAP_RISKY;
              break;
-           default:;
+           default:
+             ;
            }
          insn_class = WORST_CLASS (insn_class, tmp_class);
          if (insn_class == TRAP_RISKY || insn_class == IRISKY)
@@ -2031,6 +1951,8 @@ static int sched_target_n_insns;
 static int target_n_insns;
 /* The number of insns from the entire region scheduled so far.  */
 static int sched_n_insns;
+/* Nonzero if the last scheduled insn was a jump.  */
+static int last_was_jump;
 
 /* Implementations of the sched_info functions for region scheduling.  */
 static void init_ready_list PARAMS ((struct ready_list *));
@@ -2039,13 +1961,15 @@ static int new_ready PARAMS ((rtx));
 static int schedule_more_p PARAMS ((void));
 static const char *rgn_print_insn PARAMS ((rtx, int));
 static int rgn_rank PARAMS ((rtx, rtx));
+static int contributes_to_priority PARAMS ((rtx, rtx));
+static void compute_jump_reg_dependencies PARAMS ((rtx, regset));
 
 /* Return nonzero if there are more insns that should be scheduled.  */
 
 static int
 schedule_more_p ()
 {
-  return sched_target_n_insns < target_n_insns;
+  return ! last_was_jump && sched_target_n_insns < target_n_insns;
 }
 
 /* Add all insns that are initially ready to the ready list READY.  Called
@@ -2063,6 +1987,7 @@ init_ready_list (ready)
   target_n_insns = 0;
   sched_target_n_insns = 0;
   sched_n_insns = 0;
+  last_was_jump = 0;
 
   /* Print debugging information.  */
   if (sched_verbose >= 5)
@@ -2133,7 +2058,7 @@ init_ready_list (ready)
              {
                rtx next;
 
-               /* Note that we havn't squirrled away the notes for
+               /* Note that we havn't squirreled away the notes for
                   blocks other than the current.  So if this is a
                   speculative insn, NEXT might otherwise be a note.  */
                next = next_nonnote_insn (insn);
@@ -2154,6 +2079,9 @@ static int
 can_schedule_ready_p (insn)
      rtx insn;
 {
+  if (GET_CODE (insn) == JUMP_INSN)
+    last_was_jump = 1;
+
   /* An interblock motion?  */
   if (INSN_BB (insn) != target_bb)
     {
@@ -2183,7 +2111,7 @@ can_schedule_ready_p (insn)
       while (SCHED_GROUP_P (temp))
        temp = PREV_INSN (temp);
 
-      /* Update source block boundaries.   */
+      /* Update source block boundaries.  */
       b1 = BLOCK_FOR_INSN (temp);
       if (temp == b1->head && insn == b1->end)
        {
@@ -2255,9 +2183,10 @@ rgn_print_insn (insn, aligned)
     sprintf (tmp, "b%3d: i%4d", INSN_BB (insn), INSN_UID (insn));
   else
     {
-      sprintf (tmp, "%d", INSN_UID (insn));
       if (current_nr_blocks > 1 && INSN_BB (insn) != target_bb)
-       sprintf (tmp, "/b%d ", INSN_BB (insn));
+       sprintf (tmp, "%d/b%d", INSN_UID (insn), INSN_BB (insn));
+      else
+       sprintf (tmp, "%d", INSN_UID (insn));
     }
   return tmp;
 }
@@ -2294,6 +2223,29 @@ rgn_rank (insn1, insn2)
   return 0;
 }
 
+/* NEXT is an instruction that depends on INSN (a backward dependence);
+   return nonzero if we should include this dependence in priority
+   calculations.  */
+
+static int
+contributes_to_priority (next, insn)
+     rtx next, insn;
+{
+  return BLOCK_NUM (next) == BLOCK_NUM (insn);
+}
+
+/* INSN is a JUMP_INSN.  Store the set of registers that must be considered
+   to be set by this jump in SET.  */
+
+static void
+compute_jump_reg_dependencies (insn, set)
+     rtx insn ATTRIBUTE_UNUSED;
+     regset set ATTRIBUTE_UNUSED;
+{
+  /* Nothing to do here, since we postprocess jumps in
+     add_branch_dependences.  */
+}
+
 /* Used in schedule_insns to initialize current_sched_info for scheduling
    regions (or single basic blocks).  */
 
@@ -2305,10 +2257,12 @@ static struct sched_info region_sched_info =
   new_ready,
   rgn_rank,
   rgn_print_insn,
+  contributes_to_priority,
+  compute_jump_reg_dependencies,
 
   NULL, NULL,
   NULL, NULL,
-  0
+  0, 0
 };
 
 /* Add dependences so that branches are scheduled to run last in their
@@ -2402,13 +2356,11 @@ add_branch_dependences (head, tail)
 static struct deps *bb_deps;
 
 /* After computing the dependencies for block BB, propagate the dependencies
-   found in TMP_DEPS to the successors of the block.  MAX_REG is the number
-   of registers.  */
+   found in TMP_DEPS to the successors of the block.  */
 static void
-propagate_deps (bb, tmp_deps, max_reg)
+propagate_deps (bb, tmp_deps)
      int bb;
      struct deps *tmp_deps;
-     int max_reg;
 {
   int b = BB_TO_BLOCK (bb);
   int e, first_edge;
@@ -2443,43 +2395,28 @@ propagate_deps (bb, tmp_deps, max_reg)
          continue;
        }
 
-      for (reg = 0; reg < max_reg; reg++)
+      /* The reg_last lists are inherited by bb_succ.  */
+      EXECUTE_IF_SET_IN_REG_SET (&tmp_deps->reg_last_in_use, 0, reg,
        {
-         /* reg-last-uses lists are inherited by bb_succ.  */
-         for (u = tmp_deps->reg_last_uses[reg]; u; u = XEXP (u, 1))
-           {
-             if (find_insn_list (XEXP (u, 0),
-                                 succ_deps->reg_last_uses[reg]))
-               continue;
-
-             succ_deps->reg_last_uses[reg]
-               = alloc_INSN_LIST (XEXP (u, 0),
-                                  succ_deps->reg_last_uses[reg]);
-           }
-
-         /* reg-last-defs lists are inherited by bb_succ.  */
-         for (u = tmp_deps->reg_last_sets[reg]; u; u = XEXP (u, 1))
-           {
-             if (find_insn_list (XEXP (u, 0),
-                                 succ_deps->reg_last_sets[reg]))
-               continue;
-
-             succ_deps->reg_last_sets[reg]
-               = alloc_INSN_LIST (XEXP (u, 0),
-                                  succ_deps->reg_last_sets[reg]);
-           }
-
-         for (u = tmp_deps->reg_last_clobbers[reg]; u; u = XEXP (u, 1))
-           {
-             if (find_insn_list (XEXP (u, 0),
-                                 succ_deps->reg_last_clobbers[reg]))
-               continue;
-
-             succ_deps->reg_last_clobbers[reg]
-               = alloc_INSN_LIST (XEXP (u, 0),
-                                  succ_deps->reg_last_clobbers[reg]);
-           }
-       }
+         struct deps_reg *tmp_deps_reg = &tmp_deps->reg_last[reg];
+         struct deps_reg *succ_deps_reg = &succ_deps->reg_last[reg];
+
+         for (u = tmp_deps_reg->uses; u; u = XEXP (u, 1))
+           if (! find_insn_list (XEXP (u, 0), succ_deps_reg->uses))
+             succ_deps_reg->uses
+               = alloc_INSN_LIST (XEXP (u, 0), succ_deps_reg->uses);
+
+         for (u = tmp_deps_reg->sets; u; u = XEXP (u, 1))
+           if (! find_insn_list (XEXP (u, 0), succ_deps_reg->sets))
+             succ_deps_reg->sets
+               = alloc_INSN_LIST (XEXP (u, 0), succ_deps_reg->sets);
+
+         for (u = tmp_deps_reg->clobbers; u; u = XEXP (u, 1))
+           if (! find_insn_list (XEXP (u, 0), succ_deps_reg->clobbers))
+             succ_deps_reg->clobbers
+               = alloc_INSN_LIST (XEXP (u, 0), succ_deps_reg->clobbers);
+       });
+      IOR_REG_SET (&succ_deps->reg_last_in_use, &tmp_deps->reg_last_in_use);
 
       /* Mem read/write lists are inherited by bb_succ.  */
       link_insn = tmp_deps->pending_read_insns;
@@ -2516,27 +2453,17 @@ propagate_deps (bb, tmp_deps, max_reg)
 
       /* last_function_call is inherited by bb_succ.  */
       for (u = tmp_deps->last_function_call; u; u = XEXP (u, 1))
-       {
-         if (find_insn_list (XEXP (u, 0),
-                             succ_deps->last_function_call))
-           continue;
-
+       if (! find_insn_list (XEXP (u, 0), succ_deps->last_function_call))
          succ_deps->last_function_call
-           = alloc_INSN_LIST (XEXP (u, 0),
-                              succ_deps->last_function_call);
-       }
+           = alloc_INSN_LIST (XEXP (u, 0), succ_deps->last_function_call);
 
       /* last_pending_memory_flush is inherited by bb_succ.  */
       for (u = tmp_deps->last_pending_memory_flush; u; u = XEXP (u, 1))
-       {
-         if (find_insn_list (XEXP (u, 0),
+       if (! find_insn_list (XEXP (u, 0),
                              succ_deps->last_pending_memory_flush))
-           continue;
-
          succ_deps->last_pending_memory_flush
            = alloc_INSN_LIST (XEXP (u, 0),
                               succ_deps->last_pending_memory_flush);
-       }
 
       /* sched_before_next_call is inherited by bb_succ.  */
       x = LOG_LINKS (tmp_deps->sched_before_next_call);
@@ -2556,8 +2483,8 @@ propagate_deps (bb, tmp_deps, max_reg)
 
    Specifically for reg-reg data dependences, the block insns are
    scanned by sched_analyze () top-to-bottom.  Two lists are
-   maintained by sched_analyze (): reg_last_sets[] for register DEFs,
-   and reg_last_uses[] for register USEs.
+   maintained by sched_analyze (): reg_last[].sets for register DEFs,
+   and reg_last[].uses for register USEs.
 
    When analysis is completed for bb, we update for its successors:
    ;  - DEFS[succ] = Union (DEFS [succ], DEFS [bb])
@@ -2571,7 +2498,6 @@ compute_block_backward_dependences (bb)
      int bb;
 {
   rtx head, tail;
-  int max_reg = max_reg_num ();
   struct deps tmp_deps;
 
   tmp_deps = bb_deps[bb];
@@ -2582,19 +2508,12 @@ compute_block_backward_dependences (bb)
   add_branch_dependences (head, tail);
 
   if (current_nr_blocks > 1)
-    propagate_deps (bb, &tmp_deps, max_reg);
+    propagate_deps (bb, &tmp_deps);
 
   /* Free up the INSN_LISTs.  */
   free_deps (&tmp_deps);
-
-  /* Assert that we won't need bb_reg_last_* for this block anymore.  */
-  free (bb_deps[bb].reg_last_uses);
-  free (bb_deps[bb].reg_last_sets);
-  free (bb_deps[bb].reg_last_clobbers);
-  bb_deps[bb].reg_last_uses = 0;
-  bb_deps[bb].reg_last_sets = 0;
-  bb_deps[bb].reg_last_clobbers = 0;
 }
+
 /* Remove all INSN_LISTs and EXPR_LISTs from the pending lists and add
    them to the unused_*_list variables, so that they can be reused.  */
 
@@ -2724,7 +2643,12 @@ schedule_region (rgn)
 
   /* Set priorities.  */
   for (bb = 0; bb < current_nr_blocks; bb++)
-    rgn_n_insns += set_priorities (BB_TO_BLOCK (bb));
+    {
+      rtx head, tail;
+      get_block_head_tail (BB_TO_BLOCK (bb), &head, &tail);
+
+      rgn_n_insns += set_priorities (head, tail);
+    }
 
   /* Compute interblock info: probabilities, split-edges, dominators, etc.  */
   if (current_nr_blocks > 1)
@@ -2733,11 +2657,8 @@ schedule_region (rgn)
 
       prob = (float *) xmalloc ((current_nr_blocks) * sizeof (float));
 
-      bbset_size = current_nr_blocks / HOST_BITS_PER_WIDE_INT + 1;
-      dom = (bbset *) xmalloc (current_nr_blocks * sizeof (bbset));
-      for (i = 0; i < current_nr_blocks; i++)
-       dom[i] = (bbset) xcalloc (bbset_size, sizeof (HOST_WIDE_INT));
-
+      dom = sbitmap_vector_alloc (current_nr_blocks, current_nr_blocks);
+      sbitmap_vector_zero (dom, current_nr_blocks);
       /* Edge to bit.  */
       rgn_nr_edges = 0;
       edge_to_bit = (int *) xmalloc (nr_edges * sizeof (int));
@@ -2752,18 +2673,10 @@ schedule_region (rgn)
          rgn_edges[rgn_nr_edges++] = i;
 
       /* Split edges.  */
-      edgeset_size = rgn_nr_edges / HOST_BITS_PER_WIDE_INT + 1;
-      edgeset_bitsize = rgn_nr_edges;
-      pot_split = (edgeset *) xmalloc (current_nr_blocks * sizeof (edgeset));
-      ancestor_edges
-       = (edgeset *) xmalloc (current_nr_blocks * sizeof (edgeset));
-      for (i = 0; i < current_nr_blocks; i++)
-       {
-         pot_split[i] =
-           (edgeset) xcalloc (edgeset_size, sizeof (HOST_WIDE_INT));
-         ancestor_edges[i] =
-           (edgeset) xcalloc (edgeset_size, sizeof (HOST_WIDE_INT));
-       }
+      pot_split = sbitmap_vector_alloc (current_nr_blocks, rgn_nr_edges);
+      sbitmap_vector_zero (pot_split, current_nr_blocks);
+      ancestor_edges = sbitmap_vector_alloc (current_nr_blocks, rgn_nr_edges);
+      sbitmap_vector_zero (ancestor_edges, current_nr_blocks);
 
       /* Compute probabilities, dominators, split_edges.  */
       for (bb = 0; bb < current_nr_blocks; bb++)
@@ -2786,8 +2699,8 @@ schedule_region (rgn)
 
       if (write_symbols != NO_DEBUG)
        {
-         save_line_notes (b);
-         rm_line_notes (b);
+         save_line_notes (b, head, tail);
+         rm_line_notes (head, tail);
        }
 
       /* rm_other_notes only removes notes which are _inside_ the
@@ -2795,10 +2708,7 @@ schedule_region (rgn)
         or after the last real insn of the block.  So if the first insn
         has a REG_SAVE_NOTE which would otherwise be emitted before the
         insn, it is redundant with the note before the start of the
-        block, and so we have to take it out.
-
-        FIXME: Probably the same thing should be done with REG_SAVE_NOTEs
-        referencing NOTE_INSN_SETJMP at the end of the block.  */
+        block, and so we have to take it out.  */
       if (INSN_P (head))
        {
          rtx note;
@@ -2806,14 +2716,9 @@ schedule_region (rgn)
          for (note = REG_NOTES (head); note; note = XEXP (note, 1))
            if (REG_NOTE_KIND (note) == REG_SAVE_NOTE)
              {
-               if (INTVAL (XEXP (note, 0)) != NOTE_INSN_SETJMP)
-                 {
-                   remove_note (head, note);
-                   note = XEXP (note, 1);
-                   remove_note (head, note);
-                 }
-               else
-                 note = XEXP (note, 1);
+               remove_note (head, note);
+               note = XEXP (note, 1);
+               remove_note (head, note);
              }
        }
 
@@ -2853,7 +2758,11 @@ schedule_region (rgn)
   if (write_symbols != NO_DEBUG)
     {
       for (bb = 0; bb < current_nr_blocks; bb++)
-       restore_line_notes (BB_TO_BLOCK (bb));
+       {
+         rtx head, tail;
+         get_block_head_tail (BB_TO_BLOCK (bb), &head, &tail);
+         restore_line_notes (head, tail);
+       }
     }
 
   /* Done with this region.  */
@@ -2865,20 +2774,12 @@ schedule_region (rgn)
 
   if (current_nr_blocks > 1)
     {
-      int i;
-
       free (prob);
-      for (i = 0; i < current_nr_blocks; ++i)
-       {
-         free (dom[i]);
-         free (pot_split[i]);
-         free (ancestor_edges[i]);
-       }
-      free (dom);
+      sbitmap_vector_free (dom);
+      sbitmap_vector_free (pot_split);
+      sbitmap_vector_free (ancestor_edges);
       free (edge_to_bit);
       free (rgn_edges);
-      free (pot_split);
-      free (ancestor_edges);
     }
 }
 
@@ -2900,8 +2801,6 @@ init_regions ()
   block_to_bb = (int *) xmalloc ((n_basic_blocks) * sizeof (int));
   containing_rgn = (int *) xmalloc ((n_basic_blocks) * sizeof (int));
 
-  blocks = sbitmap_alloc (n_basic_blocks);
-
   /* Compute regions for scheduling.  */
   if (reload_completed
       || n_basic_blocks == 1
@@ -2959,21 +2858,26 @@ init_regions ()
        }
     }
 
-  deaths_in_region = (int *) xmalloc (sizeof (int) * nr_regions);
 
-  /* Remove all death notes from the subroutine.  */
-  for (rgn = 0; rgn < nr_regions; rgn++)
+  if (CHECK_DEAD_NOTES)
     {
-      int b;
+      blocks = sbitmap_alloc (n_basic_blocks);
+      deaths_in_region = (int *) xmalloc (sizeof (int) * nr_regions);
+      /* Remove all death notes from the subroutine.  */
+      for (rgn = 0; rgn < nr_regions; rgn++)
+       {
+         int b;
 
-      sbitmap_zero (blocks);
-      for (b = RGN_NR_BLOCKS (rgn) - 1; b >= 0; --b)
-       SET_BIT (blocks, rgn_bb_table[RGN_BLOCKS (rgn) + b]);
+         sbitmap_zero (blocks);
+         for (b = RGN_NR_BLOCKS (rgn) - 1; b >= 0; --b)
+           SET_BIT (blocks, rgn_bb_table[RGN_BLOCKS (rgn) + b]);
 
-      deaths_in_region[rgn] = count_or_remove_death_notes (blocks, 1);
+         deaths_in_region[rgn] = count_or_remove_death_notes (blocks, 1);
+       }
+      sbitmap_free (blocks);
     }
-
-  sbitmap_free (blocks);
+  else
+    count_or_remove_death_notes (NULL, 1);
 }
 
 /* The one entry point in this file.  DUMP_FILE is the dump file for
@@ -3007,7 +2911,7 @@ schedule_insns (dump_file)
 
   /* Update life analysis for the subroutine.  Do single block regions
      first so that we can verify that live_at_start didn't change.  Then
-     do all other blocks.   */
+     do all other blocks.  */
   /* ??? There is an outside possibility that update_life_info, or more
      to the point propagate_block, could get called with non-zero flags
      more than once for one basic block.  This would be kinda bad if it
@@ -3026,39 +2930,51 @@ schedule_insns (dump_file)
   sbitmap_ones (large_region_blocks);
 
   blocks = sbitmap_alloc (n_basic_blocks);
+  sbitmap_zero (blocks);
 
+  /* Update life information.  For regions consisting of multiple blocks
+     we've possibly done interblock scheduling that affects global liveness.
+     For regions consisting of single blocks we need to do only local
+     liveness.  */
   for (rgn = 0; rgn < nr_regions; rgn++)
     if (RGN_NR_BLOCKS (rgn) > 1)
       any_large_regions = 1;
     else
       {
-       sbitmap_zero (blocks);
        SET_BIT (blocks, rgn_bb_table[RGN_BLOCKS (rgn)]);
        RESET_BIT (large_region_blocks, rgn_bb_table[RGN_BLOCKS (rgn)]);
-
-       /* Don't update reg info after reload, since that affects
-          regs_ever_live, which should not change after reload.  */
-       update_life_info (blocks, UPDATE_LIFE_LOCAL,
-                         (reload_completed ? PROP_DEATH_NOTES
-                          : PROP_DEATH_NOTES | PROP_REG_INFO));
-
-#ifndef HAVE_conditional_execution
-       /* ??? REG_DEAD notes only exist for unconditional deaths.  We need
-          a count of the conditional plus unconditional deaths for this to
-          work out.  */
-       /* In the single block case, the count of registers that died should
-          not have changed during the schedule.  */
-       if (count_or_remove_death_notes (blocks, 0) != deaths_in_region[rgn])
-         abort ();
-#endif
       }
 
+  /* Don't update reg info after reload, since that affects
+     regs_ever_live, which should not change after reload.  */
+  update_life_info (blocks, UPDATE_LIFE_LOCAL,
+                   (reload_completed ? PROP_DEATH_NOTES
+                    : PROP_DEATH_NOTES | PROP_REG_INFO));
   if (any_large_regions)
     {
       update_life_info (large_region_blocks, UPDATE_LIFE_GLOBAL,
                        PROP_DEATH_NOTES | PROP_REG_INFO);
     }
 
+  if (CHECK_DEAD_NOTES)
+    {
+      /* Verify the counts of basic block notes in single the basic block
+         regions.  */
+      for (rgn = 0; rgn < nr_regions; rgn++)
+       if (RGN_NR_BLOCKS (rgn) == 1)
+         {
+           int b;
+
+           sbitmap_zero (blocks);
+           SET_BIT (blocks, rgn_bb_table[RGN_BLOCKS (rgn)]);
+
+           if (deaths_in_region[rgn]
+               != count_or_remove_death_notes (blocks, 0))
+             abort ();
+         }
+      free (deaths_in_region);
+    }
+
   /* Reposition the prologue and epilogue notes in case we moved the
      prologue/epilogue insns.  */
   if (reload_completed)
@@ -3111,6 +3027,5 @@ schedule_insns (dump_file)
 
   sbitmap_free (blocks);
   sbitmap_free (large_region_blocks);
-
-  free (deaths_in_region);
 }
+#endif