OSDN Git Service

* tree-inline.c (find_builtin_longjmp_call): Save and restore
[pf3gnuchains/gcc-fork.git] / gcc / sched-rgn.c
index 892455e..c7e7f80 100644 (file)
@@ -47,6 +47,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 \f
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "toplev.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -153,7 +155,7 @@ static int *containing_rgn;
 
 void debug_regions PARAMS ((void));
 static void find_single_block_region PARAMS ((void));
-static void find_rgns PARAMS ((struct edge_list *, sbitmap *));
+static void find_rgns PARAMS ((struct edge_list *, dominance_info));
 static int too_large PARAMS ((int, int *, int *));
 
 extern void debug_live PARAMS ((int, int));
@@ -173,7 +175,6 @@ typedef struct
 bitlst;
 
 static int bitlst_table_last;
-static int bitlst_table_size;
 static int *bitlst_table;
 
 static void extract_bitlst PARAMS ((sbitmap, bitlst *));
@@ -270,16 +271,13 @@ static edgeset *ancestor_edges;
 
 static void compute_dom_prob_ps PARAMS ((int));
 
-#define ABS_VALUE(x) (((x)<0)?(-(x)):(x))
 #define INSN_PROBABILITY(INSN) (SRC_PROB (BLOCK_TO_BB (BLOCK_NUM (INSN))))
 #define IS_SPECULATIVE_INSN(INSN) (IS_SPECULATIVE (BLOCK_TO_BB (BLOCK_NUM (INSN))))
 #define INSN_BB(INSN) (BLOCK_TO_BB (BLOCK_NUM (INSN)))
 
 /* Parameters affecting the decision of rank_for_schedule().
-   ??? Nope.  But MIN_PROBABILITY is used in copmute_trg_info.  */
-#define MIN_DIFF_PRIORITY 2
+   ??? Nope.  But MIN_PROBABILITY is used in compute_trg_info.  */
 #define MIN_PROBABILITY 40
-#define MIN_PROB_DIFF 10
 
 /* Speculative scheduling functions.  */
 static int check_live_1 PARAMS ((int, rtx));
@@ -290,8 +288,6 @@ static void set_spec_fed PARAMS ((rtx));
 static int is_pfree PARAMS ((rtx, int, int));
 static int find_conditional_protection PARAMS ((rtx, int));
 static int is_conditionally_protected PARAMS ((rtx, int, int));
-static int may_trap_exp PARAMS ((rtx, int));
-static int haifa_classify_insn PARAMS ((rtx));
 static int is_prisky PARAMS ((rtx, int, int));
 static int is_exception_free PARAMS ((rtx, int, int));
 
@@ -346,7 +342,7 @@ is_cfg_nonregular ()
   /* If we have non-jumping insns which refer to labels, then we consider
      the cfg not well structured.  */
   /* Check for labels referred to other thn by jumps.  */
