GCC Middle and Back End API Reference
tree-ssa-dom.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "hash-table.h"
#include "tm.h"
#include "tree.h"
#include "flags.h"
#include "tm_p.h"
#include "basic-block.h"
#include "cfgloop.h"
#include "function.h"
#include "gimple-pretty-print.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-cfg.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-ssanames.h"
#include "tree-into-ssa.h"
#include "domwalk.h"
#include "tree-pass.h"
#include "tree-ssa-propagate.h"
#include "tree-ssa-threadupdate.h"
#include "langhooks.h"
#include "params.h"
#include "tree-ssa-threadedge.h"
#include "tree-ssa-dom.h"
Include dependency graph for tree-ssa-dom.c:

Data Structures

struct  hashable_expr
struct  cond_equivalence_s
struct  edge_info
struct  expr_hash_elt
struct  expr_elt_hasher
struct  opt_stats_d
class  dom_opt_dom_walker

Typedefs

typedef struct cond_equivalence_s cond_equivalence
typedef struct expr_hash_eltexpr_hash_elt_t

Enumerations

enum  expr_kind {
  EXPR_SINGLE, EXPR_UNARY, EXPR_BINARY, EXPR_TERNARY,
  EXPR_CALL, EXPR_PHI
}

Functions

static bool hashable_expr_equal_p (const struct hashable_expr *, const struct hashable_expr *)
static void free_expr_hash_elt (void *)
static void optimize_stmt (basic_block, gimple_stmt_iterator)
static tree lookup_avail_expr (gimple, bool)
static hashval_t avail_expr_hash (const void *)
static void htab_statistics (FILE *, hash_table< expr_elt_hasher >)
static void record_cond (cond_equivalence *)
static void record_const_or_copy (tree, tree)
static void record_equality (tree, tree)
static void record_equivalences_from_phis (basic_block)
static void record_equivalences_from_incoming_edge (basic_block)
static void eliminate_redundant_computations (gimple_stmt_iterator *)
static void record_equivalences_from_stmt (gimple, int)
static void remove_local_expressions_from_table (void)
static void restore_vars_to_original_value (void)
static edge single_incoming_edge_ignoring_loop_edges (basic_block)
static void initialize_hash_element (gimple stmt, tree lhs, struct expr_hash_elt *element)
static void initialize_expr_from_cond ()
static void initialize_hash_element_from_expr (struct hashable_expr *expr, tree lhs, struct expr_hash_elt *element)
static hashval_t iterative_hash_hashable_expr ()
static void print_expr_hash_elt ()
static void free_expr_hash_elt_contents ()
static void free_expr_hash_elt ()
static struct edge_infoallocate_edge_info ()
static void free_all_edge_infos ()
static unsigned int tree_ssa_dominator_optimize ()
static bool gate_dominator ()
gimple_opt_passmake_pass_dominator ()
static void canonicalize_comparison ()
static tree simplify_stmt_for_jump_threading (gimple stmt, gimple within_stmt)
static void record_temporary_equivalences ()
static void record_equivalences_from_phis ()
static edge single_incoming_edge_ignoring_loop_edges ()
static void record_equivalences_from_incoming_edge ()
void dump_dominator_optimization_stats ()
DEBUG_FUNCTION void debug_dominator_optimization_stats ()
static void htab_statistics ()
static void record_cond ()
static void build_and_record_new_cond (enum tree_code code, tree op0, tree op1, vec< cond_equivalence > *p)
static void record_conditions ()
static void record_const_or_copy_1 ()
int loop_depth_of_name ()
static void record_const_or_copy ()
static void record_equality ()
bool simple_iv_increment_p ()
static void cprop_into_successor_phis ()
static void record_edge_info ()
static void eliminate_redundant_computations ()
static void record_equivalences_from_stmt ()
static void cprop_operand ()
static void cprop_into_stmt ()
static void optimize_stmt ()
static tree lookup_avail_expr ()
static hashval_t avail_expr_hash ()
static void remove_stmt_or_phi ()
static tree get_rhs_or_phi_arg ()
static tree get_lhs_or_phi_result ()
static void propagate_rhs_into_lhs ()
static void eliminate_const_or_copy ()
static void eliminate_degenerate_phis_1 ()
static unsigned int eliminate_degenerate_phis ()
gimple_opt_passmake_pass_phi_only_cprop ()

Variables

static vec< expr_hash_elt_tavail_exprs_stack
static hash_table
< expr_elt_hasher
avail_exprs
static vec< treeconst_and_copies_stack
static bool cfg_altered
static bitmap need_eh_cleanup
static struct opt_stats_d opt_stats

Typedef Documentation

