GCC Middle and Back End API Reference
tree-into-ssa.c File Reference

Data Structures

struct  def_blocks_d
struct  mark_def_sites_global_data
struct  common_info_d
struct  var_info_d
struct  var_info_hasher
struct  ssa_name_info
struct  dom_dfsnum

Typedefs

typedef struct def_blocks_ddef_blocks_p
typedef struct common_info_dcommon_info_p
typedef struct var_info_dvar_info_p
typedef struct ssa_name_infossa_name_info_p

Enumerations

enum  rewrite_mode { REWRITE_ALL, REWRITE_UPDATE }

Functions

void dump_tree_ssa (FILE *)
void debug_tree_ssa (void)
void debug_def_blocks (void)
void dump_tree_ssa_stats (FILE *)
void debug_tree_ssa_stats (void)
void dump_update_ssa (FILE *)
void debug_update_ssa (void)
void dump_names_replaced_by (FILE *, tree)
void debug_names_replaced_by (tree)
void dump_var_infos (FILE *)
void debug_var_infos (void)
void dump_defs_stack (FILE *, int)
void debug_defs_stack (int)
void dump_currdefs (FILE *)
void debug_currdefs (void)
static void mark_for_renaming ()
static bool marked_for_renaming ()
static bool rewrite_uses_p ()
static void set_rewrite_uses ()
static bool register_defs_p ()
static void set_register_defs ()
static ssa_name_info_p get_ssa_name_ann ()
static var_info_p get_var_info ()
static void clear_ssa_name_info ()
static common_info_p get_common_info ()
tree get_current_def ()
void set_current_def ()
static void initialize_flags_in_bb ()
static void mark_block_for_update ()
static struct def_blocks_dget_def_blocks_for ()
static void set_def_block ()
static void set_livein_block ()
static bool is_old_name ()
static bool is_new_name ()
static bitmap names_replaced_by ()
static void add_to_repl_tbl ()
static void add_new_name_mapping ()
static void mark_def_sites ()
static int cmp_dfsnum ()
static unsigned find_dfsnum_interval ()
static void prune_unused_phi_nodes ()
static struct def_blocks_dfind_def_blocks_for ()
static void mark_phi_for_rewrite ()
static void insert_phi_nodes_for ()
static int insert_phi_nodes_compare_var_infos ()
static void insert_phi_nodes ()
static void register_new_def ()
static tree get_reaching_def ()
static void rewrite_debug_stmt_uses ()
static void rewrite_stmt ()
static void rewrite_add_phi_arguments ()
static void rewrite_enter_block (struct dom_walk_data *walk_data, basic_block bb)
static void rewrite_leave_block (struct dom_walk_data *walk_data, basic_block bb)
void dump_decl_set ()
DEBUG_FUNCTION void debug_decl_set ()
void dump_defs_stack ()
DEBUG_FUNCTION void debug_defs_stack ()
void dump_currdefs ()
void dump_tree_ssa ()
static void htab_statistics ()
void dump_tree_ssa_stats ()
int debug_var_infos_r ()
void dump_var_infos ()
static void register_new_update_single ()
static void register_new_update_set ()
static void maybe_replace_use ()
static bool maybe_replace_use_in_debug_stmt ()
static void maybe_register_def (def_operand_p def_p, gimple stmt, gimple_stmt_iterator gsi)
static void rewrite_update_stmt ()
static void rewrite_update_phi_arguments ()
static void rewrite_update_enter_block (struct dom_walk_data *walk_data, basic_block bb)
static void rewrite_update_leave_block (struct dom_walk_data *walk_data, basic_block bb)
static void rewrite_blocks ()
static void mark_def_sites_block ()
static void mark_def_site_blocks ()
static void init_ssa_renamer ()
static void fini_ssa_renamer ()
static unsigned int rewrite_into_ssa ()
gimple_opt_passmake_pass_build_ssa ()
static void mark_def_interesting ()
static void mark_use_interesting ()
static void prepare_block_for_update ()
static void prepare_use_sites_for ()
static void prepare_def_site_for ()
static void prepare_names_to_update ()
void dump_names_replaced_by ()
DEBUG_FUNCTION void debug_names_replaced_by ()
void dump_update_ssa ()
static void init_update_ssa ()
void delete_update_ssa ()
tree create_new_def_for ()
void mark_virtual_operands_for_renaming ()
bool need_ssa_update_p ()
bool name_registered_for_update_p ()
void release_ssa_name_after_update_ssa ()
static void insert_updated_phi_nodes_for (tree var, bitmap_head *dfs, bitmap blocks, unsigned update_flags)
static int insert_updated_phi_nodes_compare_uids ()
void update_ssa ()

Variables

static vec< treeblock_defs_stack
static sbitmap old_ssa_names
static sbitmap new_ssa_names
static sbitmap interesting_blocks
static bitmap names_to_release
static vec< gimple_vecphis_to_rewrite
static bitmap blocks_with_phis_to_rewrite
static struct functionupdate_ssa_initialized_fn = NULL
static hash_table
< var_info_hasher
var_infos
static vec< ssa_name_info_pinfo_for_ssa_name
static unsigned current_info_for_ssa_name_age
static bitmap_obstack update_ssa_obstack
static bitmap blocks_to_update
static bitmap symbols_to_rename_set
static vec< treesymbols_to_rename

