OSDN Git Service

2005-06-14 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / tree-into-ssa.c
index d90c752..1daea76 100644 (file)
@@ -31,7 +31,6 @@ Boston, MA 02111-1307, USA.  */
 #include "hard-reg-set.h"
 #include "basic-block.h"
 #include "output.h"
-#include "errors.h"
 #include "expr.h"
 #include "function.h"
 #include "diagnostic.h"
@@ -47,6 +46,7 @@ Boston, MA 02111-1307, USA.  */
 #include "cfgloop.h"
 #include "domwalk.h"
 #include "ggc.h"
+#include "params.h"
 
 /* This file builds the SSA form for a function as described in:
    R. Cytron, J. Ferrante, B. Rosen, M. Wegman, and K. Zadeck. Efficiently
@@ -106,8 +106,8 @@ static VEC(tree,heap) *block_defs_stack;
 /* Basic block vectors used in this file ought to be allocated in the
    heap.  We use pointer vector, because ints can be easily passed by
    value.  */
-DEF_VEC_P(int);
-DEF_VEC_ALLOC_P(int,heap);
+DEF_VEC_I(int);
+DEF_VEC_ALLOC_I(int,heap);
 
 /* Set of existing SSA names being replaced by update_ssa.  */
 static sbitmap old_ssa_names;
@@ -117,13 +117,6 @@ static sbitmap old_ssa_names;
    the operations done on them are presence tests.  */
 static sbitmap new_ssa_names;
 
-/* Set of virtual SSA names to be updated.  Since virtuals are always
-   in FUD chain form, these names are not used as a mapping mechanism
-   like OLD_SSA_NAMES and NEW_SSA_NAMES.  Instead, the names in this
-   set are used by ssa_names_to_replace to inform its caller which
-   names are going to be updated.  */
-static bitmap old_virtual_ssa_names;
-
 /* Symbols whose SSA form needs to be updated or created for the first
    time.  */
 static bitmap syms_to_rename;
@@ -159,8 +152,20 @@ static bool need_to_initialize_update_ssa_p = true;
 /* true if update_ssa needs to update virtual operands.  */
 static bool need_to_update_vops_p = false;
 
-/* true if update_ssa is replacing existing SSA names.  */
-static bool need_to_replace_names_p = false;
+/* Statistics kept by update_ssa to use in the virtual mapping
+   heuristic.  If the number of virtual mappings is beyond certain
+   threshold, the updater will switch from using the mappings into
+   renaming the virtual symbols from scratch.  In some cases, the
+   large number of name mappings for virtual names causes significant
+   slowdowns in the PHI insertion code.  */
+struct update_ssa_stats_d
+{
+  unsigned num_virtual_mappings;
+  unsigned num_total_mappings;
+  bitmap virtual_symbols;
+  unsigned num_virtual_symbols;
+};
+static struct update_ssa_stats_d update_ssa_stats;
 
 /* Global data to attach to the main dominator walk structure.  */
 struct mark_def_sites_global_data