Structure for recording known values of a conditional expression at the exits from its block.

typedef struct expr_hash_elt* expr_hash_elt_t

Stack of available expressions in AVAIL_EXPRs. Each block pushes any expressions it enters into the hash table along with a marker entry (null). When we finish processing the block, we pop off entries and remove the expressions from the global hash table until we hit the marker.


Enumeration Type Documentation

enum expr_kind

SSA Dominator optimizations for trees Copyright (C) 2001-2013 Free Software Foundation, Inc. Contributed by Diego Novillo dnovi.nosp@m.llo@.nosp@m.redha.nosp@m.t.co.nosp@m.m

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. This file implements optimizations on the dominator tree. Representation of a "naked" right-hand-side expression, to be used in recording available expressions in the expression hash table.

Enumerator:
EXPR_SINGLE 
EXPR_UNARY 
EXPR_BINARY 
EXPR_TERNARY 
EXPR_CALL 
EXPR_PHI 

Function Documentation

static struct edge_info* allocate_edge_info ( )
staticread

Allocate an EDGE_INFO for edge E and attach it to E. Return the new EDGE_INFO structure.

Referenced by cprop_into_successor_phis().

static hashval_t avail_expr_hash ( const void *  )
static
static hashval_t avail_expr_hash ( )
static

Hashing and equality functions for AVAIL_EXPRS. We compute a value number for expressions using the code of the expression and the SSA numbers of its operands.

If the hash table entry is not associated with a statement, then we can just hash the expression and not worry about virtual operands and such.

 Add the SSA version numbers of the vuse operand.  This is important
 because compound variables like arrays are not renamed in the
 operands.  Rather, the rename is done on the virtual variable
 representing all the elements of the array.   
static void build_and_record_new_cond ( enum tree_code  code,
tree  op0,
tree  op1,
vec< cond_equivalence > *  p 
)
static

Build a cond_equivalence record indicating that the comparison CODE holds between operands OP0 and OP1 and push it to **P.

Referenced by debug_dominator_optimization_stats(), and record_cond().

static void canonicalize_comparison ( )
static

Given a conditional statement CONDSTMT, convert the condition to a canonical form.

If it would be profitable to swap the operands, then do so to canonicalize the statement, enabling better optimization.

By placing canonicalization of such expressions here we transparently keep statements in canonical form, even when the statement is modified.

     For relationals we need to swap the operands
     and change the code.   

References dump_file, and print_expr_hash_elt().

static void cprop_into_stmt ( )
static

CONST_AND_COPIES is a table which maps an SSA_NAME to the current known value for that SSA_NAME (or NULL if no value is known).

Propagate values from CONST_AND_COPIES into the uses, vuses and vdef_ops of STMT.

static void cprop_into_successor_phis ( )
static

CONST_AND_COPIES is a table which maps an SSA_NAME to the current known value for that SSA_NAME (or NULL if no value is known).

Propagate values from CONST_AND_COPIES into the PHI nodes of the successors of BB.

     If this is an abnormal edge, then we do not want to copy propagate
     into the PHI alternative associated with this edge.   
     We may have an equivalence associated with this edge.  While
     we can not propagate it into non-dominated blocks, we can
     propagate them into PHIs in non-dominated blocks.   
     Push the unwind marker so we can reset the const and copies
     table back to its original state after processing this edge.   
     Extract and record any simple NAME = VALUE equivalences.

     Don't bother with [01] = COND equivalences, they're not useful
     here.   
         The alternative may be associated with a constant, so verify
         it is an SSA_NAME before doing anything with it.   
         If we have *ORIG_P in our constant/copy table, then replace
         ORIG_P with its value in our constant/copy table.   

References allocate_edge_info(), CASE_LOW, edge_def::dest, error_mark_node, fold_convert_loc(), basic_block_def::index, edge_info::lhs, NULL, edge_info::rhs, and TREE_TYPE.

static void cprop_operand ( )
static

Replace *OP_P in STMT with any known equivalent value for *OP_P from CONST_AND_COPIES.

 If the operand has a known constant value or it is known to be a
 copy of some other variable, use the value or copy stored in
 CONST_AND_COPIES.   
     Do not replace hard register operands in asm statements.   
     Certain operands are not allowed to be copy propagated due
     to their interaction with exception handling and some GCC
     extensions.   
     Do not propagate addresses that point to volatiles into memory
     stmts without volatile operands.   
     Do not propagate copies if the propagated value is at a deeper loop
     depth than the propagatee.  Otherwise, this may move loop variant
     variables outside of their loops and prevent coalescing
     opportunities.  If the value was loop invariant, it will be hoisted
     by LICM and exposed for copy propagation.   
     Do not propagate copies into simple IV increment statements.
     See PR23821 for how this can disturb IV analysis.   
     Dump details.   
     And note that we modified this statement.  This is now
     safe, even if we changed virtual operands since we will
     rescan the statement and rewrite its operands again.   