Typedef Documentation

typedef struct common_info_d* common_info_p
The information associated with decls and SSA names.   
typedef struct def_blocks_d* def_blocks_p
typedef struct ssa_name_info* ssa_name_info_p
The information associated with names.   
typedef struct var_info_d* var_info_p
The information associated with decls.   

Enumeration Type Documentation

The main entry point to the SSA renamer (rewrite_blocks) may be
   called several times to do different, but related, tasks.
   Initially, we need it to rename the whole program into SSA form.
   At other times, we may need it to only rename into SSA newly
   exposed symbols.  Finally, we can also call it to incrementally fix
   an already built SSA web.   
Enumerator:
REWRITE_ALL 
REWRITE_UPDATE 

Function Documentation

static void add_new_name_mapping ( )
static
Add a new mapping NEW_TREE -> OLD REPL_TBL.  Every entry N_i in REPL_TBL
   represents the set of names O_1 ... O_j replaced by N_i.  This is
   used by update_ssa and its helpers to introduce new SSA names in an
   already formed SSA web.   

References add_to_repl_tbl(), bitmap_ior_into(), bitmap_set_bit(), is_new_name(), names_replaced_by(), and sbitmap_resize().

Referenced by create_new_def_for(), and insert_phi_nodes_for().

static void add_to_repl_tbl ( )
inlinestatic
Add OLD to REPL_TBL[NEW_TREE].SET.   

References bitmap_set_bit(), get_ssa_name_ann(), and ssa_name_info::repl_set.

Referenced by add_new_name_mapping().

static void clear_ssa_name_info ( )
static
Clears info for SSA names.   

References current_info_for_ssa_name_age.

Referenced by delete_update_ssa().

static int cmp_dfsnum ( )
static
Compares two entries of type struct dom_dfsnum by dfs_num field.  Callback
   for qsort.   

References dom_dfsnum::dfs_num.

Referenced by prune_unused_phi_nodes().

tree create_new_def_for ( )
Create a new name for OLD_NAME in statement STMT and replace the
   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.   

References add_new_name_mapping(), bb_has_abnormal_pred(), cfun, duplicate_ssa_name(), get_ssa_name_ann(), gimple_assign_set_lhs(), gimple_bb(), ssa_name_info::info, init_update_ssa(), timevar_pop(), and timevar_push().

DEBUG_FUNCTION void debug_currdefs ( )
Dump the current reaching definition of every symbol to stderr.   

References dump_currdefs().

DEBUG_FUNCTION void debug_decl_set ( )
Dump bitmap SET (assumed to contain VAR_DECLs) to FILE.   

References dump_decl_set().

void debug_def_blocks ( void  )
void debug_defs_stack ( int  )
DEBUG_FUNCTION void debug_defs_stack ( )
Dump the renaming stack (block_defs_stack) to stderr.  Traverse the
   stack up to a maximum of N levels.  If N is -1, the whole stack is
   dumped.  New levels are created when the dominator tree traversal
   used for renaming enters a new sub-tree.   

References dump_defs_stack().

void debug_names_replaced_by ( tree  )
DEBUG_FUNCTION void debug_names_replaced_by ( )
Dump all the names replaced by NAME to stderr.   

References dump_names_replaced_by().

DEBUG_FUNCTION void debug_tree_ssa ( )
Dump SSA information to stderr.   

References dump_tree_ssa().

DEBUG_FUNCTION void debug_tree_ssa_stats ( )
Dump SSA statistics on stderr.   

References dump_tree_ssa_stats().

DEBUG_FUNCTION void debug_update_ssa ( )
Dump SSA update information to stderr.   

References dump_update_ssa().

DEBUG_FUNCTION void debug_var_infos ( )
Dump the VAR_INFOS hash table on stderr.   

References dump_var_infos().

int debug_var_infos_r ( )
Callback for htab_traverse to dump the VAR_INFOS hash table.   

References bitmap_print(), dump_flags, var_info_d::info, print_generic_expr(), and var_info_d::var.

Referenced by dump_var_infos().

void delete_update_ssa ( void  )
Deallocate data structures used for incremental SSA updates.   

References clear_ssa_name_info(), fini_ssa_renamer(), phis, release_ssa_name(), and sbitmap_free().

Referenced by copy_loop_before(), slpeel_tree_peel_loop_to_edge(), and update_ssa().

void dump_currdefs ( FILE *  )

Referenced by debug_currdefs(), and dump_tree_ssa().

void dump_currdefs ( )
Dump the current reaching definition of every symbol to FILE.   

References get_common_info(), and print_generic_expr().

void dump_decl_set ( )
Dump bitmap SET (assumed to contain VAR_DECLs) to FILE.   

Referenced by debug_decl_set(), dump_points_to_solution(), and dump_update_ssa().

void dump_defs_stack ( FILE *  ,
int   
)