@@ -222,6 +227,17 @@ enum rewrite_mode {
 #define REGISTER_DEFS_IN_THIS_STMT(T)  (T)->common.unsigned_flag
 
 
+/* Prototypes for debugging functions.  */
+extern void dump_tree_ssa (FILE *);
+extern void debug_tree_ssa (void);
+extern void debug_def_blocks (void);
+extern void dump_tree_ssa_stats (FILE *);
+extern void debug_tree_ssa_stats (void);
+void dump_update_ssa (FILE *);
+void debug_update_ssa (void);
+void dump_names_replaced_by (FILE *, tree);
+void debug_names_replaced_by (tree);
+
 /* Get the information associated with NAME.  */
 
 static inline struct ssa_name_info *
@@ -260,7 +276,7 @@ set_phi_state (tree var, enum need_phi_state state)
 
 /* Return the current definition for VAR.  */
 
-static inline tree
+tree
 get_current_def (tree var)
 {
   if (TREE_CODE (var) == SSA_NAME)
@@ -272,7 +288,7 @@ get_current_def (tree var)
 
 /* Sets current definition of VAR to DEF.  */
 
-static inline void
+void
 set_current_def (tree var, tree def)
 {
   if (TREE_CODE (var) == SSA_NAME)
@@ -447,10 +463,8 @@ symbol_marked_for_renaming (tree sym)
 static inline bool
 is_old_name (tree name)
 {
-  if (!need_to_replace_names_p)
-    return false;
-
-  return TEST_BIT (old_ssa_names, SSA_NAME_VERSION (name));
+  unsigned ver = SSA_NAME_VERSION (name);
+  return ver < new_ssa_names->n_bits && TEST_BIT (old_ssa_names, ver);
 }
 
 
@@ -459,10 +473,8 @@ is_old_name (tree name)
 static inline bool
 is_new_name (tree name)
 {
-  if (!need_to_replace_names_p)
-    return false;
-
-  return TEST_BIT (new_ssa_names, SSA_NAME_VERSION (name));
+  unsigned ver = SSA_NAME_VERSION (name);
+  return ver < new_ssa_names->n_bits && TEST_BIT (new_ssa_names, ver);
 }
 
 
@@ -542,6 +554,9 @@ add_new_name_mapping (tree new, tree old)
 {
   timevar_push (TV_TREE_SSA_INCREMENTAL);
 
+  /* OLD and NEW must be different SSA names for the same symbol.  */
+  gcc_assert (new != old && SSA_NAME_VAR (new) == SSA_NAME_VAR (old));
+
   /* We may need to grow NEW_SSA_NAMES and OLD_SSA_NAMES because our
      caller may have created new names since the set was created.  */
   if (new_ssa_names->n_bits <= num_ssa_names - 1)
@@ -551,34 +566,31 @@ add_new_name_mapping (tree new, tree old)
       old_ssa_names = sbitmap_resize (old_ssa_names, new_sz, 0);
     }
 
-  /* We don't need to keep replacement mappings for virtual names.
-     Since these names are kept in FUD-chain form, we need to traverse
-     the CFG from ENTRY to repair FUD chains.  */
+  /* If this mapping is for virtual names, we will need to update
+     virtual operands.  */
   if (!is_gimple_reg (new))
     {
       tree sym;
+      size_t uid;
 
-      gcc_assert (!is_gimple_reg (old));
+      need_to_update_vops_p = true;
 
-      if (DECL_P (old))
-       sym = new;
-      else
+      /* Keep counts of virtual mappings and symbols to use in the
+        virtual mapping heuristic.  If we have large numbers of
+        virtual mappings for a relatively low number of symbols, it
+        will make more sense to rename the symbols from scratch.
+        Otherwise, the insertion of PHI nodes for each of the old
+        names in these mappings will be very slow.  */
+      sym = SSA_NAME_VAR (new);
+      uid = var_ann (sym)->uid;
+      update_ssa_stats.num_virtual_mappings++;
+      if (!bitmap_bit_p (update_ssa_stats.virtual_symbols, uid))
        {
-         sym = SSA_NAME_VAR (old);
-         bitmap_set_bit (old_virtual_ssa_names, SSA_NAME_VERSION (old));
+         bitmap_set_bit (update_ssa_stats.virtual_symbols, uid);
+         update_ssa_stats.num_virtual_symbols++;
        }
-
-      mark_sym_for_renaming (sym);
-      need_to_update_vops_p = true;
-
-      timevar_pop (TV_TREE_SSA_INCREMENTAL);
-
-      return;
     }
 
-  /* Assume that OLD and NEW are different GIMPLE register names.  */
-  gcc_assert (new != old && is_gimple_reg (old));
-
   /* Update the REPL_TBL table.  */
   add_to_repl_tbl (new, old);
 
@@ -592,8 +604,8 @@ add_new_name_mapping (tree new, tree old)
   SET_BIT (new_ssa_names, SSA_NAME_VERSION (new));
   SET_BIT (old_ssa_names, SSA_NAME_VERSION (old));
 
-  /* Indicate that we are going to be replacing existing names.  */
-  need_to_replace_names_p = true;
+  /* Update mapping counter to use in the virtual mapping heuristic.  */
+  update_ssa_stats.num_total_mappings++;
 
   timevar_pop (TV_TREE_SSA_INCREMENTAL);
 }
@@ -603,7 +615,7 @@ add_new_name_mapping (tree new, tree old)
    for every variable in the function.  For every statement S in block
    BB:
 
-   1- Variables defined by S in DEF_OPS(S) are marked in the bitmap
+   1- Variables defined by S in the DEFS of S are marked in the bitmap
       WALK_DATA->GLOBAL_DATA->KILLS.
 
    2- If S uses a variable VAR and there is no preceding kill of VAR,
@@ -635,7 +647,7 @@ mark_def_sites (struct dom_walk_data *walk_data,
   /* If a variable is used before being set, then the variable is live
      across a block boundary, so mark it live-on-entry to BB.  */
   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
-                           SSA_OP_USE | SSA_OP_VUSE | SSA_OP_VMUSTDEFKILL)
+                           SSA_OP_USE | SSA_OP_VUSE | SSA_OP_VMUSTKILL)
     {
       tree sym = USE_FROM_PTR (use_p);
       gcc_assert (DECL_P (sym));
@@ -802,24 +814,20 @@ insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
                            0, bb_index, bi)
     {
       bb = BASIC_BLOCK (bb_index);
-      phi = create_phi_node (var, bb);
 
-      if (TREE_CODE (var) == SSA_NAME)
+      if (update_p && TREE_CODE (var) == SSA_NAME)
        {
+         /* If we are rewriting SSA names, create the LHS of the PHI
+            node by duplicating VAR.  This is useful in the case of
+            pointers, to also duplicate pointer attributes (alias
+            information, in particular).  */
          edge_iterator ei;
+         tree new_lhs;
 
-         /* FIXME.  After removing rewrite_ssa_into_ssa, change this
-            if() to gcc_assert().  */
-         if (update_p)
-           {
-             /* If we are rewriting SSA names, create the LHS of the
-                PHI node by duplicating VAR.  This is useful in the
-                case of pointers, to also duplicate pointer
-                attributes (alias information, in particular).  */
-             tree new_lhs = duplicate_ssa_name (var, phi);
-             SET_PHI_RESULT (phi, new_lhs);
-             add_new_name_mapping (new_lhs, var);
-           }
+         phi = create_phi_node (var, bb);
+         new_lhs = duplicate_ssa_name (var, phi);
+         SET_PHI_RESULT (phi, new_lhs);
+         add_new_name_mapping (new_lhs, var);
 
          /* Add VAR to every argument slot of PHI.  We need VAR in
             every argument so that rewrite_update_phi_arguments knows
@@ -830,6 +838,11 @@ insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
          FOR_EACH_EDGE (e, ei, bb->preds)
            add_phi_arg (phi, var, e);
        }
+      else
+       {
+         tree sym = DECL_P (var) ? var : SSA_NAME_VAR (var);
+         phi = create_phi_node (sym, bb);
+       }
 
       /* Mark this PHI node as interesting for update_ssa.  */
       REGISTER_DEFS_IN_THIS_STMT (phi) = 1;
@@ -838,55 +851,36 @@ insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
 }
 
 
-/* Helper for insert_phi_nodes.  If VAR needs PHI nodes, insert them
-   at the dominance frontier (DFS) of blocks defining VAR.  */
-
-static inline void
-insert_phi_nodes_1 (tree var, bitmap *dfs)
-{
-  struct def_blocks_d *def_map;
-  bitmap idf;
-
-  def_map = find_def_blocks_for (var);
-  if (def_map == NULL)
-    return;
-
-  if (get_phi_state (var) != NEED_PHI_STATE_NO)
-    {
-      idf = find_idf (def_map->def_blocks, dfs);
-      insert_phi_nodes_for (var, idf, false);
-      BITMAP_FREE (idf);
-    }
-}
-
-
 /* Insert PHI nodes at the dominance frontier of blocks with variable
    definitions.  DFS contains the dominance frontier information for
    the flowgraph.  PHI nodes will only be inserted at the dominance
    frontier of definition blocks for variables whose NEED_PHI_STATE
    annotation is marked as ``maybe'' or ``unknown'' (computed by
-   mark_def_sites).  If NAMES_TO_RENAME is not NULL, do the same but
-   for ssa name rewriting.  */
+   mark_def_sites).  */
 
 static void
-insert_phi_nodes (bitmap *dfs, bitmap names_to_rename)
+insert_phi_nodes (bitmap *dfs)
 {
   unsigned i;
 
   timevar_push (TV_TREE_INSERT_PHI_NODES);
 
-  if (names_to_rename)
+  for (i = 0; i < num_referenced_vars; i++)
     {
-      bitmap_iterator bi;
+      struct def_blocks_d *def_map;
+      bitmap idf;
+      tree var = referenced_var (i);
 
-      EXECUTE_IF_SET_IN_BITMAP (names_to_rename, 0, i, bi)
-       if (ssa_name (i))
-         insert_phi_nodes_1 (ssa_name (i), dfs);
-    }
-  else
-    {
-      for (i = 0; i < num_referenced_vars; i++)
-       insert_phi_nodes_1 (referenced_var (i), dfs);
+      def_map = find_def_blocks_for (var);
+      if (def_map == NULL)
+       continue;
+
+      if (get_phi_state (var) != NEED_PHI_STATE_NO)
+       {
+         idf = find_idf (def_map->def_blocks, dfs);
+         insert_phi_nodes_for (var, idf, false);
+         BITMAP_FREE (idf);
+       }
     }
 
   timevar_pop (TV_TREE_INSERT_PHI_NODES);
@@ -1347,18 +1341,6 @@ rewrite_update_init_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
 }
 
 
-/* Replace the operand pointed by USE_P with USE's current reaching
-   definition.  */
-
-static inline void
-replace_use (use_operand_p use_p, tree use)
-{
-  tree rdef = get_reaching_def (use);
-  if (rdef != use)
-    SET_USE (use_p, rdef);
-}
-
-
 /* Called after visiting block BB.  Unwind BLOCK_DEFS_STACK to restore
    the current reaching definition of every name re-written in BB to
    the original reaching definition before visiting BB.  This
@@ -1385,6 +1367,65 @@ rewrite_update_fini_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
 }
 
 
+/* If the operand pointed to by USE_P is a name in OLD_SSA_NAMES or
+   it is a symbol marked for renaming, replace it with USE_P's current
+   reaching definition.  */
+
+static inline void
+maybe_replace_use (use_operand_p use_p)
+{
+  tree rdef = NULL_TREE;
+  tree use = USE_FROM_PTR (use_p);
+  tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
+
+  if (symbol_marked_for_renaming (sym))
+    rdef = get_reaching_def (sym);
+  else if (is_old_name (use))
+    rdef = get_reaching_def (use);
+
+  if (rdef && rdef != use)
+    SET_USE (use_p, rdef);
+}
+
+
+/* If the operand pointed to by DEF_P is an SSA name in NEW_SSA_NAMES
+   or OLD_SSA_NAMES, or if it is a symbol marked for renaming,
+   register it as the current definition for the names replaced by
+   DEF_P.  */
+
+static inline void
+maybe_register_def (def_operand_p def_p, tree stmt)
+{
+  tree def = DEF_FROM_PTR (def_p);
+  tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
+
+  /* If DEF is a naked symbol that needs renaming, create a
+     new name for it.  */
+  if (symbol_marked_for_renaming (sym))
+    {
+      if (DECL_P (def))
+       {
+         def = make_ssa_name (def, stmt);
+         SET_DEF (def_p, def);
+       }
+
+      register_new_update_single (def, sym);
+    }
+  else
+    {
+      /* If DEF is a new name, register it as a new definition
+        for all the names replaced by DEF.  */
+      if (is_new_name (def))
+       register_new_update_set (def, names_replaced_by (def));
+
+      /* If DEF is an old name, register DEF as a new
+        definition for itself.  */
+      if (is_old_name (def))
+       register_new_update_single (def, def);
+    }
+}
+
+
 /* Update every variable used in the statement pointed-to by SI.  The
    statement is assumed to be in SSA form already.  Names in
    OLD_SSA_NAMES used by SI will be updated to their current reaching
@@ -1422,26 +1463,12 @@ rewrite_update_stmt (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
   if (REWRITE_THIS_STMT (stmt))
     {
       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
-       {
-         tree use = USE_FROM_PTR (use_p);
-         tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
-
-         if (symbol_marked_for_renaming (sym))
-           replace_use (use_p, sym);
-         else if (is_old_name (use))
-           replace_use (use_p, use);
-       }
+       maybe_replace_use (use_p);
 
       if (need_to_update_vops_p)
        FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
                                  SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS)
-         {
-           tree use = USE_FROM_PTR (use_p);
-           tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
-
-           if (symbol_marked_for_renaming (sym))
-             replace_use (use_p, sym);
-         }
+         maybe_replace_use (use_p);
     }
 
   /* Register definitions of names in NEW_SSA_NAMES and OLD_SSA_NAMES.
@@ -1450,57 +1477,27 @@ rewrite_update_stmt (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
   if (REGISTER_DEFS_IN_THIS_STMT (stmt))
     {
       FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_DEF)
-       {
-         tree def = DEF_FROM_PTR (def_p);
-         tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
-
-         /* If DEF is a naked symbol that needs renaming, create a
-            new name for it.  */
-         if (symbol_marked_for_renaming (sym))
-           {
-             if (DECL_P (def))
-               {
-                 def = make_ssa_name (def, stmt);
-                 SET_DEF (def_p, def);
-               }
-
-             register_new_update_single (def, sym);
-           }
-         else
-           {
-             /* If DEF is a new name, register it as a new definition
-                for all the names replaced by DEF.  */
-             if (is_new_name (def))
-               register_new_update_set (def, names_replaced_by (def));
-
-             /* If DEF is an old name, register DEF as a new
-                definition for itself.  */
-             if (is_old_name (def))
-               register_new_update_single (def, def);
-           }
-       }
+       maybe_register_def (def_p, stmt);
 
       if (need_to_update_vops_p)
        FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_VIRTUAL_DEFS)