DEBUG_FUNCTION void debug_dominator_optimization_stats ( void  )

Dump SSA statistics on stderr.

References build_and_record_new_cond(), and edge_info::cond_equivalences.

void dump_dominator_optimization_stats ( )

Dump SSA statistics on FILE.

References COMPARISON_CLASS_P, TREE_CODE, and TREE_OPERAND.

Referenced by record_equivalences_from_incoming_edge().

static void eliminate_const_or_copy ( )
static

STMT is either a PHI node (potentially a degenerate PHI node) or a statement that is a trivial copy or constant initialization.

Attempt to eliminate T by propagating its RHS into all uses of its LHS. This may in turn set new bits in INTERESTING_NAMES for nodes we want to revisit later.

All exit paths should clear INTERESTING_NAMES for the result of STMT.

 If the LHS of this statement or PHI has no uses, then we can
 just eliminate it.  This can occur if, for example, the PHI
 was created by block duplication due to threading and its only
 use was in the conditional at the end of the block which was
 deleted.   
 Get the RHS of the assignment or PHI node if the PHI is a
 degenerate.   
     For virtual operands we have to propagate into all uses as
     otherwise we will create overlapping life-ranges.   
 Note that STMT may well have been deleted by now, so do
 not access it, instead use the saved version # to clear
 T's entry in the worklist.   

References eliminate_degenerate_phis(), execute(), and gate_dominator().

static unsigned int eliminate_degenerate_phis ( )
static

A very simple pass to eliminate degenerate PHI nodes from the IL. This is meant to be fast enough to be able to be run several times in the optimization pipeline.

Certain optimizations, particularly those which duplicate blocks or remove edges from the CFG can create or expose PHIs which are trivial copies or constant initializations.

While we could pick up these optimizations in DOM or with the combination of copy-prop and CCP, those solutions are far too heavy-weight for our needs.

This implementation has two phases so that we can efficiently eliminate the first order degenerate PHIs and second order degenerate PHIs.

The first phase performs a dominator walk to identify and eliminate the vast majority of the degenerate PHIs. When a degenerate PHI is identified and eliminated any affected statements or PHIs are put on a worklist.

The second phase eliminates degenerate PHIs and trivial copies or constant initializations using the worklist. This is how we pick up the secondary optimization opportunities with minimal cost.

 Bitmap of blocks which need EH information updated.  We can not
 update it on-the-fly as doing so invalidates the dominator tree.   
 INTERESTING_NAMES is effectively our worklist, indexed by
 SSA_NAME_VERSION.

 A set bit indicates that the statement or PHI node which
 defines the SSA_NAME should be (re)examined to determine if
 it has become a degenerate PHI or trivial const/copy propagation
 opportunity.

 Experiments have show we generally get better compilation
 time behavior with bitmaps rather than sbitmaps.   
 First phase.  Eliminate degenerate PHIs via a dominator
 walk of the CFG.

 Experiments have indicated that we generally get better
 compile-time behavior by visiting blocks in the first
 phase in dominator order.  Presumably this is because walking
 in dominator order leaves fewer PHIs for later examination
 by the worklist phase.   
 Second phase.  Eliminate second order degenerate PHIs as well
 as trivial copies or constant initializations identified by
 the first phase or this phase.  Basically we keep iterating
 until our set of INTERESTING_NAMEs is empty.    
     EXECUTE_IF_SET_IN_BITMAP does not like its bitmap
     changed during the loop.  Copy it to another bitmap and
     use that.   
         Ignore SSA_NAMEs that have been released because
         their defining statement was deleted (unreachable).   
     If we changed the CFG schedule loops for fixup by cfgcleanup.   
 Propagation of const and copies may make some EH edges dead.  Purge
 such edges from the CFG as needed.   

Referenced by eliminate_const_or_copy().

static void eliminate_degenerate_phis_1 ( )
static

The first phase in degenerate PHI elimination.

Eliminate the degenerate PHIs in BB, then recurse on the dominator children of BB.

Recurse into the dominator children of BB.

static void eliminate_redundant_computations ( gimple_stmt_iterator )
static
static void eliminate_redundant_computations ( )
static

Search for redundant computations in STMT. If any are found, then replace them with the variable holding the result of the computation.

