OSDN Git Service

* tree-cfg.c (create_bb): Remove unnecessary memset.
[pf3gnuchains/gcc-fork.git] / gcc / tree-cfg.c
index 0bf7b16..8c1a06f 100644 (file)
@@ -93,7 +93,6 @@ static int tree_verify_flow_info (void);
 static void tree_make_forwarder_block (edge);
 static bool thread_jumps (void);
 static bool tree_forwarder_block_p (basic_block);
-static void bsi_commit_edge_inserts_1 (edge e);
 static void tree_cfg2vcg (FILE *);
 
 /* Flowgraph optimization and cleanup.  */
@@ -376,9 +375,10 @@ create_bb (void *h, void *e, basic_block after)
 
   gcc_assert (!e);
 
-  /* Create and initialize a new basic block.  */
+  /* Create and initialize a new basic block.  Since alloc_block uses
+     ggc_alloc_cleared to allocate a basic block, we do not have to
+     clear the newly allocated basic block here.  */
   bb = alloc_block ();
-  memset (bb, 0, sizeof (*bb));
 
   bb->index = last_basic_block;
   bb->flags = BB_NEW;
@@ -1201,7 +1201,6 @@ remove_useless_stmts_cond (tree *stmt_p, struct rus_data *data)
   else_has_label = data->has_label;
   data->has_label = save_has_label | then_has_label | else_has_label;
 
-  fold_stmt (stmt_p);
   then_clause = COND_EXPR_THEN (*stmt_p);
   else_clause = COND_EXPR_ELSE (*stmt_p);
   cond = COND_EXPR_COND (*stmt_p);
@@ -1601,7 +1600,7 @@ remove_useless_stmts_1 (tree *tp, struct rus_data *data)
          }
       }
       break;
-    case SWITCH_EXPR:
+    case ASM_EXPR:
       fold_stmt (tp);
       data->last_goto = NULL;
       break;
@@ -1943,9 +1942,9 @@ cleanup_control_expr_graph (basic_block bb, block_stmt_iterator bsi)
 }
 
 
-/* Given a control block BB and a predicate VAL, return the edge that
-   will be taken out of the block.  If VAL does not match a unique
-   edge, NULL is returned.  */
+/* Given a basic block BB ending with COND_EXPR or SWITCH_EXPR, and a
+   predicate VAL, return the edge that will be taken out of the block.
+   If VAL does not match a unique edge, NULL is returned.  */
 
 edge
 find_taken_edge (basic_block bb, tree val)
@@ -1956,15 +1955,16 @@ find_taken_edge (basic_block bb, tree val)
 
   gcc_assert (stmt);
   gcc_assert (is_ctrl_stmt (stmt));
+  gcc_assert (val);
 
   /* If VAL is a predicate of the form N RELOP N, where N is an
      SSA_NAME, we can usually determine its truth value.  */
-  if (val && COMPARISON_CLASS_P (val))
+  if (COMPARISON_CLASS_P (val))
     val = fold (val);
 
   /* If VAL is not a constant, we can't determine which edge might
      be taken.  */
-  if (val == NULL || !really_constant_p (val))
+  if (!really_constant_p (val))
     return NULL;
 
   if (TREE_CODE (stmt) == COND_EXPR)
@@ -1973,7 +1973,7 @@ find_taken_edge (basic_block bb, tree val)
   if (TREE_CODE (stmt) == SWITCH_EXPR)
     return find_taken_edge_switch_expr (bb, val);
 
-  return EDGE_SUCC (bb, 0);
+  gcc_unreachable ();
 }
 
 
@@ -1988,11 +1988,6 @@ find_taken_edge_cond_expr (basic_block bb, tree val)
 
   extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
 
-  /* If both edges of the branch lead to the same basic block, it doesn't
-     matter which edge is taken.  */
-  if (true_edge->dest == false_edge->dest)
-    return true_edge;
-
   /* Otherwise, try to determine which branch of the if() will be taken.
      If VAL is a constant but it can't be reduced to a 0 or a 1, then
      we don't really know which edge will be taken at runtime.  This
@@ -2872,22 +2867,25 @@ bsi_commit_edge_inserts (int *new_blocks)
 
   blocks = n_basic_blocks;
 
-  bsi_commit_edge_inserts_1 (EDGE_SUCC (ENTRY_BLOCK_PTR, 0));
+  bsi_commit_one_edge_insert (EDGE_SUCC (ENTRY_BLOCK_PTR, 0), NULL);
 
   FOR_EACH_BB (bb)
     FOR_EACH_EDGE (e, ei, bb->succs)
-      bsi_commit_edge_inserts_1 (e);
+      bsi_commit_one_edge_insert (e, NULL);
 
   if (new_blocks)
     *new_blocks = n_basic_blocks - blocks;
 }
 
 
-/* Commit insertions pending at edge E.  */
+/* Commit insertions pending at edge E. If a new block is created, set NEW_BB
+   to this block, otherwise set it to NULL.  */
 
