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
class  rewrite_dom_walker
class  rewrite_update_dom_walker
class  mark_def_dom_walker

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  need_phi_state { NEED_PHI_STATE_UNKNOWN, NEED_PHI_STATE_NO, NEED_PHI_STATE_MAYBE }
enum  rewrite_mode { REWRITE_ALL, REWRITE_UPDATE }

Functions

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 ()
DEBUG_FUNCTION void debug_decl_set ()
void dump_defs_stack ()
DEBUG_FUNCTION void debug_defs_stack ()
void dump_currdefs ()
DEBUG_FUNCTION void debug_currdefs ()
void dump_tree_ssa ()
DEBUG_FUNCTION void debug_tree_ssa ()
static void htab_statistics ()
void dump_tree_ssa_stats ()
DEBUG_FUNCTION void debug_tree_ssa_stats ()
int debug_var_infos_r ()
void dump_var_infos ()
DEBUG_FUNCTION void debug_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_blocks ()
static void init_ssa_renamer ()
static void fini_ssa_renamer ()
static unsigned int rewrite_into_ssa ()
static bool gate_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 ()
DEBUG_FUNCTION void debug_update_ssa ()
static void init_update_ssa ()
void delete_update_ssa ()
tree create_new_def_for ()
void mark_virtual_operands_for_renaming ()
void mark_virtual_operand_for_renaming ()
void mark_virtual_phi_result_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

   It is advantageous to avoid things like life analysis for variables which
   do not need PHI nodes.  This enum describes whether or not a particular
   variable may need a PHI node.  
Enumerator:
NEED_PHI_STATE_UNKNOWN 
     This is the default.  If we are still in this state after finding
     all the definition and use sites, then we will assume the variable
     needs PHI nodes.  This is probably an overly conservative assumption.  
NEED_PHI_STATE_NO 
     This state indicates that we have seen one or more sets of the
     variable in a single basic block and that the sets dominate all
     uses seen so far.  If after finding all definition and use sites
     we are still in this state, then the variable does not need any
     PHI nodes.  
NEED_PHI_STATE_MAYBE 
     This state indicates that we have either seen multiple definitions of
     the variable in multiple blocks, or that we encountered a use in a
     block that was not dominated by the block containing the set(s) of
     this variable.  This variable is assumed to need PHI nodes.  
   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 
       Convert the whole function into SSA form.  
REWRITE_UPDATE 
       Incrementally update the SSA web by replacing existing SSA
       names with new ones.  See update_ssa for details.  

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.  
     OLD and NEW_TREE must be different SSA names for the same symbol.  
     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.  
     Update the REPL_TBL table.  
     If OLD had already been registered as a new name, then all the
     names that OLD replaces should also be replaced by NEW_TREE.  
     Register NEW_TREE and OLD in NEW_SSA_NAMES and OLD_SSA_NAMES,
     respectively.  

References bitmap_bit_p(), set_livein_block(), and set_rewrite_uses().

static void add_to_repl_tbl ( )
inlinestatic
   Add OLD to REPL_TBL[NEW_TREE].SET.  
static void clear_ssa_name_info ( )
static
   Clears info for SSA names.  
     If current_info_for_ssa_name_age wraps we use stale information.
     Asser that this does not happen.  
static int cmp_dfsnum ( )
static
   Compares two entries of type struct dom_dfsnum by dfs_num field.  Callback
   for qsort.  

References bb_dom_dfs_in(), bb_dom_dfs_out(), dom_dfsnum::bb_index, CDI_DOMINATORS, and dom_dfsnum::dfs_num.

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.  
         If needed, mark NEW_NAME as occurring in an abnormal PHI node. 
     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.  

Referenced by gimple_redirect_edge_and_branch().

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

References get_reaching_def(), and marked_for_renaming().

DEBUG_FUNCTION void debug_decl_set ( )
   Dump bitmap SET (assumed to contain VAR_DECLs) to FILE.  
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 get_common_info().

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

References is_new_name(), and is_old_name().

DEBUG_FUNCTION void debug_tree_ssa ( void  )
   Dump SSA information to stderr.  

References get_ssa_name_ann(), and ssa_name_info::info.