-         {
-           tree def = DEF_FROM_PTR (def_p);
-           tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
-
-           if (symbol_marked_for_renaming (sym))
-             {
-               if (DECL_P (def))
-                 {
-                   def = make_ssa_name (def, stmt);
-                   SET_DEF (def_p, def);
-                 }
-
-               register_new_update_single (def, sym);
-             }
-         }
+         maybe_register_def (def_p, stmt);
     }
 }
 
 
+/* Replace the operand pointed by USE_P with USE's current reaching
+   definition.  */
+
+static inline void
+replace_use (use_operand_p use_p, tree use)
+{
+  tree rdef = get_reaching_def (use);
+  if (rdef != use)
+    SET_USE (use_p, rdef);
+}
+
+
 /* Visit all the successor blocks of BB looking for PHI nodes.  For
    every PHI node found, check if any of its arguments is in
    OLD_SSA_NAMES.  If so, and if the argument has a current reaching
@@ -1670,7 +1667,7 @@ mark_def_site_blocks (sbitmap interesting_blocks)
   struct mark_def_sites_global_data mark_def_sites_global_data;
 
   /* Allocate memory for the DEF_BLOCKS hash table.  */
-  def_blocks = htab_create (VARRAY_ACTIVE_SIZE (referenced_vars),
+  def_blocks = htab_create (VEC_length (tree, referenced_vars),
                            def_blocks_hash, def_blocks_eq, def_blocks_free);
 
   for (i = 0; i < num_referenced_vars; i++)
@@ -1752,7 +1749,7 @@ rewrite_into_ssa (void)
   sbitmap_zero (interesting_blocks);
 
   /* Initialize dominance frontier.  */
-  dfs = (bitmap *) xmalloc (last_basic_block * sizeof (bitmap *));
+  dfs = (bitmap *) xmalloc (last_basic_block * sizeof (bitmap));
   FOR_EACH_BB (bb)
     dfs[bb->index] = BITMAP_ALLOC (NULL);
 
@@ -1764,7 +1761,7 @@ rewrite_into_ssa (void)
   mark_def_site_blocks (interesting_blocks);
 
   /* 3- Insert PHI nodes at dominance frontiers of definition blocks.  */
-  insert_phi_nodes (dfs, NULL);
+  insert_phi_nodes (dfs);
 
   /* 4- Rename all the blocks.  */
   rewrite_blocks (ENTRY_BLOCK_PTR, REWRITE_ALL, interesting_blocks);
@@ -1812,15 +1809,6 @@ mark_def_interesting (tree var, tree stmt, basic_block bb, bitmap blocks,
     {
       bool is_phi_p = TREE_CODE (stmt) == PHI_NODE;
 
-#if defined ENABLE_CHECKING
-      /* If VAR is a virtual, then it had better be a symbol.
-        Virtuals are in FUD-chain form, so we are interested in the
-        definition and use sites of the symbol, not the individual
-        SSA names.  */
-      if (!is_gimple_reg (var))
-       gcc_assert (DECL_P (var));
-#endif
-
       set_def_block (var, bb, is_phi_p);
 
       /* If VAR is an SSA name in NEW_SSA_NAMES, this is a definition
@@ -1856,146 +1844,43 @@ mark_use_interesting (tree var, tree stmt, basic_block bb, bitmap blocks,
      replace it).  */
   if (insert_phi_p)
     {
-      struct def_blocks_d *db_p;
-
-#if defined ENABLE_CHECKING
-      /* If VAR is a virtual, then it had better be a symbol.
-        Virtuals are in FUD-chain form, so we are interested in the
-        definition and use sites of the symbol, not the individual
-        SSA names.  */
-      if (!is_gimple_reg (var))
-       gcc_assert (DECL_P (var));
-#endif
-
-      db_p = get_def_blocks_for (var);
+      struct def_blocks_d *db_p = get_def_blocks_for (var);
       if (!bitmap_bit_p (db_p->def_blocks, bb->index))
        set_livein_block (var, bb);
     }
 }
 
 
-/* If any of the arguments of PHI is in OLD_SSA_NAMES, mark PHI to
-   be rewritten.  BB is the block where PHI resides, BLOCKS is the
-   region to be renamed and INSERT_PHI_P is true if the updating
-   process should insert new PHI nodes.  */
-
-static void
-prepare_phi_args_for_update (tree phi, basic_block bb, bitmap blocks,
-                             bool insert_phi_p)
-{
-  int i;
-
-  for (i = 0; i < PHI_NUM_ARGS (phi); i++)
-    {
-      tree arg = PHI_ARG_DEF (phi, i);
-
-      if (TREE_CODE (arg) == SSA_NAME && is_old_name (arg))
-       {
-         /* Mark this use of ARG interesting for the renamer.  Notice
-            that we explicitly call mark_use_interesting with
-            INSERT_PHI_P == false.
-
-            This is to avoid marking ARG as live-in in this block BB.
-            If we were to mark ARG live-in to BB, then ARG would be
-            considered live-in through ALL incoming edges to BB which
-            is not what we want.  Since we are updating the SSA form
-            for ARG, we don't really know what other names of ARG are
-            coming in through other edges into BB.
-
-            If we considered ARG live-in at BB, then the PHI
-            placement algorithm may try to insert PHI nodes in blocks
-            that are not only unnecessary but also the renamer would
-            not know how to fill in.  */
-         mark_use_interesting (arg, phi, bb, blocks, false);
-
-         /* As discussed above, we only want to mark ARG live-in
-            through the edge corresponding to its slot inside the PHI
-            argument list.  So, we look for the block BB1 where ARG is
-            flowing through.  If BB1 does not contain a definition of
-            ARG, then consider ARG live-in at BB1.  */
-         if (insert_phi_p)
-           {
-             edge e = PHI_ARG_EDGE (phi, i);
-             basic_block bb1 = e->src;
-             struct def_blocks_d *db = get_def_blocks_for (arg);
-
-             if (!bitmap_bit_p (db->def_blocks, bb1->index))
-               set_livein_block (arg, bb1);
-           }
-       }
-    }
-}
-
-
 /* Do a dominator walk starting at BB processing statements that
-   reference variables in OLD_SSA_NAMES and NEW_SSA_NAMES.
-
-   1- Mark in BLOCKS the defining block of every name N in
-      NEW_SSA_NAMES.
-
-   2- Mark in BLOCKS the defining block of every name O in
-      OLD_SSA_NAMES.
-
-   3- For every statement or PHI node that uses a name O in
-      OLD_SSA_NAMES.  If INSERT_PHI_P is true, mark those uses as live
-      in the corresponding block.  This is later used by the PHI
-      placement algorithm to make PHI pruning decisions.
+   reference symbols in SYMS_TO_RENAME.  This is very similar to
+   mark_def_sites, but the scan handles statements whose operands may
+   already be SSA names.  Blocks that contain defs or uses of symbols
+   in SYMS_TO_RENAME are added to BLOCKS.
 
-   If VISIT_DOM_P is true, all the dominator children of BB are also
-   visited.
-
-   FIXME.  This process is slower than necessary.  Once we have
-   immediate uses merged in, we should be able to just visit the
-   immediate uses of all the names that we are about to replace,
-   instead of visiting the whole block.  */
+   If INSERT_PHI_P is true, mark those uses as live in the
+   corresponding block.  This is later used by the PHI placement
+   algorithm to make PHI pruning decisions.  */
 
 static void
-prepare_block_for_update (basic_block bb, bool insert_phi_p,
-                          bitmap blocks, bool visit_dom_p)
+prepare_block_for_update (basic_block bb, bitmap blocks, bool insert_phi_p)
 {
   basic_block son;
   block_stmt_iterator si;
   tree phi;
 
   /* Process PHI nodes marking interesting those that define or use
-     the names that we are interested in.  */
+     the symbols that we are interested in.  */
   for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
     {
       tree lhs_sym, lhs = PHI_RESULT (phi);
 
-      REWRITE_THIS_STMT (phi) = 0;
-      REGISTER_DEFS_IN_THIS_STMT (phi) = 0;
-
-      /* Ignore virtual PHIs if we are not updating virtual operands.
-        Note that even if NEED_TO_REPLACE_NAMES_P is false, we need
-        to process real PHIs because we may be rewriting GIMPLE regs
-        into SSA for the first time.  Therefore, we cannot do a
-        similar shortcut for real PHIs.  */
-      if (!need_to_update_vops_p && !is_gimple_reg (lhs))
-       continue;
-
       lhs_sym = DECL_P (lhs) ? lhs : SSA_NAME_VAR (lhs);
 
       if (symbol_marked_for_renaming (lhs_sym))
        {
-         /* If the LHS is a virtual symbol marked for renaming, then
-            we don't need to scan the argument list.  Since virtual
-            operands are in FUD-chain form, all the arguments of this
-            PHI must be the same symbol as the LHS.  So, we just need
-            to mark this site as both an interesting use and an
-            interesting def for the symbol.  */
          mark_use_interesting (lhs_sym, phi, bb, blocks, insert_phi_p);
          mark_def_interesting (lhs_sym, phi, bb, blocks, insert_phi_p);
        }
-      else if (need_to_replace_names_p)
-       {
-         /* If the LHS is in OLD_SSA_NAMES or NEW_SSA_NAMES, this is
-            a definition site for it.  */
-         if (is_old_name (lhs) || is_new_name (lhs))
-           mark_def_interesting (lhs, phi, bb, blocks, insert_phi_p);
-
-         prepare_phi_args_for_update (phi, bb, blocks, insert_phi_p);
-       }
     }
 
   /* Process the statements.  */
@@ -2008,17 +1893,11 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p,
       
       stmt = bsi_stmt (si);
 
-      REWRITE_THIS_STMT (stmt) = 0;
-      REGISTER_DEFS_IN_THIS_STMT (stmt) = 0;
-
-      /* Note, even if NEED_TO_REPLACE_NAMES_P is false, we need to
-        scan real uses and defs, as we may be renaming a GIMPLE
-        register for the first time.  */
       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
        {
          tree use = USE_FROM_PTR (use_p);
          tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
-         if (symbol_marked_for_renaming (sym) || is_old_name (use))
+         if (symbol_marked_for_renaming (sym))
            mark_use_interesting (use, stmt, bb, blocks, insert_phi_p);
        }
 
@@ -2027,23 +1906,10 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p,
          tree def = DEF_FROM_PTR (def_p);
          tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
 
-         if (symbol_marked_for_renaming (sym)
-             || is_new_name (def)
-             || is_old_name (def))
+         if (symbol_marked_for_renaming (sym))
            mark_def_interesting (def, stmt, bb, blocks, insert_phi_p);
        }
 
-      /* If we don't need to update virtual operands, continue to the
-        next statement.  */
-      if (!need_to_update_vops_p)
-       continue;
-
-      /* For every interesting N_i = V_MAY_DEF <N_j> and
-        N_i = V_MUST_DEF <N_j>, mark the statement as interesting.
-        Notice that N_j may in fact be a naked symbol (if this
-        statement is the result of basic block duplication). The
-        rename process will later fill in the appropriate reaching
-        definition for the symbol.  */
       FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, i, SSA_OP_VIRTUAL_DEFS)
        {
          tree def = DEF_FROM_PTR (def_p);
@@ -2056,7 +1922,6 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p,
            }
        }
 
