#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;
typedef struct def_blocks_d *def_blocks_p;
-DEF_VEC_P(def_blocks_p);
-DEF_VEC_ALLOC_P(def_blocks_p,heap);
-
-
-/* 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
released after we finish updating the SSA web. */
static bitmap names_to_release;
+/* VEC of VECs 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, heap) *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;
/* Global data to attach to the main dominator walk structure. */
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;
+
+DEF_VEC_P(var_info_p);
+DEF_VEC_ALLOC_P(var_info_p,heap);
+
+/* 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. */
static VEC(ssa_name_info_p, heap) *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,heap) *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)))
+ VEC_safe_push (tree, heap, symbols_to_rename, 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. */
unsigned len = VEC_length (ssa_name_info_p, info_for_ssa_name);
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;
+ VEC_safe_grow_cleared (ssa_name_info_p, heap,
+ info_for_ssa_name, 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 = VEC_index (ssa_name_info_p, 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;
+ VEC_replace (ssa_name_info_p, 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)
+ && TEST_BIT (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)
+ && TEST_BIT (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));
+ 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);
respectively. */
SET_BIT (new_ssa_names, SSA_NAME_VERSION (new_tree));
SET_BIT (old_ssa_names, SSA_NAME_VERSION (old));
-
- timevar_pop (TV_TREE_SSA_INCREMENTAL);
}
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))
/* 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);
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);
+
+ n = (unsigned) last_basic_block + 1;
+ if (VEC_length (gimple_vec, phis_to_rewrite) < n)
+ VEC_safe_grow_cleared (gimple_vec, heap, phis_to_rewrite, n);
phis = VEC_index (gimple_vec, phis_to_rewrite, idx);
if (!phis)
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);
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 def_blocks after DECL_UID of their var. */
+/* Sort var_infos after DECL_UID of their var. */
static int
-insert_phi_nodes_compare_def_blocks (const void *a, const void *b)
+insert_phi_nodes_compare_var_infos (const void *a, const void *b)
{
- const struct def_blocks_d *defa = *(struct def_blocks_d * const *)a;
- const struct def_blocks_d *defb = *(struct def_blocks_d * const *)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
{
htab_iterator hi;
unsigned i;
- struct def_blocks_d *def_map;
- VEC(def_blocks_p,heap) *vars;
+ var_info_p info;
+ VEC(var_info_p,heap) *vars;
timevar_push (TV_TREE_INSERT_PHI_NODES);
- vars = VEC_alloc (def_blocks_p, heap, htab_elements (def_blocks));
- FOR_EACH_HTAB_ELEMENT (def_blocks, def_map, struct def_blocks_d *, hi)
- if (get_phi_state (def_map->var) != NEED_PHI_STATE_NO)
- VEC_quick_push (def_blocks_p, vars, def_map);
+ vars = VEC_alloc (var_info_p, heap, 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)
+ VEC_quick_push (var_info_p, vars, info);
/* Do two stages to avoid code generation differences for UID
differences but no UID ordering differences. */
- VEC_qsort (def_blocks_p, vars, insert_phi_nodes_compare_def_blocks);
+ VEC_qsort (var_info_p, vars, insert_phi_nodes_compare_var_infos);
- FOR_EACH_VEC_ELT (def_blocks_p, vars, i, def_map)
+ FOR_EACH_VEC_ELT (var_info_p, vars, i, info)
{
- bitmap idf = compute_idf (def_map->def_blocks, dfs);
- insert_phi_nodes_for (def_map->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);
}
- VEC_free(def_blocks_p, heap, vars);
+ VEC_free(var_info_p, heap, vars);
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
VEC_safe_push (tree, heap, block_defs_stack, 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);
}
}
}
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))
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));
}
of a variable when a new real or virtual definition is found. */
if (TEST_BIT (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
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, " ");
}
void
dump_currdefs (FILE *file)
{
- referenced_var_iterator i;
+ unsigned i;
tree var;
+ if (VEC_empty (tree, symbols_to_rename))
+ 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 (tree, 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)
+ if (var_infos)
{
- fprintf (file, " def_blocks: ");
- htab_statistics (file, def_blocks);
- }
-
- if (repl_tbl)
- {
- 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
/* 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
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);
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))
{
- 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);
}
return;
saved_def = VEC_pop (tree, block_defs_stack);
- set_current_def (var, saved_def);
+ get_common_info (var)->current_def = saved_def;
}
}
if (dump_file && (dump_flags & TDF_STATS))
{
dump_dfa_stats (dump_file);
- if (def_blocks)
+ if (var_infos)
dump_tree_ssa_stats (dump_file);
}
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_length (tree, 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 (cfun);
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;
}
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);
}
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;
dump_names_replaced_by (file, ssa_name (i));
}
- 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;
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 (symbols_to_rename_set);
+ symbols_to_rename_set = NULL;
+ VEC_free (tree, heap, symbols_to_rename);
if (names_to_release)
{
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);
- SET_DEF (def, new_name);
+ gcc_assert (update_ssa_initialized_fn == cfun);
+
+ 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;
-}
-
+ get_ssa_name_ann (old_name)->info.current_def = 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);
+ timevar_pop (TV_TREE_SSA_INCREMENTAL);
- add_new_name_mapping (new_tree, old);
+ return new_name;
}
-/* Register symbol SYM to be renamed by update_ssa. */
+/* Mark virtual operands of FN for renaming by update_ssa. */
void
-mark_sym_for_renaming (tree sym)
+mark_virtual_operands_for_renaming (struct function *fn)
{
- bitmap_set_bit (SYMS_TO_RENAME (cfun), DECL_UID (sym));
+ 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. */
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);
}
}
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);
+ phis_to_rewrite = VEC_alloc (gimple_vec, heap, 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;
- }
-
/* 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);
+ sbitmap tmp = sbitmap_alloc (SBITMAP_SIZE (old_ssa_names));
+ bitmap_copy (tmp, old_ssa_names);
EXECUTE_IF_SET_IN_SBITMAP (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,
+ FOR_EACH_VEC_ELT (tree, 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);
+ 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 (tree, 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);