DEBUG_FUNCTION void debug_tree_ssa_stats ( void  )
   Dump SSA statistics on stderr.  

References make_ssa_name(), and target_for_debug_bind().

DEBUG_FUNCTION void debug_update_ssa ( void  )
   Dump SSA update information to stderr.  
DEBUG_FUNCTION void debug_var_infos ( void  )
   Dump the VAR_INFOS hash table on stderr.  
int debug_var_infos_r ( )
   Callback for htab_traverse to dump the VAR_INFOS hash table.  

References edge_def::flags, gsi_bb(), and basic_block_def::succs.

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

References bitmap_copy().

Referenced by ssa_name_has_uses_outside_loop_p().

void dump_currdefs ( )
   Dump the current reaching definition of every symbol to FILE.  
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.  
void dump_names_replaced_by ( )
   Dump all the names replaced by NAME to FILE.  

References dump_file, and print_gimple_stmt().

Referenced by prepare_block_for_update().

void dump_tree_ssa ( )
   Dump SSA information to FILE.  
void dump_tree_ssa_stats ( )
   Dump SSA statistics on FILE.  

References marked_for_renaming().

void dump_update_ssa ( )
   Dump SSA update information to FILE.  

References bitmap_set_bit().

void dump_var_infos ( )
   Dump the VAR_INFOS hash table on FILE.  

References gsi_insert_on_edge_immediate().

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 create_phi_node(), and target_for_debug_bind().

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.  
static void fini_ssa_renamer ( )
static
   Deallocate internal data structures used by the renamer.  
static bool gate_into_ssa ( )
static
   Gate for IPCP optimization.  
     Do nothing for funcions that was produced already in SSA form.  

Referenced by rewrite_blocks().

static common_info_p get_common_info ( )
inlinestatic
   Get access to the auxiliar information stored per SSA name or decl.  

References bitmap_set_bit(), basic_block_def::index, and initialize_flags_in_bb().

Referenced by debug_defs_stack(), get_var_info(), initialize_flags_in_bb(), and insert_phi_nodes_compare_var_infos().

tree get_current_def ( )
   Return the current definition for VAR.  

References def_blocks_d::def_blocks.

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.  

Referenced by initialize_flags_in_bb().

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.  
     Lookup the current reaching definition for VAR.  
     If there is no reaching definition for VAR, create and register a
     default definition for it (if needed).  
     Return the current reaching definition for VAR, or the default
     definition, if we had to create one.  

Referenced by debug_currdefs(), maybe_register_def(), and rewrite_debug_stmt_uses().

static ssa_name_info_p get_ssa_name_ann ( )
inlinestatic
   Get the information associated with NAME.  
     Re-allocate the vector at most once per update/into-SSA.  
     But allocate infos lazily.  

Referenced by debug_tree_ssa(), and set_livein_block().

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

References get_common_info().

static void htab_statistics ( )
static
   Dump statistics for the hash table HTAB.  
static void init_ssa_renamer ( )
static
   Initialize internal data needed during renaming.  
     Allocate memory for the DEF_BLOCKS hash table.  
static void init_update_ssa ( )
static
   Initialize data structures used for incremental SSA updates.  
     Reserve more space than the current number of names.  The calls to
     add_new_name_mapping are typically done after creating new SSA
     names, so we'll need to reallocate these arrays.  
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.  
         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.  

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

Referenced by get_common_info().

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.  
     Do two stages to avoid code generation differences for UID
     differences but no UID ordering differences.  

References cfun, and get_or_create_ssa_default_def().

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

References get_common_info().

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.  
     Remove the blocks where we already have PHI nodes for VAR.  
     Remove obviously useless phi nodes.  
     And insert the PHI nodes.  
             If we are rewriting SSA names, create the LHS of the PHI
             node by duplicating VAR.  This is useful in the case of
             pointers, to also duplicate pointer attributes (alias
             information, in particular).  
             Add VAR to every argument slot of PHI.  We need VAR in
             every argument so that rewrite_update_phi_arguments knows
             which name is this PHI node replacing.  If VAR is a
             symbol marked for renaming, this is not necessary, the
             renamer will use the symbol on the LHS to get its
             reaching definition.  
         Mark this PHI node as interesting for update_ssa.  
