OSDN Git Service

PR target/6838
[pf3gnuchains/gcc-fork.git] / gcc / cfgrtl.c
index 5210b03..4509fa4 100644 (file)
@@ -90,7 +90,7 @@ can_delete_note_p (note)
 {
   return (NOTE_LINE_NUMBER (note) == NOTE_INSN_DELETED
          || NOTE_LINE_NUMBER (note) == NOTE_INSN_BASIC_BLOCK
-          || NOTE_LINE_NUMBER (note) == NOTE_INSN_PREDICTION);
+         || NOTE_LINE_NUMBER (note) == NOTE_INSN_PREDICTION);
 }
 
 /* True if a given label can be deleted.  */
@@ -119,7 +119,7 @@ delete_insn (insn)
   if (GET_CODE (insn) == CODE_LABEL)
     {
       /* Some labels can't be directly removed from the INSN chain, as they
-         might be references via variables, constant pool etc. 
+         might be references via variables, constant pool etc.
          Convert them to the special NOTE_INSN_DELETED_LABEL note.  */
       if (! can_delete_label_p (insn))
        {
@@ -311,7 +311,7 @@ create_basic_block_structure (index, head, end, bb_note, after)
 
   bb->head = head;
   bb->end = end;
-  bb->sindex = index;
+  bb->index = index;
   bb->flags = BB_NEW;
   link_block (bb, after);
   BASIC_BLOCK (index) = bb;
@@ -338,10 +338,11 @@ create_basic_block (head, end, after)
   basic_block bb;
   int index = last_basic_block++;
 
-  /* Place the new block to the end.  */
+  /* Place the new block just after the end.  */
   VARRAY_GROW (basic_block_info, last_basic_block);
 
-  num_basic_blocks++;
+  n_basic_blocks++;
+
   bb = create_basic_block_structure (index, head, end, NULL, after);
   bb->aux = NULL;
   return bb;
@@ -370,13 +371,13 @@ flow_delete_block_noexpunge (b)
      NOTE_INSN_EH_REGION_END notes.  */
 
   /* Get rid of all NOTE_INSN_PREDICTIONs hanging before the block.  */
-  
+
   for (insn = PREV_INSN (b->head); insn; insn = PREV_INSN (insn))
     {
       if (GET_CODE (insn) != NOTE)
-        break;
+       break;
       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
-        NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
+       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
     }
 
   insn = b->head;
@@ -423,7 +424,7 @@ flow_delete_block (b)
      basic_block b;
 {
   int deleted_handler = flow_delete_block_noexpunge (b);
-  
+
   /* Remove the basic block from the array.  */
   expunge_block (b);
 
@@ -444,7 +445,7 @@ compute_bb_for_insn (max)
 
   VARRAY_BB_INIT (basic_block_for_insn, max, "basic_block_for_insn");
 
-  FOR_ALL_BB (bb)
+  FOR_EACH_BB (bb)
     {
       rtx end = bb->end;
       rtx insn;
@@ -764,7 +765,7 @@ try_redirect_by_replacing_jump (e, target)
        return false;
       if (rtl_dump_file)
        fprintf (rtl_dump_file, "Redirecting jump %i from %i to %i.\n",
-                INSN_UID (insn), e->dest->sindex, target->sindex);
+                INSN_UID (insn), e->dest->index, target->index);
       if (!redirect_jump (insn, block_label (target), 0))
        {
          if (target == EXIT_BLOCK_PTR)
@@ -961,7 +962,7 @@ redirect_edge_and_branch (e, target)
 
   if (rtl_dump_file)
     fprintf (rtl_dump_file, "Edge %i->%i redirected to %i\n",
-            e->src->sindex, e->dest->sindex, target->sindex);
+            e->src->index, e->dest->index, target->index);
 
   if (e->dest != target)
     redirect_edge_succ_nodup (e, target);
@@ -1010,7 +1011,8 @@ force_nonfallthru_and_redirect (e, target)
     {
       /* Create the new structures.  */
       note = last_loop_beg_note (e->src->end);
-      jump_block = create_basic_block (NEXT_INSN (note), NULL, e->src);
+      jump_block
+       = create_basic_block (NEXT_INSN (note), NULL, e->src);
       jump_block->count = e->count;
       jump_block->frequency = EDGE_FREQUENCY (e);
       jump_block->loop_depth = target->loop_depth;
@@ -1157,11 +1159,15 @@ tidy_fallthru_edges ()
 {
   basic_block b, c;
 
-  for (b = ENTRY_BLOCK_PTR->next_bb, c = b->next_bb;
-       c && c != EXIT_BLOCK_PTR; b = c, c = c->next_bb)
+  if (ENTRY_BLOCK_PTR->next_bb == EXIT_BLOCK_PTR)
+    return;
+
+  FOR_BB_BETWEEN (b, ENTRY_BLOCK_PTR->next_bb, EXIT_BLOCK_PTR->prev_bb, next_bb)
     {
       edge s;
 
+      c = b->next_bb;
+
       /* We care about simple conditional or unconditional jumps with
         a single successor.
 
@@ -1199,10 +1205,11 @@ back_edge_of_syntactic_loop_p (bb1, bb2)
   if (bb1 == bb2)
     return true;
 
+  /* ??? Could we guarantee that bb indices are monotone, so that we could
+     just compare them?  */
   for (bb = bb1; bb && bb != bb2; bb = bb->next_bb)
-    {
-    }
-  
+    continue;
+
   if (!bb)
     return false;
 
@@ -1363,8 +1370,8 @@ commit_one_edge_insertion (e, watch_calls)
       /* The first insn after the call may be a stack pop, skip it.  */
       while (next
             && keep_with_call_p (next))
-        {
-          after = next;
+       {
+         after = next;
          next = next_nonnote_insn (next);
        }
       bb = e->dest;
@@ -1453,7 +1460,7 @@ commit_one_edge_insertion (e, watch_calls)
 
       e->flags &= ~EDGE_FALLTHRU;
       emit_barrier_after (last);
-    
+
       if (before)
        delete_insn (before);
     }
@@ -1468,15 +1475,12 @@ commit_one_edge_insertion (e, watch_calls)
 void
 commit_edge_insertions ()
 {
-  int i;
   basic_block bb;
 
 #ifdef ENABLE_CHECKING
   verify_flow_info ();
 #endif
 
-  i = -1;
-  
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
     {
       edge e, next;
@@ -1496,14 +1500,12 @@ commit_edge_insertions ()
 void
 commit_edge_insertions_watch_calls ()
 {
-  int i;
   basic_block bb;
 
 #ifdef ENABLE_CHECKING
   verify_flow_info ();
 #endif
 
-  i = -1;
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
     {
       edge e, next;
@@ -1529,7 +1531,7 @@ dump_bb (bb, outf)
   edge e;
 
   fprintf (outf, ";; Basic block %d, loop depth %d, count ",
-          bb->sindex, bb->loop_depth);
+          bb->index, bb->loop_depth);
   fprintf (outf, HOST_WIDEST_INT_PRINT_DEC, (HOST_WIDEST_INT) bb->count);
   putc ('\n', outf);
 
@@ -1592,9 +1594,10 @@ print_rtl_with_bb (outf, rtx_first)
        = (basic_block *) xcalloc (max_uid, sizeof (basic_block));
       enum bb_state *in_bb_p
        = (enum bb_state *) xcalloc (max_uid, sizeof (enum bb_state));
+
       basic_block bb;
 
-      FOR_ALL_BB_REVERSE (bb)
+      FOR_EACH_BB_REVERSE (bb)
        {
          rtx x;
 
@@ -1620,7 +1623,7 @@ print_rtl_with_bb (outf, rtx_first)
          if ((bb = start[INSN_UID (tmp_rtx)]) != NULL)
            {
              fprintf (outf, ";; Start of basic block %d, registers live:",
-                      bb->sindex);
+                      bb->index);
              dump_regset (bb->global_live_at_start, outf);
              putc ('\n', outf);
            }
@@ -1637,7 +1640,7 @@ print_rtl_with_bb (outf, rtx_first)
          if ((bb = end[INSN_UID (tmp_rtx)]) != NULL)
            {
              fprintf (outf, ";; End of basic block %d, registers live:\n",
-                      bb->sindex);
+                      bb->index);
              dump_regset (bb->global_live_at_end, outf);
              putc ('\n', outf);
            }
@@ -1715,23 +1718,23 @@ verify_flow_info ()
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR->next_bb, NULL, next_bb)
     {
       if (bb != EXIT_BLOCK_PTR
-         && bb != BASIC_BLOCK (bb->sindex))
+         && bb != BASIC_BLOCK (bb->index))
        {
-         error ("bb %d on wrong place", bb->sindex);
+         error ("bb %d on wrong place", bb->index);
          err = 1;
        }
 
       if (bb->prev_bb != last_bb_seen)
        {
          error ("prev_bb of %d should be %d, not %d",
-                bb->sindex, last_bb_seen->sindex, bb->prev_bb->sindex);
+                bb->index, last_bb_seen->index, bb->prev_bb->index);
          err = 1;
        }
-        
+
       last_bb_seen = bb;
     }
 
-  FOR_ALL_BB_REVERSE (bb)
+  FOR_EACH_BB_REVERSE (bb)
     {
       rtx head = bb->head;
       rtx end = bb->end;
@@ -1744,7 +1747,7 @@ verify_flow_info ()
       if (!x)
        {
          error ("end insn %d for block %d not found in the insn stream",
-                INSN_UID (end), bb->sindex);
+                INSN_UID (end), bb->index);
          err = 1;
        }
 
@@ -1758,7 +1761,7 @@ verify_flow_info ()
          if (bb_info[INSN_UID (x)] != NULL)
            {
              error ("insn %d is in multiple basic blocks (%d and %d)",
-                    INSN_UID (x), bb->sindex, bb_info[INSN_UID (x)]->sindex);
+                    INSN_UID (x), bb->index, bb_info[INSN_UID (x)]->index);
              err = 1;
            }
 
@@ -1770,7 +1773,7 @@ verify_flow_info ()
       if (!x)
        {
          error ("head insn %d for block %d not found in the insn stream",
-                INSN_UID (head), bb->sindex);
+                INSN_UID (head), bb->index);
          err = 1;
        }
 
@@ -1778,7 +1781,7 @@ verify_flow_info ()
     }
 
   /* Now check the basic blocks (boundaries etc.) */
-  FOR_ALL_BB_REVERSE (bb)
+  FOR_EACH_BB_REVERSE (bb)
     {
       int n_fallthru = 0, n_eh = 0, n_call = 0, n_abnormal = 0, n_branch = 0;
       edge e;
@@ -1797,39 +1800,39 @@ verify_flow_info ()
            }
        }
       if (bb->count < 0)
-        {
-          error ("verify_flow_info: Wrong count of block %i %i",
-                bb->sindex, (int)bb->count);
-          err = 1;
-        }
+       {
+         error ("verify_flow_info: Wrong count of block %i %i",
+                bb->index, (int)bb->count);
+         err = 1;
+       }
       if (bb->frequency < 0)
-        {
-          error ("verify_flow_info: Wrong frequency of block %i %i",
-                bb->sindex, bb->frequency);
-          err = 1;
-        }
+       {
+         error ("verify_flow_info: Wrong frequency of block %i %i",
+                bb->index, bb->frequency);
+         err = 1;
+       }
       for (e = bb->succ; e; e = e->succ_next)
        {
-         if (last_visited [e->dest->sindex + 2] == bb)
+         if (last_visited [e->dest->index + 2] == bb)
            {
              error ("verify_flow_info: Duplicate edge %i->%i",
-                    e->src->sindex, e->dest->sindex);
+                    e->src->index, e->dest->index);
              err = 1;
            }
          if (e->probability < 0 || e->probability > REG_BR_PROB_BASE)
            {
              error ("verify_flow_info: Wrong probability of edge %i->%i %i",
-                    e->src->sindex, e->dest->sindex, e->probability);
+                    e->src->index, e->dest->index, e->probability);
              err = 1;
            }
          if (e->count < 0)
            {
              error ("verify_flow_info: Wrong count of edge %i->%i %i",
-                    e->src->sindex, e->dest->sindex, (int)e->count);
+                    e->src->index, e->dest->index, (int)e->count);
              err = 1;
            }
 