If safe, record this expression into the available expression hash table.

 Certain expressions on the RHS can be optimized away, but can not
 themselves be entered into the hash tables.   
     Do not record equivalences for increments of ivs.  This would create
     overlapping live ranges for a very questionable gain.   
 Check if the expression has been computed before.   
 Get the type of the expression we are trying to optimize.   
   We can't propagate into a phi, so the logic below doesn't apply.
   Instead record an equivalence between the cached LHS and the
   PHI result of this statement, provided they are in the same block.
   This should be sufficient to kill the redundant phi.   
 It is safe to ignore types here since we have already done
 type checking in the hashing and equality routines.  In fact
 type checking here merely gets in the way of constant
 propagation.  Also, make sure that it is safe to propagate
 CACHED_LHS into the expression in STMT.   
     Since it is always necessary to mark the result as modified,
     perhaps we should move this into propagate_tree_value_into_stmt
     itself.   

References dump_file, dump_flags, print_generic_expr(), and set_ssa_name_value().

static void free_all_edge_infos ( )
static

Free all EDGE_INFO structures associated with edges in the CFG. If a particular edge can be threaded, copy the redirection target from the EDGE_INFO structure into the edge's AUX field as required by code to update the CFG and SSA graph for jump threading.

References BITMAP_ALLOC, calculate_dominance_info(), CDI_DOMINATORS, hash_table< Descriptor, Allocator >::create(), loop_optimizer_init(), LOOPS_HAVE_SIMPLE_LATCHES, NULL, and opt_stats.

static void free_expr_hash_elt ( void *  )
static
static void free_expr_hash_elt ( )
static

Delete an expr_hash_elt and reclaim its storage.

References edge_def::aux, edge_info::cond_equivalences, and NULL.

static void free_expr_hash_elt_contents ( )
static

Delete variable sized pieces of the expr_hash_elt ELEMENT.

References edge_def::aux, FOR_EACH_BB, FOR_EACH_EDGE, and basic_block_def::preds.

static bool gate_dominator ( )
static

Referenced by eliminate_const_or_copy().

static tree get_lhs_or_phi_result ( )
static

Given a statement STMT, which is either a PHI node or an assignment, return the "lhs" of the node.

static tree get_rhs_or_phi_arg ( )
static

Given a statement STMT, which is either a PHI node or an assignment, return the "rhs" of the node, in the case of a non-degenerate phi, NULL is returned.

static bool hashable_expr_equal_p ( const struct hashable_expr expr0,
const struct hashable_expr expr1 
)
static

Hashtable helpers.

Compare two hashable_expr structures for equivalence. They are considered equivalent when the the expressions they denote must necessarily be equal. The logic is intended to follow that of operand_equal_p in fold-const.c

 If either type is NULL, there is nothing to check.   
 If both types don't have the same signedness, precision, and mode,
 then we can't consider  them equal.   
     For commutative ops, allow the other order.   
     For commutative ops, allow the other order.   
       If the calls are to different functions, then they
       clearly cannot be equal.   
static void htab_statistics ( FILE *  ,
hash_table< expr_elt_hasher  
)
static
static void htab_statistics ( )
static

Dump statistics for the hash table HTAB.

static void initialize_expr_from_cond ( )
static

Given a conditional expression COND as a tree, initialize a hashable_expr expression EXPR. The conditional must be a comparison or logical negation. A constant or a variable is not permitted.

References avail_expr_hash(), expr_hash_elt::expr, expr_hash_elt::hash, expr_hash_elt::lhs, NULL, expr_hash_elt::stamp, and expr_hash_elt::stmt.

static void initialize_hash_element ( gimple  stmt,
tree  lhs,
struct expr_hash_elt element 
)
static

Given a statement STMT, initialize the hash table element pointed to by ELEMENT.

static void initialize_hash_element_from_expr ( struct hashable_expr expr,
tree  lhs,
struct expr_hash_elt element 
)
static

Given a hashable_expr expression EXPR and an LHS, initialize the hash table element pointed to by ELEMENT.

References EXPR_SINGLE, EXPR_UNARY, operand_equal_p(), hashable_expr::ops, and hashable_expr::single.

static hashval_t iterative_hash_hashable_expr ( )
static

Compute a hash value for a hashable_expr value EXPR and a previously accumulated hash value VAL. If two hashable_expr values compare equal with hashable_expr_equal_p, they must hash to the same value, given an identical value of VAL. The logic is intended to follow iterative_hash_expr in tree.c.

Make sure to include signedness in the hash computation. Don't hash the type, that can lead to having nodes which compare equal according to operand_equal_p, but which have different hash codes.

static tree lookup_avail_expr ( gimple  ,
bool   
)
static
static tree lookup_avail_expr ( )
static

Search for an existing instance of STMT in the AVAIL_EXPRS table. If found, return its LHS. Otherwise insert STMT in the table and return NULL_TREE.