-      /* Similarly, for V_USE <N_i>.  */
       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_VUSE)
        {
          tree use = USE_FROM_PTR (use_p);
@@ -2068,16 +1933,76 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p,
     }
 
   /* Now visit all the blocks dominated by BB.  */
-  if (visit_dom_p)
-    for (son = first_dom_son (CDI_DOMINATORS, bb);
-        son;
-        son = next_dom_son (CDI_DOMINATORS, son))
-      prepare_block_for_update (son, insert_phi_p, blocks, true);
+  for (son = first_dom_son (CDI_DOMINATORS, bb);
+      son;
+      son = next_dom_son (CDI_DOMINATORS, son))
+    prepare_block_for_update (son, blocks, insert_phi_p);
+}
+
+
+/* Helper for prepare_names_to_update.  Mark all the use sites for
+   NAME as interesting.  BLOCKS and INSERT_PHI_P are as in
+   prepare_names_to_update.  */
+
+static void
+prepare_use_sites_for (tree name, bitmap blocks, bool insert_phi_p)
+{
+  use_operand_p use_p;
+  imm_use_iterator iter;
+
+  FOR_EACH_IMM_USE_FAST (use_p, iter, name)
+    {
+      tree stmt = USE_STMT (use_p);
+      basic_block bb = bb_for_stmt (stmt);
+
+      if (TREE_CODE (stmt) == PHI_NODE)
+       {
+         /* Mark this use of NAME interesting for the renamer.
+            Notice that we explicitly call mark_use_interesting with
+            INSERT_PHI_P == false.
+
+            This is to avoid marking NAME as live-in in this block
+            BB. If we were to mark NAME live-in to BB, then NAME
+            would be considered live-in through ALL incoming edges to
+            BB which is not what we want.  Since we are updating the
+            SSA form for NAME, we don't really know what other names
+            of NAME are coming in through other edges into BB.
+
+            If we considered NAME live-in at BB, then the PHI
+            placement algorithm may try to insert PHI nodes in blocks
+            that are not only unnecessary but also the renamer would
+            not know how to fill in.  */
+         mark_use_interesting (name, stmt, bb, blocks, false);
+
+         /* As discussed above, we only want to mark NAME live-in
+            through the edge corresponding to its slot inside the PHI
+            argument list.  So, we look for the block BB1 where NAME
+            is flowing through.  If BB1 does not contain a definition
+            of NAME, then consider NAME live-in at BB1.  */
+         if (insert_phi_p)
+           {
+             int ix = PHI_ARG_INDEX_FROM_USE (use_p);
+             edge e = PHI_ARG_EDGE (stmt, ix);
+             basic_block bb1 = e->src;
+             struct def_blocks_d *db = get_def_blocks_for (name);
+
+             if (!bitmap_bit_p (db->def_blocks, bb1->index))
+               set_livein_block (name, bb1);
+           }
+       }
+      else
+       {
+         /* For regular statements, mark this as an interesting use
+            for NAME.  */
+         mark_use_interesting (name, stmt, bb, blocks, insert_phi_p);
+       }
+    }
 }
 
 
-/* Helper for prepare_def_sites.  Mark the definition site for NAME as
-   interesting.  BLOCKS and INSERT_PHI_P are as in prepare_def_sites.  */
+/* Helper for prepare_names_to_update.  Mark the definition site for
+   NAME as interesting.  BLOCKS and INSERT_PHI_P are as in
+   prepare_names_to_update.  */
 
 static void
 prepare_def_site_for (tree name, bitmap blocks, bool insert_phi_p)
@@ -2085,7 +2010,6 @@ prepare_def_site_for (tree name, bitmap blocks, bool insert_phi_p)
   tree stmt;
   basic_block bb;
 
-  gcc_assert (name && is_gimple_reg (name));
   gcc_assert (names_to_release == NULL
              || !bitmap_bit_p (names_to_release, SSA_NAME_VERSION (name)));
 
@@ -2099,15 +2023,17 @@ prepare_def_site_for (tree name, bitmap blocks, bool insert_phi_p)
 }
 
 
-/* Mark definition sites of names in NEW_SSA_NAMES and OLD_SSA_NAMES.
-   Add each definition block to BLOCKS.  INSERT_PHI_P is true if the
-   caller wants to insert PHI nodes for newly created names.  */
+/* Mark definition and use sites of names in NEW_SSA_NAMES and
+   OLD_SSA_NAMES.  Add each definition block to BLOCKS.  INSERT_PHI_P
+   is true if the caller wants to insert PHI nodes for newly created
+   names.  */
 
 static void
-prepare_def_sites (bitmap blocks, bool insert_phi_p)
+prepare_names_to_update (bitmap blocks, bool insert_phi_p)
 {
   unsigned i;
   bitmap_iterator bi;
+  sbitmap_iterator sbi;
 
   /* If a name N from NEW_SSA_NAMES is also marked to be released,
      remove it from NEW_SSA_NAMES so that we don't try to visit its
@@ -2118,14 +2044,20 @@ prepare_def_sites (bitmap blocks, bool insert_phi_p)
     EXECUTE_IF_SET_IN_BITMAP (names_to_release, 0, i, bi)
       RESET_BIT (new_ssa_names, i);
 
+  /* First process names in NEW_SSA_NAMES.  Otherwise, uses of old
+     names may be considered to be live-in on blocks that contain
+     definitions for their replacements.  */
+  EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i, sbi)
+    prepare_def_site_for (ssa_name (i), blocks, insert_phi_p);
+
   /* If an old name is in NAMES_TO_RELEASE, we cannot remove it from
      OLD_SSA_NAMES, but we have to ignore its definition site.  */
-  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i,
-    if (names_to_release == NULL || !bitmap_bit_p (names_to_release, i))
-      prepare_def_site_for (ssa_name (i), blocks, insert_phi_p));
-
-  EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i,
-    prepare_def_site_for (ssa_name (i), blocks, insert_phi_p));
+  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
+    {
+      if (names_to_release == NULL || !bitmap_bit_p (names_to_release, i))
+       prepare_def_site_for (ssa_name (i), blocks, insert_phi_p);
+      prepare_use_sites_for (ssa_name (i), blocks, insert_phi_p);
+    }
 }
 
 
@@ -2161,10 +2093,10 @@ debug_names_replaced_by (tree name)
 }
 
 
-/* Dump the SSA name replacement table to FILE.  */
+/* Dump SSA update information to FILE.  */
 
 void