-         last_visited [e->dest->sindex + 2] = bb;
+         last_visited [e->dest->index + 2] = bb;
 
          if (e->flags & EDGE_FALLTHRU)
            n_fallthru++;
@@ -1855,7 +1858,7 @@ verify_flow_info ()
                {
                  error
                    ("verify_flow_info: Incorrect blocks for fallthru %i->%i",
-                    e->src->sindex, e->dest->sindex);
+                    e->src->index, e->dest->index);
                  err = 1;
                }
              else
@@ -1870,7 +1873,7 @@ verify_flow_info ()
                      )
                    {
                      error ("verify_flow_info: Incorrect fallthru %i->%i",
-                            e->src->sindex, e->dest->sindex);
+                            e->src->index, e->dest->index);
                      fatal_insn ("wrong insn in the fallthru edge", insn);
                      err = 1;
                    }
@@ -1879,7 +1882,7 @@ verify_flow_info ()
          if (e->src != bb)
            {
              error ("verify_flow_info: Basic block %d succ edge is corrupted",
-                    bb->sindex);
+                    bb->index);
              fprintf (stderr, "Predecessor: ");
              dump_edge_info (stderr, e, 0);
              fprintf (stderr, "\nSuccessor: ");
@@ -1888,13 +1891,13 @@ verify_flow_info ()
              err = 1;
            }
 