Also, when an expression is first inserted in the table, it is also is also added to AVAIL_EXPRS_STACK, so that it can be removed when we finish processing this block and its children.

 Get LHS of phi, assignment, or call; else NULL_TREE.   
 Don't bother remembering constant assignments and copy operations.
 Constants and copy operations are handled by the constant/copy propagator
 in optimize_stmt.   
 Finally try to find the expression in the main expression hash table.   
 Extract the LHS of the assignment so that it can be used as the current
 definition of another variable.   
 See if the LHS appears in the CONST_AND_COPIES table.  If it does, then
 use the value from the const_and_copies table.   

References dump_file, dump_flags, FOR_EACH_IMM_USE_ON_STMT, FOR_EACH_IMM_USE_STMT, gimple_debug_bind_p(), loop_depth_of_name(), may_propagate_copy(), may_propagate_copy_into_asm(), print_generic_expr(), print_gimple_stmt(), propagate_value(), SSA_NAME_DEF_STMT, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, and TREE_CODE.

int loop_depth_of_name ( )

Return the loop depth of the basic block of the defining statement of X. This number should not be treated as absolutely correct because the loop information may not be completely up-to-date when dom runs. However, it will be relatively correct, and as more passes are taught to keep loop info up to date, the result will become more and more accurate.

If it's not an SSA_NAME, we have no clue where the definition is.

 Otherwise return the loop depth of the defining statement's bb.
 Note that there may not actually be a bb for this statement, if the
 ssa_name is live on entry.   

Referenced by lookup_avail_expr().

gimple_opt_pass* make_pass_dominator ( )

References NULL.

gimple_opt_pass* make_pass_phi_only_cprop ( )
static void optimize_stmt ( basic_block  ,
gimple_stmt_iterator   
)
static

Local functions.

static void optimize_stmt ( )
static

Optimize the statement pointed to by iterator SI.

We try to perform some simplistic global redundancy elimination and constant propagation:

1- To detect global redundancy, we keep track of expressions that have been computed in this block and its dominators. If we find that the same expression is computed more than once, we eliminate repeated computations by using the target of the first one.

2- Constant values and copy assignments. This is used to do very simplistic constant and copy propagation. When a constant or copy assignment is found, we map the value on the RHS of the assignment to the variable in the LHS in the CONST_AND_COPIES table.

 Const/copy propagate into USES, VUSES and the RHS of VDEFs.   
 If the statement has been modified with constant replacements,
 fold its RHS before checking for redundant computations.   
     Try to fold the statement making sure that STMT is kept
     up to date.   
     We only need to consider cases that can yield a gimple operand.   
       This should never be an ADDR_EXPR.   
     Indicate that maybe_clean_or_replace_eh_stmt needs to be called,
     even if fold_stmt updated the stmt already and thus cleared
     gimple_modified_p flag on it.   
 Check for redundant computations.  Do this optimization only
 for assignments that have no volatile ops and conditionals.   
         Resolve __builtin_constant_p.  If it hasn't been
         folded to integer_one_node by now, it's fairly
         certain that the value simply isn't constant.   
     Perform simple redundant store elimination.   
         Build a new statement with the RHS and LHS exchanged.   
 Record any additional equivalences created by this statement.   
 If STMT is a COND_EXPR and it was modified, then we may know
 where it goes.  If that is the case, then mark the CFG as altered.

 This will cause us to later call remove_unreachable_blocks and
 cleanup_tree_cfg when it is safe to do so.  It is not safe to
 clean things up here since removal of edges and such can trigger
 the removal of PHI nodes, which in turn can release SSA_NAMEs to
 the manager.

 That's all fine and good, except that once SSA_NAMEs are released
 to the manager, we must not call create_ssa_name until all references
 to released SSA_NAMEs have been eliminated.

 All references to the deleted SSA_NAMEs can not be eliminated until
 we remove unreachable blocks.

 We can not remove unreachable blocks until after we have completed
 any queued jump threading.

 We can not complete any queued jump threads until we have taken
 appropriate variables out of SSA form.  Taking variables out of
 SSA form can call create_ssa_name and thus we lose.

 Ultimately I suspect we're going to need to change the interface
 into the SSA_NAME manager.   
     If we simplified a statement in such a way as to be shown that it
     cannot trap, update the eh information and the cfg to match.   

References bitmap_set_bit, boolean_type_node, dump_file, dump_flags, find_taken_edge(), fold_binary_loc(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), gimple_location(), gimple_switch_index(), basic_block_def::index, maybe_clean_or_replace_eh_stmt(), NULL, TREE_CODE, and update_stmt_if_modified().