static int insert_updated_phi_nodes_compare_uids ( )
static
   Sort symbols_to_rename after their DECL_UID.  
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.  
     Get all the definition sites for VAR.  
     No need to do anything if there were no definitions to VAR.  
     Compute the initial iterated dominance frontier.  
             If doing regular SSA updates for GIMPLE registers, we are
             only interested in IDF blocks dominated by the nearest
             common dominator of all the definition blocks.  
             Otherwise, do not prune the IDF for VAR.  
         Otherwise, VAR is a symbol that needs to be put into SSA form
         for the first time, so we need to compute the full IDF for
         it.  
         Make sure that PRUNED_IDF blocks and all their feeding blocks
         are included in the region to be updated.  The feeding blocks
         are important to guarantee that the PHI arguments are renamed
         properly.  
         FIXME, this is not needed if we are updating symbols.  We are
         already starting at the ENTRY block anyway.  

References internal_error(), and print_generic_expr().

static bool is_new_name ( )
inlinestatic
   Return true if NAME is in NEW_SSA_NAMES.  

Referenced by debug_names_replaced_by(), and register_new_update_single().

static bool is_old_name ( )
inlinestatic
   Return true if NAME is in OLD_SSA_NAMES.  

Referenced by debug_names_replaced_by(), maybe_register_def(), and register_new_update_single().

gimple_opt_pass* make_pass_build_ssa ( )

References bitmap_bit_p(), and gimple_bb().

static void mark_block_for_update ( )
static
   Mark block BB as interesting for update_ssa.  

Referenced by mark_def_dom_walker::before_dom_children(), and mark_def_interesting().

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.  
         If VAR is an SSA name in NEW_SSA_NAMES, this is a definition
         site for both itself and all the old names replaced by it.  

References basic_block_def::index, and mark_block_for_update().

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.  
     Since this is the first time that we rewrite the program into SSA
     form, force an operand scan on every statement.  
     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.  
     Now process the defs.  Mark BB as the definition block and add
     each def to the set of killed symbols.  
     If we found the statement interesting then also mark the block BB
     as interesting.  

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

static void mark_for_renaming ( )
static
   Mark SYM for renaming.  

References GF_PLF_1, and gimple_plf().

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

References gsi_after_labels(), gsi_insert_before(), GSI_SAME_STMT, and si.

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.  
     If VAR has not been defined in BB, then it is live-on-entry
     to BB.  Note that we cannot just use the block holding VAR's
     definition because if VAR is one of the names in OLD_SSA_NAMES,
     it will have several definitions (itself and all the names that
     replace it).  

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

void mark_virtual_operand_for_renaming ( )
   Replace all uses of NAME by underlying variable and mark it
   for renaming.  This assumes the defining statement of NAME is
   going to be removed.  

Referenced by delete_worklist().

void mark_virtual_operands_for_renaming ( )
   Mark virtual operands of FN for renaming by update_ssa.  
void mark_virtual_phi_result_for_renaming ( )
   Replace all uses of the virtual PHI result by its underlying variable
   and mark it for renaming.  This assumes the PHI node is going to be
   removed.  
static bool marked_for_renaming ( )
static
   Return true if SYM is marked for renaming.  

References GF_PLF_1, and gimple_set_plf().

Referenced by debug_currdefs(), dump_tree_ssa_stats(), and maybe_register_def().

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.  
     If DEF is a naked symbol that needs renaming, create a new
     name for it.  
                 If stmt ends the bb, insert the debug stmt on the single
                 non-EH edge from the stmt.  
                     If there are other predecessors to ef->dest, then
                     there must be PHI nodes for the modified
                     variable, and therefore there will be debug bind
                     stmts after the PHI nodes.  The debug bind notes
                     we'd insert would force the creation of a new
                     block (diverging codegen) and be redundant with
                     the post-PHI bind stmts, so don't add them.

                     As for the exit edge, there wouldn't be redundant
                     bind stmts, but there wouldn't be a PC to bind
                     them to either, so avoid diverging the CFG.  
                         If there were PHI nodes in the node, we'd
                         have to make sure the value we're binding
                         doesn't need rewriting.  But there shouldn't
                         be PHI nodes in a single-predecessor block,
                         so we just add the note.  
         If DEF is a new name, register it as a new definition
         for all the names replaced by DEF.  
         If DEF is an old name, register DEF as a new
         definition for itself.  