-dump_repl_tbl (FILE *file)
+dump_update_ssa (FILE *file)
 {
   unsigned i;
   bitmap_iterator bi;
@@ -2174,12 +2106,26 @@ dump_repl_tbl (FILE *file)
 
   if (new_ssa_names && sbitmap_first_set_bit (new_ssa_names) >= 0)
     {
+      sbitmap_iterator sbi;
+
       fprintf (file, "\nSSA replacement table\n");
       fprintf (file, "N_i -> { O_1 ... O_j } means that N_i replaces "
                     "O_1, ..., O_j\n\n");
 
-      EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i,
-       dump_names_replaced_by (file, ssa_name (i)));
+      EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i, sbi)
+       dump_names_replaced_by (file, ssa_name (i));
+
+      fprintf (file, "\n");
+      fprintf (file, "Number of virtual NEW -> OLD mappings: %7u\n",
+              update_ssa_stats.num_virtual_mappings);
+      fprintf (file, "Number of real NEW -> OLD mappings:    %7u\n",
+              update_ssa_stats.num_total_mappings
+              - update_ssa_stats.num_virtual_mappings);
+      fprintf (file, "Number of total NEW -> OLD mappings:   %7u\n",
+              update_ssa_stats.num_total_mappings);
+
+      fprintf (file, "\nNumber of virtual symbols: %u\n",
+              update_ssa_stats.num_virtual_symbols);
     }
 
   if (syms_to_rename && !bitmap_empty_p (syms_to_rename))
@@ -2192,16 +2138,6 @@ dump_repl_tbl (FILE *file)
        }
     }
 
-  if (old_virtual_ssa_names && !bitmap_empty_p (old_virtual_ssa_names))
-    {
-      fprintf (file, "\n\nVirtual SSA names to be updated\n\n");
-      EXECUTE_IF_SET_IN_BITMAP (old_virtual_ssa_names, 0, i, bi)
-       {
-         print_generic_expr (file, ssa_name (i), 0);
-         fprintf (file, " ");
-       }
-    }
-
   if (names_to_release && !bitmap_empty_p (names_to_release))
     {
       fprintf (file, "\n\nSSA names to release after updating the SSA web\n\n");
@@ -2216,12 +2152,12 @@ dump_repl_tbl (FILE *file)
 }
 
 
-/* Dump the SSA name replacement table to stderr.  */
+/* Dump SSA update information to stderr.  */
 
 void
-debug_repl_tbl (void)
+debug_update_ssa (void)
 {
-  dump_repl_tbl (stderr);
+  dump_update_ssa (stderr);
 }
 
 
@@ -2230,7 +2166,7 @@ debug_repl_tbl (void)
 static void
 init_update_ssa (void)
 {
-  /* Reserve 1/3 more than the current number of names.  The calls to
+  /* Reserve more space than the current number of names.  The calls to
      add_new_name_mapping are typically done after creating new SSA
      names, so we'll need to reallocate these arrays.  */
   old_ssa_names = sbitmap_alloc (num_ssa_names + NAME_SETS_GROWTH_FACTOR);
@@ -2242,16 +2178,16 @@ init_update_ssa (void)
   repl_tbl = htab_create (20, repl_map_hash, repl_map_eq, repl_map_free);
   need_to_initialize_update_ssa_p = false;
   need_to_update_vops_p = false;
-  need_to_replace_names_p = false;
   syms_to_rename = BITMAP_ALLOC (NULL);
-  old_virtual_ssa_names = BITMAP_ALLOC (NULL);
   names_to_release = NULL;
+  memset (&update_ssa_stats, 0, sizeof (update_ssa_stats));
+  update_ssa_stats.virtual_symbols = BITMAP_ALLOC (NULL);
 }
 
 
 /* Deallocate data structures used for incremental SSA updates.  */
 
-static void
+void
 delete_update_ssa (void)
 {
   unsigned i;
@@ -2268,9 +2204,8 @@ delete_update_ssa (void)
 
   need_to_initialize_update_ssa_p = true;
   need_to_update_vops_p = false;
-  need_to_replace_names_p = false;
   BITMAP_FREE (syms_to_rename);
-  BITMAP_FREE (old_virtual_ssa_names);
+  BITMAP_FREE (update_ssa_stats.virtual_symbols);
 
   if (names_to_release)
     {
@@ -2289,10 +2224,6 @@ delete_update_ssa (void)
          SSA_NAME_AUX (n) = NULL;
        }
     }
-
-  /* Unmark all the names we may have protected from being released in
-     insert_updated_phi_nodes_for.  */
-  unmark_all_for_rewrite ();
 }
 
 
@@ -2371,6 +2302,9 @@ mark_set_for_renaming (bitmap set)
   bitmap_iterator bi;
   unsigned i;
 
+  if (bitmap_empty_p (set))
+    return;
+
   if (need_to_initialize_update_ssa_p)
     init_update_ssa ();
 
@@ -2415,12 +2349,11 @@ ssa_names_to_replace (void)
 {
   unsigned i;
   bitmap ret;
+  sbitmap_iterator sbi;
   
   ret = BITMAP_ALLOC (NULL);
-  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i,
-    bitmap_set_bit (ret, i));
-
-  bitmap_ior_into (ret, old_virtual_ssa_names);
+  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
+    bitmap_set_bit (ret, i);
 
   return ret;
 }
@@ -2450,8 +2383,7 @@ release_ssa_name_after_update_ssa (tree name)
    - If UPDATE_FLAGS == TODO_update_ssa, we are only interested in PHI
      nodes inside the region affected by the block that defines VAR
      and the blocks that define all its replacements.  All these
-     definition blocks have been gathered by prepare_block_for_update
-     and they are stored in DEF_BLOCKS[VAR]->DEF_BLOCKS.
+     definition blocks are stored in DEF_BLOCKS[VAR]->DEF_BLOCKS.
 
      First, we compute the entry point to the region (ENTRY).  This is
      given by the nearest common dominator to all the definition
@@ -2521,31 +2453,6 @@ insert_updated_phi_nodes_for (tree var, bitmap *dfs, bitmap blocks,
         for the first time, so we need to compute the full IDF for
         it.  */
       bitmap_copy (pruned_idf, idf);
-
-      /* There may already be PHI nodes for VAR in the flowgraph.
-        Some of them are no longer necessary.  PRUNED_IDF is
-        the set of blocks that need PHI nodes for VAR and
-        DB.PHI_BLOCKS is the set of blocks that already contain a PHI
-        node for VAR.  Therefore, the set DB.PHI_BLOCKS - PRUNED_IDF
-        gives us the set of blocks that contain PHI nodes which are
-        no longer needed.  */
-      if (!bitmap_empty_p (db->phi_blocks) && !bitmap_empty_p (pruned_idf))
-       EXECUTE_IF_AND_COMPL_IN_BITMAP (db->phi_blocks, pruned_idf, 0, i, bi)
-         {
-           tree phi, prev;
-           unsigned ver;
-
-           phi = find_phi_node_for (BASIC_BLOCK (i), var, &prev);
-           
-           /* Protect the name on PHI's LHS from being released into
-              the SSA name free list.  Since we have still not
-              updated the SSA form of the program, there may be
-              instances of PHI's LHS in the IL.  */
-           ver = SSA_NAME_VERSION (PHI_RESULT (phi));
-           mark_for_rewrite (PHI_RESULT (phi));
-           release_ssa_name_after_update_ssa (PHI_RESULT (phi));
-           remove_phi_node (phi, prev);
-         }
     }
 
   if (!bitmap_empty_p (pruned_idf))
@@ -2574,6 +2481,73 @@ insert_updated_phi_nodes_for (tree var, bitmap *dfs, bitmap blocks,
 }
 
 
+/* Heuristic to determine whether SSA name mappings for virtual names
+   should be discarded and their symbols rewritten from scratch.  When
+   there is a large number of mappings for virtual names, the
+   insertion of PHI nodes for the old names in the mappings takes
+   considerable more time than if we inserted PHI nodes for the
+   symbols instead.
+
+   Currently the heuristic takes these stats into account:
+
+       - Number of mappings for virtual SSA names.
+       - Number of distinct virtual symbols involved in those mappings.
+
+   If the number of virtual mappings is much larger than the number of
+   virtual symbols, then it will be faster to compute PHI insertion
+   spots for the symbols.  Even if this involves traversing the whole
+   CFG, which is what happens when symbols are renamed from scratch.  */
+
+static bool
+switch_virtuals_to_full_rewrite_p (void)
+{
+  if (update_ssa_stats.num_virtual_mappings < (unsigned) MIN_VIRTUAL_MAPPINGS)
+    return false;
+
+  if (update_ssa_stats.num_virtual_mappings
+      > (unsigned) VIRTUAL_MAPPINGS_TO_SYMS_RATIO
+        * update_ssa_stats.num_virtual_symbols)
+    return true;
+
+  return false;
+}
+
+
+/* Remove every virtual mapping and mark all the affected virtual
+   symbols for renaming.  */
+
+static void
+switch_virtuals_to_full_rewrite (void)
+{
+  unsigned i;
+  sbitmap_iterator sbi;
+
+  if (dump_file)
+    {
+      fprintf (dump_file, "\nEnabled virtual name mapping heuristic.\n");
+      fprintf (dump_file, "\tNumber of virtual mappings:       %7u\n",
+              update_ssa_stats.num_virtual_mappings);
+      fprintf (dump_file, "\tNumber of unique virtual symbols: %7u\n",
+              update_ssa_stats.num_virtual_symbols);
+      fprintf (dump_file, "Updating FUD-chains from top of CFG will be "
+                         "faster than processing\nthe name mappings.\n\n");
+    }
+
+  /* Remove all virtual names from NEW_SSA_NAMES and OLD_SSA_NAMES.
+     Note that it is not really necessary to remove the mappings from
+     REPL_TBL, that would only waste time.  */
+  EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i, sbi)
+    if (!is_gimple_reg (ssa_name (i)))
+      RESET_BIT (new_ssa_names, i);
+
+  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
+    if (!is_gimple_reg (ssa_name (i)))
+      RESET_BIT (old_ssa_names, i);
+
+  bitmap_ior_into (syms_to_rename, update_ssa_stats.virtual_symbols);
+}
+
+
 /* Given a set of newly created SSA names (NEW_SSA_NAMES) and a set of
    existing SSA names (OLD_SSA_NAMES), update the SSA form so that:
 
@@ -2641,12 +2615,13 @@ insert_updated_phi_nodes_for (tree var, bitmap *dfs, bitmap blocks,
 void
 update_ssa (unsigned update_flags)
 {
-  bitmap *dfs, blocks;
+  bitmap blocks;
   basic_block bb, start_bb;
   bitmap_iterator bi;
   unsigned i;
   sbitmap tmp;
   bool insert_phi_p;
+  sbitmap_iterator sbi;
 
   if (!need_ssa_update_p ())
     return;
@@ -2663,31 +2638,21 @@ update_ssa (unsigned update_flags)
              || update_flags == TODO_update_ssa_only_virtuals);
 
   /* If we only need to update virtuals, remove all the mappings for
-     real names before proceeding.  */
+     real names before proceeding.  The caller is responsible for
+     having dealt with the name mappings before calling update_ssa.  */
   if (update_flags == TODO_update_ssa_only_virtuals)
     {
       sbitmap_zero (old_ssa_names);
       sbitmap_zero (new_ssa_names);
       htab_empty (repl_tbl);
-      need_to_replace_names_p = false;
     }
 