-         edge_checksum[e->dest->sindex + 2] += (size_t) e;
+         edge_checksum[e->dest->index + 2] += (size_t) e;
        }
 
       if (n_eh && GET_CODE (PATTERN (bb->end)) != RESX
          && !find_reg_note (bb->end, REG_EH_REGION, NULL_RTX))
        {
-         error ("Missing REG_EH_REGION note in the end of bb %i", bb->sindex);
+         error ("Missing REG_EH_REGION note in the end of bb %i", bb->index);
          err = 1;
        }
       if (n_branch
@@ -1902,28 +1905,28 @@ verify_flow_info ()
              || (n_branch > 1 && (any_uncondjump_p (bb->end)
                                   || any_condjump_p (bb->end)))))
        {
-         error ("Too many outgoing branch edges from bb %i", bb->sindex);
+         error ("Too many outgoing branch edges from bb %i", bb->index);
          err = 1;
        }
       if (n_fallthru && any_uncondjump_p (bb->end))
        {
-         error ("Fallthru edge after unconditional jump %i", bb->sindex);
+         error ("Fallthru edge after unconditional jump %i", bb->index);
          err = 1;
        }
       if (n_branch != 1 && any_uncondjump_p (bb->end))
        {
-         error ("Wrong amount of branch edges after unconditional jump %i", bb->sindex);
+         error ("Wrong amount of branch edges after unconditional jump %i", bb->index);
          err = 1;
        }
       if (n_branch != 1 && any_condjump_p (bb->end)
          && JUMP_LABEL (bb->end) != bb->next_bb->head)
        {
-         error ("Wrong amount of branch edges after conditional jump %i", bb->sindex);
+         error ("Wrong amount of branch edges after conditional jump %i", bb->index);
          err = 1;
        }
       if (n_call && GET_CODE (bb->end) != CALL_INSN)
        {
-         error ("Call edges for non-call insn in bb %i", bb->sindex);
+         error ("Call edges for non-call insn in bb %i", bb->index);
          err = 1;
        }
       if (n_abnormal
@@ -1932,10 +1935,10 @@ verify_flow_info ()
              || any_condjump_p (bb->end)
              || any_uncondjump_p (bb->end)))
        {
-         error ("Abnormal edges for no purpose in bb %i", bb->sindex);
+         error ("Abnormal edges for no purpose in bb %i", bb->index);
          err = 1;
        }