References edge_def::flags, get_reaching_def(), gimple_location(), gimple_phi_arg_location(), gimple_phi_arg_set_location(), gimple_phi_num_args(), gimple_phi_result(), is_old_name(), marked_for_renaming(), rewrite_uses_p(), and virtual_operand_p().

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.  
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.  
         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
         dominates the use.  
bool name_registered_for_update_p ( )
   Return true if name N has been registered in the replacement table.  

Referenced by find_released_ssa_name().

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

References update_stmt().

Referenced by register_new_update_single().

bool need_ssa_update_p ( )
   Return true if there is any work to be done by update_ssa
   for function FN.  

References bitmap_clear().

Referenced by prepare_block_for_update(), and standard_iv_increment_position().

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.  
     Process PHI nodes marking interesting those that define or use
     the symbols that we are interested in.  
         Mark the uses in phi nodes as interesting.  It would be more correct
         to process the arguments of the phi nodes of the successor edges of
         BB at the end of prepare_block_for_update, however, that turns out
         to be significantly more expensive.  Doing it here is conservatively
         correct -- it may only cause us to believe a value to be live in a
         block that also contains its definition, and thus insert a few more
         phi nodes for it.  
     Process the statements.  
     Now visit all the blocks dominated by BB.  

References bitmap_empty_p(), bitmap_first_set_bit(), cfun, dump_decl_set(), dump_names_replaced_by(), need_ssa_update_p(), and print_generic_expr().

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.  