Referenced by debug_defs_stack(), and dump_tree_ssa().

void dump_defs_stack ( )
Dump the renaming stack (block_defs_stack) to FILE.  Traverse the
   stack up to a maximum of N levels.  If N is -1, the whole stack is
   dumped.  New levels are created when the dominator tree traversal
   used for renaming enters a new sub-tree.   

References is_gimple_reg(), and print_generic_expr().

void dump_names_replaced_by ( FILE *  ,
tree   
)
void dump_names_replaced_by ( )
Dump all the names replaced by NAME to FILE.   

References names_replaced_by(), and print_generic_expr().

void dump_tree_ssa ( FILE *  )
Prototypes for debugging functions.   

Referenced by debug_tree_ssa().

void dump_tree_ssa ( )
void dump_tree_ssa_stats ( FILE *  )
void dump_tree_ssa_stats ( )
Dump SSA statistics on FILE.   

References htab_statistics(), and hash_table< Descriptor, Allocator >::is_created().

void dump_update_ssa ( FILE *  )

Referenced by debug_update_ssa(), and update_ssa().

void dump_update_ssa ( )
void dump_var_infos ( FILE *  )

Referenced by debug_var_infos(), and dump_tree_ssa().

void dump_var_infos ( )
static struct def_blocks_d* find_def_blocks_for ( )
staticread
Return the set of blocks where variable VAR is defined and the blocks
   where VAR is live on entry (livein).  Return NULL, if no entry is
   found in DEF_BLOCKS.   

References def_blocks_d::def_blocks, and get_common_info().

Referenced by insert_phi_nodes_for(), and insert_updated_phi_nodes_for().

static unsigned find_dfsnum_interval ( )
static
Among the intervals starting at the N points specified in DEFS, find
   the one that contains S, and return its bb_index.   

References dom_dfsnum::bb_index, and dom_dfsnum::dfs_num.

Referenced by prune_unused_phi_nodes().

tree get_current_def ( )
Return the current definition for VAR.   

References get_common_info().

static struct def_blocks_d* get_def_blocks_for ( )
staticread
Return the set of blocks where variable VAR is defined and the blocks
   where VAR is live on entry (livein).  If no entry is found in
   DEF_BLOCKS, a new one is created and returned.   

References def_blocks_d::def_blocks, def_blocks_d::livein_blocks, and def_blocks_d::phi_blocks.

Referenced by mark_use_interesting(), rewrite_debug_stmt_uses(), set_def_block(), and set_livein_block().

static tree get_reaching_def ( )
static
Perform a depth-first traversal of the dominator tree looking for
   variables to rename.  BB is the block where to start searching.
   Renaming is a five step process:

   1- Every definition made by PHI nodes at the start of the blocks is
      registered as the current definition for the corresponding variable.

   2- Every statement in BB is rewritten.  USE and VUSE operands are
      rewritten with their corresponding reaching definition.  DEF and
      VDEF targets are registered as new definitions.

   3- All the PHI nodes in successor blocks of BB are visited.  The
      argument corresponding to BB is replaced with its current reaching
      definition.

   4- Recursively rewrite every dominator child block of BB.

   5- Restore (in reverse order) the current reaching definition for every
      new definition introduced in this block.  This is done so that when
      we return from the recursive call, all the current reaching
      definitions are restored to the names that were valid in the
      dominator parent of BB.   
Return the current definition for variable VAR.  If none is found,
   create a new SSA name to act as the zeroth definition for VAR.   

References cfun, get_common_info(), get_or_create_ssa_default_def(), and var_info_d::info.

Referenced by maybe_replace_use(), rewrite_add_phi_arguments(), rewrite_stmt(), and rewrite_update_phi_arguments().

static var_info_p get_var_info ( )
inlinestatic
Return and allocate the auxiliar information for DECL.   

References hash_table< Descriptor, Allocator >::find_slot_with_hash(), and var_info_d::var.

Referenced by get_common_info(), maybe_replace_use_in_debug_stmt(), and update_ssa().

static void init_update_ssa ( )
static
Initialize data structures used for incremental SSA updates.   

References bitmap_clear(), bitmap_obstack_initialize(), and sbitmap_alloc().

Referenced by create_new_def_for(), and update_ssa().

static void initialize_flags_in_bb ( )
static
Cleans up the REWRITE_THIS_STMT and REGISTER_DEFS_IN_THIS_STMT flags for
   all statements in basic block BB.   

References gimple_modified_p(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), set_register_defs(), and set_rewrite_uses().

Referenced by mark_block_for_update().

static void insert_phi_nodes ( )
static
Insert PHI nodes at the dominance frontier of blocks with variable
   definitions.  DFS contains the dominance frontier information for
   the flowgraph.   

References compute_idf(), hash_table< Descriptor, Allocator >::elements(), var_info_d::info, insert_phi_nodes_compare_var_infos(), insert_phi_nodes_for(), NEED_PHI_STATE_NO, timevar_pop(), timevar_push(), and var_info_d::var.

Referenced by rewrite_into_ssa().