-  if (update_flags == TODO_update_ssa
-      || update_flags == TODO_update_ssa_full_phi
-      || update_flags == TODO_update_ssa_only_virtuals)
-    insert_phi_p = true;
-  else
-    insert_phi_p = false;
+  insert_phi_p = (update_flags != TODO_update_ssa_no_phi);
 
   if (insert_phi_p)
     {
-      /* If the caller requested PHI nodes to be added, compute
-        dominance frontiers and initialize live-in information data
-        structures (DEF_BLOCKS).  */
-      dfs = (bitmap *) xmalloc (last_basic_block * sizeof (bitmap *));
-      FOR_EACH_BB (bb)
-       dfs[bb->index] = BITMAP_ALLOC (NULL);
-      compute_dominance_frontiers (dfs);
+      /* If the caller requested PHI nodes to be added, initialize
+        live-in information data structures (DEF_BLOCKS).  */
 
       /* For each SSA name N, the DEF_BLOCKS table describes where the
         name is defined, which blocks have PHI nodes for N, and which
@@ -2698,65 +2663,107 @@ update_ssa (unsigned update_flags)
     }
   else
     {
-      dfs = NULL;
       def_blocks = NULL;
     }
 
   blocks = BITMAP_ALLOC (NULL);
 
-  /* Determine the CFG region that we are going to update.  First add
-     all the blocks that define each of the names in NEW_SSA_NAMES
-     and OLD_SSA_NAMES.  */
-  prepare_def_sites (blocks, insert_phi_p);
-
-  /* Next, determine the nearest common dominator START_BB for all the
-     blocks in the region.  */
-  if (!bitmap_empty_p (syms_to_rename) || bitmap_empty_p (blocks))
+  /* Clear the REWRITE_THIS_STMT and REGISTER_DEFS_IN_THIS_STMT flags
+     for every statement and PHI node.  */
+  FOR_EACH_BB (bb)
     {
-      /* If the region to update is seemingly empty, or if we have to
-        rename some symbols from scratch, we need to start the
-        process at the root of the CFG.
+      block_stmt_iterator si;
+      tree phi;
 
-        FIXME, it should be possible to determine the nearest block
-        that had a definition for each of the symbols that are marked
-        for updating.  For now this seems more work than it's worth.  */
+      for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
+       {
+         REWRITE_THIS_STMT (phi) = 0;
+         REGISTER_DEFS_IN_THIS_STMT (phi) = 0;
+       }
+
+      for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
+       {
+         tree stmt = bsi_stmt (si);
+         /* We are going to use the operand cache API, such as
+            SET_USE, SET_DEF, and FOR_EACH_IMM_USE_FAST.  The operand
+            cache for each statement should be up-to-date.  */
+         gcc_assert (!stmt_modified_p (stmt));
+         REWRITE_THIS_STMT (stmt) = 0;
+         REGISTER_DEFS_IN_THIS_STMT (stmt) = 0;
+       }
+    }
+
+  /* Heuristic to avoid massive slow downs when the replacement
+     mappings include lots of virtual names.  */
+  if (insert_phi_p && switch_virtuals_to_full_rewrite_p ())
+    switch_virtuals_to_full_rewrite ();
+
+  /* If there are names defined in the replacement table, prepare
+     definition and use sites for all the names in NEW_SSA_NAMES and
+     OLD_SSA_NAMES.  */
+  if (sbitmap_first_set_bit (new_ssa_names) >= 0)
+    {
+      prepare_names_to_update (blocks, insert_phi_p);
+
+      /* If all the names in NEW_SSA_NAMES had been marked for
+        removal, and there are no symbols to rename, then there's
+        nothing else to do.  */
+      if (sbitmap_first_set_bit (new_ssa_names) < 0
+         && bitmap_empty_p (syms_to_rename))
+       goto done;
+    }
+
+  /* Next, determine the block at which to start the renaming process.  */
+  if (!bitmap_empty_p (syms_to_rename))
+    {
+      /* If we have to rename some symbols from scratch, we need to
+        start the process at the root of the CFG.  FIXME, it should
+        be possible to determine the nearest block that had a
+        definition for each of the symbols that are marked for
+        updating.  For now this seems more work than it's worth.  */
       start_bb = ENTRY_BLOCK_PTR;
+
+      /* Traverse the CFG looking for definitions and uses of symbols
+        in SYMS_TO_RENAME.  Mark interesting blocks and statements
+        and set local live-in information for the PHI placement
+        heuristics.  */
+      prepare_block_for_update (start_bb, blocks, insert_phi_p);
     }
   else
-    start_bb = nearest_common_dominator_for_set (CDI_DOMINATORS, blocks);
-
-  /* Traverse all the blocks dominated by START_BB.  Mark interesting
-     blocks and statements and set local live-in information for the
-     PHI placement heuristics.  */
-  prepare_block_for_update (start_bb, insert_phi_p, blocks, true);
-
-  /* If are going to insert PHI nodes, blocks in the dominance
-     frontier of START_BB may be affected.  Note that we don't need to
-     visit the dominator children of blocks in the dominance frontier
-     of START_BB.  None of the changes inside this region can affect
-     blocks on the outside.  */
-  if (insert_phi_p && start_bb->index >= 0)
-    EXECUTE_IF_SET_IN_BITMAP (dfs[start_bb->index], 0, i, bi)
-      prepare_block_for_update (BASIC_BLOCK (i), insert_phi_p,
-                               blocks, false);
+    {
+      /* Otherwise, the entry block to the region is the nearest
+        common dominator for the blocks in BLOCKS.  */
+      start_bb = nearest_common_dominator_for_set (CDI_DOMINATORS, blocks);
+    }
 
   /* If requested, insert PHI nodes at the iterated dominance frontier
-     of every block making new definitions for names in OLD_SSA_NAMES
+     of every block, creating new definitions for names in OLD_SSA_NAMES
      and for symbols in SYMS_TO_RENAME.  */
   if (insert_phi_p)
     {
+      bitmap *dfs;
+
+      /* If the caller requested PHI nodes to be added, compute
+        dominance frontiers.  */
+      dfs = xmalloc (last_basic_block * sizeof (bitmap));
+      FOR_EACH_BB (bb)
+       dfs[bb->index] = BITMAP_ALLOC (NULL);
+      compute_dominance_frontiers (dfs);
+
       if (sbitmap_first_set_bit (old_ssa_names) >= 0)
        {
-         /* insert_updated_phi_nodes_for will call
-            add_new_name_mapping when inserting new PHI nodes, so the
-            set OLD_SSA_NAMES will grow while we are traversing it
-            (but it will not gain any new members).  Copy
-            OLD_SSA_NAMES to a temporary for traversal.  */
+         sbitmap_iterator sbi;
+
+         /* insert_update_phi_nodes_for will call add_new_name_mapping
+            when inserting new PHI nodes, so the set OLD_SSA_NAMES
+            will grow while we are traversing it (but it will not
+            gain any new members).  Copy OLD_SSA_NAMES to a temporary
+            for traversal.  */
          sbitmap tmp = sbitmap_alloc (old_ssa_names->n_bits);
          sbitmap_copy (tmp, old_ssa_names);
-         EXECUTE_IF_SET_IN_SBITMAP (tmp, 0, i,
+         EXECUTE_IF_SET_IN_SBITMAP (tmp, 0, i, sbi)
            insert_updated_phi_nodes_for (ssa_name (i), dfs, blocks,
-                                         update_flags));
+                                         update_flags);
          sbitmap_free (tmp);
        }
 
@@ -2764,6 +2771,10 @@ update_ssa (unsigned update_flags)
        insert_updated_phi_nodes_for (referenced_var (i), dfs, blocks,
                                      update_flags);
 
+      FOR_EACH_BB (bb)
+       BITMAP_FREE (dfs[bb->index]);
+      free (dfs);
+
       /* Insertion of PHI nodes may have added blocks to the region.
         We need to re-compute START_BB to include the newly added
         blocks.  */
@@ -2773,22 +2784,8 @@ update_ssa (unsigned update_flags)
 
   /* Reset the current definition for name and symbol before renaming
      the sub-graph.  */
-  if (update_flags == TODO_update_ssa_full_phi)
-    {
-      /* If we are not prunning the IDF for new PHI nodes, set the
-        current name of every GIMPLE register to NULL.  This way, PHI
-        arguments coming from edges with uninitialized values will be
-        renamed to use the symbol's default definition.  */
-      EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i,
-       set_current_def (ssa_name (i), NULL_TREE));
-    }
-  else
-    {
-      /* Otherwise, set each old name to be its current reaching
-        definition.  */
-      EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i,
-       set_current_def (ssa_name (i), NULL_TREE));
-    }
+  EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
+    set_current_def (ssa_name (i), NULL_TREE);
 
   EXECUTE_IF_SET_IN_BITMAP (syms_to_rename, 0, i, bi)
     set_current_def (referenced_var (i), NULL_TREE);
