OSDN Git Service

2007-07-08 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / cfgbuild.c
index 6a7395a..cb216af 100644 (file)
@@ -28,7 +28,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 
    Available functionality:
      - CFG construction
-         find_basic_blocks  */
+        find_basic_blocks  */
 \f
 #include "config.h"
 #include "system.h"
@@ -120,12 +120,17 @@ control_flow_insn_p (rtx insn)
              || can_throw_internal (insn));
 
     case INSN:
+      /* Treat trap instructions like noreturn calls (same provision).  */
+      if (GET_CODE (PATTERN (insn)) == TRAP_IF
+         && XEXP (PATTERN (insn), 0) == const1_rtx)
+       return true;
+
       return (flag_non_call_exceptions && can_throw_internal (insn));
 
     case BARRIER:
       /* It is nonsense to reach barrier when looking for the
-         end of basic block, but before dead code is eliminated
-         this may happen.  */
+        end of basic block, but before dead code is eliminated
+        this may happen.  */
       return false;
 
     default:
@@ -145,7 +150,7 @@ count_basic_blocks (rtx f)
   for (insn = f; insn; insn = NEXT_INSN (insn))
     {
       /* Code labels and barriers causes current basic block to be
-         terminated at previous real insn.  */
+        terminated at previous real insn.  */
       if ((LABEL_P (insn) || BARRIER_P (insn))
          && saw_insn)
        count++, saw_insn = false;
@@ -397,7 +402,7 @@ make_edges (basic_block min, basic_block max, int update_p)
 
       while (insn
             && NOTE_P (insn)
-            && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
+            && NOTE_KIND (insn) != NOTE_INSN_BASIC_BLOCK)
        insn = NEXT_INSN (insn);
 
       if (!insn)
@@ -464,22 +469,18 @@ find_basic_blocks_1 (rtx f)
       switch (code)
        {
        case NOTE:
-         {
-           int kind = NOTE_LINE_NUMBER (insn);
-
-           /* Look for basic block notes with which to keep the
-              basic_block_info pointers stable.  Unthread the note now;
-              we'll put it back at the right place in create_basic_block.
-              Or not at all if we've already found a note in this block.  */
-           if (kind == NOTE_INSN_BASIC_BLOCK)
-             {
-               if (bb_note == NULL_RTX)
-                 bb_note = insn;
-               else
-                 next = delete_insn (insn);
-             }
-           break;
-         }
+         /* Look for basic block notes with which to keep the
+            basic_block_info pointers stable.  Unthread the note now;
+            we'll put it back at the right place in create_basic_block.
+            Or not at all if we've already found a note in this block.  */
+         if (NOTE_INSN_BASIC_BLOCK_P (insn))
+           {
+             if (bb_note == NULL_RTX)
+               bb_note = insn;
+             else
+               next = delete_insn (insn);
+           }
+         break;
 
        case CODE_LABEL:
        case JUMP_INSN:
@@ -543,9 +544,7 @@ find_basic_blocks (rtx f)
      actually lay them out.  */
 
   basic_block_info = VEC_alloc (basic_block, gc, n_basic_blocks);
-  VEC_safe_grow (basic_block, gc, basic_block_info, n_basic_blocks);
-  memset (VEC_address (basic_block, basic_block_info), 0,
-         sizeof (basic_block) * n_basic_blocks);
+  VEC_safe_grow_cleared (basic_block, gc, basic_block_info, n_basic_blocks);
   SET_BASIC_BLOCK (ENTRY_BLOCK, ENTRY_BLOCK_PTR);
   SET_BASIC_BLOCK (EXIT_BLOCK, EXIT_BLOCK_PTR);
 
@@ -612,13 +611,13 @@ purge_dead_tablejump_edges (basic_block bb, rtx table)
   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
     {
       if (FULL_STATE (e->dest) & BLOCK_USED_BY_TABLEJUMP)
-        SET_STATE (e->dest, FULL_STATE (e->dest)
-                            & ~(size_t) BLOCK_USED_BY_TABLEJUMP);
+       SET_STATE (e->dest, FULL_STATE (e->dest)
+                           & ~(size_t) BLOCK_USED_BY_TABLEJUMP);
       else if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
-        {
-          remove_edge (e);
-          continue;
-        }
+       {
+         remove_edge (e);
+         continue;
+       }
       ei_next (&ei);
     }
 }
@@ -631,7 +630,7 @@ find_bb_boundaries (basic_block bb)
 {
   basic_block orig_bb = bb;
   rtx insn = BB_HEAD (bb);
-  rtx end = BB_END (bb);
+  rtx end = BB_END (bb), x;
   rtx table;
   rtx flow_transfer_insn = NULL_RTX;
   edge fallthru = NULL;
@@ -652,7 +651,16 @@ find_bb_boundaries (basic_block bb)
        {
          fallthru = split_block (bb, PREV_INSN (insn));
          if (flow_transfer_insn)
-           BB_END (bb) = flow_transfer_insn;
+           {
+             BB_END (bb) = flow_transfer_insn;
+
+             /* Clean up the bb field for the insns between the blocks.  */
+             for (x = NEXT_INSN (flow_transfer_insn);
+                  x != BB_HEAD (fallthru->dest);
+                  x = NEXT_INSN (x))
+               if (!BARRIER_P (x))
+                 set_block_for_insn (x, NULL);
+           }
 
          bb = fallthru->dest;
          remove_edge (fallthru);
@@ -667,6 +675,14 @@ find_bb_boundaries (basic_block bb)
        {
          fallthru = split_block (bb, PREV_INSN (insn));
          BB_END (bb) = flow_transfer_insn;
+
+         /* Clean up the bb field for the insns between the blocks.  */
+         for (x = NEXT_INSN (flow_transfer_insn);
+              x != BB_HEAD (fallthru->dest);
+              x = NEXT_INSN (x))
+           if (!BARRIER_P (x))
+             set_block_for_insn (x, NULL);
+
          bb = fallthru->dest;
          remove_edge (fallthru);
          flow_transfer_insn = NULL_RTX;
@@ -683,7 +699,18 @@ find_bb_boundaries (basic_block bb)
      return and barrier, or possibly other sequence not behaving like
      ordinary jump, we need to take care and move basic block boundary.  */
   if (flow_transfer_insn)
-    BB_END (bb) = flow_transfer_insn;
+    {
+      BB_END (bb) = flow_transfer_insn;
+
+      /* Clean up the bb field for the insns that do not belong to BB.  */
+      x = flow_transfer_insn;
+      while (x != end)
+       {
+         x = NEXT_INSN (x);
+         if (!BARRIER_P (x))
+           set_block_for_insn (x, NULL);
+       }
+    }
 
   /* We've possibly replaced the conditional jump by conditional jump
      followed by cleanup at fallthru edge, so the outgoing edges may