Referenced by mark_use_interesting().

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.  
     If a name N from NEW_SSA_NAMES is also marked to be released,
     remove it from NEW_SSA_NAMES so that we don't try to visit its
     defining basic block (which most likely doesn't exist).  Notice
     that we cannot do the same with names in OLD_SSA_NAMES because we
     want to replace existing instances.  
     First process names in NEW_SSA_NAMES.  Otherwise, uses of old
     names may be considered to be live-in on blocks that contain
     definitions for their replacements.  
     If an old name is in NAMES_TO_RELEASE, we cannot remove it from
     OLD_SSA_NAMES, but we have to ignore its definition site.  
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.  
             For regular statements, mark this as an interesting use
             for NAME.  

Referenced by mark_use_interesting().

static void prune_unused_phi_nodes ( )
static
   Clean bits from PHIS for phi nodes whose value cannot be used in USES.
   KILLS is a bitmap of blocks where the value is defined before any use.  
     The phi must dominate a use, or an argument of a live phi.  Also, we
     do not create any phi nodes in def blocks, unless they are also livein.  
     We want to remove the unnecessary phi nodes, but we do not want to compute
     liveness information, as that may be linear in the size of CFG, and if
     there are lot of different variables to rewrite, this may lead to quadratic
     behavior.

     Instead, we basically emulate standard dce.  We put all uses to worklist,
     then for each of them find the nearest def that dominates them.  If this
     def is a phi node, we mark it live, and if it was not live before, we
     add the predecessors of its basic block to the worklist.

     To quickly locate the nearest def that dominates use, we use dfs numbering
     of the dominance tree (that is already available in order to speed up
     queries).  For each def, we have the interval given by the dfs number on
     entry to and on exit from the corresponding subtree in the dominance tree.
     The nearest dominator for a given use is the smallest of these intervals
     that contains entry and exit dfs numbers for the basic block with the use.
     If we store the bounds for all the uses to an array and sort it, we can
     locate the nearest dominating def in logarithmic time by binary search.
     Now each DEFS entry contains the number of the basic block to that the
     dfs number corresponds.  Change them to the number of basic block that
     corresponds to the interval following the dfs number.  Also, for the
     dfs_out numbers, increase the dfs number by one (so that it corresponds
     to the start of the following interval, not to the end of the current
     one).  We use WORKLIST as a stack.  
             This is a closing element.  Interval corresponding to the top
             of the stack after removing it follows.  
             Opening element.  Nothing to do, just push it to the stack and move
             it to the correct position.  
         If this interval starts at the same point as the previous one, cancel
         the previous one.  
     Now process the uses.  
         If there is a phi node in USE_BB, it is made live.  Otherwise,
         find the def that dominates the immediate dominator of USE_BB
         (the kill in USE_BB does not dominate the use).  
         If the phi node is already live, there is nothing to do.  
         Add the new uses to the worklist.  
             In case there is a kill directly in the use block, do not record
             the use (this is also necessary for correctness, as we assume that
             uses dominated by a def directly in their block have been filtered
             out before).  
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.  
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.  
     If this variable is set in a single basic block and all uses are
     dominated by the set(s) in that single basic block, then there is
     no reason to record anything for this variable in the block local
     definition stacks.  Doing so just wastes time and memory.

     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 SYM is not a GIMPLE register, then CURRDEF may be a name whose
     SSA_NAME_VAR is not necessarily SYM.  In this case, also push SYM
     in the stack so that we know which symbol is being defined by
     this SSA name when we unwind the stack.  
     Push the current reaching definition into BLOCK_DEFS_STACK.  This
     stack is later used by the dominator tree callbacks to restore
     the reaching definitions for all the variables defined in the
     block after a recursive visit to all its immediately dominated
     blocks.  If there is no current reaching definition, then just
     record the underlying _DECL node.  
     Set the current reaching definition for SYM to be DEF.  

References gimple_debug_source_bind_get_value(), gimple_debug_source_bind_get_var(), gimple_debug_source_bind_p(), and gsi_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 dump_file, and print_gimple_stmt().

Referenced by register_new_update_single().

static void register_new_update_single ( )
inlinestatic
   Register NEW_NAME to be the new reaching definition for OLD_NAME.  
     Push the current reaching definition into BLOCK_DEFS_STACK.
     This stack is later used by the dominator tree callbacks to
     restore the reaching definitions for all the variables
     defined in the block after a recursive visit to all its
     immediately dominated blocks.  
     Set the current reaching definition for OLD_NAME to be
     NEW_NAME.  

References is_new_name(), is_old_name(), names_replaced_by(), and register_new_update_set().

void release_ssa_name_after_update_ssa ( )
   Mark NAME to be released after update_ssa has finished.  
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.  
             Virtual operand PHI args do not need a location.  
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.  
     Rewrite all the basic blocks in the program.  
     Recursively walk the dominator tree rewriting each statement in
     each basic block.  
     Debugging dumps.  

References opt_pass::execute(), opt_pass::gate(), gate_into_ssa(), gimple_opt_pass::gimple_opt_pass(), and rewrite_into_ssa().

static void rewrite_debug_stmt_uses ( )
static
   Helper function for rewrite_stmt.  Rewrite uses in a debug stmt.  
                 Search a few source bind stmts at the start of first bb to
                 see if a DEBUG_EXPR_DECL can't be reused.  
                 If not, add a new source bind stmt.  
             Check if info->current_def can be trusted.  
             If definition is in current bb, it is fine.  
             If definition bb doesn't dominate the current bb,
             it can't be used.  
             If there is just one definition and dominates the current
             bb, it is fine.  
                 If there are some non-debug uses in the current bb,
                 it is fine.  
                 Otherwise give up for now.  

References get_reaching_def(), and is_gimple_debug().

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.

   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).  
     Initialize operand data structures.  
     Initialize internal data needed by the renamer.  
     Initialize the set of interesting blocks.  The callback
     mark_def_sites will add to this set those blocks that the renamer
     should process.  
     Initialize dominance frontier.  
     1- Compute dominance frontiers.  
     2- Find and mark definition sites.  
     3- Insert PHI nodes at dominance frontiers of definition blocks.  
     4- Rename all the blocks.  
     Free allocated memory.  
     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.  

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.  
     If mark_def_sites decided that we don't need to rewrite this
     statement, ignore it.  
     Step 1.  Rewrite USES in the statement.  
     Step 2.  Register the statement's DEF operands.  
               If we rewrite a DECL into SSA form then drop its
               clobber stmts and replace uses with a new default def.  
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.  
                 When updating a PHI node for a recently introduced
                 symbol we may find NULL arguments.  That's why we
                 take the symbol from the LHS of the PHI node.  
             Update the argument if there is a reaching def.  
                 Virtual operands do not need a location.  
                     Single element PHI nodes  behave like copies, so get the
                     location from the phi argument.  
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.  
     Only update marked statements.  
     Rewrite USES included in OLD_SSA_NAMES and USES whose underlying
     symbol is marked for renaming.  
                 DOM sometimes threads jumps in such a way that a
                 debug stmt ends up referencing a SSA variable that no
                 longer dominates the debug stmt, but such that all
                 incoming definitions refer to the same definition in
                 an earlier dominator.  We could try to recover that
                 definition somehow, but this will have to do for now.

                 Introducing a default definition, which is what
                 maybe_replace_use() would do in such cases, may
                 modify code generation, for the otherwise-unused
                 default definition would never go away, modifying SSA
                 version numbers all over.  
     Register definitions of names in NEW_SSA_NAMES and OLD_SSA_NAMES.
     Also register definitions for names whose underlying symbol is
     marked for renaming.  
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.  