static int insert_phi_nodes_compare_var_infos ( )
static
Sort var_infos after DECL_UID of their var.   

References var_info_d::var.

Referenced by insert_phi_nodes().

static void insert_phi_nodes_for ( )
static
Insert PHI nodes for variable VAR using the iterated dominance
   frontier given in PHI_INSERTION_POINTS.  If UPDATE_P is true, this
   function assumes that the caller is incrementally updating the
   existing SSA form, in which case VAR may be an SSA name instead of
   a symbol.

   PHI_INSERTION_POINTS is updated to reflect nodes that already had a
   PHI node for VAR.  On exit, only the nodes that received a PHI node
   for VAR will be present in PHI_INSERTION_POINTS.   

References add_new_name_mapping(), add_phi_arg(), bitmap_and_compl_into(), create_phi_node(), def_blocks_d::def_blocks, dump_file, dump_flags, duplicate_ssa_name(), find_def_blocks_for(), gsi_after_labels(), gsi_insert_before(), GSI_SAME_STMT, def_blocks_d::livein_blocks, mark_block_for_update(), mark_phi_for_rewrite(), def_blocks_d::phi_blocks, basic_block_def::preds, print_generic_expr(), prune_unused_phi_nodes(), set_register_defs(), si, and target_for_debug_bind().

Referenced by insert_phi_nodes(), and insert_updated_phi_nodes_for().

static int insert_updated_phi_nodes_compare_uids ( )
static
Sort symbols_to_rename after their DECL_UID.   

Referenced by update_ssa().

static void insert_updated_phi_nodes_for ( tree  var,
bitmap_head dfs,
bitmap  blocks,
unsigned  update_flags 
)
static
Insert new PHI nodes to replace VAR.  DFS contains dominance
   frontier information.  BLOCKS is the set of blocks to be updated.

   This is slightly different than the regular PHI insertion
   algorithm.  The value of UPDATE_FLAGS controls how PHI nodes for
   real names (i.e., GIMPLE registers) are inserted:

   - If UPDATE_FLAGS == TODO_update_ssa, we are only interested in PHI
     nodes inside the region affected by the block that defines VAR
     and the blocks that define all its replacements.  All these
     definition blocks are stored in DEF_BLOCKS[VAR]->DEF_BLOCKS.

     First, we compute the entry point to the region (ENTRY).  This is
     given by the nearest common dominator to all the definition
     blocks. When computing the iterated dominance frontier (IDF), any
     block not strictly dominated by ENTRY is ignored.

     We then call the standard PHI insertion algorithm with the pruned
     IDF.

   - If UPDATE_FLAGS == TODO_update_ssa_full_phi, the IDF for real
     names is not pruned.  PHI nodes are inserted at every IDF block.   

References bitmap_copy(), bitmap_empty_p(), bitmap_ior_into(), bitmap_set_bit(), CDI_DOMINATORS, compute_idf(), def_blocks_d::def_blocks, dominated_by_p(), find_def_blocks_for(), basic_block_def::index, insert_phi_nodes_for(), is_old_name(), marked_for_renaming(), nearest_common_dominator_for_set(), basic_block_def::preds, and edge_def::src.

Referenced by update_ssa().

static bool is_new_name ( )
inlinestatic
gimple_opt_pass* make_pass_build_ssa ( )
static void mark_block_for_update ( )
static
static void mark_def_interesting ( )
static
Mark the definition of VAR at STMT and BB as interesting for the
   renamer.  BLOCKS is the set of blocks that need updating.   

References bitmap_bit_p(), basic_block_def::index, is_new_name(), names_replaced_by(), set_def_block(), and set_register_defs().

Referenced by prepare_block_for_update(), and prepare_def_site_for().

static void mark_def_site_blocks ( )
static
Mark the definition site blocks for each variable, so that we know
   where the variable is actually live.

   The INTERESTING_BLOCKS global will be filled in with all the blocks
   that should be processed by the renamer.  It is assumed that the
   caller has already initialized and zeroed it.   

References dom_walk_data::after_dom_children, dom_walk_data::before_dom_children, dom_walk_data::block_local_data_size, CDI_DOMINATORS, fini_walk_dominator_tree(), dom_walk_data::global_data, init_walk_dominator_tree(), dom_walk_data::initialize_block_local_data, mark_def_sites_global_data::kills, mark_def_sites_block(), and walk_dominator_tree().

Referenced by rewrite_into_ssa().

static void mark_def_sites ( )
static
Call back for walk_dominator_tree used to collect definition sites
   for every variable in the function.  For every statement S in block
   BB:

   1- Variables defined by S in the DEFS of S are marked in the bitmap
      KILLS.

   2- If S uses a variable VAR and there is no preceding kill of VAR,
      then it is marked in the LIVEIN_BLOCKS bitmap associated with VAR.

   This information is used to determine which variables are live
   across block boundaries to reduce the number of PHI nodes
   we create.   

References bitmap_bit_p(), bitmap_set_bit(), basic_block_def::index, is_gimple_debug(), register_defs_p(), rewrite_uses_p(), set_def_block(), set_livein_block(), set_register_defs(), set_rewrite_uses(), and update_stmt().