@@ -2809,7 +2806,7 @@ update_ssa (unsigned update_flags)
       int c;
       unsigned i;
 
-      dump_repl_tbl (dump_file);
+      dump_update_ssa (dump_file);
 
       fprintf (dump_file, "Incremental SSA update started at block: %d\n\n",
               start_bb->index);
@@ -2833,465 +2830,9 @@ update_ssa (unsigned update_flags)
     }
 
   /* Free allocated memory.  */
-  if (insert_phi_p)
-    {
-      FOR_EACH_BB (bb)
-       BITMAP_FREE (dfs[bb->index]);
-      free (dfs);
-    }
-
+done:
   BITMAP_FREE (blocks);
   delete_update_ssa ();
 
   timevar_pop (TV_TREE_SSA_INCREMENTAL);
 }
-
-
-/*---------------------------------------------------------------------------
-    Functions to fix a program in invalid SSA form into valid SSA
-    form.  The main entry point here is rewrite_ssa_into_ssa.
----------------------------------------------------------------------------*/
-
-/* Called after visiting basic block BB.  Restore CURRDEFS to its
-   original value.  */
-
-static void
-ssa_rewrite_finalize_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
-                           basic_block bb ATTRIBUTE_UNUSED)
-{
-
-  /* Step 5.  Restore the current reaching definition for each variable
-     referenced in the block (in reverse order).  */
-  while (VEC_length (tree, block_defs_stack) > 0)
-    {
-      tree var = VEC_pop (tree, block_defs_stack);
-      tree saved_def;
-      
-      if (var == NULL)
-       break;
-
-      saved_def = VEC_pop (tree, block_defs_stack);
-      set_current_def (var, saved_def);
-    }
-}
-
-
-/* Register DEF (an SSA_NAME) to be a new definition for the original
-   ssa name VAR and push VAR's current reaching definition
-   into the stack pointed by BLOCK_DEFS_P.  */
-
-static void
-ssa_register_new_def (tree var, tree def)
-{
-  tree currdef;
-   
-  /* If this variable is set in a single basic block and all uses are
-     dominated by the set(s) in that single basic block, then there is
-     nothing to do.  TODO we should not be called at all, and just
-     keep the original name.  */
-  if (get_phi_state (var) == NEED_PHI_STATE_NO)
-    {
-      set_current_def (var, def);
-      return;
-    }
-
-  currdef = get_current_def (var);
-
-  /* Push the current reaching definition into *BLOCK_DEFS_P.  This stack is
-     later used by the dominator tree callbacks to restore the reaching
-     definitions for all the variables defined in the block after a recursive
-     visit to all its immediately dominated blocks.  */
-  VEC_reserve (tree, heap, block_defs_stack, 2);
-  VEC_quick_push (tree, block_defs_stack, currdef);
-  VEC_quick_push (tree, block_defs_stack, var);
-
-  /* Set the current reaching definition for VAR to be DEF.  */
-  set_current_def (var, def);
-}
-
-
-/* Same as rewrite_stmt, for rewriting ssa names.  */
-
-static void
-ssa_rewrite_stmt (struct dom_walk_data *walk_data,
-                 basic_block bb ATTRIBUTE_UNUSED,
-                 block_stmt_iterator si)
-{
-  stmt_ann_t ann;
-  tree stmt, var;
-  ssa_op_iter iter;
-  use_operand_p use_p;
-  def_operand_p def_p;
-  sbitmap names_to_rename = walk_data->global_data;
-
-  stmt = bsi_stmt (si);
-  ann = stmt_ann (stmt);
-
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    {
-      fprintf (dump_file, "Renaming statement ");
-      print_generic_stmt (dump_file, stmt, TDF_SLIM);
-      fprintf (dump_file, "\n");
-    }
-
-  /* We have just scanned the code for operands.  No statement should
-     be modified.  */
-  gcc_assert (!ann->modified);
-
-  /* Step 1.  Rewrite USES and VUSES in the statement.  */
-  FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES | SSA_OP_ALL_KILLS)
-    {
-      if (TEST_BIT (names_to_rename, SSA_NAME_VERSION (USE_FROM_PTR (use_p))))
-       SET_USE (use_p, get_reaching_def (USE_FROM_PTR (use_p)));
-    }
-
-  /* Step 2.  Register the statement's DEF and VDEF operands.  */
-  FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_ALL_DEFS)
-    {
-      var = DEF_FROM_PTR (def_p);
-
-      if (!TEST_BIT (names_to_rename, SSA_NAME_VERSION (var)))
-       continue;
-
-      SET_DEF (def_p, duplicate_ssa_name (var, stmt));
-      ssa_register_new_def (var, DEF_FROM_PTR (def_p));
-    }
-}
-
-
-/* Ditto, for ssa name rewriting.  */
-
-static void
-ssa_rewrite_phi_arguments (struct dom_walk_data *walk_data, basic_block bb)
-{
-  edge e;
-  sbitmap names_to_rename = walk_data->global_data;
-  use_operand_p op;
-  edge_iterator ei;
-
-  FOR_EACH_EDGE (e, ei, bb->succs)
-    {
-      tree phi;
-
-      if (e->dest == EXIT_BLOCK_PTR)
-       continue;
-
-      for (phi = phi_nodes (e->dest); phi; phi = PHI_CHAIN (phi))
-       {
-         op = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
-         if (TREE_CODE (USE_FROM_PTR (op)) != SSA_NAME)
-           continue;
-         
-         if (!TEST_BIT (names_to_rename, SSA_NAME_VERSION (USE_FROM_PTR (op))))
-           continue; 
-
-         SET_USE (op, get_reaching_def (USE_FROM_PTR (op)));
-         if (e->flags & EDGE_ABNORMAL)
-           SSA_NAME_OCCURS_IN_ABNORMAL_PHI (USE_FROM_PTR (op)) = 1;
-       }
-    }
-}
-
-/* Ditto, for rewriting ssa names.  */
-
-static void
-ssa_rewrite_initialize_block (struct dom_walk_data *walk_data, basic_block bb)
-{
-  tree phi, new_name;
-  sbitmap names_to_rename = walk_data->global_data;
-  edge e;
-  bool abnormal_phi;
-  edge_iterator ei;
-
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file, "\n\nRenaming block #%d\n\n", bb->index);
-
-  /* Mark the unwind point for this block.  */
-  VEC_safe_push (tree, heap, block_defs_stack, NULL_TREE);
-
-  FOR_EACH_EDGE (e, ei, bb->preds)
-    if (e->flags & EDGE_ABNORMAL)
-      break;
-  abnormal_phi = (e != NULL);
-
-  /* Step 1.  Register new definitions for every PHI node in the block.
-     Conceptually, all the PHI nodes are executed in parallel and each PHI
-     node introduces a new version for the associated variable.  */
-  for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
-    {
-      tree result = PHI_RESULT (phi);
-
-      if (TEST_BIT (names_to_rename, SSA_NAME_VERSION (result)))
-       {
-         new_name = duplicate_ssa_name (result, phi);
-         SET_PHI_RESULT (phi, new_name);
-
-         if (abnormal_phi)
-           SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_name) = 1;
-         ssa_register_new_def (result, new_name);
-       }
-    }
-}
-
-
-/* Same as mark_def_sites, but works over SSA names.  */
-
-static void
-ssa_mark_def_sites (struct dom_walk_data *walk_data,
-                   basic_block bb,
-                   block_stmt_iterator bsi)
-{
-  struct mark_def_sites_global_data *gd = walk_data->global_data;
-  bitmap kills = gd->kills;
-  size_t uid, def_uid;
-  tree stmt, use, def;
-  ssa_op_iter iter;
-
-  /* Mark all the blocks that have definitions for each variable in the
-     names_to_rename bitmap.  */
-  stmt = bsi_stmt (bsi);
-  update_stmt_if_modified (stmt);
-
-  /* If a variable is used before being set, then the variable is live
-     across a block boundary, so mark it live-on-entry to BB.  */
-  FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_ALL_USES | SSA_OP_ALL_KILLS)
-    {
-      uid = SSA_NAME_VERSION (use);
-
-      if (TEST_BIT (gd->names_to_rename, uid)
-         && !bitmap_bit_p (kills, uid))
-       set_livein_block (use, bb);
-    }
-         
-  /* Now process the definition made by this statement.  Mark the
-     variables in KILLS.  */
-  FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
-    {
-      def_uid = SSA_NAME_VERSION (def);
-
-      if (TEST_BIT (gd->names_to_rename, def_uid))
-       {
-         set_def_block (def, bb, false);
-         bitmap_set_bit (kills, def_uid);
-       }
-    }
-}
-
-
-/* Block initialization routine for mark_def_sites.  Clear the 
-   KILLS bitmap at the start of each block.  */
-
-static void
-ssa_mark_def_sites_initialize_block (struct dom_walk_data *walk_data,
-                                    basic_block bb)
-{
-  struct mark_def_sites_global_data *gd = walk_data->global_data;
-  bitmap kills = gd->kills;
-  tree phi, def;
-  unsigned def_uid;
-
-  bitmap_clear (kills);
-
-  for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
-    {
-      def = PHI_RESULT (phi);
-      def_uid = SSA_NAME_VERSION (def);
-
-      if (!TEST_BIT (gd->names_to_rename, def_uid))
-       continue;
-
-      set_def_block (def, bb, true);
-      bitmap_set_bit (kills, def_uid);
-    }
-}
-
-/* Marks ssa names used as arguments of phis at the end of BB.  */
-
-static void
-ssa_mark_phi_uses (struct dom_walk_data *walk_data, basic_block bb)
-{
-  struct mark_def_sites_global_data *gd = walk_data->global_data;
-  bitmap kills = gd->kills;
-  edge e;
-  tree phi, use;
-  unsigned uid;
-  edge_iterator ei;
-
-  FOR_EACH_EDGE (e, ei, bb->succs)
-    {
-      if (e->dest == EXIT_BLOCK_PTR)
-       continue;
-
-      for (phi = phi_nodes (e->dest); phi; phi = PHI_CHAIN (phi))
-       {
-         use = PHI_ARG_DEF_FROM_EDGE (phi, e);
-         if (TREE_CODE (use) != SSA_NAME)
-           continue;
-
-         uid = SSA_NAME_VERSION (use);
-
-         if (TEST_BIT (gd->names_to_rename, uid)
-             && !bitmap_bit_p (kills, uid))
-           set_livein_block (use, bb);
-       }
-    }
-}
-       
-   
-/* The marked ssa names may have more than one definition;
-   add PHI nodes and rewrite them to fix this.  */
-
-void
-rewrite_ssa_into_ssa (void)
-{
-  bitmap *dfs;
-  basic_block bb;
-  struct dom_walk_data walk_data;
-  struct mark_def_sites_global_data mark_def_sites_global_data;
-  unsigned i;
-  sbitmap snames_to_rename;
-  bitmap to_rename;
-  bitmap_iterator bi;
-  
-  if (!any_marked_for_rewrite_p ())
-    return;
-  to_rename = marked_ssa_names ();
-
-  timevar_push (TV_TREE_SSA_OTHER);
-
-  /* Allocate memory for the DEF_BLOCKS hash table.  */
-  def_blocks = htab_create (num_ssa_names,
-                           def_blocks_hash, def_blocks_eq, def_blocks_free);
-
-  /* Initialize dominance frontier and immediate dominator bitmaps. 
-     Also count the number of predecessors for each block.  Doing so
-     can save significant time during PHI insertion for large graphs.  */
-  dfs = (bitmap *) xmalloc (last_basic_block * sizeof (bitmap *));
-  FOR_EACH_BB (bb)
-    dfs[bb->index] = BITMAP_ALLOC (NULL);
-
-  /* Ensure that the dominance information is OK.  */
-  calculate_dominance_info (CDI_DOMINATORS);
-
-  /* Compute dominance frontiers.  */
-  compute_dominance_frontiers (dfs);
-
-  /* Setup callbacks for the generic dominator tree walker to find and
-     mark definition sites.  */
-  walk_data.walk_stmts_backward = false;
-  walk_data.dom_direction = CDI_DOMINATORS;
-  walk_data.interesting_blocks = NULL;
-  walk_data.initialize_block_local_data = NULL;
-  walk_data.before_dom_children_before_stmts
-         = ssa_mark_def_sites_initialize_block;
-  walk_data.before_dom_children_walk_stmts = ssa_mark_def_sites;
-  walk_data.before_dom_children_after_stmts = ssa_mark_phi_uses; 
-  walk_data.after_dom_children_before_stmts =  NULL;
-  walk_data.after_dom_children_walk_stmts =  NULL;
-  walk_data.after_dom_children_after_stmts =  NULL;
-
-  snames_to_rename = sbitmap_alloc (num_ssa_names);
-  sbitmap_zero (snames_to_rename);
-  EXECUTE_IF_SET_IN_BITMAP (to_rename, 0, i, bi)
-    {
-      SET_BIT (snames_to_rename, i);
-      set_current_def (ssa_name (i), NULL_TREE);
-    }
-
-  mark_def_sites_global_data.kills = BITMAP_ALLOC (NULL);
-  mark_def_sites_global_data.names_to_rename = snames_to_rename;
-  walk_data.global_data = &mark_def_sites_global_data;
-
-  block_defs_stack = VEC_alloc (tree, heap, 10);
-
-  /* We do not have any local data.  */
-  walk_data.block_local_data_size = 0;
-
-  /* Initialize the dominator walker.  */
-  init_walk_dominator_tree (&walk_data);
-
-  /* Recursively walk the dominator tree.  */
-  walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
-
-  /* Finalize the dominator walker.  */
-  fini_walk_dominator_tree (&walk_data);
-
-  /* We no longer need this bitmap, clear and free it.  */
-  BITMAP_FREE (mark_def_sites_global_data.kills);
-
-  /* Insert PHI nodes at dominance frontiers of definition blocks.  */
-  insert_phi_nodes (dfs, to_rename);
-
-  /* Rewrite all the basic blocks in the program.  */
-  timevar_push (TV_TREE_SSA_REWRITE_BLOCKS);
-
-  /* Setup callbacks for the generic dominator tree walker.  */
-  walk_data.walk_stmts_backward = false;
-  walk_data.dom_direction = CDI_DOMINATORS;
-  walk_data.interesting_blocks = NULL;
-  walk_data.initialize_block_local_data = NULL;
-  walk_data.before_dom_children_before_stmts = ssa_rewrite_initialize_block;
-  walk_data.before_dom_children_walk_stmts = ssa_rewrite_stmt;
-  walk_data.before_dom_children_after_stmts = ssa_rewrite_phi_arguments;
-  walk_data.after_dom_children_before_stmts = NULL;
-  walk_data.after_dom_children_walk_stmts =  NULL;
-  walk_data.after_dom_children_after_stmts =  ssa_rewrite_finalize_block;
-  walk_data.global_data = snames_to_rename;
-  walk_data.block_local_data_size = 0;
-
-  /* Initialize the dominator walker.  */
-  init_walk_dominator_tree (&walk_data);
-
-  /* Recursively walk the dominator tree rewriting each statement in
-     each basic block.  */
-  walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
-
-  /* Finalize the dominator walker.  */
-  fini_walk_dominator_tree (&walk_data);
-
-  unmark_all_for_rewrite ();
-
-  EXECUTE_IF_SET_IN_BITMAP (to_rename, 0, i, bi)
-    {
-      /* Free SSA_NAME_AUX.  We don't have to zero it because
-        release_ssa_name will.  */
-      if (SSA_NAME_AUX (ssa_name (i)))
-       free (SSA_NAME_AUX (ssa_name (i)));
-
-      release_ssa_name (ssa_name (i));
-    }
-
-  sbitmap_free (snames_to_rename);
-
-  timevar_pop (TV_TREE_SSA_REWRITE_BLOCKS);
-
-  /* Debugging dumps.  */
-  if (dump_file && (dump_flags & TDF_STATS))
-    {
-      dump_dfa_stats (dump_file);
-      dump_tree_ssa_stats (dump_file);
-    }
-
-  /* Free allocated memory.  */
-  FOR_EACH_BB (bb)
-    BITMAP_FREE (dfs[bb->index]);
-  free (dfs);
-
-  htab_delete (def_blocks);
-
-#ifdef ENABLE_CHECKING
-  for (i = 1; i < num_ssa_names; i++)
-    {
-      tree name = ssa_name (i);
-      if (!name)
-       continue;
-
-      gcc_assert (SSA_NAME_AUX (name) == NULL);
-    }
-#endif
-
-  BITMAP_FREE (to_rename);
-  
-  VEC_free (tree, heap, block_defs_stack);
-  timevar_pop (TV_TREE_SSA_OTHER);
-}