Referenced by maybe_register_def().

void set_current_def ( )
   Sets current definition of VAR to DEF.  
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.  
     Set the bit corresponding to the block where VAR is defined.  
     Keep track of whether or not we may need to insert PHI nodes.

     If we are in the UNKNOWN state, then this is the first definition
     of VAR.  Additionally, we have not seen any uses of VAR yet, so
     we do not need a PHI node for this variable at this time (i.e.,
     transition to NEED_PHI_STATE_NO).

     If we are in any other state, then we either have multiple definitions
     of this variable occurring in different blocks or we saw a use of the
     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.  
static void set_livein_block ( )
static
   Mark block BB as having VAR live at the entry to BB.  
     Set the bit corresponding to the block where VAR is live in.  
     Keep track of whether or not we may need to insert PHI nodes.

     If we reach here in NEED_PHI_STATE_NO, see if this use is dominated
     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.  

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

Referenced by add_new_name_mapping().

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

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

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

References ssa_name_info::age, current_info_for_ssa_name_age, ssa_name_info::info, and NEED_PHI_STATE_UNKNOWN.

Referenced by add_new_name_mapping().

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*.  
     Only one update flag should be set.  
         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.  
     Ensure that the dominance information is up-to-date.  
     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 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.  
     Next, determine the block at which to start the renaming process.  
         If we rename bare symbols initialize the mapping to
         auxiliar info we need to keep track of.  
         If we have to rename some symbols from scratch, we need to
         start the process at the root of the CFG.  FIXME, it should
         be possible to determine the nearest block that had a
         definition for each of the symbols that are marked for
         updating.  For now this seems more work than it's worth.  
         Traverse the CFG looking for existing definitions and uses of
         symbols in SSA operands.  Mark interesting blocks and
         statements and set local live-in information for the PHI
         placement heuristics.  
             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.  
         Otherwise, the entry block to the region is the nearest
         common dominator for the blocks in BLOCKS.  
     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 found.  
         If the caller requested PHI nodes to be added, compute
         dominance frontiers.  
             insert_update_phi_nodes_for will call add_new_name_mapping
             when inserting new PHI nodes, so the set OLD_SSA_NAMES
             will grow while we are traversing it (but it will not
             gain any new members).  Copy OLD_SSA_NAMES to a temporary
             for traversal.  
         Insertion of PHI nodes may have added blocks to the region.
         We need to re-compute START_BB to include the newly added
         blocks.  
     Reset the current definition for name and symbol before renaming
     the sub-graph.  
     Now start the renaming process at START_BB.  
     Debugging dumps.  
     Free allocated memory.  

Referenced by canonicalize_loop_closed_ssa(), close_phi_written_to_memory(), expand_omp_sections(), find_uses_to_rename(), scale_dominated_blocks_in_loop(), and sese_add_exit_phis_edge().


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

Referenced by set_rewrite_uses().

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.