-static void
-bsi_commit_edge_inserts_1 (edge e)
+void
+bsi_commit_one_edge_insert (edge e, basic_block *new_bb)
 {
+  if (new_bb)
+    *new_bb = NULL;
   if (PENDING_STMT (e))
     {
       block_stmt_iterator bsi;
@@ -2895,7 +2893,7 @@ bsi_commit_edge_inserts_1 (edge e)
 
       PENDING_STMT (e) = NULL_TREE;
 
-      if (tree_find_edge_insert_loc (e, &bsi, NULL))
+      if (tree_find_edge_insert_loc (e, &bsi, new_bb))
        bsi_insert_after (&bsi, stmt, BSI_NEW_STMT);
       else
        bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
@@ -3658,7 +3656,7 @@ tree_make_forwarder_block (edge fallthru)
   edge e;
   edge_iterator ei;
   basic_block dummy, bb;
-  tree phi, new_phi, var, prev, next;
+  tree phi, new_phi, var;
 
   dummy = fallthru->src;
   bb = fallthru->dest;
@@ -3678,14 +3676,7 @@ tree_make_forwarder_block (edge fallthru)
     }
 
   /* Ensure that the PHI node chain is in the same order.  */
-  prev = NULL;
-  for (phi = phi_nodes (bb); phi; phi = next)
-    {
-      next = PHI_CHAIN (phi);
-      PHI_CHAIN (phi) = prev;
-      prev = phi;
-    }
-  set_phi_nodes (bb, prev);
+  set_phi_nodes (bb, phi_reverse (phi_nodes (bb)));
 
   /* Add the arguments we have stored on edges.  */
   FOR_EACH_EDGE (e, ei, bb->preds)
@@ -3693,12 +3684,7 @@ tree_make_forwarder_block (edge fallthru)
       if (e == fallthru)
        continue;
 
-      for (phi = phi_nodes (bb), var = PENDING_STMT (e);
-          phi;
-          phi = PHI_CHAIN (phi), var = TREE_CHAIN (var))
-       add_phi_arg (&phi, TREE_VALUE (var), e);
-
-      PENDING_STMT (e) = NULL;
+      flush_pending_stmts (e);
     }
 }
 
@@ -3788,9 +3774,6 @@ thread_jumps_from_bb (basic_block bb)
          continue;
        }
 
-      count = e->count;
-      freq = EDGE_FREQUENCY (e);
-
       /* Now walk through as many forwarder blocks as possible to find
         the ultimate destination we want to thread our jump to.  */
       last = EDGE_SUCC (e->dest, 0);
@@ -3839,6 +3822,8 @@ thread_jumps_from_bb (basic_block bb)
 
       /* Perform the redirection.  */
       retval = true;
+      count = e->count;
+      freq = EDGE_FREQUENCY (e);
       old_dest = e->dest;
       e = redirect_edge_and_branch (e, dest);
 
@@ -3943,7 +3928,7 @@ thread_jumps (void)
   basic_block bb;
   bool retval = false;
   basic_block *worklist = xmalloc (sizeof (basic_block) * last_basic_block);
-  unsigned int size = 0;
+  basic_block *current = worklist;
 
   FOR_EACH_BB (bb)
     {
@@ -3951,6 +3936,10 @@ thread_jumps (void)
       bb->flags &= ~BB_VISITED;
     }
 
+  /* We pretend to have ENTRY_BLOCK_PTR in WORKLIST.  This way,
+     ENTRY_BLOCK_PTR will never be entered into WORKLIST.  */
+  ENTRY_BLOCK_PTR->flags |= BB_VISITED;
+
   /* Initialize WORKLIST by putting non-forwarder blocks that
      immediately precede forwarder blocks because those are the ones
      that we know we can thread jumps from.  We use BB_VISITED to
@@ -3972,28 +3961,24 @@ thread_jumps (void)
         among BB's predecessors.  */
       FOR_EACH_EDGE (e, ei, bb->preds)
        {
-         /* We are not interested in threading jumps from a forwarder
-            block.  */
-         if (!bb_ann (e->src)->forwardable
-             /* We don't want to visit ENTRY_BLOCK_PTR.  */
-             && e->src->index >= 0
-             /* We don't want to put a duplicate into WORKLIST.  */
-             && (e->src->flags & BB_VISITED) == 0)
+         /* We don't want to put a duplicate into WORKLIST.  */
+         if ((e->src->flags & BB_VISITED) == 0
+             /* We are not interested in threading jumps from a forwarder
+                block.  */
+             && !bb_ann (e->src)->forwardable)
            {
              e->src->flags |= BB_VISITED;
-             worklist[size] = e->src;
-             size++;
+             *current++ = e->src;
            }
        }
     }
 
   /* Now let's drain WORKLIST.  */