Referenced by mark_def_sites_block().

static void mark_def_sites_block ( )
static
Block processing routine for mark_def_sites.  Clear the KILLS bitmap
   at the start of each block, and call mark_def_sites for each statement.   

References bitmap_clear(), dom_walk_data::global_data, gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), mark_def_sites_global_data::kills, and mark_def_sites().

Referenced by mark_def_site_blocks().

static void mark_for_renaming ( )
static
Mark SYM for renaming.   

References bitmap_set_bit().

Referenced by prepare_block_for_update().

static void mark_phi_for_rewrite ( )
static
Marks phi node PHI in basic block BB for rewrite.   

References bitmap_set_bit(), basic_block_def::index, phis, rewrite_uses_p(), and set_rewrite_uses().

Referenced by insert_phi_nodes_for(), and mark_use_interesting().

static void mark_use_interesting ( )
inlinestatic
Mark the use of VAR at STMT and BB as interesting for the
   renamer.  INSERT_PHI_P is true if we are going to insert new PHI
   nodes.   

References bitmap_bit_p(), def_blocks_d::def_blocks, get_common_info(), get_def_blocks_for(), gimple_bb(), basic_block_def::index, is_gimple_debug(), mark_block_for_update(), mark_phi_for_rewrite(), set_livein_block(), and set_rewrite_uses().

Referenced by prepare_block_for_update(), and prepare_use_sites_for().

void mark_virtual_operands_for_renaming ( )
Mark virtual operands of FN for renaming by update_ssa.   
static bool marked_for_renaming ( )
static
static void maybe_register_def ( def_operand_p  def_p,
gimple  stmt,
gimple_stmt_iterator  gsi 
)
inlinestatic
If the operand pointed to by DEF_P is an SSA name in NEW_SSA_NAMES
   or OLD_SSA_NAMES, or if it is a symbol marked for renaming,
   register it as the current definition for the names replaced by
   DEF_P.   

References edge_def::dest, edge_def::flags, gsi_bb(), gsi_insert_after(), gsi_insert_on_edge_immediate(), gsi_one_before_end_p(), GSI_SAME_STMT, is_new_name(), is_old_name(), make_ssa_name(), marked_for_renaming(), names_replaced_by(), register_new_update_set(), register_new_update_single(), single_pred_p(), stmt_ends_bb_p(), basic_block_def::succs, and target_for_debug_bind().

Referenced by rewrite_update_stmt().

static void maybe_replace_use ( )
inlinestatic
If the operand pointed to by USE_P is a name in OLD_SSA_NAMES or
   it is a symbol marked for renaming, replace it with USE_P's current
   reaching definition.   

References get_reaching_def(), is_old_name(), and marked_for_renaming().

Referenced by rewrite_update_stmt().

static bool maybe_replace_use_in_debug_stmt ( )
inlinestatic
Same as maybe_replace_use, but without introducing default stmts,
   returning false to indicate a need to do so.   

References get_ssa_name_ann(), get_var_info(), var_info_d::info, ssa_name_info::info, is_old_name(), and marked_for_renaming().

Referenced by rewrite_update_stmt().

bool name_registered_for_update_p ( )
Return true if name N has been registered in the replacement table.   

References cfun, is_new_name(), and is_old_name().

static bitmap names_replaced_by ( )
inlinestatic
Return the names replaced by NEW_TREE (i.e., REPL_TBL[NEW_TREE].SET).   

References get_ssa_name_ann(), and ssa_name_info::repl_set.

Referenced by add_new_name_mapping(), dump_names_replaced_by(), mark_def_interesting(), maybe_register_def(), and rewrite_update_enter_block().

bool need_ssa_update_p ( )
Return true if there is any work to be done by update_ssa
   for function FN.   
static void prepare_block_for_update ( )
static
Do a dominator walk starting at BB processing statements that
   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.

   If INSERT_PHI_P is true, mark those uses as live in the
   corresponding block.  This is later used by the PHI placement
   algorithm to make PHI pruning decisions.

   FIXME.  Most of this would be unnecessary if we could associate a
           symbol to all the SSA names that reference it.  But that
           sounds like it would be expensive to maintain.  Still, it
           would be interesting to see if it makes better sense to do
           that.   

References CDI_DOMINATORS, cfun, first_dom_son(), function::gimple_df, gimple_phi_result(), gimple_vdef(), gimple_vuse(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), mark_block_for_update(), mark_def_interesting(), mark_for_renaming(), mark_use_interesting(), next_dom_son(), basic_block_def::preds, gimple_df::rename_vops, si, edge_def::src, and virtual_operand_p().

Referenced by update_ssa().

static void prepare_def_site_for ( )
static
Helper for prepare_names_to_update.  Mark the definition site for
   NAME as interesting.  BLOCKS and INSERT_PHI_P are as in
   prepare_names_to_update.   

References bitmap_bit_p(), gimple_bb(), basic_block_def::index, mark_block_for_update(), and mark_def_interesting().