static void print_expr_hash_elt ( )
static
static void propagate_rhs_into_lhs ( )
static

Propagate RHS into all uses of LHS (when possible).

RHS and LHS are derived from STMT, which is passed in solely so that we can remove it if propagation is successful.

When propagating into a PHI node or into a statement which turns into a trivial copy or constant initialization, set the appropriate bit in INTERESTING_NAMEs so that we will visit those nodes as well in an effort to pick up secondary optimization opportunities.

 First verify that propagation is valid and isn't going to move a
 loop variant variable outside its loop.   
     Dump details.   
     Walk over every use of LHS and try to replace the use with RHS.
     At this point the only reason why such a propagation would not
     be successful would be if the use occurs in an ASM_EXPR.   
         Leave debug stmts alone.  If we succeed in propagating
         all non-debug uses, we'll drop the DEF, and propagation
         into debug stmts will occur then.   
         It's not always safe to propagate into an ASM_EXPR.   
         It's not ok to propagate into the definition stmt of RHS.
            <bb 9>:
              # prephitmp.12_36 = PHI <g_67.1_6(9)>
              g_67.1_6 = prephitmp.12_36;
              goto <bb 9>;
         While this is strictly all dead code we do not want to
         deal with this here.   
         Dump details.   
         Propagate the RHS into this use of the LHS.   
         Special cases to avoid useless calls into the folding
         routines, operand scanning, etc.

         Propagation into a PHI may cause the PHI to become
         a degenerate, so mark the PHI as interesting.  No other
         actions are necessary.   
             Dump details.   
         From this point onward we are propagating into a
         real statement.  Folding may (or may not) be possible,
         we may expose new operands, expose dead EH edges,
         etc.   
         NOTE tuples. In the tuples world, fold_stmt_inplace
         cannot fold a call that simplifies to a constant,
         because the GIMPLE_CALL must be replaced by a
         GIMPLE_ASSIGN, and there is no way to effect such a
         transformation in-place.  We might want to consider
         using the more general fold_stmt here.   
         Sometimes propagation can expose new operands to the
         renamer.   
         Dump details.   
         If we replaced a variable index with a constant, then
         we would need to update the invariant flag for ADDR_EXPRs.   
         If we cleaned up EH information from the statement,
         mark its containing block as needing EH cleanups.   
         Propagation may expose new trivial copy/constant propagation
         opportunities.   
         Propagation into these nodes may make certain edges in
         the CFG unexecutable.  We want to identify them as PHI nodes
         at the destination of those unexecutable edges may become
         degenerates.   
                 Remove all outgoing edges except TE.   
                         Mark all the PHI nodes at the destination of
                         the unexecutable edge as interesting.   
                 And fixup the flags on the single remaining edge.   
     Ensure there is nothing else to do.  
     If we were able to propagate away all uses of LHS, then
     we can remove STMT.   

References bitmap_set_bit, gimple_phi_result(), gsi_stmt(), and SSA_NAME_VERSION.

static void record_cond ( cond_equivalence )
static
static void record_cond ( )
static

Enter condition equivalence into the expression hash table. This indicates that a conditional expression has a known boolean value.

References build_and_record_new_cond(), and edge_info::cond_equivalences.

static void record_conditions ( )
static

Record that COND is true and INVERTED is false into the edge information structure. Also record that any conditions dominated by COND are true as well.

For example, if a < b is true, then a <= b must also be true.

Now store the original true and false conditions into the first two slots.

 It is possible for INVERTED to be the negation of a comparison,
 and not a valid RHS or GIMPLE_COND condition.  This happens because
 invert_truthvalue may return such an expression when asked to invert
 a floating-point comparison.  These comparisons are not assumed to
 obey the trichotomy law.   
static void record_const_or_copy ( tree  ,
tree   
)
static

Referenced by record_equality().

static void record_const_or_copy ( )
static

Record that X is equal to Y in const_and_copies. Record undo information in the block-local vector.

References edge_def::dest, edge_def::flags, FOR_EACH_EDGE, gsi_start_phis(), and basic_block_def::succs.

static void record_const_or_copy_1 ( )
static

A helper function for record_const_or_copy and record_equality. Do the work of recording the value and undo info.

static void record_edge_info ( )
static

We have finished optimizing BB, record any information implied by taking a specific outgoing edge from BB.

     A COND_EXPR may create equivalences too.   
         Special case comparing booleans against a constant as we
         know the value of OP0 on both arms of the branch.  i.e., we
         can record an equivalence for OP0 rather than COND.   
     ??? TRUTH_NOT_EXPR can create an equivalence too.   

References edge_info::lhs, and edge_info::rhs.

