OSDN Git Service

* basic-block.h (last_basic_block): Declare.
[pf3gnuchains/gcc-fork.git] / gcc / cfg.c
index 47dfb23..313516b 100644 (file)
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -65,6 +65,10 @@ static char *flow_firstobj;
 
 int n_basic_blocks;
 
+/* First free basic block number.  */
+
+int last_basic_block;
+
 /* Number of edges in the current function.  */
 
 int n_edges;
@@ -93,6 +97,8 @@ struct basic_block_def entry_exit_blocks[2]
     NULL,                      /* global_live_at_end */
     NULL,                      /* aux */
     ENTRY_BLOCK,               /* index */
+    NULL,                      /* prev_bb */
+    EXIT_BLOCK_PTR,            /* next_bb */
     0,                         /* loop_depth */
     0,                         /* count */
     0,                         /* frequency */
@@ -111,6 +117,8 @@ struct basic_block_def entry_exit_blocks[2]
     NULL,                      /* global_live_at_end */
     NULL,                      /* aux */
     EXIT_BLOCK,                        /* index */
+    ENTRY_BLOCK_PTR,           /* prev_bb */
+    NULL,                      /* next_bb */
     0,                         /* loop_depth */
     0,                         /* count */
     0,                         /* frequency */
@@ -163,12 +171,11 @@ free_edge (e)
 void
 clear_edges ()
 {
-  int i;
+  basic_block bb;
   edge e;
 
-  for (i = 0; i < n_basic_blocks; ++i)
+  FOR_EACH_BB (bb)
     {
-      basic_block bb = BASIC_BLOCK (i);
       edge e = bb->succ;
 
       while (e)
@@ -220,36 +227,63 @@ alloc_block ()
   return bb;
 }
 
-/* Remove block B from the basic block array and compact behind it.  */
-
+/* Link block B to chain after AFTER.  */
 void
-expunge_block_nocompact (b)
-     basic_block b;
+link_block (b, after)
+     basic_block b, after;
 {
-  /* Invalidate data to make bughunting easier.  */
-  memset (b, 0, sizeof *b);
-  b->index = -3;
-  b->succ = (edge) first_deleted_block;
-  first_deleted_block = (basic_block) b;
+  b->next_bb = after->next_bb;
+  b->prev_bb = after;
+  after->next_bb = b;
+  b->next_bb->prev_bb = b;
 }
 
+/* Unlink block B from chain.  */
 void
-expunge_block (b)
+unlink_block (b)
      basic_block b;
 {
-  int i, n = n_basic_blocks;
+  b->next_bb->prev_bb = b->prev_bb;
+  b->prev_bb->next_bb = b->next_bb;
+}
 
-  for (i = b->index; i + 1 < n; ++i)
+/* Sequentially order blocks and compact the arrays.  */
+void
+compact_blocks ()
+{
+  int i;
+  basic_block bb;
+  i = 0;
+  FOR_EACH_BB (bb)
     {
-      basic_block x = BASIC_BLOCK (i + 1);
-      BASIC_BLOCK (i) = x;
-      x->index = i;
+      BASIC_BLOCK (i) = bb;
+      bb->index = i;
+      i++;
     }
 
+  if (i != n_basic_blocks)
+    abort ();
+
+  last_basic_block = n_basic_blocks;
+}
+
+
+/* Remove block B from the basic block array.  */
+
+void
+expunge_block (b)
+     basic_block b;
+{
+  unlink_block (b);
+  BASIC_BLOCK (b->index) = NULL;
   n_basic_blocks--;
-  basic_block_info->num_elements--;
 
-  expunge_block_nocompact (b);
+  /* Invalidate data to make bughunting easier.  */
+  memset (b, 0, sizeof *b);
+  b->index = -3;
+  b->succ = (edge) first_deleted_block;
+  first_deleted_block = (basic_block) b;
 }
 \f
 /* Create an edge connecting SRC and DST with FLAGS optionally using
@@ -453,11 +487,10 @@ redirect_edge_pred (e, new_pred)
 void
 clear_bb_flags ()
 {
-  int i;
-  ENTRY_BLOCK_PTR->flags = 0;
-  EXIT_BLOCK_PTR->flags = 0;
-  for (i = 0; i < n_basic_blocks; i++)
-    BASIC_BLOCK (i)->flags = 0;
+  basic_block bb;
+
+  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+    bb->flags = 0;
 }
 \f
 void
@@ -465,6 +498,7 @@ dump_flow_info (file)
      FILE *file;
 {
   int i;
+  basic_block bb;
   static const char * const reg_class_names[] = REG_CLASS_NAMES;
 
   fprintf (file, "%d registers.\n", max_regno);
@@ -512,18 +546,24 @@ dump_flow_info (file)
       }
 
   fprintf (file, "\n%d basic blocks, %d edges.\n", n_basic_blocks, n_edges);
-  for (i = 0; i < n_basic_blocks; i++)
+  FOR_EACH_BB (bb)
     {
-      basic_block bb = BASIC_BLOCK (i);
       edge e;
       int sum;
       gcov_type lsum;
 
       fprintf (file, "\nBasic block %d: first insn %d, last %d, ",
               i, INSN_UID (bb->head), INSN_UID (bb->end));
+      fprintf (file, "prev %d, next %d, ",
+              bb->prev_bb->index, bb->next_bb->index);
       fprintf (file, "loop_depth %d, count ", bb->loop_depth);
       fprintf (file, HOST_WIDEST_INT_PRINT_DEC, bb->count);
-      fprintf (file, ", freq %i.\n", bb->frequency);
+      fprintf (file, ", freq %i", bb->frequency);
+      if (maybe_hot_bb_p (bb))
+       fprintf (file, ", maybe hot");
+      if (probably_never_executed_bb_p (bb))
+       fprintf (file, ", probably never executed");
+      fprintf (file, ".\n");
 
       fprintf (file, "Predecessors: ");
       for (e = bb->pred; e; e = e->pred_next)
@@ -675,13 +715,10 @@ alloc_aux_for_blocks (size)
   first_block_aux_obj = (char *) obstack_alloc (&block_aux_obstack, 0);
   if (size)
     {
-      int i;
-
-      for (i = 0; i < n_basic_blocks; i++)
-       alloc_aux_for_block (BASIC_BLOCK (i), size);
+      basic_block bb;
 
-      alloc_aux_for_block (ENTRY_BLOCK_PTR, size);
-      alloc_aux_for_block (EXIT_BLOCK_PTR, size);
+      FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+       alloc_aux_for_block (bb, size);
     }
 }
 
@@ -690,13 +727,10 @@ alloc_aux_for_blocks (size)
 void
 clear_aux_for_blocks ()
 {
-  int i;
-
-  for (i = 0; i < n_basic_blocks; i++)
-    BASIC_BLOCK (i)->aux = NULL;
+  basic_block bb;
 
-  ENTRY_BLOCK_PTR->aux = NULL;
-  EXIT_BLOCK_PTR->aux = NULL;
+  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
+    bb->aux = NULL;
 }
 
 /* Free data allocated in block_aux_obstack and clear AUX pointers
@@ -750,17 +784,12 @@ alloc_aux_for_edges (size)
   first_edge_aux_obj = (char *) obstack_alloc (&edge_aux_obstack, 0);
   if (size)
     {
-      int i;
-      for (i = -1; i < n_basic_blocks; i++)
+      basic_block bb;
+
+      FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
        {
-         basic_block bb;
          edge e;
 
-         if (i >= 0)
-           bb = BASIC_BLOCK (i);
-         else
-           bb = ENTRY_BLOCK_PTR;
-
          for (e = bb->succ; e; e = e->succ_next)
            alloc_aux_for_edge (e, size);
        }
@@ -772,18 +801,11 @@ alloc_aux_for_edges (size)
 void
 clear_aux_for_edges ()
 {
-  int i;
+  basic_block bb;
+  edge e;
 
-  for (i = -1; i < n_basic_blocks; i++)
+  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
     {
-      basic_block bb;
-      edge e;
-
-      if (i >= 0)
-       bb = BASIC_BLOCK (i);
-      else
-       bb = ENTRY_BLOCK_PTR;
-
       for (e = bb->succ; e; e = e->succ_next)
        e->aux = NULL;
     }