Referenced by prepare_names_to_update().

static void prepare_names_to_update ( )
static
Mark definition and use sites of names in NEW_SSA_NAMES and
   OLD_SSA_NAMES.  INSERT_PHI_P is true if the caller wants to insert
   PHI nodes for newly created names.   

References bitmap_bit_p(), bitmap_clear_bit(), prepare_def_site_for(), and prepare_use_sites_for().

Referenced by update_ssa().

static void prepare_use_sites_for ( )
static
Helper for prepare_names_to_update.  Mark all the use sites for
   NAME as interesting.  BLOCKS and INSERT_PHI_P are as in
   prepare_names_to_update.   

References gimple_bb(), gimple_phi_arg_edge(), mark_use_interesting(), and edge_def::src.

Referenced by prepare_names_to_update().

static void prune_unused_phi_nodes ( )
static
static bool register_defs_p ( )
inlinestatic
Return true if the DEFs created by statement STMT should be
   registered when marking new definition sites.  This is slightly
   different than rewrite_uses_p: it's used by update_ssa to
   distinguish statements that need to have both uses and defs
   processed from those that only need to have their defs processed.
   Statements that define new SSA names only need to have their defs
   registered, but they don't need to have their uses renamed.   

References GF_PLF_1, and gimple_plf().

Referenced by mark_def_sites(), rewrite_stmt(), rewrite_update_enter_block(), and rewrite_update_stmt().

static void register_new_def ( )
static
Push SYM's current reaching definition into BLOCK_DEFS_STACK and
   register DEF (an SSA_NAME) to be a new definition for SYM.   

References get_common_info(), var_info_d::info, is_gimple_reg(), and NEED_PHI_STATE_NO.

Referenced by rewrite_enter_block(), and rewrite_stmt().

static void register_new_update_set ( )
inlinestatic
Register NEW_NAME to be the new reaching definition for all the
   names in OLD_NAMES.  Used by the incremental SSA update routines to
   replace old SSA names with new ones.   

References register_new_update_single().

Referenced by maybe_register_def(), and rewrite_update_enter_block().

static void register_new_update_single ( )
inlinestatic
Register NEW_NAME to be the new reaching definition for OLD_NAME.   

References get_common_info(), and var_info_d::info.

Referenced by maybe_register_def(), register_new_update_set(), and rewrite_update_enter_block().

void release_ssa_name_after_update_ssa ( )
Mark NAME to be released after update_ssa has finished.   

References bitmap_set_bit(), and cfun.

static void rewrite_add_phi_arguments ( )
static
SSA Rewriting 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 reaching definition for the variable and the edge through which
   that definition is reaching the PHI node.   

References add_phi_arg(), edge_def::dest, get_reaching_def(), gimple_location(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), basic_block_def::succs, and virtual_operand_p().

Referenced by rewrite_enter_block().

static void rewrite_blocks ( )
static
Rewrite the actual blocks, statements, and PHI arguments, to be in SSA
   form.

   ENTRY indicates the block where to start.  Every block dominated by
      ENTRY will be rewritten.

   WHAT indicates what actions will be taken by the renamer (see enum
      rewrite_mode).

   BLOCKS are the set of interesting blocks for the dominator walker
      to process.  If this set is NULL, then all the nodes dominated
      by ENTRY are walked.  Otherwise, blocks dominated by ENTRY that
      are not present in BLOCKS are ignored.   

References dom_walk_data::after_dom_children, dom_walk_data::before_dom_children, CDI_DOMINATORS, dump_dfa_stats(), dump_file, dump_flags, dump_tree_ssa_stats(), fini_walk_dominator_tree(), init_walk_dominator_tree(), hash_table< Descriptor, Allocator >::is_created(), memset(), REWRITE_ALL, rewrite_enter_block(), rewrite_leave_block(), REWRITE_UPDATE, rewrite_update_enter_block(), rewrite_update_leave_block(), timevar_pop(), timevar_push(), and walk_dominator_tree().

Referenced by rewrite_into_ssa(), and update_ssa().

static void rewrite_enter_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
SSA Rewriting Step 1.  Initialization, create a block local stack
   of reaching definitions for new SSA names produced in this block
   (BLOCK_DEFS).  Register new definitions for every PHI node in the
   block.   

References bitmap_bit_p(), dump_file, dump_flags, gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), basic_block_def::index, register_new_def(), rewrite_add_phi_arguments(), and rewrite_stmt().

Referenced by rewrite_blocks().

static unsigned int rewrite_into_ssa ( )
static
Main entry point into the SSA builder.  The renaming process
   proceeds in four main phases:

   1- Compute dominance frontier and immediate dominators, needed to
      insert PHI nodes and rename the function in dominator tree
      order.

   2- Find and mark all the blocks that define variables
      (mark_def_site_blocks).

   3- Insert PHI nodes at dominance frontiers (insert_phi_nodes).

   4- Rename all the blocks (rewrite_blocks) and statements in the program.

   Steps 3 and 4 are done using the dominator tree walker
   (walk_dominator_tree).   