static void record_equality ( tree  ,
tree   
)
static
static void record_equality ( )
static

Similarly, but assume that X and Y are the two operands of an EQ_EXPR. This constrains the cases in which we may treat this as assignment.

 If one of the previous values is invariant, or invariant in more loops
 (by depth), then use that.
 Otherwise it doesn't matter which value we choose, just so
 long as we canonicalize on one value.   
 After the swapping, we must have one SSA_NAME.   
 For IEEE, -0.0 == 0.0, so we don't necessarily know the sign of a
 variable compared against zero.  If we're honoring signed zeros,
 then we cannot record this value unless we know that the value is
 nonzero.   

References edge_info::lhs, record_const_or_copy(), edge_info::rhs, and TREE_CODE.

static void record_equivalences_from_incoming_edge ( basic_block  )
static
static void record_equivalences_from_incoming_edge ( )
static

Record any equivalences created by the incoming edge to BB. If BB has more than one incoming edge, then no equivalence is created.

 If our parent block ended with a control statement, then we may be
 able to record some equivalences based on which outgoing edge from
 the parent was followed.   
 If we had a single incoming edge from our parent block, then enter
 any data associated with the edge into our tables.   
         If LHS is an SSA_NAME and RHS is a constant integer and LHS was
         set via a widening type conversion, then we may be able to record
         additional equivalences.   
                 If the conversion widens the original value and
                 the constant is in the range of the type of OLD_RHS,
                 then convert the constant and record the equivalence.

                 Note that int_fits_type_p does not check the precision
                 if the upper and lower bounds are OK.   

References dump_dominator_optimization_stats().

static void record_equivalences_from_phis ( basic_block  )
static
static void record_equivalences_from_phis ( )
static

PHI nodes can create equivalences too.

Ignoring any alternatives which are the same as the result, if all the alternatives are equal, then the PHI node creates an equivalence.

         Ignore alternatives which are the same as our LHS.  Since
         LHS is a PHI_RESULT, it is known to be a SSA_NAME, so we
         can simply compare pointers.   
         If we have not processed an alternative yet, then set
         RHS to this alternative.   
         If we have processed an alternative (stored in RHS), then
         see if it is equal to this one.  If it isn't, then stop
         the search.   
     If we had no interesting alternatives, then all the RHS alternatives
     must have been the same as LHS.   
     If we managed to iterate through each PHI alternative without
     breaking out of the loop, then we have a PHI which may create
     a useful equivalence.  We do not need to record unwind data for
     this, since this is a true assignment and not an equivalence
     inferred from a comparison.  All uses of this ssa name are dominated
     by this assignment, so unwinding just costs time and space.   
static void record_equivalences_from_stmt ( gimple  ,
int   
)
static
static void record_equivalences_from_stmt ( )
static

STMT, a GIMPLE_ASSIGN, may create certain equivalences, in either the available expressions table or the const_and_copies table. Detect and record those equivalences. We handle only very simple copy equivalences here. The heavy lifing is done by eliminate_redundant_computations.

If the RHS of the assignment is a constant or another variable that
may be propagated, register it in the CONST_AND_COPIES table.  We
do not need to record unwind data for this, since this is a true
assignment and not an equivalence inferred from a comparison.  All
uses of this ssa name are dominated by this assignment, so unwinding
just costs time and space.   
 A memory store, even an aliased store, creates a useful
 equivalence.  By exchanging the LHS and RHS, creating suitable
 vops and recording the result in the available expression table,
 we may be able to expose more redundant loads.   


     Build a new statement with the RHS and LHS exchanged.   
         NOTE tuples.  The call to gimple_build_assign below replaced
         a call to build_gimple_modify_stmt, which did not set the
         SSA_NAME_DEF_STMT on the LHS of the assignment.  Doing so
         may cause an SSA validation failure, as the LHS may be a
         default-initialized name and should have no definition.  I'm
         a bit dubious of this, as the artificial statement that we
         generate here may in fact be ill-formed, but it is simply
         used as an internal device in this pass, and never becomes
         part of the CFG.   
     Finally enter the statement into the available expression
     table.   
static void record_temporary_equivalences ( )
static

Record into the equivalence tables any equivalences implied by traversing edge E (which are cached in E->aux).

Callers are responsible for managing the unwinding markers.

 If we have info associated with this edge, record it into
 our equivalence tables.   
     If we have a simple NAME = VALUE equivalence, record it.   
     If we have 0 = COND or 1 = COND equivalences, record them
     into our expression hash tables.   

References gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), NULL, and operand_equal_for_phi_arg_p().

Referenced by restore_vars_to_original_value().