-  FOR_ALL_BB (b)
+  FOR_EACH_BB (b)
     for (insn = b->head;; insn = NEXT_INSN (insn))
       {
        code = GET_CODE (insn);
@@ -394,7 +390,7 @@ build_control_flow (edge_list)
      test is redundant with the one in find_rgns, but it's much
     cheaper to go ahead and catch the trivial case here.  */
   unreachable = 0;
-  FOR_ALL_BB (b)
+  FOR_EACH_BB (b)
     {
       if (b->pred == NULL
          || (b->pred->src == b
@@ -414,7 +410,7 @@ build_control_flow (edge_list)
 
       if (e->dest != EXIT_BLOCK_PTR
          && e->src != ENTRY_BLOCK_PTR)
-       new_edge (e->src->sindex, e->dest->sindex);
+       new_edge (e->src->index, e->dest->index);
     }
 
   /* Increment by 1, since edge 0 is unused.  */
@@ -547,13 +543,13 @@ find_single_block_region ()
 
   nr_regions = 0;
 
-  FOR_ALL_BB (bb)
+  FOR_EACH_BB (bb)
     {
-      rgn_bb_table[nr_regions] = bb->sindex;
+      rgn_bb_table[nr_regions] = bb->index;
       RGN_NR_BLOCKS (nr_regions) = 1;
       RGN_BLOCKS (nr_regions) = nr_regions;
-      CONTAINING_RGN (bb->sindex) = nr_regions;
-      BLOCK_TO_BB (bb->sindex) = 0;
+      CONTAINING_RGN (bb->index) = nr_regions;
+      BLOCK_TO_BB (bb->index) = 0;
       nr_regions++;
     }
 }
@@ -624,7 +620,7 @@ too_large (block, num_bbs, num_insns)
 static void
 find_rgns (edge_list, dom)
      struct edge_list *edge_list;
-     sbitmap *dom;
+     dominance_info dom;
 {
   int *max_hdr, *dfs_nr, *stack, *degree;
   char no_loops = 1;
@@ -640,7 +636,7 @@ find_rgns (edge_list, dom)
   /* Note if a block is a natural loop header.  */
   sbitmap header;
 
-  /* Note if a block is an natural inner loop header.  */
+  /* Note if a block is a natural inner loop header.  */
   sbitmap inner;
 
   /* Note if a block is in the block queue.  */
@@ -774,8 +770,8 @@ find_rgns (edge_list, dom)
      the entry node by placing a nonzero value in dfs_nr.  Thus if
      dfs_nr is zero for any block, then it must be unreachable.  */
   unreachable = 0;
-  FOR_ALL_BB (bb)
-    if (dfs_nr[bb->sindex] == 0)
+  FOR_EACH_BB (bb)
+    if (dfs_nr[bb->index] == 0)
       {
        unreachable = 1;
        break;
@@ -785,14 +781,14 @@ find_rgns (edge_list, dom)
      to hold degree counts.  */
   degree = dfs_nr;
 
-  FOR_ALL_BB (bb)
-    degree[bb->sindex] = 0;
+  FOR_EACH_BB (bb)
+    degree[bb->index] = 0;
   for (i = 0; i < num_edges; i++)
     {
       edge e = INDEX_EDGE (edge_list, i);
 
       if (e->dest != EXIT_BLOCK_PTR)
-       degree[e->dest->sindex]++;
+       degree[e->dest->index]++;
     }
 
   /* Do not perform region scheduling if there are any unreachable
@@ -804,16 +800,16 @@ find_rgns (edge_list, dom)
       if (no_loops)
        SET_BIT (header, 0);
 
-      /* Second travsersal:find reducible inner loops and topologically sort
+      /* Second traversal:find reducible inner loops and topologically sort
         block of each region.  */
 
-      queue = (int *) xmalloc (num_basic_blocks * sizeof (int));
+      queue = (int *) xmalloc (n_basic_blocks * sizeof (int));
 
       /* Find blocks which are inner loop headers.  We still have non-reducible
         loops to consider at this point.  */
-      FOR_ALL_BB (bb)
+      FOR_EACH_BB (bb)
        {
-         if (TEST_BIT (header, bb->sindex) && TEST_BIT (inner, bb->sindex))
+         if (TEST_BIT (header, bb->index) && TEST_BIT (inner, bb->index))
            {
              edge e;
              basic_block jbb;
@@ -829,15 +825,15 @@ find_rgns (edge_list, dom)
                 If there exists a block that is not dominated by the loop
                 header, then the block is reachable from outside the loop
                 and thus the loop is not a natural loop.  */
-             FOR_ALL_BB (jbb)
+             FOR_EACH_BB (jbb)
                {
                  /* First identify blocks in the loop, except for the loop
                     entry block.  */
-                 if (bb->sindex == max_hdr[jbb->sindex] && bb != jbb)
+                 if (bb->index == max_hdr[jbb->index] && bb != jbb)
                    {
                      /* Now verify that the block is dominated by the loop
                         header.  */
-                     if (!TEST_BIT (dom[jbb->sindex], bb->sindex))
+                     if (!dominated_by_p (dom, jbb, bb))
                        break;
                    }
                }
@@ -852,13 +848,13 @@ find_rgns (edge_list, dom)
                 with no loops at all.  */
              head = tail = -1;
              too_large_failure = 0;
-             loop_head = max_hdr[bb->sindex];
+             loop_head = max_hdr[bb->index];
 
              /* Decrease degree of all I's successors for topological
                 ordering.  */
              for (e = bb->succ; e; e = e->succ_next)
                if (e->dest != EXIT_BLOCK_PTR)
-                 --degree[e->dest->sindex];
+                 --degree[e->dest->index];
 
              /* Estimate # insns, and count # blocks in the region.  */
              num_bbs = 1;
@@ -871,17 +867,17 @@ find_rgns (edge_list, dom)
                 Place those blocks into the queue.  */
              if (no_loops)
                {
-                 FOR_ALL_BB (jbb)
+                 FOR_EACH_BB (jbb)
                    /* Leaf nodes have only a single successor which must
                       be EXIT_BLOCK.  */
                    if (jbb->succ
                        && jbb->succ->dest == EXIT_BLOCK_PTR
                        && jbb->succ->succ_next == NULL)
                      {
-                       queue[++tail] = jbb->sindex;
-                       SET_BIT (in_queue, jbb->sindex);
+                       queue[++tail] = jbb->index;
+                       SET_BIT (in_queue, jbb->index);
 
-                       if (too_large (jbb->sindex, &num_bbs, &num_insns))
+                       if (too_large (jbb->index, &num_bbs, &num_insns))
                          {
                            too_large_failure = 1;
                            break;
@@ -897,9 +893,9 @@ find_rgns (edge_list, dom)
                      if (e->src == ENTRY_BLOCK_PTR)
                        continue;
 
-                     node = e->src->sindex;
+                     node = e->src->index;
 
-                     if (max_hdr[node] == loop_head && node != bb->sindex)
+                     if (max_hdr[node] == loop_head && node != bb->index)
                        {
                          /* This is a loop latch.  */
                          queue[++tail] = node;
@@ -951,7 +947,7 @@ find_rgns (edge_list, dom)
 
                  for (e = BASIC_BLOCK (child)->pred; e; e = e->pred_next)
                    {
-                     node = e->src->sindex;
+                     node = e->src->index;
 
                      /* See discussion above about nodes not marked as in
                         this loop during the initial DFS traversal.  */
@@ -961,7 +957,7 @@ find_rgns (edge_list, dom)
                          tail = -1;
                          break;
                        }
-                     else if (!TEST_BIT (in_queue, node) && node != bb->sindex)
+                     else if (!TEST_BIT (in_queue, node) && node != bb->index)
                        {
                          queue[++tail] = node;
                          SET_BIT (in_queue, node);
@@ -978,12 +974,12 @@ find_rgns (edge_list, dom)
              if (tail >= 0 && !too_large_failure)
                {
                  /* Place the loop header into list of region blocks.  */
-                 degree[bb->sindex] = -1;
-                 rgn_bb_table[idx] = bb->sindex;
+                 degree[bb->index] = -1;
+                 rgn_bb_table[idx] = bb->index;
                  RGN_NR_BLOCKS (nr_regions) = num_bbs;
                  RGN_BLOCKS (nr_regions) = idx++;
-                 CONTAINING_RGN (bb->sindex) = nr_regions;
-                 BLOCK_TO_BB (bb->sindex) = count = 0;
+                 CONTAINING_RGN (bb->index) = nr_regions;
+                 BLOCK_TO_BB (bb->index) = count = 0;
 
                  /* Remove blocks from queue[] when their in degree
                     becomes zero.  Repeat until no blocks are left on the
@@ -1008,7 +1004,7 @@ find_rgns (edge_list, dom)
                               e;
                               e = e->succ_next)
                            if (e->dest != EXIT_BLOCK_PTR)
-                             --degree[e->dest->sindex];
+                             --degree[e->dest->index];
                        }
                      else
                        --head;
@@ -1022,14 +1018,14 @@ find_rgns (edge_list, dom)
 
   /* Any block that did not end up in a region is placed into a region
      by itself.  */
-  FOR_ALL_BB (bb)
-    if (degree[bb->sindex] >= 0)
+  FOR_EACH_BB (bb)
+    if (degree[bb->index] >= 0)
       {
-       rgn_bb_table[idx] = bb->sindex;
+       rgn_bb_table[idx] = bb->index;
        RGN_NR_BLOCKS (nr_regions) = 1;
        RGN_BLOCKS (nr_regions) = idx++;
-       CONTAINING_RGN (bb->sindex) = nr_regions++;
-       BLOCK_TO_BB (bb->sindex) = 0;
+       CONTAINING_RGN (bb->index) = nr_regions++;
+       BLOCK_TO_BB (bb->index) = 0;
       }
 
   free (max_hdr);
@@ -1293,7 +1289,7 @@ debug_candidates (trg)
     debug_candidate (i);
 }
 
-/* Functions for speculative scheduing.  */
+/* Functions for speculative scheduling.  */
 
 /* Return 0 if x is a set of a register alive in the beginning of one
    of the split-blocks of src, otherwise return 1.  */
@@ -1492,91 +1488,13 @@ update_live (insn, src)
     }
 }
 
-/* Exception Free Loads:
-
-   We define five classes of speculative loads: IFREE, IRISKY,
-   PFREE, PRISKY, and MFREE.
-
-   IFREE loads are loads that are proved to be exception-free, just
-   by examining the load insn.  Examples for such loads are loads
-   from TOC and loads of global data.
-
-   IRISKY loads are loads that are proved to be exception-risky,
-   just by examining the load insn.  Examples for such loads are
-   volatile loads and loads from shared memory.
-
-   PFREE loads are loads for which we can prove, by examining other
-   insns, that they are exception-free.  Currently, this class consists
-   of loads for which we are able to find a "similar load", either in
-   the target block, or, if only one split-block exists, in that split
-   block.  Load2 is similar to load1 if both have same single base
-   register.  We identify only part of the similar loads, by finding
-   an insn upon which both load1 and load2 have a DEF-USE dependence.
-
-   PRISKY loads are loads for which we can prove, by examining other
-   insns, that they are exception-risky.  Currently we have two proofs for
-   such loads.  The first proof detects loads that are probably guarded by a
-   test on the memory address.  This proof is based on the
-   backward and forward data dependence information for the region.
-   Let load-insn be the examined load.
-   Load-insn is PRISKY iff ALL the following hold:
-
-   - insn1 is not in the same block as load-insn
-   - there is a DEF-USE dependence chain (insn1, ..., load-insn)
-   - test-insn is either a compare or a branch, not in the same block
-     as load-insn
-   - load-insn is reachable from test-insn
-   - there is a DEF-USE dependence chain (insn1, ..., test-insn)
-
-   This proof might fail when the compare and the load are fed
-   by an insn not in the region.  To solve this, we will add to this
-   group all loads that have no input DEF-USE dependence.
-
-   The second proof detects loads that are directly or indirectly
-   fed by a speculative load.  This proof is affected by the
-   scheduling process.  We will use the flag  fed_by_spec_load.
-   Initially, all insns have this flag reset.  After a speculative
-   motion of an insn, if insn is either a load, or marked as
-   fed_by_spec_load, we will also mark as fed_by_spec_load every
-   insn1 for which a DEF-USE dependence (insn, insn1) exists.  A
-   load which is fed_by_spec_load is also PRISKY.
-
-   MFREE (maybe-free) loads are all the remaining loads. They may be
-   exception-free, but we cannot prove it.
-
-   Now, all loads in IFREE and PFREE classes are considered
-   exception-free, while all loads in IRISKY and PRISKY classes are
-   considered exception-risky.  As for loads in the MFREE class,
-   these are considered either exception-free or exception-risky,
-   depending on whether we are pessimistic or optimistic.  We have
-   to take the pessimistic approach to assure the safety of
-   speculative scheduling, but we can take the optimistic approach
-   by invoking the -fsched_spec_load_dangerous option.  */
-
-enum INSN_TRAP_CLASS
-{
-  TRAP_FREE = 0, IFREE = 1, PFREE_CANDIDATE = 2,
-  PRISKY_CANDIDATE = 3, IRISKY = 4, TRAP_RISKY = 5
-};
-
-#define WORST_CLASS(class1, class2) \
-((class1 > class2) ? class1 : class2)
-
-/* Non-zero if block bb_to is equal to, or reachable from block bb_from.  */
+/* Nonzero if block bb_to is equal to, or reachable from block bb_from.  */
 #define IS_REACHABLE(bb_from, bb_to)                                   \
   (bb_from == bb_to                                                    \
    || IS_RGN_ENTRY (bb_from)                                           \
    || (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)                       \
-  (GET_CODE (x) == REG                                 \
-   || ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS  \
-       || (GET_CODE (x) == LO_SUM))                    \
-       && (CONSTANT_P (XEXP (x, 0))                    \
-          || CONSTANT_P (XEXP (x, 1)))))
-
 /* Turns on the fed_by_spec_load flag for insns fed by load_insn.  */
 
 static void
@@ -1731,160 +1649,6 @@ is_pfree (load_insn, bb_src, bb_trg)
   return 0;
 }                              /* is_pfree */
 
-/* Returns a class that insn with GET_DEST(insn)=x may belong to,
-   as found by analyzing insn's expression.  */
-
-static int
-may_trap_exp (x, is_store)
-     rtx x;
-     int is_store;
-{
-  enum rtx_code code;
-
-  if (x == 0)
-    return TRAP_FREE;
-  code = GET_CODE (x);
-  if (is_store)
-    {
-      if (code == MEM && may_trap_p (x))
-       return TRAP_RISKY;
-      else
-       return TRAP_FREE;
-    }
-  if (code == MEM)
-    {
-      /* The insn uses memory:  a volatile load.  */
-      if (MEM_VOLATILE_P (x))
-       return IRISKY;
-      /* An exception-free load.  */
-      if (!may_trap_p (x))
-       return IFREE;
-      /* A load with 1 base register, to be further checked.  */
-      if (CONST_BASED_ADDRESS_P (XEXP (x, 0)))
-       return PFREE_CANDIDATE;
-      /* No info on the load, to be further checked.  */
-      return PRISKY_CANDIDATE;
-    }
-  else
-    {
-      const char *fmt;
-      int i, insn_class = TRAP_FREE;
-
-      /* Neither store nor load, check if it may cause a trap.  */
-      if (may_trap_p (x))
-       return TRAP_RISKY;
-      /* Recursive step: walk the insn...  */
-      fmt = GET_RTX_FORMAT (code);
-      for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
-       {
-         if (fmt[i] == 'e')
-           {
-             int tmp_class = may_trap_exp (XEXP (x, i), is_store);
-             insn_class = WORST_CLASS (insn_class, tmp_class);
-           }
-         else if (fmt[i] == 'E')
-           {
-             int j;
-             for (j = 0; j < XVECLEN (x, i); j++)
-               {
-                 int tmp_class = may_trap_exp (XVECEXP (x, i, j), is_store);
-                 insn_class = WORST_CLASS (insn_class, tmp_class);
-                 if (insn_class == TRAP_RISKY || insn_class == IRISKY)
-                   break;
-               }
-           }
-         if (insn_class == TRAP_RISKY || insn_class == IRISKY)
-           break;
-       }
-      return insn_class;
-    }
-}
-
-/* Classifies insn for the purpose of verifying that it can be
-   moved speculatively, by examining it's patterns, returning:
-   TRAP_RISKY: store, or risky non-load insn (e.g. division by variable).
-   TRAP_FREE: non-load insn.
-   IFREE: load from a globaly safe location.
-   IRISKY: volatile load.
-   PFREE_CANDIDATE, PRISKY_CANDIDATE: load that need to be checked for
-   being either PFREE or PRISKY.  */
-
-static int
-haifa_classify_insn (insn)
-     rtx insn;
-{
-  rtx pat = PATTERN (insn);
-  int tmp_class = TRAP_FREE;
-  int insn_class = TRAP_FREE;
-  enum rtx_code code;
-
-  if (GET_CODE (pat) == PARALLEL)
-    {
-      int i, len = XVECLEN (pat, 0);
-
-      for (i = len - 1; i >= 0; i--)
-       {
-         code = GET_CODE (XVECEXP (pat, 0, i));
-         switch (code)
-           {
-           case CLOBBER:
-             /* Test if it is a 'store'.  */
-             tmp_class = may_trap_exp (XEXP (XVECEXP (pat, 0, i), 0), 1);
-             break;
-           case SET:
-             /* Test if it is a store.  */
-             tmp_class = may_trap_exp (SET_DEST (XVECEXP (pat, 0, i)), 1);
-             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));
-             break;
-           case COND_EXEC:
-           case TRAP_IF:
-             tmp_class = TRAP_RISKY;
-             break;
-           default:
-             ;
-           }
-         insn_class = WORST_CLASS (insn_class, tmp_class);
-         if (insn_class == TRAP_RISKY || insn_class == IRISKY)
-           break;
-       }
-    }
-  else
-    {
-      code = GET_CODE (pat);
-      switch (code)
-       {
-       case CLOBBER:
-         /* Test if it is a 'store'.  */
-         tmp_class = may_trap_exp (XEXP (pat, 0), 1);
-         break;
-       case SET:
-         /* Test if it is a store.  */
-         tmp_class = may_trap_exp (SET_DEST (pat), 1);
-         if (tmp_class == TRAP_RISKY)
-           break;
-         /* Test if it is a load.  */
-         tmp_class =
-           WORST_CLASS (tmp_class,
-                        may_trap_exp (SET_SRC (pat), 0));
-         break;
-       case COND_EXEC:
-       case TRAP_IF:
-         tmp_class = TRAP_RISKY;
-         break;
-       default:;
-       }
-      insn_class = tmp_class;
-    }
-
-  return insn_class;
-}
-
 /* Return 1 if load_insn is prisky (i.e. if load_insn is fed by
    a load moved speculatively, or if load_insn is protected by
    a compare on load_insn's address).  */
@@ -2016,7 +1780,6 @@ init_ready_list (ready)
       bblst_table = (int *) xmalloc (bblst_size * sizeof (int));
 
       bitlst_table_last = 0;
-      bitlst_table_size = rgn_nr_edges;
       bitlst_table = (int *) xmalloc (rgn_nr_edges * sizeof (int));
 
       compute_trg_info (target_bb);
@@ -2026,17 +1789,9 @@ init_ready_list (ready)
      Count number of insns in the target block being scheduled.  */
   for (insn = NEXT_INSN (prev_head); insn != next_tail; insn = NEXT_INSN (insn))
     {
-      rtx next;
-
-      if (! INSN_P (insn))
-       continue;
-      next = NEXT_INSN (insn);
-
-      if (INSN_DEP_COUNT (insn) == 0
-         && (SCHED_GROUP_P (next) == 0 || ! INSN_P (next)))
+      if (INSN_DEP_COUNT (insn) == 0)
        ready_add (ready, insn);
-      if (!(SCHED_GROUP_P (insn)))
-       target_n_insns++;
+      target_n_insns++;
     }
 
   /* Add to ready list all 'ready' insns in valid source blocks.
@@ -2070,19 +1825,8 @@ init_ready_list (ready)
                                                             insn, insn) <= 3)))
                        && check_live (insn, bb_src)
                        && is_exception_free (insn, bb_src, target_bb))))
-             {
-               rtx next;
-
-               /* Note that we haven'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);
-               if (INSN_DEP_COUNT (insn) == 0
-                   && (! next
-                       || SCHED_GROUP_P (next) == 0
-                       || ! INSN_P (next)))
-                 ready_add (ready, insn);
-             }
+             if (INSN_DEP_COUNT (insn) == 0)
+               ready_add (ready, insn);
          }
       }
 }
@@ -2100,7 +1844,6 @@ can_schedule_ready_p (insn)
   /* An interblock motion?  */
   if (INSN_BB (insn) != target_bb)
     {
-      rtx temp;
       basic_block b1;
 
       if (IS_SPECULATIVE_INSN (insn))
@@ -2117,18 +1860,9 @@ can_schedule_ready_p (insn)
        }
       nr_inter++;
 
-      /* Find the beginning of the scheduling group.  */
-      /* ??? Ought to update basic block here, but later bits of
-        schedule_block assumes the original insn block is
-        still intact.  */
-
-      temp = insn;
-      while (SCHED_GROUP_P (temp))
-       temp = PREV_INSN (temp);
-
       /* Update source block boundaries.  */
-      b1 = BLOCK_FOR_INSN (temp);
-      if (temp == b1->head && insn == b1->end)
+      b1 = BLOCK_FOR_INSN (insn);
+      if (insn == b1->head && insn == b1->end)
        {
          /* We moved all the insns in the basic block.
             Emit a note after the last insn and update the
@@ -2142,9 +1876,9 @@ can_schedule_ready_p (insn)
          /* We took insns from the end of the basic block,
             so update the end of block boundary so that it
             points to the first insn we did not move.  */
-         b1->end = PREV_INSN (temp);
+         b1->end = PREV_INSN (insn);
        }
-      else if (temp == b1->head)
+      else if (insn == b1->head)
        {
          /* We took insns from the start of the basic block,
             so update the start of block boundary so that
@@ -2364,17 +2098,6 @@ add_branch_dependences (head, tail)
          CANT_MOVE (insn) = 1;
 
          last = insn;
-         /* Skip over insns that are part of a group.
-            Make each insn explicitly depend on the previous insn.
-            This ensures that only the group header will ever enter
-            the ready queue (and, when scheduled, will automatically
-            schedule the SCHED_GROUP_P block).  */
-         while (SCHED_GROUP_P (insn))
-           {
-             rtx temp = prev_nonnote_insn (insn);
-             add_dependence (insn, temp, REG_DEP_ANTI);
-             insn = temp;
-           }
        }
 
       /* Don't overrun the bounds of the basic block.  */
@@ -2396,10 +2119,6 @@ add_branch_dependences (head, tail)
 
        add_dependence (last, insn, REG_DEP_ANTI);
        INSN_REF_COUNT (insn) = 1;
-
-       /* Skip over insns that are part of a group.  */
-       while (SCHED_GROUP_P (insn))
-         insn = prev_nonnote_insn (insn);
       }
 }
 
@@ -2534,7 +2253,7 @@ propagate_deps (bb, pred_deps)
 /* Compute backward dependences inside bb.  In a multiple blocks region:
    (1) a bb is analyzed after its predecessors, and (2) the lists in
    effect at the end of bb (after analyzing for bb) are inherited by
-   bb's successrs.
+   bb's successors.
 
    Specifically for reg-reg data dependences, the block insns are
    scanned by sched_analyze () top-to-bottom.  Two lists are
@@ -2715,7 +2434,7 @@ schedule_region (rgn)
 
   init_deps_global ();
 
-  /* Initializations for region data dependence analyisis.  */
+  /* Initializations for region data dependence analysis.  */
   bb_deps = (struct deps *) xmalloc (sizeof (struct deps) * current_nr_blocks);
   for (bb = 0; bb < current_nr_blocks; bb++)
     init_deps (bb_deps + bb);
@@ -2731,6 +2450,10 @@ schedule_region (rgn)
       get_block_head_tail (BB_TO_BLOCK (bb), &head, &tail);
 
       compute_forward_dependences (head, tail);
+
+      if (targetm.sched.dependencies_evaluation_hook)
+       targetm.sched.dependencies_evaluation_hook (head, tail);
+
     }
 
   /* Set priorities.  */
@@ -2888,14 +2611,14 @@ init_regions ()
   int rgn;
 
   nr_regions = 0;
-  rgn_table = (region *) xmalloc ((num_basic_blocks) * sizeof (region));
-  rgn_bb_table = (int *) xmalloc ((num_basic_blocks) * sizeof (int));
+  rgn_table = (region *) xmalloc ((n_basic_blocks) * sizeof (region));
+  rgn_bb_table = (int *) xmalloc ((n_basic_blocks) * sizeof (int));
   block_to_bb = (int *) xmalloc ((last_basic_block) * sizeof (int));
   containing_rgn = (int *) xmalloc ((last_basic_block) * sizeof (int));
 
   /* Compute regions for scheduling.  */
   if (reload_completed
-      || num_basic_blocks == 1
+      || n_basic_blocks == 1
       || !flag_schedule_interblock)
     {
       find_single_block_region ();
@@ -2909,26 +2632,17 @@ init_regions ()
        }
       else
        {
-         sbitmap *dom;
+         dominance_info dom;
          struct edge_list *edge_list;
 
-         dom = sbitmap_vector_alloc (last_basic_block, last_basic_block);
-
-         /* The scheduler runs after flow; therefore, we can't blindly call
-            back into find_basic_blocks since doing so could invalidate the
-            info in global_live_at_start.
-
-            Consider a block consisting entirely of dead stores; after life
-            analysis it would be a block of NOTE_INSN_DELETED notes.  If
-            we call find_basic_blocks again, then the block would be removed
-            entirely and invalidate our the register live information.
-
-            We could (should?) recompute register live information.  Doing
-            so may even be beneficial.  */
+         /* The scheduler runs after estimate_probabilities; therefore, we
+            can't blindly call back into find_basic_blocks since doing so
+            could invalidate the branch probability info.  We could,
+            however, call cleanup_cfg.  */
          edge_list = create_edge_list ();
 
          /* Compute the dominators and post dominators.  */
-         calculate_dominance_info (NULL, dom, CDI_DOMINATORS);
+         dom = calculate_dominance_info (CDI_DOMINATORS);
 
          /* build_control_flow will return nonzero if it detects unreachable
             blocks or any other irregularity with the cfg which prevents
@@ -2946,7 +2660,7 @@ init_regions ()
 
          /* For now.  This will move as more and more of haifa is converted
             to using the cfg code in flow.c.  */
-         free (dom);
+         free_dominance_info (dom);
        }
     }
 
@@ -2986,11 +2700,9 @@ schedule_insns (dump_file)
 
   /* Taking care of this degenerate case makes the rest of
      this code simpler.  */
-  if (num_basic_blocks == 0)
+  if (n_basic_blocks == 0)
     return;
 
-  scope_to_insns_initialize ();
-
   nr_inter = 0;
   nr_spec = 0;
 
@@ -3008,7 +2720,7 @@ schedule_insns (dump_file)
      first so that we can verify that live_at_start didn't change.  Then
      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
+     to the point propagate_block, could get called with nonzero flags
      more than once for one basic block.  This would be kinda bad if it
      were to happen, since REG_INFO would be accumulated twice for the
      block, and we'd have twice the REG_DEAD notes.
@@ -3018,13 +2730,13 @@ schedule_insns (dump_file)
      best way to test for this kind of thing...  */
 
   allocate_reg_life_data ();
-  compute_bb_for_insn (get_max_uid ());
+  compute_bb_for_insn ();
 
   any_large_regions = 0;
   large_region_blocks = sbitmap_alloc (last_basic_block);
   sbitmap_zero (large_region_blocks);
-  FOR_ALL_BB (bb)
-    SET_BIT (large_region_blocks, bb->sindex);
+  FOR_EACH_BB (bb)
+    SET_BIT (large_region_blocks, bb->index);
 
   blocks = sbitmap_alloc (last_basic_block);
   sbitmap_zero (blocks);
@@ -3079,8 +2791,6 @@ schedule_insns (dump_file)
   if (write_symbols != NO_DEBUG)
     rm_redundant_line_notes ();
 
-  scope_to_insns_finalize ();
-
   if (sched_verbose)
     {
       if (reload_completed == 0 && flag_schedule_interblock)