References bitmap_clear(), bitmap_default_obstack, calculate_dominance_info(), CDI_DOMINATORS, cfun, compute_dominance_frontiers(), fini_ssa_renamer(), free(), basic_block_def::index, init_ssa_operands(), init_ssa_renamer(), insert_phi_nodes(), mark_def_site_blocks(), REWRITE_ALL, rewrite_blocks(), sbitmap_alloc(), and sbitmap_free().

static void rewrite_leave_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
Called after visiting all the statements in basic block BB and all
   of its dominator children.  Restore CURRDEFS to its original value.   

References get_common_info(), and is_gimple_reg().

Referenced by rewrite_blocks().

static void rewrite_stmt ( )
static
SSA Rewriting 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.   

References cfun, dump_file, dump_flags, get_or_create_ssa_default_def(), get_reaching_def(), gimple_build_nop(), gimple_clobber_p(), gimple_vdef(), gsi_insert_after(), gsi_replace(), GSI_SAME_STMT, gsi_stmt(), is_gimple_debug(), is_gimple_reg(), make_ssa_name(), print_gimple_stmt(), register_defs_p(), register_new_def(), rewrite_debug_stmt_uses(), rewrite_uses_p(), and target_for_debug_bind().

Referenced by rewrite_enter_block().

static void rewrite_update_enter_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
Initialization of block data structures for the incremental SSA
   update pass.  Create a block local stack of reaching definitions
   for new SSA names produced in this block (BLOCK_DEFS).  Register
   new definitions for every PHI node in the block.   

References bb_has_abnormal_pred(), bitmap_bit_p(), dump_file, dump_flags, gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), basic_block_def::index, is_new_name(), is_old_name(), marked_for_renaming(), names_replaced_by(), register_defs_p(), register_new_update_set(), register_new_update_single(), rewrite_update_phi_arguments(), and rewrite_update_stmt().

Referenced by rewrite_blocks().

static void rewrite_update_leave_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
Called after visiting block BB.  Unwind BLOCK_DEFS_STACK to restore
   the current reaching definition of every name re-written in BB to
   the original reaching definition before visiting BB.  This
   unwinding must be done in the opposite order to what is done in
   register_new_update_set.   

References get_common_info(), and var_info_d::var.

Referenced by rewrite_blocks().

static void rewrite_update_phi_arguments ( )
static
Visit all the successor blocks of BB looking for PHI nodes.  For
   every PHI node found, check if any of its arguments is in
   OLD_SSA_NAMES.  If so, and if the argument has a current reaching
   definition, replace it.   

References bitmap_bit_p(), edge_def::dest, edge_def::flags, get_reaching_def(), gimple_location(), gimple_phi_arg_location(), gimple_phi_arg_set_location(), gimple_phi_num_args(), gimple_phi_result(), basic_block_def::index, is_old_name(), marked_for_renaming(), phis, rewrite_uses_p(), basic_block_def::succs, and virtual_operand_p().

Referenced by rewrite_update_enter_block().

static void rewrite_update_stmt ( )
static
Update every variable used in the statement pointed-to by SI.  The
   statement is assumed to be in SSA form already.  Names in
   OLD_SSA_NAMES used by SI will be updated to their current reaching
   definition.  Names in OLD_SSA_NAMES or NEW_SSA_NAMES defined by SI
   will be registered as a new definition for their corresponding name
   in OLD_SSA_NAMES.   

References dump_file, dump_flags, gimple_debug_bind_reset_value(), is_gimple_debug(), maybe_register_def(), maybe_replace_use(), maybe_replace_use_in_debug_stmt(), print_gimple_stmt(), register_defs_p(), rewrite_uses_p(), and update_stmt().

Referenced by rewrite_update_enter_block().

static bool rewrite_uses_p ( )
inlinestatic
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.   

References gimple_visited_p().

Referenced by mark_def_sites(), mark_phi_for_rewrite(), rewrite_stmt(), rewrite_update_phi_arguments(), and rewrite_update_stmt().

void set_current_def ( )
Sets current definition of VAR to DEF.   

References get_common_info().

static void set_def_block ( )
static
Mark block BB as the definition site for variable VAR.  PHI_P is true if
   VAR is defined by a PHI node.   

References bitmap_set_bit(), def_blocks_d::def_blocks, get_common_info(), get_def_blocks_for(), basic_block_def::index, NEED_PHI_STATE_MAYBE, NEED_PHI_STATE_NO, NEED_PHI_STATE_UNKNOWN, and def_blocks_d::phi_blocks.

Referenced by mark_def_interesting(), and mark_def_sites().

static void set_register_defs ( )
inlinestatic
If REGISTER_DEFS_P is true, mark STMT to have its DEFs registered.   

References GF_PLF_1, and gimple_set_plf().

Referenced by initialize_flags_in_bb(), insert_phi_nodes_for(), mark_def_interesting(), and mark_def_sites().

static void set_rewrite_uses ( )
inlinestatic
Set the rewrite marker on STMT to the value given by REWRITE_P.   

References gimple_set_visited().