static void remove_local_expressions_from_table ( )
static

Initialize local stacks for this optimizer and record equivalences upon entry to BB. Equivalences can come from the edge traversed to reach BB or they may come from PHI nodes at the start of BB. Remove all the expressions in LOCALS from TABLE, stopping when there are LIMIT entries left in LOCALs.

Remove all the expressions made available in this block.

     This must precede the actual removal from the hash table,
     as ELEMENT and the table entry may share a call argument
     vector which will be freed during removal.   
static void remove_stmt_or_phi ( )
static

PHI-ONLY copy and constant propagation. This pass is meant to clean up degenerate PHIs created by or exposed by jump threading. Given a statement STMT, which is either a PHI node or an assignment, remove it from the IL.

References bitmap_set_bit, dump_file, and dump_flags.

static void restore_vars_to_original_value ( )
static

Use the source/dest pairs in CONST_AND_COPIES_STACK to restore CONST_AND_COPIES to its original state, stopping when we hit a NULL marker.

References gimple_build_cond(), integer_zero_node, dom_opt_dom_walker::m_dummy_cond, NULL, NULL_TREE, record_temporary_equivalences(), simplify_stmt_for_jump_threading(), and dom_opt_dom_walker::thread_across_edge().

bool simple_iv_increment_p ( )

Returns true when STMT is a simple iv increment. It detects the following situation:

i_1 = phi (..., i_2) i_2 = i_1 +/- ...

static tree simplify_stmt_for_jump_threading ( gimple  stmt,
gimple  within_stmt 
)
static

A trivial wrapper so that we can present the generic jump threading code with a simple API for simplifying statements.

Referenced by restore_vars_to_original_value().

static edge single_incoming_edge_ignoring_loop_edges ( basic_block  )
static
static edge single_incoming_edge_ignoring_loop_edges ( )
static

Ignoring loop backedges, if BB has precisely one incoming edge then return that edge. Otherwise return NULL.

     A loop back edge can be identified by the destination of
     the edge dominating the source of the edge.   
     If we have already seen a non-loop edge, then we must have
     multiple incoming non-loop edges and thus we return NULL.   
     This is the first non-loop incoming edge we have found.  Record
     it.   

References fold_convert, record_equality(), and TREE_TYPE.

static unsigned int tree_ssa_dominator_optimize ( )
static

Jump threading, redundancy elimination and const/copy propagation.

This pass may expose new symbols that need to be renamed into SSA. For every new symbol exposed, its corresponding bit will be set in VARS_TO_RENAME.

 Create our hash tables.   
 We need to know loop structures in order to avoid destroying them
 in jump threading.  Note that we still can e.g. thread through loop
 headers to an exit edge, or through loop header to the loop body, assuming
 that we update the loop info.   
 Initialize the value-handle array.   
 We need accurate information regarding back edges in the CFG
 for jump threading; this may include back edges that are not part of
 a single loop.   
 Recursively walk the dominator tree optimizing statements.   
 If we exposed any new variables, go ahead and put them into
 SSA form now, before we handle jump threading.  This simplifies
 interactions between rewriting of _DECL nodes into SSA form
 and rewriting SSA_NAME nodes into SSA form after block
 duplication and CFG manipulation.   
 Thread jumps, creating duplicate blocks as needed.   
 Removal of statements may make some EH edges dead.  Purge
 such edges from the CFG as needed.   
     Jump threading may have created forwarder blocks from blocks
     needing EH cleanup; the new successor of these blocks, which
     has inherited from the original block, needs the cleanup.
     Don't clear bits in the bitmap, as that can break the bitmap
     iterator.   
 Debugging dumps.   
 Delete our main hashtable.   
 Free asserted bitmaps and stacks.   
 Free the value-handle array.   

Variable Documentation

hash_table<expr_elt_hasher> avail_exprs
static

Hash table with expressions made available during the renaming process. When an assignment of the form X_i = EXPR is found, the statement is stored in this table. If the same expression EXPR is later found on the RHS of another statement, it is replaced with X_i (thus performing global redundancy elimination). Similarly as we pass through conditionals we record the conditional itself as having either a true or false value in this table.

vec<expr_hash_elt_t> avail_exprs_stack
static
bool cfg_altered
static

Track whether or not we have changed the control flow graph.

vec<tree> const_and_copies_stack
static

Stack of dest,src pairs that need to be restored during finalization.

A NULL entry is used to mark the end of pairs which need to be restored during finalization of this block.

bitmap need_eh_cleanup
static

Bitmap of blocks that have had EH statements cleaned. We should remove their dead edges eventually.

struct opt_stats_d opt_stats
static

Referenced by free_all_edge_infos().