-       
+
       if (!n_fallthru)
        {
          rtx insn;
@@ -1947,7 +1950,7 @@ verify_flow_info ()
                || (GET_CODE (insn) == NOTE
                    && NOTE_LINE_NUMBER (insn) == NOTE_INSN_BASIC_BLOCK))
                {
-                 error ("missing barrier after block %i", bb->sindex);
+                 error ("missing barrier after block %i", bb->index);
                  err = 1;
                  break;
                }
@@ -1957,7 +1960,7 @@ verify_flow_info ()
        {
          if (e->dest != bb)
            {
-             error ("basic block %d pred edge is corrupted", bb->sindex);
+             error ("basic block %d pred edge is corrupted", bb->index);
              fputs ("Predecessor: ", stderr);
              dump_edge_info (stderr, e, 0);
              fputs ("\nSuccessor: ", stderr);
@@ -1965,7 +1968,7 @@ verify_flow_info ()
              fputc ('\n', stderr);
              err = 1;
            }
-         edge_checksum[e->dest->sindex + 2] -= (size_t) e;
+         edge_checksum[e->dest->index + 2] -= (size_t) e;
        }
 
       for (x = bb->head; x != NEXT_INSN (bb->end); x = NEXT_INSN (x))
@@ -1975,11 +1978,11 @@ verify_flow_info ()
            if (! BLOCK_FOR_INSN (x))
              error
                ("insn %d inside basic block %d but block_for_insn is NULL",
-                INSN_UID (x), bb->sindex);
+                INSN_UID (x), bb->index);
            else
              error
                ("insn %d inside basic block %d but block_for_insn is %i",
-                INSN_UID (x), bb->sindex, BLOCK_FOR_INSN (x)->sindex);
+                INSN_UID (x), bb->index, BLOCK_FOR_INSN (x)->index);
 
            err = 1;
          }