Referenced by initialize_flags_in_bb(), mark_def_sites(), mark_phi_for_rewrite(), and mark_use_interesting().

void update_ssa ( )
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:

   1- The names in OLD_SSA_NAMES dominated by the definitions of
      NEW_SSA_NAMES are all re-written to be reached by the
      appropriate definition from NEW_SSA_NAMES.

   2- If needed, new PHI nodes are added to the iterated dominance
      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 create_new_def_for to create new defs for names that the
   caller wants to replace.

   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:

     1  L0:
     2  x_1 = PHI (0, x_5)
     3  if (x_1 < 10)
     4    if (x_1 > 7)
     5      y_2 = 0
     6    else
     7      y_3 = x_1 + x_7
     8    endif
     9    x_5 = x_1 + 1
     10   goto L0;
     11 endif

   Suppose that we insert new names x_10 and x_11 (lines 4 and 8).

     1  L0:
     2  x_1 = PHI (0, x_5)
     3  if (x_1 < 10)
     4    x_10 = ...
     5    if (x_1 > 7)
     6      y_2 = 0
     7    else
     8      x_11 = ...
     9      y_3 = x_1 + x_7
     10   endif
     11   x_5 = x_1 + 1
     12   goto L0;
     13 endif

   We want to replace all the uses of x_1 with the new definitions of
   x_10 and x_11.  Note that the only uses that should be replaced are
   those at lines 5, 9 and 11.  Also, the use of x_7 at line 9 should
   *not* be replaced (this is why we cannot just mark symbol 'x' for
   renaming).

   Additionally, we may need to insert a PHI node at line 11 because
   that is a merge point for x_10 and x_11.  So the use of x_1 at line
   11 will be replaced with the new PHI node.  The insertion of PHI
   nodes is optional.  They are not strictly necessary to preserve the
   SSA form, and depending on what the caller inserted, they may not
   even be useful for the optimizers.  UPDATE_FLAGS controls various
   aspects of how update_ssa operates, see the documentation for
   TODO_update_ssa*.   

References bitmap_clear(), bitmap_copy(), bitmap_default_obstack, bitmap_first_set_bit(), bitmap_set_bit(), calculate_dominance_info(), CDI_DOMINATORS, cfun, compute_dominance_frontiers(), hash_table< Descriptor, Allocator >::create(), delete_update_ssa(), dump_file, dump_flags, dump_update_ssa(), free(), get_ssa_name_ann(), get_var_info(), function::gimple_df, basic_block_def::index, var_info_d::info, ssa_name_info::info, init_update_ssa(), insert_updated_phi_nodes_compare_uids(), insert_updated_phi_nodes_for(), internal_error(), marked_for_renaming(), nearest_common_dominator_for_set(), need_ssa_update_p(), prepare_block_for_update(), prepare_names_to_update(), print_generic_expr(), rewrite_blocks(), REWRITE_UPDATE, sbitmap_alloc(), sbitmap_free(), gimple_df::ssa_renaming_needed, timevar_pop(), timevar_push(), and virtual_operand_p().


Variable Documentation

vec<tree> block_defs_stack
static
Stack of trees used to restore the global currdefs to its original
   state after completing rewriting of a block and its dominator
   children.  Its elements have the following properties:

   - An SSA_NAME (N) indicates that the current definition of the
     underlying variable should be set to the given SSA_NAME.  If the
     symbol associated with the SSA_NAME is not a GIMPLE register, the
     next slot in the stack must be a _DECL node (SYM).  In this case,
     the name N in the previous slot is the current reaching
     definition for SYM.

   - A _DECL node indicates that the underlying variable has no
     current definition.

   - A NULL node at the top entry is used to mark the last slot
     associated with the current block.   
bitmap blocks_to_update
static
The set of blocks affected by update_ssa.   
bitmap blocks_with_phis_to_rewrite
static
The bitmap of non-NULL elements of PHIS_TO_REWRITE.   
unsigned current_info_for_ssa_name_age
static
vec<ssa_name_info_p> info_for_ssa_name
static
sbitmap interesting_blocks
static
bitmap names_to_release
static
Set of SSA names that have been marked to be released after they
   were registered in the replacement table.  They will be finally
   released after we finish updating the SSA web.   
sbitmap new_ssa_names
static
Set of new SSA names being added by update_ssa.  Note that both
   NEW_SSA_NAMES and OLD_SSA_NAMES are dense bitmaps because most of
   the operations done on them are presence tests.   
sbitmap old_ssa_names
static
Set of existing SSA names being replaced by update_ssa.   
vec<gimple_vec> phis_to_rewrite
static
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.   
vec<tree> symbols_to_rename
static
bitmap symbols_to_rename_set
static
The set of symbols we ought to re-write into SSA form in update_ssa.   
struct function* update_ssa_initialized_fn = NULL
static
The function the SSA updating data structures have been initialized for.
   NULL if they need to be initialized by create_new_def_for.   
bitmap_obstack update_ssa_obstack
static
hash_table<var_info_hasher> var_infos
static
Each entry in VAR_INFOS contains an element of type STRUCT 
   VAR_INFO_D.