-  while (size > 0)
+  while (worklist != current)
     {
-      size--;
-      bb = worklist[size];
+      bb = *--current;
 
-      /* BB->INDEX is not longer in WORKLIST, so clear BB_VISITED.  */
+      /* BB is no longer in WORKLIST, so clear BB_VISITED.  */
       bb->flags &= ~BB_VISITED;
 
       if (thread_jumps_from_bb (bb))
@@ -4013,23 +3998,22 @@ thread_jumps (void)
                 predecessors.  */
              FOR_EACH_EDGE (f, ej, bb->preds)
                {
-                 /* We are not interested in threading jumps from a
-                    forwarder block.  */
-                 if (!bb_ann (f->src)->forwardable
-                     /* We don't want to visit ENTRY_BLOCK_PTR.  */
-                     && f->src->index >= 0
-                     /* We don't want to put a duplicate into WORKLIST.  */
-                     && (f->src->flags & BB_VISITED) == 0)
+                 /* We don't want to put a duplicate into WORKLIST.  */
+                 if ((f->src->flags & BB_VISITED) == 0
+                     /* We are not interested in threading jumps from a
+                        forwarder block.  */
+                     && !bb_ann (f->src)->forwardable)
                    {
                      f->src->flags |= BB_VISITED;
-                     worklist[size] = f->src;
-                     size++;
+                     *current++ = f->src;
                    }
                }
            }
        }
     }
 
+  ENTRY_BLOCK_PTR->flags &= ~BB_VISITED;
+
   free (worklist);
 
   return retval;
@@ -4286,12 +4270,12 @@ tree_duplicate_bb (basic_block bb)
   /* First copy the phi nodes.  We do not copy phi node arguments here,
      since the edges are not ready yet.  Keep the chain of phi nodes in
      the same order, so that we can add them later.  */
-  for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+  for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
     {
       mark_for_rewrite (PHI_RESULT (phi));
       create_phi_node (PHI_RESULT (phi), new_bb);
     }
-  set_phi_nodes (new_bb, nreverse (phi_nodes (new_bb)));
+  set_phi_nodes (new_bb, phi_reverse (phi_nodes (new_bb)));
 
   bsi_tgt = bsi_start (new_bb);
   for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
@@ -4508,7 +4492,7 @@ rewrite_to_new_ssa_names_bb (basic_block bb, htab_t map)
     if (e->flags & EDGE_ABNORMAL)
       break;
 
-  for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+  for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
     {
       rewrite_to_new_ssa_names_def (PHI_RESULT_PTR (phi), phi, map);
       if (e)
@@ -4544,12 +4528,16 @@ rewrite_to_new_ssa_names_bb (basic_block bb, htab_t map)
 
       v_must_defs = V_MUST_DEF_OPS (ann);
       for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
-       rewrite_to_new_ssa_names_def
-               (V_MUST_DEF_OP_PTR (v_must_defs, i), stmt, map);
+       {
+         rewrite_to_new_ssa_names_def
+           (V_MUST_DEF_RESULT_PTR (v_must_defs, i), stmt, map);
+         rewrite_to_new_ssa_names_use
+           (V_MUST_DEF_KILL_PTR (v_must_defs, i),  map);
+       }
     }
 
   FOR_EACH_EDGE (e, ei, bb->succs)
-    for (phi = phi_nodes (e->dest); phi; phi = TREE_CHAIN (phi))
+    for (phi = phi_nodes (e->dest); phi; phi = PHI_CHAIN (phi))
       {
        rewrite_to_new_ssa_names_use
                (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e), map);
@@ -4594,7 +4582,7 @@ tree_duplicate_sese_region (edge entry, edge exit,
   struct loop *loop = entry->dest->loop_father;
   edge exit_copy;
   bitmap definitions;
-  tree phi, var;
+  tree phi;
   basic_block *doms;
   htab_t ssa_name_map = NULL;
   edge redirected;
@@ -4663,11 +4651,7 @@ tree_duplicate_sese_region (edge entry, edge exit,
   /* Redirect the entry and add the phi node arguments.  */
   redirected = redirect_edge_and_branch (entry, entry->dest->rbi->copy);
   gcc_assert (redirected != NULL);
-  for (phi = phi_nodes (entry->dest), var = PENDING_STMT (entry);
-       phi;
-       phi = TREE_CHAIN (phi), var = TREE_CHAIN (var))
-    add_phi_arg (&phi, TREE_VALUE (var), entry);
-  PENDING_STMT (entry) = NULL;
+  flush_pending_stmts (entry);
 
   /* Concerning updating of dominators:  We must recount dominators
      for entry block and its copy.  Anything that is outside of the region, but
@@ -5129,7 +5113,7 @@ bool
 tree_purge_all_dead_eh_edges (bitmap blocks)
 {
   bool changed = false;
-  size_t i;
+  unsigned i;
   bitmap_iterator bi;
 
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)