@@ -1993,7 +1996,7 @@ verify_flow_info ()
          if (bb->end == x)
            {
              error ("NOTE_INSN_BASIC_BLOCK is missing for block %d",
-                    bb->sindex);
+                    bb->index);
              err = 1;
            }
 
@@ -2003,7 +2006,7 @@ verify_flow_info ()
       if (!NOTE_INSN_BASIC_BLOCK_P (x) || NOTE_BASIC_BLOCK (x) != bb)
        {
          error ("NOTE_INSN_BASIC_BLOCK is missing for block %d",
-                bb->sindex);
+                bb->index);
          err = 1;
        }
 
@@ -2016,7 +2019,7 @@ verify_flow_info ()
            if (NOTE_INSN_BASIC_BLOCK_P (x))
              {
                error ("NOTE_INSN_BASIC_BLOCK %d in middle of basic block %d",
-                      INSN_UID (x), bb->sindex);
+                      INSN_UID (x), bb->index);
                err = 1;
              }
 
@@ -2027,7 +2030,7 @@ verify_flow_info ()
                || GET_CODE (x) == CODE_LABEL
                || GET_CODE (x) == BARRIER)
              {
-               error ("in basic block %d:", bb->sindex);
+               error ("in basic block %d:", bb->index);
                fatal_insn ("flow control insn inside a basic block", x);
              }
          }
@@ -2038,16 +2041,16 @@ verify_flow_info ()
     edge e;
 
     for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
-      edge_checksum[e->dest->sindex + 2] += (size_t) e;
+      edge_checksum[e->dest->index + 2] += (size_t) e;
 
     for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
-      edge_checksum[e->dest->sindex + 2] -= (size_t) e;
+      edge_checksum[e->dest->index + 2] -= (size_t) e;
   }
 
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
-    if (edge_checksum[bb->sindex + 2])
+    if (edge_checksum[bb->index + 2])
       {
-       error ("basic block %i edge lists are corrupted", bb->sindex);
+       error ("basic block %i edge lists are corrupted", bb->index);
        err = 1;
       }
 
@@ -2098,10 +2101,10 @@ verify_flow_info ()
            fatal_insn ("return not followed by barrier", x);
     }
 
-  if (num_bb_notes != num_basic_blocks)
+  if (num_bb_notes != n_basic_blocks)
     internal_error
-      ("number of bb notes in insn chain (%d) != num_basic_blocks (%d)",
-       num_bb_notes, num_basic_blocks);
+      ("number of bb notes in insn chain (%d) != n_basic_blocks (%d)",
+       num_bb_notes, n_basic_blocks);
 
   if (err)
     internal_error ("verify_flow_info failed");
@@ -2188,7 +2191,7 @@ purge_dead_edges (bb)
 
          /* Avoid abnormal flags to leak from computed jumps turned
             into simplejumps.  */
+
          e->flags &= ~EDGE_ABNORMAL;
 
          /* See if this edge is one we should keep.  */
@@ -2220,7 +2223,7 @@ purge_dead_edges (bb)
        return purged;
 
       if (rtl_dump_file)
-       fprintf (rtl_dump_file, "Purged edges from bb %i\n", bb->sindex);
+       fprintf (rtl_dump_file, "Purged edges from bb %i\n", bb->index);
 
       if (!optimize)
        return purged;
@@ -2230,7 +2233,7 @@ purge_dead_edges (bb)
        {
          bb->succ->probability = REG_BR_PROB_BASE;
          bb->succ->count = bb->count;
-        }
+       }
       else
        {
          note = find_reg_note (insn, REG_BR_PROB, NULL);
@@ -2279,7 +2282,7 @@ purge_dead_edges (bb)
 
   if (rtl_dump_file)
     fprintf (rtl_dump_file, "Purged non-fallthru edges from bb %i\n",
-            bb->sindex);
+            bb->index);
   return purged;
 }
 
@@ -2300,13 +2303,13 @@ purge_all_dead_edges (update_life_p)
       sbitmap_zero (blocks);
     }
 
-  FOR_ALL_BB (bb)
+  FOR_EACH_BB (bb)
     {
       bool purged_here = purge_dead_edges (bb);
 
       purged |= purged_here;
       if (purged_here && update_life_p)
-       SET_BIT (blocks, bb->sindex);
+       SET_BIT (blocks, bb->index);
     }
 
   if (update_life_p && purged)