/* Rewrite a program in Normal form into SSA.
- Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 2001-2013 Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>
This file is part of GCC.
#include "tm_p.h"
#include "langhooks.h"
#include "basic-block.h"
-#include "output.h"
#include "function.h"
-#include "tree-pretty-print.h"
#include "gimple-pretty-print.h"
#include "bitmap.h"
#include "tree-flow.h"
#include "gimple.h"
#include "tree-inline.h"
-#include "timevar.h"
#include "hashtab.h"
-#include "tree-dump.h"
#include "tree-pass.h"
#include "cfgloop.h"
#include "domwalk.h"
#include "params.h"
-#include "vecprim.h"
+#include "diagnostic-core.h"
/* This file builds the SSA form for a function as described in:
definitions for VAR. */
struct def_blocks_d
{
- /* The variable. */
- tree var;
-
/* Blocks that contain definitions of VAR. Bit I will be set if the
Ith block contains a definition of VAR. */
bitmap def_blocks;
bitmap livein_blocks;
};
+typedef struct def_blocks_d *def_blocks_p;
-/* Each entry in DEF_BLOCKS contains an element of type STRUCT
- DEF_BLOCKS_D, mapping a variable VAR to a bitmap describing all the
- basic blocks where VAR is defined (assigned a new value). It also
- contains a bitmap of all the blocks where VAR is live-on-entry
- (i.e., there is a use of VAR in block B without a preceding
- definition in B). The live-on-entry information is used when
- computing PHI pruning heuristics. */
-static htab_t def_blocks;
/* Stack of trees used to restore the global currdefs to its original
state after completing rewriting of a block and its dominator
- A NULL node at the top entry is used to mark the last slot
associated with the current block. */
-static VEC(tree,heap) *block_defs_stack;
+static vec<tree> block_defs_stack;
/* Set of existing SSA names being replaced by update_ssa. */
released after we finish updating the SSA web. */
static bitmap names_to_release;
-static VEC(gimple_vec, heap) *phis_to_rewrite;
+/* vec of vec of PHIs to rewrite in a basic block. Element I corresponds
+ the to basic block with index I. Allocated once per compilation, *not*
+ released between different functions. */
+static vec<gimple_vec> phis_to_rewrite;
/* The bitmap of non-NULL elements of PHIS_TO_REWRITE. */
static bitmap blocks_with_phis_to_rewrite;
/* Growth factor for NEW_SSA_NAMES and OLD_SSA_NAMES. These sets need
- to grow as the callers to register_new_name_mapping will typically
- create new names on the fly. FIXME. Currently set to 1/3 to avoid
- frequent reallocations but still need to find a reasonable growth
- strategy. */
+ to grow as the callers to create_new_def_for will create new names on
+ the fly.
+ FIXME. Currently set to 1/3 to avoid frequent reallocations but still
+ need to find a reasonable growth strategy. */
#define NAME_SETS_GROWTH_FACTOR (MAX (3, num_ssa_names / 3))
-/* Tuple used to represent replacement mappings. */
-struct repl_map_d
-{
- tree name;
- bitmap set;
-};
-
-
-/* NEW -> OLD_SET replacement table. If we are replacing several
- existing SSA names O_1, O_2, ..., O_j with a new name N_i,
- then REPL_TBL[N_i] = { O_1, O_2, ..., O_j }. */
-static htab_t repl_tbl;
/* The function the SSA updating data structures have been initialized for.
- NULL if they need to be initialized by register_new_name_mapping. */
+ NULL if they need to be initialized by create_new_def_for. */
static struct function *update_ssa_initialized_fn = NULL;
-/* 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
{
bitmap kills;
};
-
-/* Information stored for SSA names. */
-struct ssa_name_info
+/* Information stored for both SSA names and decls. */
+struct common_info_d
{
- /* The current reaching definition replacing this SSA name. */
- tree current_def;
-
/* This field indicates whether or not the variable may need PHI nodes.
See the enum's definition for more detailed information about the
states. */
ENUM_BITFIELD (need_phi_state) need_phi_state : 2;
+ /* The current reaching definition replacing this var. */
+ tree current_def;
+
+ /* Definitions for this var. */
+ struct def_blocks_d def_blocks;
+};
+
+/* The information associated with decls and SSA names. */
+typedef struct common_info_d *common_info_p;
+
+/* Information stored for decls. */
+struct var_info_d
+{
+ /* The variable. */
+ tree var;
+
+ /* Information stored for both SSA names and decls. */
+ struct common_info_d info;
+};
+
+/* The information associated with decls. */
+typedef struct var_info_d *var_info_p;
+
+
+/* Each entry in VAR_INFOS contains an element of type STRUCT
+ VAR_INFO_D. */
+static htab_t var_infos;
+
+
+/* Information stored for SSA names. */
+struct ssa_name_info
+{
/* Age of this record (so that info_for_ssa_name table can be cleared
quickly); if AGE < CURRENT_INFO_FOR_SSA_NAME_AGE, then the fields
are assumed to be null. */
unsigned age;
+
+ /* Replacement mappings, allocated from update_ssa_obstack. */
+ bitmap repl_set;
+
+ /* Information stored for both SSA names and decls. */
+ struct common_info_d info;
};
/* The information associated with names. */
typedef struct ssa_name_info *ssa_name_info_p;
-DEF_VEC_P (ssa_name_info_p);
-DEF_VEC_ALLOC_P (ssa_name_info_p, heap);
-static VEC(ssa_name_info_p, heap) *info_for_ssa_name;
+static vec<ssa_name_info_p> info_for_ssa_name;
static unsigned current_info_for_ssa_name_age;
+static bitmap_obstack update_ssa_obstack;
+
/* The set of blocks affected by update_ssa. */
static bitmap blocks_to_update;
extern void debug_update_ssa (void);
extern void dump_names_replaced_by (FILE *, tree);
extern void debug_names_replaced_by (tree);
-extern void dump_def_blocks (FILE *);
-extern void debug_def_blocks (void);
+extern void dump_var_infos (FILE *);
+extern void debug_var_infos (void);
extern void dump_defs_stack (FILE *, int);
extern void debug_defs_stack (int);
extern void dump_currdefs (FILE *);
extern void debug_currdefs (void);
+
+/* The set of symbols we ought to re-write into SSA form in update_ssa. */
+static bitmap symbols_to_rename_set;
+static vec<tree> symbols_to_rename;
+
+/* Mark SYM for renaming. */
+
+static void
+mark_for_renaming (tree sym)
+{
+ if (!symbols_to_rename_set)
+ symbols_to_rename_set = BITMAP_ALLOC (NULL);
+ if (bitmap_set_bit (symbols_to_rename_set, DECL_UID (sym)))
+ symbols_to_rename.safe_push (sym);
+}
+
+/* Return true if SYM is marked for renaming. */
+
+static bool
+marked_for_renaming (tree sym)
+{
+ if (!symbols_to_rename_set || sym == NULL_TREE)
+ return false;
+ return bitmap_bit_p (symbols_to_rename_set, DECL_UID (sym));
+}
+
+
/* Return true if STMT needs to be rewritten. When renaming a subset
of the variables, not all statements will be processed. This is
decided in mark_def_sites. */
get_ssa_name_ann (tree name)
{
unsigned ver = SSA_NAME_VERSION (name);
- unsigned len = VEC_length (ssa_name_info_p, info_for_ssa_name);
+ unsigned len = info_for_ssa_name.length ();
struct ssa_name_info *info;
+ /* Re-allocate the vector at most once per update/into-SSA. */
if (ver >= len)
- {
- unsigned new_len = num_ssa_names;
+ info_for_ssa_name.safe_grow_cleared (num_ssa_names);
- VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name, new_len);
- while (len++ < new_len)
- {
- struct ssa_name_info *info = XCNEW (struct ssa_name_info);
- info->age = current_info_for_ssa_name_age;
- VEC_quick_push (ssa_name_info_p, info_for_ssa_name, info);
- }
+ /* But allocate infos lazily. */
+ info = info_for_ssa_name[ver];
+ if (!info)
+ {
+ info = XCNEW (struct ssa_name_info);
+ info->age = current_info_for_ssa_name_age;
+ info->info.need_phi_state = NEED_PHI_STATE_UNKNOWN;
+ info_for_ssa_name[ver] = info;
}
- info = VEC_index (ssa_name_info_p, info_for_ssa_name, ver);
if (info->age < current_info_for_ssa_name_age)
{
- info->need_phi_state = NEED_PHI_STATE_UNKNOWN;
- info->current_def = NULL_TREE;
info->age = current_info_for_ssa_name_age;
+ info->repl_set = NULL;
+ info->info.need_phi_state = NEED_PHI_STATE_UNKNOWN;
+ info->info.current_def = NULL_TREE;
+ info->info.def_blocks.def_blocks = NULL;
+ info->info.def_blocks.phi_blocks = NULL;
+ info->info.def_blocks.livein_blocks = NULL;
}
return info;
}
+/* Return and allocate the auxiliar information for DECL. */
+
+static inline var_info_p
+get_var_info (tree decl)
+{
+ struct var_info_d vi;
+ void **slot;
+ vi.var = decl;
+ slot = htab_find_slot_with_hash (var_infos, &vi, DECL_UID (decl), INSERT);
+ if (*slot == NULL)
+ {
+ var_info_p v = XCNEW (struct var_info_d);
+ v->var = decl;
+ *slot = (void *)v;
+ return v;
+ }
+ return (var_info_p) *slot;
+}
+
/* Clears info for SSA names. */
clear_ssa_name_info (void)
{
current_info_for_ssa_name_age++;
-}
-
-/* Get phi_state field for VAR. */
-
-static inline enum need_phi_state
-get_phi_state (tree var)
-{
- if (TREE_CODE (var) == SSA_NAME)
- return get_ssa_name_ann (var)->need_phi_state;
- else
- return var_ann (var)->need_phi_state;
+ /* If current_info_for_ssa_name_age wraps we use stale information.
+ Asser that this does not happen. */
+ gcc_assert (current_info_for_ssa_name_age != 0);
}
-/* Sets phi_state field for VAR to STATE. */
+/* Get access to the auxiliar information stored per SSA name or decl. */
-static inline void
-set_phi_state (tree var, enum need_phi_state state)
+static inline common_info_p
+get_common_info (tree var)
{
if (TREE_CODE (var) == SSA_NAME)
- get_ssa_name_ann (var)->need_phi_state = state;
+ return &get_ssa_name_ann (var)->info;
else
- var_ann (var)->need_phi_state = state;
+ return &get_var_info (var)->info;
}
tree
get_current_def (tree var)
{
- if (TREE_CODE (var) == SSA_NAME)
- return get_ssa_name_ann (var)->current_def;
- else
- return var_ann (var)->current_def;
+ return get_common_info (var)->current_def;
}
void
set_current_def (tree var, tree def)
{
- if (TREE_CODE (var) == SSA_NAME)
- get_ssa_name_ann (var)->current_def = def;
- else
- var_ann (var)->current_def = def;
-}
-
-
-/* Compute global livein information given the set of blocks where
- an object is locally live at the start of the block (LIVEIN)
- and the set of blocks where the object is defined (DEF_BLOCKS).
-
- Note: This routine augments the existing local livein information
- to include global livein (i.e., it modifies the underlying bitmap
- for LIVEIN). */
-
-void
-compute_global_livein (bitmap livein ATTRIBUTE_UNUSED, bitmap def_blocks ATTRIBUTE_UNUSED)
-{
- basic_block bb, *worklist, *tos;
- unsigned i;
- bitmap_iterator bi;
-
- tos = worklist
- = (basic_block *) xmalloc (sizeof (basic_block) * (last_basic_block + 1));
-
- EXECUTE_IF_SET_IN_BITMAP (livein, 0, i, bi)
- *tos++ = BASIC_BLOCK (i);
-
- /* Iterate until the worklist is empty. */
- while (tos != worklist)
- {
- edge e;
- edge_iterator ei;
-
- /* Pull a block off the worklist. */
- bb = *--tos;
-
- /* For each predecessor block. */
- FOR_EACH_EDGE (e, ei, bb->preds)
- {
- basic_block pred = e->src;
- int pred_index = pred->index;
-
- /* None of this is necessary for the entry block. */
- if (pred != ENTRY_BLOCK_PTR
- && ! bitmap_bit_p (livein, pred_index)
- && ! bitmap_bit_p (def_blocks, pred_index))
- {
- *tos++ = pred;
- bitmap_set_bit (livein, pred_index);
- }
- }
- }
-
- free (worklist);
+ get_common_info (var)->current_def = def;
}
-
/* Cleans up the REWRITE_THIS_STMT and REGISTER_DEFS_IN_THIS_STMT flags for
all statements in basic block BB. */
/* 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 (!gimple_modified_p (stmt));
+ gcc_checking_assert (!gimple_modified_p (stmt));
set_rewrite_uses (stmt, false);
set_register_defs (stmt, false);
}
static void
mark_block_for_update (basic_block bb)
{
- gcc_assert (blocks_to_update != NULL);
+ gcc_checking_assert (blocks_to_update != NULL);
if (!bitmap_set_bit (blocks_to_update, bb->index))
return;
initialize_flags_in_bb (bb);
DEF_BLOCKS, a new one is created and returned. */
static inline struct def_blocks_d *
-get_def_blocks_for (tree var)
+get_def_blocks_for (common_info_p info)
{
- struct def_blocks_d db, *db_p;
- void **slot;
-
- db.var = var;
- slot = htab_find_slot (def_blocks, (void *) &db, INSERT);
- if (*slot == NULL)
+ struct def_blocks_d *db_p = &info->def_blocks;
+ if (!db_p->def_blocks)
{
- db_p = XNEW (struct def_blocks_d);
- db_p->var = var;
- db_p->def_blocks = BITMAP_ALLOC (NULL);
- db_p->phi_blocks = BITMAP_ALLOC (NULL);
- db_p->livein_blocks = BITMAP_ALLOC (NULL);
- *slot = (void *) db_p;
+ db_p->def_blocks = BITMAP_ALLOC (&update_ssa_obstack);
+ db_p->phi_blocks = BITMAP_ALLOC (&update_ssa_obstack);
+ db_p->livein_blocks = BITMAP_ALLOC (&update_ssa_obstack);
}
- else
- db_p = (struct def_blocks_d *) *slot;
return db_p;
}
set_def_block (tree var, basic_block bb, bool phi_p)
{
struct def_blocks_d *db_p;
- enum need_phi_state state;
+ common_info_p info;
- state = get_phi_state (var);
- db_p = get_def_blocks_for (var);
+ info = get_common_info (var);
+ db_p = get_def_blocks_for (info);
/* Set the bit corresponding to the block where VAR is defined. */
bitmap_set_bit (db_p->def_blocks, bb->index);
variable which was not dominated by the block containing the
definition(s). In this case we may need a PHI node, so enter
state NEED_PHI_STATE_MAYBE. */
- if (state == NEED_PHI_STATE_UNKNOWN)
- set_phi_state (var, NEED_PHI_STATE_NO);
+ if (info->need_phi_state == NEED_PHI_STATE_UNKNOWN)
+ info->need_phi_state = NEED_PHI_STATE_NO;
else
- set_phi_state (var, NEED_PHI_STATE_MAYBE);
+ info->need_phi_state = NEED_PHI_STATE_MAYBE;
}
static void
set_livein_block (tree var, basic_block bb)
{
+ common_info_p info;
struct def_blocks_d *db_p;
- enum need_phi_state state = get_phi_state (var);
- db_p = get_def_blocks_for (var);
+ info = get_common_info (var);
+ db_p = get_def_blocks_for (info);
/* Set the bit corresponding to the block where VAR is live in. */
bitmap_set_bit (db_p->livein_blocks, bb->index);
by the single block containing the definition(s) of this variable. If
it is, then we remain in NEED_PHI_STATE_NO, otherwise we transition to
NEED_PHI_STATE_MAYBE. */
- if (state == NEED_PHI_STATE_NO)
+ if (info->need_phi_state == NEED_PHI_STATE_NO)
{
int def_block_index = bitmap_first_set_bit (db_p->def_blocks);
if (def_block_index == -1
|| ! dominated_by_p (CDI_DOMINATORS, bb,
BASIC_BLOCK (def_block_index)))
- set_phi_state (var, NEED_PHI_STATE_MAYBE);
+ info->need_phi_state = NEED_PHI_STATE_MAYBE;
}
else
- set_phi_state (var, NEED_PHI_STATE_MAYBE);
-}
-
-
-/* Return true if symbol SYM is marked for renaming. */
-
-bool
-symbol_marked_for_renaming (tree sym)
-{
- return bitmap_bit_p (SYMS_TO_RENAME (cfun), DECL_UID (sym));
+ info->need_phi_state = NEED_PHI_STATE_MAYBE;
}
unsigned ver = SSA_NAME_VERSION (name);
if (!new_ssa_names)
return false;
- return ver < new_ssa_names->n_bits && TEST_BIT (old_ssa_names, ver);
+ return (ver < SBITMAP_SIZE (new_ssa_names)
+ && bitmap_bit_p (old_ssa_names, ver));
}
unsigned ver = SSA_NAME_VERSION (name);
if (!new_ssa_names)
return false;
- return ver < new_ssa_names->n_bits && TEST_BIT (new_ssa_names, ver);
-}
-
-
-/* Hashing and equality functions for REPL_TBL. */
-
-static hashval_t
-repl_map_hash (const void *p)
-{
- return htab_hash_pointer ((const void *)((const struct repl_map_d *)p)->name);
-}
-
-static int
-repl_map_eq (const void *p1, const void *p2)
-{
- return ((const struct repl_map_d *)p1)->name
- == ((const struct repl_map_d *)p2)->name;
-}
-
-static void
-repl_map_free (void *p)
-{
- BITMAP_FREE (((struct repl_map_d *)p)->set);
- free (p);
+ return (ver < SBITMAP_SIZE (new_ssa_names)
+ && bitmap_bit_p (new_ssa_names, ver));
}
static inline bitmap
names_replaced_by (tree new_tree)
{
- struct repl_map_d m;
- void **slot;
-
- m.name = new_tree;
- slot = htab_find_slot (repl_tbl, (void *) &m, NO_INSERT);
-
- /* If N was not registered in the replacement table, return NULL. */
- if (slot == NULL || *slot == NULL)
- return NULL;
-
- return ((struct repl_map_d *) *slot)->set;
+ return get_ssa_name_ann (new_tree)->repl_set;
}
static inline void
add_to_repl_tbl (tree new_tree, tree old)
{
- struct repl_map_d m, *mp;
- void **slot;
-
- m.name = new_tree;
- slot = htab_find_slot (repl_tbl, (void *) &m, INSERT);
- if (*slot == NULL)
- {
- mp = XNEW (struct repl_map_d);
- mp->name = new_tree;
- mp->set = BITMAP_ALLOC (NULL);
- *slot = (void *) mp;
- }
- else
- mp = (struct repl_map_d *) *slot;
-
- bitmap_set_bit (mp->set, SSA_NAME_VERSION (old));
+ bitmap *set = &get_ssa_name_ann (new_tree)->repl_set;
+ if (!*set)
+ *set = BITMAP_ALLOC (&update_ssa_obstack);
+ bitmap_set_bit (*set, SSA_NAME_VERSION (old));
}
static void
add_new_name_mapping (tree new_tree, tree old)
{
- timevar_push (TV_TREE_SSA_INCREMENTAL);
-
/* OLD and NEW_TREE must be different SSA names for the same symbol. */
- gcc_assert (new_tree != old && SSA_NAME_VAR (new_tree) == SSA_NAME_VAR (old));
-
- /* If this mapping is for virtual names, we will need to update
- virtual operands. If this is a mapping for .MEM, then we gather
- the symbols associated with each name. */
- if (!is_gimple_reg (new_tree))
- {
- tree sym;
-
- update_ssa_stats.num_virtual_mappings++;
- update_ssa_stats.num_virtual_symbols++;
-
- /* 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_tree);
- bitmap_set_bit (update_ssa_stats.virtual_symbols, DECL_UID (sym));
- }
+ gcc_checking_assert (new_tree != old
+ && SSA_NAME_VAR (new_tree) == 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)
+ if (SBITMAP_SIZE (new_ssa_names) <= num_ssa_names - 1)
{
unsigned int new_sz = num_ssa_names + NAME_SETS_GROWTH_FACTOR;
new_ssa_names = sbitmap_resize (new_ssa_names, new_sz, 0);
/* Register NEW_TREE and OLD in NEW_SSA_NAMES and OLD_SSA_NAMES,
respectively. */
- SET_BIT (new_ssa_names, SSA_NAME_VERSION (new_tree));
- SET_BIT (old_ssa_names, SSA_NAME_VERSION (old));
-
- /* Update mapping counter to use in the virtual mapping heuristic. */
- update_ssa_stats.num_total_mappings++;
-
- timevar_pop (TV_TREE_SSA_INCREMENTAL);
+ bitmap_set_bit (new_ssa_names, SSA_NAME_VERSION (new_tree));
+ bitmap_set_bit (old_ssa_names, SSA_NAME_VERSION (old));
}
form, force an operand scan on every statement. */
update_stmt (stmt);
- gcc_assert (blocks_to_update == NULL);
+ gcc_checking_assert (blocks_to_update == NULL);
set_register_defs (stmt, false);
set_rewrite_uses (stmt, false);
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
{
tree sym = USE_FROM_PTR (use_p);
- gcc_assert (DECL_P (sym));
+ gcc_checking_assert (DECL_P (sym));
set_rewrite_uses (stmt, true);
}
if (rewrite_uses_p (stmt))
- SET_BIT (interesting_blocks, bb->index);
+ bitmap_set_bit (interesting_blocks, bb->index);
return;
}
/* 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)
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
{
tree sym = USE_FROM_PTR (use_p);
- gcc_assert (DECL_P (sym));
+ gcc_checking_assert (DECL_P (sym));
if (!bitmap_bit_p (kills, DECL_UID (sym)))
set_livein_block (sym, bb);
set_rewrite_uses (stmt, true);
/* Now process the defs. Mark BB as the definition block and add
each def to the set of killed symbols. */
- FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
+ FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
{
- gcc_assert (DECL_P (def));
+ gcc_checking_assert (DECL_P (def));
set_def_block (def, bb, false);
bitmap_set_bit (kills, DECL_UID (def));
set_register_defs (stmt, true);
/* If we found the statement interesting then also mark the block BB
as interesting. */
if (rewrite_uses_p (stmt) || register_defs_p (stmt))
- SET_BIT (interesting_blocks, bb->index);
+ bitmap_set_bit (interesting_blocks, bb->index);
}
/* Structure used by prune_unused_phi_nodes to record bounds of the intervals
static void
prune_unused_phi_nodes (bitmap phis, bitmap kills, bitmap uses)
{
- VEC(int, heap) *worklist;
+ vec<int> worklist;
bitmap_iterator bi;
unsigned i, b, p, u, top;
bitmap live_phis;
dfs_out numbers, increase the dfs number by one (so that it corresponds
to the start of the following interval, not to the end of the current
one). We use WORKLIST as a stack. */
- worklist = VEC_alloc (int, heap, n_defs + 1);
- VEC_quick_push (int, worklist, 1);
+ worklist.create (n_defs + 1);
+ worklist.quick_push (1);
top = 1;
n_defs = 1;
for (i = 1; i < adef; i++)
{
/* This is a closing element. Interval corresponding to the top
of the stack after removing it follows. */
- VEC_pop (int, worklist);
- top = VEC_index (int, worklist, VEC_length (int, worklist) - 1);
+ worklist.pop ();
+ top = worklist[worklist.length () - 1];
defs[n_defs].bb_index = top;
defs[n_defs].dfs_num = defs[i].dfs_num + 1;
}
it to the correct position. */
defs[n_defs].bb_index = defs[i].bb_index;
defs[n_defs].dfs_num = defs[i].dfs_num;
- VEC_quick_push (int, worklist, b);
+ worklist.quick_push (b);
top = b;
}
else
n_defs++;
}
- VEC_pop (int, worklist);
- gcc_assert (VEC_empty (int, worklist));
+ worklist.pop ();
+ gcc_assert (worklist.is_empty ());
/* Now process the uses. */
live_phis = BITMAP_ALLOC (NULL);
EXECUTE_IF_SET_IN_BITMAP (uses, 0, i, bi)
{
- VEC_safe_push (int, heap, worklist, i);
+ worklist.safe_push (i);
}
- while (!VEC_empty (int, worklist))
+ while (!worklist.is_empty ())
{
- b = VEC_pop (int, worklist);
+ b = worklist.pop ();
if (b == ENTRY_BLOCK)
continue;
continue;
bitmap_set_bit (uses, u);
- VEC_safe_push (int, heap, worklist, u);
+ worklist.safe_push (u);
}
}
- VEC_free (int, heap, worklist);
+ worklist.release ();
bitmap_copy (phis, live_phis);
BITMAP_FREE (live_phis);
free (defs);
static inline struct def_blocks_d *
find_def_blocks_for (tree var)
{
- struct def_blocks_d dm;
- dm.var = var;
- return (struct def_blocks_d *) htab_find (def_blocks, &dm);
-}
-
-
-/* Retrieve or create a default definition for symbol SYM. */
-
-static inline tree
-get_default_def_for (tree sym)
-{
- tree ddef = gimple_default_def (cfun, sym);
-
- if (ddef == NULL_TREE)
- {
- ddef = make_ssa_name (sym, gimple_build_nop ());
- set_default_def (sym, ddef);
- }
-
- return ddef;
+ def_blocks_p p = &get_common_info (var)->def_blocks;
+ if (!p->def_blocks)
+ return NULL;
+ return p;
}
mark_phi_for_rewrite (basic_block bb, gimple phi)
{
gimple_vec phis;
- unsigned i, idx = bb->index;
+ unsigned n, idx = bb->index;
if (rewrite_uses_p (phi))
return;
return;
bitmap_set_bit (blocks_with_phis_to_rewrite, idx);
- VEC_reserve (gimple_vec, heap, phis_to_rewrite, last_basic_block + 1);
- for (i = VEC_length (gimple_vec, phis_to_rewrite); i <= idx; i++)
- VEC_quick_push (gimple_vec, phis_to_rewrite, NULL);
- phis = VEC_index (gimple_vec, phis_to_rewrite, idx);
- if (!phis)
- phis = VEC_alloc (gimple, heap, 10);
+ n = (unsigned) last_basic_block + 1;
+ if (phis_to_rewrite.length () < n)
+ phis_to_rewrite.safe_grow_cleared (n);
- VEC_safe_push (gimple, heap, phis, phi);
- VEC_replace (gimple_vec, phis_to_rewrite, idx, phis);
+ phis = phis_to_rewrite[idx];
+ phis.reserve (10);
+
+ phis.safe_push (phi);
+ phis_to_rewrite[idx] = phis;
}
/* Insert PHI nodes for variable VAR using the iterated dominance
gimple phi;
basic_block bb;
bitmap_iterator bi;
- struct def_blocks_d *def_map;
-
- def_map = find_def_blocks_for (var);
- gcc_assert (def_map);
+ struct def_blocks_d *def_map = find_def_blocks_for (var);
/* Remove the blocks where we already have PHI nodes for VAR. */
bitmap_and_compl_into (phi_insertion_points, def_map->phi_blocks);
if (update_p)
mark_block_for_update (bb);
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "creating PHI node in block #%d for ", bb_index);
+ print_generic_expr (dump_file, var, TDF_SLIM);
+ fprintf (dump_file, "\n");
+ }
phi = NULL;
if (TREE_CODE (var) == SSA_NAME)
edge_iterator ei;
tree new_lhs;
- gcc_assert (update_p);
- phi = create_phi_node (var, bb);
-
- new_lhs = duplicate_ssa_name (var, phi);
- gimple_phi_set_result (phi, new_lhs);
+ gcc_checking_assert (update_p);
+ new_lhs = duplicate_ssa_name (var, NULL);
+ phi = create_phi_node (new_lhs, bb);
add_new_name_mapping (new_lhs, var);
/* Add VAR to every argument slot of PHI. We need VAR in
{
tree tracked_var;
- gcc_assert (DECL_P (var));
+ gcc_checking_assert (DECL_P (var));
phi = create_phi_node (var, bb);
tracked_var = target_for_debug_bind (var);
}
}
+/* Sort var_infos after DECL_UID of their var. */
+
+static int
+insert_phi_nodes_compare_var_infos (const void *a, const void *b)
+{
+ const struct var_info_d *defa = *(struct var_info_d * const *)a;
+ const struct var_info_d *defb = *(struct var_info_d * const *)b;
+ if (DECL_UID (defa->var) < DECL_UID (defb->var))
+ return -1;
+ else
+ return 1;
+}
/* Insert PHI nodes at the dominance frontier of blocks with variable
definitions. DFS contains the dominance frontier information for
static void
insert_phi_nodes (bitmap_head *dfs)
{
- referenced_var_iterator rvi;
- bitmap_iterator bi;
- tree var;
- bitmap vars;
- unsigned uid;
+ htab_iterator hi;
+ unsigned i;
+ var_info_p info;
+ vec<var_info_p> vars;
timevar_push (TV_TREE_INSERT_PHI_NODES);
+ vars.create (htab_elements (var_infos));
+ FOR_EACH_HTAB_ELEMENT (var_infos, info, var_info_p, hi)
+ if (info->info.need_phi_state != NEED_PHI_STATE_NO)
+ vars.quick_push (info);
+
/* Do two stages to avoid code generation differences for UID
differences but no UID ordering differences. */
+ vars.qsort (insert_phi_nodes_compare_var_infos);
- vars = BITMAP_ALLOC (NULL);
- FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
+ FOR_EACH_VEC_ELT (vars, i, info)
{
- struct def_blocks_d *def_map;
-
- def_map = find_def_blocks_for (var);
- if (def_map == NULL)
- continue;
-
- if (get_phi_state (var) != NEED_PHI_STATE_NO)
- bitmap_set_bit (vars, DECL_UID (var));
- }
-
- EXECUTE_IF_SET_IN_BITMAP (vars, 0, uid, bi)
- {
- tree var = referenced_var (uid);
- struct def_blocks_d *def_map;
- bitmap idf;
-
- def_map = find_def_blocks_for (var);
- idf = compute_idf (def_map->def_blocks, dfs);
- insert_phi_nodes_for (var, idf, false);
+ bitmap idf = compute_idf (info->info.def_blocks.def_blocks, dfs);
+ insert_phi_nodes_for (info->var, idf, false);
BITMAP_FREE (idf);
}
- BITMAP_FREE (vars);
+ vars.release ();
timevar_pop (TV_TREE_INSERT_PHI_NODES);
}
static void
register_new_def (tree def, tree sym)
{
+ common_info_p info = get_common_info (sym);
tree currdef;
/* If this variable is set in a single basic block and all uses are
This is the same test to prune the set of variables which may
need PHI nodes. So we just use that information since it's already
computed and available for us to use. */
- if (get_phi_state (sym) == NEED_PHI_STATE_NO)
+ if (info->need_phi_state == NEED_PHI_STATE_NO)
{
- set_current_def (sym, def);
+ info->current_def = def;
return;
}
- currdef = get_current_def (sym);
+ currdef = info->current_def;
/* If SYM is not a GIMPLE register, then CURRDEF may be a name whose
SSA_NAME_VAR is not necessarily SYM. In this case, also push SYM
in the stack so that we know which symbol is being defined by
this SSA name when we unwind the stack. */
if (currdef && !is_gimple_reg (sym))
- VEC_safe_push (tree, heap, block_defs_stack, sym);
+ block_defs_stack.safe_push (sym);
/* Push the current reaching definition into BLOCK_DEFS_STACK. This
stack is later used by the dominator tree callbacks to restore
block after a recursive visit to all its immediately dominated
blocks. If there is no current reaching definition, then just
record the underlying _DECL node. */
- VEC_safe_push (tree, heap, block_defs_stack, currdef ? currdef : sym);
+ block_defs_stack.safe_push (currdef ? currdef : sym);
/* Set the current reaching definition for SYM to be DEF. */
- set_current_def (sym, def);
+ info->current_def = def;
}
static tree
get_reaching_def (tree var)
{
+ common_info_p info = get_common_info (var);
tree currdef;
/* Lookup the current reaching definition for VAR. */
- currdef = get_current_def (var);
+ currdef = info->current_def;
/* If there is no reaching definition for VAR, create and register a
default definition for it (if needed). */
if (currdef == NULL_TREE)
{
tree sym = DECL_P (var) ? var : SSA_NAME_VAR (var);
- currdef = get_default_def_for (sym);
- set_current_def (var, currdef);
+ currdef = get_or_create_ssa_default_def (cfun, sym);
}
/* Return the current reaching definition for VAR, or the default
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
{
- tree var = USE_FROM_PTR (use_p), def = NULL_TREE;
- gcc_assert (DECL_P (var));
- if (var_ann (var) == NULL)
+ tree var = USE_FROM_PTR (use_p), def;
+ common_info_p info = get_common_info (var);
+ gcc_checking_assert (DECL_P (var));
+ def = info->current_def;
+ if (!def)
{
if (TREE_CODE (var) == PARM_DECL && single_succ_p (ENTRY_BLOCK_PTR))
{
}
else
{
- def = get_current_def (var);
- /* Check if get_current_def can be trusted. */
- if (def)
+ /* Check if info->current_def can be trusted. */
+ basic_block bb = gimple_bb (stmt);
+ basic_block def_bb
+ = SSA_NAME_IS_DEFAULT_DEF (def)
+ ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def));
+
+ /* If definition is in current bb, it is fine. */
+ if (bb == def_bb)
+ ;
+ /* If definition bb doesn't dominate the current bb,
+ it can't be used. */
+ else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
+ def = NULL;
+ /* If there is just one definition and dominates the current
+ bb, it is fine. */
+ else if (info->need_phi_state == NEED_PHI_STATE_NO)
+ ;
+ else
{
- basic_block bb = gimple_bb (stmt);
- basic_block def_bb
- = SSA_NAME_IS_DEFAULT_DEF (def)
- ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def));
+ struct def_blocks_d *db_p = get_def_blocks_for (info);
- /* If definition is in current bb, it is fine. */
- if (bb == def_bb)
- ;
- /* If definition bb doesn't dominate the current bb,
- it can't be used. */
- else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
- def = NULL;
- /* If there is just one definition and dominates the current
- bb, it is fine. */
- else if (get_phi_state (var) == NEED_PHI_STATE_NO)
+ /* If there are some non-debug uses in the current bb,
+ it is fine. */
+ if (bitmap_bit_p (db_p->livein_blocks, bb->index))
;
+ /* Otherwise give up for now. */
else
- {
- struct def_blocks_d *db_p = get_def_blocks_for (var);
-
- /* If there are some non-debug uses in the current bb,
- it is fine. */
- if (bitmap_bit_p (db_p->livein_blocks, bb->index))
- ;
- /* Otherwise give up for now. */
- else
- def = NULL;
- }
+ def = NULL;
}
}
if (def == NULL)
definition of a variable when a new real or virtual definition is found. */
static void
-rewrite_stmt (gimple_stmt_iterator si)
+rewrite_stmt (gimple_stmt_iterator *si)
{
use_operand_p use_p;
def_operand_p def_p;
ssa_op_iter iter;
- gimple stmt = gsi_stmt (si);
+ gimple stmt = gsi_stmt (*si);
/* If mark_def_sites decided that we don't need to rewrite this
statement, ignore it. */
if (is_gimple_debug (stmt))
rewrite_debug_stmt_uses (stmt);
else
- FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
{
tree var = USE_FROM_PTR (use_p);
- gcc_assert (DECL_P (var));
+ gcc_checking_assert (DECL_P (var));
SET_USE (use_p, get_reaching_def (var));
}
}
/* Step 2. Register the statement's DEF operands. */
if (register_defs_p (stmt))
- FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_DEF)
+ FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_ALL_DEFS)
{
tree var = DEF_FROM_PTR (def_p);
- tree name = make_ssa_name (var, stmt);
+ tree name;
tree tracked_var;
- gcc_assert (DECL_P (var));
+
+ gcc_checking_assert (DECL_P (var));
+
+ if (gimple_clobber_p (stmt)
+ && is_gimple_reg (var))
+ {
+ /* If we rewrite a DECL into SSA form then drop its
+ clobber stmts and replace uses with a new default def. */
+ gcc_checking_assert (TREE_CODE (var) == VAR_DECL
+ && !gimple_vdef (stmt));
+ gsi_replace (si, gimple_build_nop (), true);
+ register_new_def (get_or_create_ssa_default_def (cfun, var), var);
+ break;
+ }
+
+ name = make_ssa_name (var, stmt);
SET_DEF (def_p, name);
register_new_def (DEF_FROM_PTR (def_p), var);
if (tracked_var)
{
gimple note = gimple_build_debug_bind (tracked_var, name, stmt);
- gsi_insert_after (&si, note, GSI_SAME_STMT);
+ gsi_insert_after (si, note, GSI_SAME_STMT);
}
}
}
for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi);
gsi_next (&gsi))
{
- tree currdef;
- gimple stmt;
+ tree currdef, res;
+ location_t loc;
phi = gsi_stmt (gsi);
- currdef = get_reaching_def (SSA_NAME_VAR (gimple_phi_result (phi)));
- stmt = SSA_NAME_DEF_STMT (currdef);
- add_phi_arg (phi, currdef, e, gimple_location (stmt));
+ res = gimple_phi_result (phi);
+ currdef = get_reaching_def (SSA_NAME_VAR (res));
+ /* Virtual operand PHI args do not need a location. */
+ if (virtual_operand_p (res))
+ loc = UNKNOWN_LOCATION;
+ else
+ loc = gimple_location (SSA_NAME_DEF_STMT (currdef));
+ add_phi_arg (phi, currdef, e, loc);
}
}
}
rewrite_enter_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
basic_block bb)
{
- gimple phi;
gimple_stmt_iterator gsi;
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);
+ block_defs_stack.safe_push (NULL_TREE);
/* 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 (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
{
- tree result;
-
- phi = gsi_stmt (gsi);
- result = gimple_phi_result (phi);
- gcc_assert (is_gimple_reg (result));
+ tree result = gimple_phi_result (gsi_stmt (gsi));
register_new_def (result, SSA_NAME_VAR (result));
}
/* Step 2. Rewrite every variable used in each statement in the block
with its immediate reaching definitions. Update the current definition
of a variable when a new real or virtual definition is found. */
- if (TEST_BIT (interesting_blocks, bb->index))
+ if (bitmap_bit_p (interesting_blocks, bb->index))
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- rewrite_stmt (gsi);
+ rewrite_stmt (&gsi);
/* Step 3. Visit all the successor blocks of BB looking for PHI nodes.
For every PHI node found, add a new argument containing the current
basic_block bb ATTRIBUTE_UNUSED)
{
/* Restore CURRDEFS to its original state. */
- while (VEC_length (tree, block_defs_stack) > 0)
+ while (block_defs_stack.length () > 0)
{
- tree tmp = VEC_pop (tree, block_defs_stack);
+ tree tmp = block_defs_stack.pop ();
tree saved_def, var;
if (tmp == NULL_TREE)
saved_def = tmp;
var = SSA_NAME_VAR (saved_def);
if (!is_gimple_reg (var))
- var = VEC_pop (tree, block_defs_stack);
+ var = block_defs_stack.pop ();
}
else
{
var = tmp;
}
- set_current_def (var, saved_def);
+ get_common_info (var)->current_def = saved_def;
}
}
EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
{
- tree var = referenced_var_lookup (cfun, i);
- if (var)
- print_generic_expr (file, var, 0);
- else
- fprintf (file, "D.%u", i);
+ fprintf (file, "D.%u", i);
fprintf (file, " ");
}
i = 1;
fprintf (file, "Level %d (current level)\n", i);
- for (j = (int) VEC_length (tree, block_defs_stack) - 1; j >= 0; j--)
+ for (j = (int) block_defs_stack.length () - 1; j >= 0; j--)
{
tree name, var;
- name = VEC_index (tree, block_defs_stack, j);
+ name = block_defs_stack[j];
if (name == NULL_TREE)
{
i++;
if (!is_gimple_reg (var))
{
j--;
- var = VEC_index (tree, block_defs_stack, j);
+ var = block_defs_stack[j];
}
}
void
dump_currdefs (FILE *file)
{
- referenced_var_iterator i;
+ unsigned i;
tree var;
+ if (symbols_to_rename.is_empty ())
+ return;
+
fprintf (file, "\n\nCurrent reaching definitions\n\n");
- FOR_EACH_REFERENCED_VAR (cfun, var, i)
- if (SYMS_TO_RENAME (cfun) == NULL
- || bitmap_bit_p (SYMS_TO_RENAME (cfun), DECL_UID (var)))
- {
- fprintf (file, "CURRDEF (");
- print_generic_expr (file, var, 0);
- fprintf (file, ") = ");
- if (get_current_def (var))
- print_generic_expr (file, get_current_def (var), 0);
- else
- fprintf (file, "<NIL>");
- fprintf (file, "\n");
- }
+ FOR_EACH_VEC_ELT (symbols_to_rename, i, var)
+ {
+ common_info_p info = get_common_info (var);
+ fprintf (file, "CURRDEF (");
+ print_generic_expr (file, var, 0);
+ fprintf (file, ") = ");
+ if (info->current_def)
+ print_generic_expr (file, info->current_def, 0);
+ else
+ fprintf (file, "<NIL>");
+ fprintf (file, "\n");
+ }
}
fprintf (file, "SSA renaming information for %s\n\n", funcname);
- dump_def_blocks (file);
+ dump_var_infos (file);
dump_defs_stack (file, -1);
dump_currdefs (file);
dump_tree_ssa_stats (file);
void
dump_tree_ssa_stats (FILE *file)
{
- if (def_blocks || repl_tbl)
- fprintf (file, "\nHash table statistics:\n");
-
- if (def_blocks)
- {
- fprintf (file, " def_blocks: ");
- htab_statistics (file, def_blocks);
- }
-
- if (repl_tbl)
+ if (var_infos)
{
- fprintf (file, " repl_tbl: ");
- htab_statistics (file, repl_tbl);
+ fprintf (file, "\nHash table statistics:\n");
+ fprintf (file, " var_infos: ");
+ htab_statistics (file, var_infos);
+ fprintf (file, "\n");
}
-
- if (def_blocks || repl_tbl)
- fprintf (file, "\n");
}
}
-/* Hashing and equality functions for DEF_BLOCKS. */
+/* Hashing and equality functions for VAR_INFOS. */
static hashval_t
-def_blocks_hash (const void *p)
+var_info_hash (const void *p)
{
- return htab_hash_pointer
- ((const void *)((const struct def_blocks_d *)p)->var);
+ return DECL_UID (((const struct var_info_d *)p)->var);
}
static int
-def_blocks_eq (const void *p1, const void *p2)
+var_info_eq (const void *p1, const void *p2)
{
- return ((const struct def_blocks_d *)p1)->var
- == ((const struct def_blocks_d *)p2)->var;
+ return ((const struct var_info_d *)p1)->var
+ == ((const struct var_info_d *)p2)->var;
}
-/* Free memory allocated by one entry in DEF_BLOCKS. */
-
-static void
-def_blocks_free (void *p)
-{
- struct def_blocks_d *entry = (struct def_blocks_d *) p;
- BITMAP_FREE (entry->def_blocks);
- BITMAP_FREE (entry->phi_blocks);
- BITMAP_FREE (entry->livein_blocks);
- free (entry);
-}
-
-
-/* Callback for htab_traverse to dump the DEF_BLOCKS hash table. */
+/* Callback for htab_traverse to dump the VAR_INFOS hash table. */
static int
-debug_def_blocks_r (void **slot, void *data)
+debug_var_infos_r (void **slot, void *data)
{
FILE *file = (FILE *) data;
- struct def_blocks_d *db_p = (struct def_blocks_d *) *slot;
+ struct var_info_d *info = (struct var_info_d *) *slot;
fprintf (file, "VAR: ");
- print_generic_expr (file, db_p->var, dump_flags);
- bitmap_print (file, db_p->def_blocks, ", DEF_BLOCKS: { ", "}");
- bitmap_print (file, db_p->livein_blocks, ", LIVEIN_BLOCKS: { ", "}");
- bitmap_print (file, db_p->phi_blocks, ", PHI_BLOCKS: { ", "}\n");
+ print_generic_expr (file, info->var, dump_flags);
+ bitmap_print (file, info->info.def_blocks.def_blocks,
+ ", DEF_BLOCKS: { ", "}");
+ bitmap_print (file, info->info.def_blocks.livein_blocks,
+ ", LIVEIN_BLOCKS: { ", "}");
+ bitmap_print (file, info->info.def_blocks.phi_blocks,
+ ", PHI_BLOCKS: { ", "}\n");
return 1;
}
-/* Dump the DEF_BLOCKS hash table on FILE. */
+/* Dump the VAR_INFOS hash table on FILE. */
void
-dump_def_blocks (FILE *file)
+dump_var_infos (FILE *file)
{
fprintf (file, "\n\nDefinition and live-in blocks:\n\n");
- if (def_blocks)
- htab_traverse (def_blocks, debug_def_blocks_r, file);
+ if (var_infos)
+ htab_traverse (var_infos, debug_var_infos_r, file);
}
-/* Dump the DEF_BLOCKS hash table on stderr. */
+/* Dump the VAR_INFOS hash table on stderr. */
DEBUG_FUNCTION void
-debug_def_blocks (void)
+debug_var_infos (void)
{
- dump_def_blocks (stderr);
+ dump_var_infos (stderr);
}
static inline void
register_new_update_single (tree new_name, tree old_name)
{
- tree currdef = get_current_def (old_name);
+ common_info_p info = get_common_info (old_name);
+ tree currdef = info->current_def;
/* Push the current reaching definition into BLOCK_DEFS_STACK.
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, old_name);
+ block_defs_stack.reserve (2);
+ block_defs_stack.quick_push (currdef);
+ block_defs_stack.quick_push (old_name);
/* Set the current reaching definition for OLD_NAME to be
NEW_NAME. */
- set_current_def (old_name, new_name);
+ info->current_def = new_name;
}
tree use = USE_FROM_PTR (use_p);
tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
- if (symbol_marked_for_renaming (sym))
+ if (marked_for_renaming (sym))
rdef = get_reaching_def (sym);
else if (is_old_name (use))
rdef = get_reaching_def (use);
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_current_def (sym);
+ if (marked_for_renaming (sym))
+ rdef = get_var_info (sym)->info.current_def;
else if (is_old_name (use))
{
- rdef = get_current_def (use);
+ rdef = get_ssa_name_ann (use)->info.current_def;
/* We can't assume that, if there's no current definition, the
default one should be used. It could be the case that we've
rearranged blocks so that the earlier definition no longer
/* If DEF is a naked symbol that needs renaming, create a new
name for it. */
- if (symbol_marked_for_renaming (sym))
+ if (marked_for_renaming (sym))
{
if (DECL_P (def))
{
FOR_EACH_EDGE (e, ei, bb->succs)
if (!(e->flags & EDGE_EH))
{
- gcc_assert (!ef);
+ gcc_checking_assert (!ef);
ef = e;
}
/* If there are other predecessors to ef->dest, then
if (!bitmap_bit_p (blocks_with_phis_to_rewrite, e->dest->index))
continue;
- phis = VEC_index (gimple_vec, phis_to_rewrite, e->dest->index);
- FOR_EACH_VEC_ELT (gimple, phis, i, phi)
+ phis = phis_to_rewrite[e->dest->index];
+ FOR_EACH_VEC_ELT (phis, i, phi)
{
tree arg, lhs_sym, reaching_def = NULL;
use_operand_p arg_p;
- gcc_assert (rewrite_uses_p (phi));
+ gcc_checking_assert (rewrite_uses_p (phi));
arg_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
arg = USE_FROM_PTR (arg_p);
{
tree sym = DECL_P (arg) ? arg : SSA_NAME_VAR (arg);
- if (symbol_marked_for_renaming (sym))
+ if (marked_for_renaming (sym))
reaching_def = get_reaching_def (sym);
else if (is_old_name (arg))
reaching_def = get_reaching_def (arg);
/* Update the argument if there is a reaching def. */
if (reaching_def)
{
- gimple stmt;
source_location locus;
int arg_i = PHI_ARG_INDEX_FROM_USE (arg_p);
SET_USE (arg_p, reaching_def);
- stmt = SSA_NAME_DEF_STMT (reaching_def);
- /* Single element PHI nodes behave like copies, so get the
- location from the phi argument. */
- if (gimple_code (stmt) == GIMPLE_PHI &&
- gimple_phi_num_args (stmt) == 1)
- locus = gimple_phi_arg_location (stmt, 0);
+ /* Virtual operands do not need a location. */
+ if (virtual_operand_p (reaching_def))
+ locus = UNKNOWN_LOCATION;
else
- locus = gimple_location (stmt);
+ {
+ gimple stmt = SSA_NAME_DEF_STMT (reaching_def);
+
+ /* Single element PHI nodes behave like copies, so get the
+ location from the phi argument. */
+ if (gimple_code (stmt) == GIMPLE_PHI
+ && gimple_phi_num_args (stmt) == 1)
+ locus = gimple_phi_arg_location (stmt, 0);
+ else
+ locus = gimple_location (stmt);
+ }
gimple_phi_arg_set_location (phi, arg_i, locus);
}
bb->index);
/* Mark the unwind point for this block. */
- VEC_safe_push (tree, heap, block_defs_stack, NULL_TREE);
+ block_defs_stack.safe_push (NULL_TREE);
if (!bitmap_bit_p (blocks_to_update, bb->index))
return;
lhs = gimple_phi_result (phi);
lhs_sym = SSA_NAME_VAR (lhs);
- if (symbol_marked_for_renaming (lhs_sym))
+ if (marked_for_renaming (lhs_sym))
register_new_update_single (lhs, lhs_sym);
else
{
}
/* Step 2. Rewrite every variable used in each statement in the block. */
- if (TEST_BIT (interesting_blocks, bb->index))
+ if (bitmap_bit_p (interesting_blocks, bb->index))
{
- gcc_assert (bitmap_bit_p (blocks_to_update, bb->index));
+ gcc_checking_assert (bitmap_bit_p (blocks_to_update, bb->index));
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
rewrite_update_stmt (gsi_stmt (gsi), gsi);
}
rewrite_update_leave_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
basic_block bb ATTRIBUTE_UNUSED)
{
- while (VEC_length (tree, block_defs_stack) > 0)
+ while (block_defs_stack.length () > 0)
{
- tree var = VEC_pop (tree, block_defs_stack);
+ tree var = block_defs_stack.pop ();
tree saved_def;
/* NULL indicates the unwind stop point for this block (see
if (var == NULL)
return;
- saved_def = VEC_pop (tree, block_defs_stack);
- set_current_def (var, saved_def);
+ saved_def = block_defs_stack.pop ();
+ get_common_info (var)->current_def = saved_def;
}
}
else
gcc_unreachable ();
- block_defs_stack = VEC_alloc (tree, heap, 10);
+ block_defs_stack.create (10);
/* Initialize the dominator walker. */
init_walk_dominator_tree (&walk_data);
if (dump_file && (dump_flags & TDF_STATS))
{
dump_dfa_stats (dump_file);
- if (def_blocks)
+ if (var_infos)
dump_tree_ssa_stats (dump_file);
}
- VEC_free (tree, heap, block_defs_stack);
+ block_defs_stack.release ();
timevar_pop (TV_TREE_SSA_REWRITE_BLOCKS);
}
static void
init_ssa_renamer (void)
{
- tree var;
- referenced_var_iterator rvi;
-
cfun->gimple_df->in_ssa_p = false;
/* Allocate memory for the DEF_BLOCKS hash table. */
- gcc_assert (def_blocks == NULL);
- def_blocks = htab_create (num_referenced_vars, def_blocks_hash,
- def_blocks_eq, def_blocks_free);
+ gcc_assert (var_infos == NULL);
+ var_infos = htab_create (vec_safe_length (cfun->local_decls),
+ var_info_hash, var_info_eq, free);
- FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
- set_current_def (var, NULL_TREE);
+ bitmap_obstack_initialize (&update_ssa_obstack);
}
static void
fini_ssa_renamer (void)
{
- if (def_blocks)
+ if (var_infos)
{
- htab_delete (def_blocks);
- def_blocks = NULL;
+ htab_delete (var_infos);
+ var_infos = NULL;
}
+ bitmap_obstack_release (&update_ssa_obstack);
+
+ cfun->gimple_df->ssa_renaming_needed = 0;
+ cfun->gimple_df->rename_vops = 0;
cfun->gimple_df->in_ssa_p = true;
}
{
bitmap_head *dfs;
basic_block bb;
+ unsigned i;
/* Initialize operand data structures. */
- init_ssa_operands ();
+ init_ssa_operands (cfun);
/* Initialize internal data needed by the renamer. */
init_ssa_renamer ();
mark_def_sites will add to this set those blocks that the renamer
should process. */
interesting_blocks = sbitmap_alloc (last_basic_block);
- sbitmap_zero (interesting_blocks);
+ bitmap_clear (interesting_blocks);
/* Initialize dominance frontier. */
dfs = XNEWVEC (bitmap_head, last_basic_block);
fini_ssa_renamer ();
+ /* Try to get rid of all gimplifier generated temporaries by making
+ its SSA names anonymous. This way we can garbage collect them
+ all after removing unused locals which we do in our TODO. */
+ for (i = 1; i < num_ssa_names; ++i)
+ {
+ tree decl, name = ssa_name (i);
+ if (!name
+ || SSA_NAME_IS_DEFAULT_DEF (name))
+ continue;
+ decl = SSA_NAME_VAR (name);
+ if (decl
+ && TREE_CODE (decl) == VAR_DECL
+ && !VAR_DECL_IS_VIRTUAL_OPERAND (decl)
+ && DECL_ARTIFICIAL (decl)
+ && DECL_IGNORED_P (decl)
+ && !DECL_NAME (decl))
+ SET_SSA_NAME_VAR_OR_IDENTIFIER (name, NULL_TREE);
+ }
+
return 0;
}
{
GIMPLE_PASS,
"ssa", /* name */
+ OPTGROUP_NONE, /* optinfo_flags */
NULL, /* gate */
rewrite_into_ssa, /* execute */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
TV_TREE_SSA_OTHER, /* tv_id */
- PROP_cfg | PROP_referenced_vars, /* properties_required */
+ PROP_cfg, /* properties_required */
PROP_ssa, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
- TODO_update_ssa_only_virtuals
- | TODO_verify_ssa
+ TODO_verify_ssa
| TODO_remove_unused_locals /* todo_flags_finish */
}
};
static void
mark_def_interesting (tree var, gimple stmt, basic_block bb, bool insert_phi_p)
{
- gcc_assert (bitmap_bit_p (blocks_to_update, bb->index));
+ gcc_checking_assert (bitmap_bit_p (blocks_to_update, bb->index));
set_register_defs (stmt, true);
if (insert_phi_p)
replace it). */
if (insert_phi_p)
{
- struct def_blocks_d *db_p = get_def_blocks_for (var);
+ struct def_blocks_d *db_p = get_def_blocks_for (get_common_info (var));
if (!bitmap_bit_p (db_p->def_blocks, bb->index))
set_livein_block (var, bb);
}
/* Do a dominator walk starting at BB processing statements that
- reference symbols in SYMS_TO_RENAME. This is very similar to
+ reference symbols in SSA operands. This is very similar to
mark_def_sites, but the scan handles statements whose operands may
already be SSA names.
gimple phi = gsi_stmt (si);
tree lhs_sym, lhs = gimple_phi_result (phi);
- lhs_sym = DECL_P (lhs) ? lhs : SSA_NAME_VAR (lhs);
-
- if (!symbol_marked_for_renaming (lhs_sym))
+ if (TREE_CODE (lhs) == SSA_NAME
+ && (! virtual_operand_p (lhs)
+ || ! cfun->gimple_df->rename_vops))
continue;
+ lhs_sym = DECL_P (lhs) ? lhs : SSA_NAME_VAR (lhs);
+ mark_for_renaming (lhs_sym);
mark_def_interesting (lhs_sym, phi, bb, insert_phi_p);
/* Mark the uses in phi nodes as interesting. It would be more correct
stmt = gsi_stmt (si);
- FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_ALL_USES)
+ if (cfun->gimple_df->rename_vops
+ && gimple_vuse (stmt))
{
- tree use = USE_FROM_PTR (use_p);
+ tree use = gimple_vuse (stmt);
tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
- if (symbol_marked_for_renaming (sym))
- mark_use_interesting (sym, stmt, bb, insert_phi_p);
+ mark_for_renaming (sym);
+ mark_use_interesting (sym, stmt, bb, insert_phi_p);
}
- FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, i, SSA_OP_ALL_DEFS)
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
{
- tree def = DEF_FROM_PTR (def_p);
+ tree use = USE_FROM_PTR (use_p);
+ if (!DECL_P (use))
+ continue;
+ mark_for_renaming (use);
+ mark_use_interesting (use, stmt, bb, insert_phi_p);
+ }
+
+ if (cfun->gimple_df->rename_vops
+ && gimple_vdef (stmt))
+ {
+ tree def = gimple_vdef (stmt);
tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
- if (symbol_marked_for_renaming (sym))
- mark_def_interesting (sym, stmt, bb, insert_phi_p);
+ mark_for_renaming (sym);
+ mark_def_interesting (sym, stmt, bb, insert_phi_p);
+ }
+
+ FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, i, SSA_OP_DEF)
+ {
+ tree def = DEF_FROM_PTR (def_p);
+ if (!DECL_P (def))
+ continue;
+ mark_for_renaming (def);
+ mark_def_interesting (def, stmt, bb, insert_phi_p);
}
}
gimple stmt;
basic_block bb;
- gcc_assert (names_to_release == NULL
- || !bitmap_bit_p (names_to_release, SSA_NAME_VERSION (name)));
+ gcc_checking_assert (names_to_release == NULL
+ || !bitmap_bit_p (names_to_release,
+ SSA_NAME_VERSION (name)));
stmt = SSA_NAME_DEF_STMT (name);
bb = gimple_bb (stmt);
if (bb)
{
- gcc_assert (bb->index < last_basic_block);
+ gcc_checking_assert (bb->index < last_basic_block);
mark_block_for_update (bb);
mark_def_interesting (name, stmt, bb, insert_phi_p);
}
want to replace existing instances. */
if (names_to_release)
EXECUTE_IF_SET_IN_BITMAP (names_to_release, 0, i, bi)
- RESET_BIT (new_ssa_names, i);
+ bitmap_clear_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)
+ EXECUTE_IF_SET_IN_BITMAP (new_ssa_names, 0, i, sbi)
prepare_def_site_for (ssa_name (i), 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, sbi)
+ EXECUTE_IF_SET_IN_BITMAP (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), insert_phi_p);
if (!need_ssa_update_p (cfun))
return;
- if (new_ssa_names && sbitmap_first_set_bit (new_ssa_names) >= 0)
+ if (new_ssa_names && bitmap_first_set_bit (new_ssa_names) >= 0)
{
sbitmap_iterator sbi;
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, sbi)
+ EXECUTE_IF_SET_IN_BITMAP (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 (!bitmap_empty_p (SYMS_TO_RENAME (cfun)))
+ if (symbols_to_rename_set && !bitmap_empty_p (symbols_to_rename_set))
{
fprintf (file, "\nSymbols to be put in SSA form\n");
- dump_decl_set (file, SYMS_TO_RENAME (cfun));
+ dump_decl_set (file, symbols_to_rename_set);
fprintf (file, "\n");
}
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);
- sbitmap_zero (old_ssa_names);
+ bitmap_clear (old_ssa_names);
new_ssa_names = sbitmap_alloc (num_ssa_names + NAME_SETS_GROWTH_FACTOR);
- sbitmap_zero (new_ssa_names);
+ bitmap_clear (new_ssa_names);
+
+ bitmap_obstack_initialize (&update_ssa_obstack);
- repl_tbl = htab_create (20, repl_map_hash, repl_map_eq, repl_map_free);
names_to_release = NULL;
- memset (&update_ssa_stats, 0, sizeof (update_ssa_stats));
- update_ssa_stats.virtual_symbols = BITMAP_ALLOC (NULL);
update_ssa_initialized_fn = fn;
}
sbitmap_free (new_ssa_names);
new_ssa_names = NULL;
- htab_delete (repl_tbl);
- repl_tbl = NULL;
-
- bitmap_clear (SYMS_TO_RENAME (update_ssa_initialized_fn));
- BITMAP_FREE (update_ssa_stats.virtual_symbols);
+ BITMAP_FREE (symbols_to_rename_set);
+ symbols_to_rename_set = NULL;
+ symbols_to_rename.release ();
if (names_to_release)
{
if (blocks_with_phis_to_rewrite)
EXECUTE_IF_SET_IN_BITMAP (blocks_with_phis_to_rewrite, 0, i, bi)
{
- gimple_vec phis = VEC_index (gimple_vec, phis_to_rewrite, i);
-
- VEC_free (gimple, heap, phis);
- VEC_replace (gimple_vec, phis_to_rewrite, i, NULL);
+ gimple_vec phis = phis_to_rewrite[i];
+ phis.release ();
+ phis_to_rewrite[i].create (0);
}
BITMAP_FREE (blocks_with_phis_to_rewrite);
BITMAP_FREE (blocks_to_update);
+
update_ssa_initialized_fn = NULL;
}
/* Create a new name for OLD_NAME in statement STMT and replace the
- operand pointed to by DEF_P with the newly created name. Return
- the new name and register the replacement mapping <NEW, OLD> in
+ operand pointed to by DEF_P with the newly created name. If DEF_P
+ is NULL then STMT should be a GIMPLE assignment.
+ Return the new name and register the replacement mapping <NEW, OLD> in
update_ssa's tables. */
tree
create_new_def_for (tree old_name, gimple stmt, def_operand_p def)
{
- tree new_name = duplicate_ssa_name (old_name, stmt);
+ tree new_name;
+
+ timevar_push (TV_TREE_SSA_INCREMENTAL);
+
+ if (!update_ssa_initialized_fn)
+ init_update_ssa (cfun);
+
+ gcc_assert (update_ssa_initialized_fn == cfun);
- SET_DEF (def, new_name);
+ new_name = duplicate_ssa_name (old_name, stmt);
+ if (def)
+ SET_DEF (def, new_name);
+ else
+ gimple_assign_set_lhs (stmt, new_name);
if (gimple_code (stmt) == GIMPLE_PHI)
{
SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_name) = bb_has_abnormal_pred (bb);
}
- register_new_name_mapping (new_name, old_name);
+ add_new_name_mapping (new_name, old_name);
/* For the benefit of passes that will be updating the SSA form on
their own, set the current reaching definition of OLD_NAME to be
NEW_NAME. */
- set_current_def (old_name, new_name);
-
- return new_name;
-}
-
-
-/* Register name NEW to be a replacement for name OLD. This function
- must be called for every replacement that should be performed by
- update_ssa. */
-
-void
-register_new_name_mapping (tree new_tree, tree old)
-{
- if (!update_ssa_initialized_fn)
- init_update_ssa (cfun);
-
- gcc_assert (update_ssa_initialized_fn == cfun);
+ get_ssa_name_ann (old_name)->info.current_def = new_name;
- add_new_name_mapping (new_tree, old);
-}
-
-
-/* Register symbol SYM to be renamed by update_ssa. */
+ timevar_pop (TV_TREE_SSA_INCREMENTAL);
-void
-mark_sym_for_renaming (tree sym)
-{
- bitmap_set_bit (SYMS_TO_RENAME (cfun), DECL_UID (sym));
+ return new_name;
}
-/* Register all the symbols in SET to be renamed by update_ssa. */
+/* Mark virtual operands of FN for renaming by update_ssa. */
void
-mark_set_for_renaming (bitmap set)
+mark_virtual_operands_for_renaming (struct function *fn)
{
- bitmap_iterator bi;
- unsigned i;
-
- if (set == NULL || bitmap_empty_p (set))
- return;
-
- EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
- mark_sym_for_renaming (referenced_var (i));
+ fn->gimple_df->ssa_renaming_needed = 1;
+ fn->gimple_df->rename_vops = 1;
}
{
gcc_assert (fn != NULL);
return (update_ssa_initialized_fn == fn
- || (fn->gimple_df
- && !bitmap_empty_p (SYMS_TO_RENAME (fn))));
-}
-
-/* Return true if SSA name mappings have been registered for SSA updating. */
-
-bool
-name_mappings_registered_p (void)
-{
- if (!update_ssa_initialized_fn)
- return false;
-
- gcc_assert (update_ssa_initialized_fn == cfun);
-
- return repl_tbl && htab_elements (repl_tbl) > 0;
+ || (fn->gimple_df && fn->gimple_df->ssa_renaming_needed));
}
/* Return true if name N has been registered in the replacement table. */
}
-/* Return the set of all the SSA names marked to be replaced. */
-
-bitmap
-ssa_names_to_replace (void)
-{
- unsigned i = 0;
- bitmap ret;
- sbitmap_iterator sbi;
-
- gcc_assert (update_ssa_initialized_fn == NULL
- || update_ssa_initialized_fn == cfun);
-
- ret = BITMAP_ALLOC (NULL);
- EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
- bitmap_set_bit (ret, i);
-
- return ret;
-}
-
-
/* Mark NAME to be released after update_ssa has finished. */
void
if (TREE_CODE (var) == SSA_NAME)
gcc_checking_assert (is_old_name (var));
else
- gcc_checking_assert (symbol_marked_for_renaming (var));
+ gcc_checking_assert (marked_for_renaming (var));
/* Get all the definition sites for VAR. */
db = find_def_blocks_for (var);
else
{
/* Otherwise, do not prune the IDF for VAR. */
- gcc_assert (update_flags == TODO_update_ssa_full_phi);
+ gcc_checking_assert (update_flags == TODO_update_ssa_full_phi);
bitmap_copy (pruned_idf, idf);
}
}
BITMAP_FREE (idf);
}
+/* Sort symbols_to_rename after their DECL_UID. */
-/* 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)
+static int
+insert_updated_phi_nodes_compare_uids (const void *a, const void *b)
{
- unsigned i = 0;
- 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);
-
- mark_set_for_renaming (update_ssa_stats.virtual_symbols);
+ const_tree syma = *(const const_tree *)a;
+ const_tree symb = *(const const_tree *)b;
+ if (DECL_UID (syma) == DECL_UID (symb))
+ return 0;
+ return DECL_UID (syma) < DECL_UID (symb) ? -1 : 1;
}
-
/* 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:
frontier of the blocks where each of NEW_SSA_NAMES are defined.
The mapping between OLD_SSA_NAMES and NEW_SSA_NAMES is setup by
- calling register_new_name_mapping for every pair of names that the
+ calling create_new_def_for to create new defs for names that the
caller wants to replace.
- The caller identifies the new names that have been inserted and the
- names that need to be replaced by calling register_new_name_mapping
- for every pair <NEW, OLD>. Note that the function assumes that the
- new names have already been inserted in the IL.
+ The caller cretaes the new names to be inserted and the names that need
+ to be replaced by calling create_new_def_for for each old definition
+ to be replaced. Note that the function assumes that the
+ new defining statement has already been inserted in the IL.
For instance, given the following code:
unsigned i = 0;
bool insert_phi_p;
sbitmap_iterator sbi;
+ tree sym;
+
+ /* Only one update flag should be set. */
+ gcc_assert (update_flags == TODO_update_ssa
+ || update_flags == TODO_update_ssa_no_phi
+ || update_flags == TODO_update_ssa_full_phi
+ || update_flags == TODO_update_ssa_only_virtuals);
if (!need_ssa_update_p (cfun))
return;
if (!update_ssa_initialized_fn)
init_update_ssa (cfun);
+ else if (update_flags == TODO_update_ssa_only_virtuals)
+ {
+ /* If we only need to update virtuals, remove all the mappings for
+ real names before proceeding. The caller is responsible for
+ having dealt with the name mappings before calling update_ssa. */
+ bitmap_clear (old_ssa_names);
+ bitmap_clear (new_ssa_names);
+ }
+
gcc_assert (update_ssa_initialized_fn == cfun);
blocks_with_phis_to_rewrite = BITMAP_ALLOC (NULL);
- if (!phis_to_rewrite)
- phis_to_rewrite = VEC_alloc (gimple_vec, heap, last_basic_block);
+ if (!phis_to_rewrite.exists ())
+ phis_to_rewrite.create (last_basic_block + 1);
blocks_to_update = BITMAP_ALLOC (NULL);
/* Ensure that the dominance information is up-to-date. */
calculate_dominance_info (CDI_DOMINATORS);
- /* Only one update flag should be set. */
- gcc_assert (update_flags == TODO_update_ssa
- || update_flags == TODO_update_ssa_no_phi
- || update_flags == TODO_update_ssa_full_phi
- || update_flags == TODO_update_ssa_only_virtuals);
-
- /* If we only need to update virtuals, remove all the mappings for
- 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);
- }
-
insert_phi_p = (update_flags != TODO_update_ssa_no_phi);
- if (insert_phi_p)
- {
- /* 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
- blocks have uses of N (i.e., N is live-on-entry in those
- blocks). */
- def_blocks = htab_create (num_ssa_names, def_blocks_hash,
- def_blocks_eq, def_blocks_free);
- }
- else
- {
- def_blocks = NULL;
- }
-
- /* 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)
+ if (bitmap_first_set_bit (new_ssa_names) >= 0)
{
prepare_names_to_update (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 (cfun)))
+ if (bitmap_first_set_bit (new_ssa_names) < 0
+ && !cfun->gimple_df->ssa_renaming_needed)
goto done;
}
/* Next, determine the block at which to start the renaming process. */
- if (!bitmap_empty_p (SYMS_TO_RENAME (cfun)))
+ if (cfun->gimple_df->ssa_renaming_needed)
{
+ /* If we rename bare symbols initialize the mapping to
+ auxiliar info we need to keep track of. */
+ var_infos = htab_create (47, var_info_hash, var_info_eq, free);
+
/* 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
start_bb = ENTRY_BLOCK_PTR;
/* Traverse the CFG looking for existing definitions and uses of
- symbols in SYMS_TO_RENAME. Mark interesting blocks and
+ symbols in SSA operands. 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);
+
+#ifdef ENABLE_CHECKING
+ for (i = 1; i < num_ssa_names; ++i)
+ {
+ tree name = ssa_name (i);
+ if (!name
+ || virtual_operand_p (name))
+ continue;
+
+ /* For all but virtual operands, which do not have SSA names
+ with overlapping life ranges, ensure that symbols marked
+ for renaming do not have existing SSA names associated with
+ them as we do not re-write them out-of-SSA before going
+ into SSA for the remaining symbol uses. */
+ if (marked_for_renaming (SSA_NAME_VAR (name)))
+ {
+ fprintf (stderr, "Existing SSA name for symbol marked for "
+ "renaming: ");
+ print_generic_expr (stderr, name, TDF_SLIM);
+ fprintf (stderr, "\n");
+ internal_error ("SSA corruption");
+ }
+ }
+#endif
}
else
{
/* If requested, insert PHI nodes at the iterated dominance frontier
of every block, creating new definitions for names in OLD_SSA_NAMES
- and for symbols in SYMS_TO_RENAME. */
+ and for symbols found. */
if (insert_phi_p)
{
bitmap_head *dfs;
bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
compute_dominance_frontiers (dfs);
- if (sbitmap_first_set_bit (old_ssa_names) >= 0)
+ if (bitmap_first_set_bit (old_ssa_names) >= 0)
{
sbitmap_iterator sbi;
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, sbi)
+ sbitmap tmp = sbitmap_alloc (SBITMAP_SIZE (old_ssa_names));
+ bitmap_copy (tmp, old_ssa_names);
+ EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, sbi)
insert_updated_phi_nodes_for (ssa_name (i), dfs, blocks_to_update,
update_flags);
sbitmap_free (tmp);
}
- EXECUTE_IF_SET_IN_BITMAP (SYMS_TO_RENAME (cfun), 0, i, bi)
- insert_updated_phi_nodes_for (referenced_var (i), dfs, blocks_to_update,
+ symbols_to_rename.qsort (insert_updated_phi_nodes_compare_uids);
+ FOR_EACH_VEC_ELT (symbols_to_rename, i, sym)
+ insert_updated_phi_nodes_for (sym, dfs, blocks_to_update,
update_flags);
FOR_EACH_BB (bb)
/* Reset the current definition for name and symbol before renaming
the sub-graph. */
- EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
- set_current_def (ssa_name (i), NULL_TREE);
+ EXECUTE_IF_SET_IN_BITMAP (old_ssa_names, 0, i, sbi)
+ get_ssa_name_ann (ssa_name (i))->info.current_def = NULL_TREE;
- EXECUTE_IF_SET_IN_BITMAP (SYMS_TO_RENAME (cfun), 0, i, bi)
- set_current_def (referenced_var (i), NULL_TREE);
+ FOR_EACH_VEC_ELT (symbols_to_rename, i, sym)
+ get_var_info (sym)->info.current_def = NULL_TREE;
/* Now start the renaming process at START_BB. */
interesting_blocks = sbitmap_alloc (last_basic_block);
- sbitmap_zero (interesting_blocks);
+ bitmap_clear (interesting_blocks);
EXECUTE_IF_SET_IN_BITMAP (blocks_to_update, 0, i, bi)
- SET_BIT (interesting_blocks, i);
+ bitmap_set_bit (interesting_blocks, i);
rewrite_blocks (start_bb, REWRITE_UPDATE);