|
GCC Middle and Back End API Reference
|
Data Structures | |
| union | pre_expr_union_d |
| struct | pre_expr_d |
| struct | bitmap_set |
| struct | bb_bitmap_sets |
| struct | expr_pred_trans_d |
| class | eliminate_dom_walker |
Typedefs | |
| typedef union pre_expr_union_d | pre_expr_union |
| typedef pre_expr_d * | pre_expr |
| typedef struct bitmap_set * | bitmap_set_t |
| typedef struct bb_bitmap_sets * | bb_value_sets_t |
| typedef expr_pred_trans_d * | expr_pred_trans_t |
| typedef struct expr_pred_trans_d * | const_expr_pred_trans_t |
Enumerations | |
| enum | pre_expr_kind { NAME, NARY, REFERENCE, CONSTANT } |
Variables | |
| static unsigned int | next_expression_id |
| static vec< pre_expr > | expressions |
| static hash_table< pre_expr_d > | expression_to_id |
| static vec< unsigned > | name_to_id |
| static alloc_pool | pre_expr_pool |
| static vec< bitmap > | value_expressions |
| static int * | postorder |
| static int | postorder_num |
| static struct { ... } | pre_stats |
| static bool | do_partial_partial |
| static alloc_pool | bitmap_set_pool |
| static bitmap_obstack | grand_bitmap_obstack |
| static bitmap | need_eh_cleanup |
| static bitmap | need_ab_cleanup |
| static hash_table < expr_pred_trans_d > | phi_translate_table |
| static sbitmap | has_abnormal_preds |
| static sbitmap | changed_blocks |
| static bitmap | inserted_exprs |
| static vec< gimple > | el_to_remove |
| static vec< gimple > | el_to_update |
| static unsigned int | el_todo |
| static vec< tree > | el_avail |
| static vec< tree > | el_avail_stack |
| typedef struct bb_bitmap_sets * bb_value_sets_t |
Sets that we need to keep track of.
| typedef struct bitmap_set * bitmap_set_t |
An unordered bitmap set. One bitmap tracks values, the other, expressions.
| typedef struct expr_pred_trans_d* const_expr_pred_trans_t |
| typedef expr_pred_trans_d * expr_pred_trans_t |
A three tuple {e, pred, v} used to cache phi translations in the
phi_translate_table.
| typedef pre_expr_d * pre_expr |
| typedef union pre_expr_union_d pre_expr_union |
| enum pre_expr_kind |
@verbatim
SSA-PRE for trees. Copyright (C) 2001-2013 Free Software Foundation, Inc. Contributed by Daniel Berlin dan@dberlin.org and Steven Bosscher stevenb@suse.de
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/.
TODO:
1. Avail sets can be shared by making an avail_find_leader that
walks up the dominator tree and looks in those avail sets.
This might affect code optimality, it's unclear right now.
2. Strength reduction can be performed by anticipating expressions
we can repair later on.
3. We can do back-substitution or smarter value numbering to catch
commutative expressions split up over multiple statements.
For ease of terminology, "expression node" in the below refers to every expression node but GIMPLE_ASSIGN, because GIMPLE_ASSIGNs represent the actual statement containing the expressions we care about, and we cache the value number by putting it in the expression.
Basic algorithm
First we walk the statements to generate the AVAIL sets, the
EXP_GEN sets, and the tmp_gen sets. EXP_GEN sets represent the
generation of values/expressions by a given block. We use them
when computing the ANTIC sets. The AVAIL sets consist of
SSA_NAME's that represent values, so we know what values are
available in what blocks. AVAIL is a forward dataflow problem. In
SSA, values are never killed, so we don't need a kill set, or a
fixpoint iteration, in order to calculate the AVAIL sets. In
traditional parlance, AVAIL sets tell us the downsafety of the
expressions/values.
Next, we generate the ANTIC sets. These sets represent the
anticipatable expressions. ANTIC is a backwards dataflow
problem. An expression is anticipatable in a given block if it could
be generated in that block. This means that if we had to perform
an insertion in that block, of the value of that expression, we
could. Calculating the ANTIC sets requires phi translation of
expressions, because the flow goes backwards through phis. We must
iterate to a fixpoint of the ANTIC sets, because we have a kill
set. Even in SSA form, values are not live over the entire
function, only from their definition point onwards. So we have to
remove values from the ANTIC set once we go past the definition
point of the leaders that make them up.
compute_antic/compute_antic_aux performs this computation.
Third, we perform insertions to make partially redundant
expressions fully redundant.
An expression is partially redundant (excluding partial
anticipation) if:
1. It is AVAIL in some, but not all, of the predecessors of a
given block.
2. It is ANTIC in all the predecessors.
In order to make it fully redundant, we insert the expression into
the predecessors where it is not available, but is ANTIC.
For the partial anticipation case, we only perform insertion if it
is partially anticipated in some block, and fully available in all
of the predecessors.
insert/insert_aux/do_regular_insertion/do_partial_partial_insertion
performs these steps.
Fourth, we eliminate fully redundant expressions.
This is a simple statement walk that replaces redundant
calculations with the now available values. Representations of value numbers: Value numbers are represented by a representative SSA_NAME. We will create fake SSA_NAME's in situations where we need a representative but do not have one (because it is a complex expression). In order to facilitate storing the value numbers in bitmaps, and keep the number of wasted SSA_NAME's down, we also associate a value_id with each value number, and create full blown ssa_name's only where we actually need them (IE in operands of existing expressions). Theoretically you could replace all the value_id's with SSA_NAME_VERSION, but this would allocate a large number of SSA_NAME's (which are each > 30 bytes) just to get a 4 byte number. It would also require an additional indirection at each point we use the value id.
Representation of expressions on value numbers: Expressions consisting of value numbers are represented the same way as our VN internally represents them, with an additional "pre_expr" wrapping around them in order to facilitate storing all of the expressions in the same sets.
Representation of sets: The dataflow sets do not need to be sorted in any particular order for the majority of their lifetime, are simply represented as two bitmaps, one that keeps track of values present in the set, and one that keeps track of expressions present in the set. When we need them in topological order, we produce it on demand by transforming the bitmap into an array and sorting it into topo order.
Type of expression, used to know which member of the PRE_EXPR union is valid.
|
static |
Add expression E to the expression set of value id V.
Referenced by create_component_ref_by_pieces(), do_partial_partial_insertion(), and insert_aux().
|
inlinestatic |
Allocate an expression id for EXPR.
Make sure we won't overflow.
vec::safe_grow_cleared allocates no headroom. Avoid frequent
re-allocations by using vec::reserve upfront. There is no
vec::quick_grow_cleared unfortunately.
|
static |
|
static |
Find the leader for a value (i.e., the name representing that value) in a given set, and return it. Return NULL if no leader is found.
Rather than walk the entire bitmap of expressions, and see
whether any of them has the value we are looking for, we look
at the reverse mapping, which tells us the set of expressions
that have a given value (IE value->expressions with that
value) and see if any of those expressions are in our set.
The number of expressions per value is usually significantly
less than the number of expressions in the set. In fact, for
large testcases, doing it this way is roughly 5-10x faster
than walking the bitmap.
If this is somehow a significant lose for some cases, we can
choose which set to walk based on which set is smaller.
References bitmap_set_contains_value(), vn_ssa_aux::value_id, and VN_INFO().
|
static |
Referenced by do_partial_partial_insertion().
|
static |
Insert an expression EXPR into a bitmapped set.
|
static |
We specifically expect this and only this function to be able to
insert constants into a set.
References bitmap_bit_p(), and expression_for_id().
|
static |
Remove an expression EXPR from a bitmapped set.
|
static |
Perform bitmapped set operation DEST &= ORIG.
References bitmap_bit_p(), bitmap_empty_p(), and value_id_constant_p().
|
inlinestatic |
References get_expr_value_id(), get_or_alloc_expression_id(), pre_expr_d::id, and value_id_constant_p().
|
static |
Referenced by bitmap_find_leader().
|
static |
Return true if bitmapped set SET contains the value VALUE_ID.
|
static |
Referenced by do_partial_partial_insertion().
|
static |
Copy a bitmapped set ORIG, into bitmapped set DEST.
|
static |
Return true if two bitmap sets are equal.
References get_tree_code_name(), vn_reference_op_struct::op0, vn_reference_op_struct::opcode, and tcc_declaration.
|
static |
Free memory used up by SET.
|
static |
Create a new bitmap set and return it.
References bitmap_clear_bit(), get_expr_value_id(), get_expression_id(), and value_id_constant_p().
|
static |
Replace an instance of value LOOKFOR with expression EXPR in SET.
The number of expressions having a given value is usually
significantly less than the total number of expressions in SET.
Thus, rather than check, for each expression in SET, whether it
has the value LOOKFOR, we walk the reverse mapping that tells us
what expressions have a given value, and see if any of those
expressions are in our set. For large testcases, this is about
5-10x faster than walking the bitmap. If this is somehow a
significant lose for some cases, we can choose which set to walk
based on the set size.
|
static |
Subtract all values and expressions contained in ORIG from DEST.
References bitmap_clear_bit().
|
static |
Subtract all the values in bitmap set B from bitmap set A.
|
static |
Referenced by do_partial_partial_insertion(), and insert_aux().
|
static |
Insert EXPR into SET if EXPR's value is not already present in SET.
Constant values are always considered to be part of the set.
If the value membership changed, add the expression.
|
static |
Referenced by create_component_ref_by_pieces().
|
static |
Replace an instance of EXPR's VALUE with EXPR in SET if it exists, and add it otherwise.
|
static |
Clean the set of expressions that are no longer valid in SET. This means expressions that are made up of values we have no leaders for in SET.
|
static |
Free the expression id field in all of our expressions, and then destroy the expressions array.
|
static |
Compute ANTIC and partial ANTIC sets.
If any predecessor edges are abnormal, we punt, so antic_in is empty.
We pre-build the map of blocks with incoming abnormal edges here. While we are here, give empty ANTIC_IN sets to each block.
At the exit block we anticipate nothing.
??? We need to clear our PHI translation cache here as the
ANTIC sets shrink and we restrict valid translations to
those having operands with leaders in ANTIC. Same below
for PA ANTIC computation. Theoretically possible, but *highly* unlikely.
Theoretically possible, but *highly* unlikely.
References build_int_cst(), get_addr_base_and_unit_offset(), HOST_WIDE_INT, and int_const_binop().
|
static |
@verbatim
Compute the ANTIC set for BLOCK.
If succs(BLOCK) > 1 then ANTIC_OUT[BLOCK] = intersection of ANTIC_IN[b] for all succ(BLOCK) else if succs(BLOCK) == 1 then ANTIC_OUT[BLOCK] = phi_translate (ANTIC_IN[succ(BLOCK)])
ANTIC_IN[BLOCK] = clean(ANTIC_OUT[BLOCK] U EXP_GEN[BLOCK] - TMP_GEN[BLOCK])
If any edges from predecessors are abnormal, antic_in is empty,
so do nothing. If the block has no successors, ANTIC_OUT is empty.
If we have one successor, we could have some phi nodes to
translate through. We trade iterations of the dataflow equations for having to
phi translate the maximal set, which is incredibly slow
(since the maximal set often has 300+ members, even when you
have a small number of blocks).
Basically, we defer the computation of ANTIC for this block
until we have processed it's successor, which will inevitably
have a *much* smaller set of values to phi translate once
clean has been run on it.
The cost of doing this is that we technically perform more
iterations, however, they are lower cost iterations.
Timings for PRE on tramp3d-v4:
without maximal set fix: 11 seconds
with maximal set fix/without deferring: 26 seconds
with maximal set fix/with deferring: 11 seconds If we have multiple successors, we take the intersection of all of
them. Note that in the case of loop exit phi nodes, we may have
phis to translate through. Of multiple successors we have to have visited one already.
Prune expressions that are clobbered in block and thus become
invalid if translated from ANTIC_OUT to ANTIC_IN. Generate ANTIC_OUT - TMP_GEN.
Start ANTIC_IN with EXP_GEN - TMP_GEN.
Then union in the ANTIC_OUT - TMP_GEN values,
to get ANTIC_OUT U EXP_GEN - TMP_GEN
|
static |
Compute the AVAIL set for all basic blocks. This function performs value numbering of the statements in each basic block. The AVAIL sets are built from information we glean while doing this value numbering, since the AVAIL sets contain only one entry per value. AVAIL_IN[BLOCK] = AVAIL_OUT[dom(BLOCK)]. AVAIL_OUT[BLOCK] = AVAIL_IN[BLOCK] U PHI_GEN[BLOCK] U TMP_GEN[BLOCK].
We pretend that default definitions are defined in the entry block.
This includes function arguments and the static chain decl. Allocate the worklist.
Seed the algorithm by putting the dominator children of the entry
block on the worklist. Loop until the worklist is empty.
Pick a block from the worklist.
Initially, the set of available values in BLOCK is that of
its immediate dominator. Generate values for PHI nodes.
We have no need for virtual phis, as they don't represent
actual computations. Now compute value numbers and populate value sets with all
the expressions computed in BLOCK. Cache whether the basic-block has any non-visible side-effect
or control flow.
If this isn't a call or it is the last stmt in the
basic-block then the CFG represents things correctly. Non-looping const functions always return normally.
Otherwise the call might not return or have side-effects
that forbids hoisting possibly trapping expressions
before it. We can value number only calls to real functions.
If the value of the call is not invalidated in
this block until it is computed, add the expression
to EXP_GEN. COND_EXPR and VEC_COND_EXPR are awkward in
that they contain an embedded complex expression.
Don't even try to shove those through PRE. If the NARY traps and there was a preceding
point in the block that might not return avoid
adding the nary to EXP_GEN. If the value of the reference is not invalidated in
this block until it is computed, add the expression
to EXP_GEN. Put the dominator children of BLOCK on the worklist of blocks
to compute available sets for.
|
static |
@verbatim
Compute PARTIAL_ANTIC for BLOCK.
If succs(BLOCK) > 1 then PA_OUT[BLOCK] = value wise union of PA_IN[b] + all ANTIC_IN not in ANTIC_OUT for all succ(BLOCK) else if succs(BLOCK) == 1 then PA_OUT[BLOCK] = phi_translate (PA_IN[succ(BLOCK)])
PA_IN[BLOCK] = dependent_clean(PA_OUT[BLOCK] - TMP_GEN[BLOCK]
If any edges from predecessors are abnormal, antic_in is empty,
so do nothing. If there are too many partially anticipatable values in the
block, phi_translate_set can take an exponential time: stop
before the translation starts. If the block has no successors, ANTIC_OUT is empty.
If we have one successor, we could have some phi nodes to
translate through. Note that we can't phi translate across DFS
back edges in partial antic, because it uses a union operation on
the successors. For recurrences like IV's, we will end up
generating a new value in the set on each go around (i + 3 (VH.1)
VH.1 + 1 (VH.2), VH.2 + 1 (VH.3), etc), forever. If we have multiple successors, we take the union of all of
them. Prune expressions that are clobbered in block and thus become
invalid if translated from PA_OUT to PA_IN. PA_IN starts with PA_OUT - TMP_GEN.
Then we subtract things from ANTIC_IN. For partial antic, we want to put back in the phi results, since
we will properly avoid making them partially antic over backedges. PA_IN[block] = PA_IN[block] - ANTIC_IN[block]
References bitmap_set_bit(), edge_def::flags, and basic_block_def::index.
|
static |
For COMPONENT_REF's and ARRAY_REF's, we can't have any intermediates for the COMPONENT_REF or MEM_REF or ARRAY_REF portion, because we'd end up with trying to rename aggregates into ssa form directly, which is a no no. Thus, this routine doesn't create temporaries, it just builds a single access expression for the array, calling find_or_generate_expression to build the innermost pieces. This function is a subroutine of create_expression_by_pieces, and should not be called on it's own unless you really know what you are doing.
References add_to_value(), bitmap_set_bit(), bitmap_value_replace_in_set(), get_next_value_id(), get_or_alloc_expr_for_name(), vn_ssa_aux::valnum, vn_ssa_aux::value_id, VN_INFO(), and VN_INFO_GET().
|
static |
The actual worker for create_component_ref_by_pieces.
Fallthrough.
For array ref vn_reference_op's, operand 1 of the array ref
is op0 of the reference op and operand 3 of the array ref is
op1. Drop zero minimum index if redundant.
We can't always put a size in units of the element alignment
here as the element alignment may be not visible. See
PR43783. Simply drop the element size for constant
sizes. op1 should be a FIELD_DECL, which are represented by themselves.
References find_or_generate_expression().
|
static |
Create an expression in pieces, so that we can handle very complex expressions that may be ANTIC, but not necessary GIMPLE. BLOCK is the basic block the expression will be inserted into, EXPR is the expression to insert (in value form) STMTS is a statement list to append the necessary insertions into. This function will die if we hit some value that shouldn't be ANTIC but is (IE there is no leader for it, or its components). The function returns NULL_TREE in case a different antic expression has to be inserted first. This function may also generate expressions that are themselves partially or fully redundant. Those that are will be either made fully redundant during the next iteration of insert (for partially redundant ones), or eliminated by eliminate (for fully redundant ones).
We may hit the NAME/CONSTANT case if we have to convert types
that value numbering saw through. Ensure genop[] is properly typed for POINTER_PLUS_EXPR. It
may have conversions stripped. Force the generated expression to be a sequence of GIMPLE
statements.
We have to call unshare_expr because force_gimple_operand may
modify the tree we pass to it. If we have any intermediate expressions to the value sets, add them
to the value sets and chain them in the instruction stream. Fold the last statement.
Add a value number to the temporary.
The value may already exist in either NEW_SETS, or AVAIL_OUT, because
we are creating the expression by pieces, and this particular piece of
the expression may have been represented. There is no harm in replacing
here.
References flow_bb_inside_loop_p(), gimple_bb(), basic_block_def::loop_father, vn_reference_op_struct::op0, vn_reference_op_struct::opcode, and simple_iv().
| void debug_bitmap_set | ( | bitmap_set_t | ) |
| DEBUG_FUNCTION void debug_bitmap_set | ( | ) |
References CONSTANT, expression_for_id(), and pre_expr_d::kind.
| void debug_bitmap_sets_for | ( | basic_block | ) |
| DEBUG_FUNCTION void debug_bitmap_sets_for | ( | ) |
| void debug_pre_expr | ( | pre_expr | ) |
| DEBUG_FUNCTION void debug_pre_expr | ( | ) |
Like print_pre_expr but always prints to stderr.
| DEBUG_FUNCTION void debug_value_expressions | ( | ) |
|
static |
Decide whether to defer a block for a later iteration, or PHI translate SOURCE to DEST using phis in PHIBLOCK. Return false if we should defer the block, and true if we processed it.
|
static |
Clean the set of expressions that are no longer valid in SET1 or SET2. This means expressions that are made up of values we have no leaders for in SET1 or SET2. This version is used for partial anticipation, which means it is not valid in either ANTIC_IN or PA_IN.
References single_succ().
|
static |
Perform insertion for partially anticipatable expressions. There is only one case we will perform insertion for these. This case is if the expression is partially anticipatable, and fully available. In this case, we know that putting it earlier will enable us to remove the later computation.
We should never run insertion for the exit block
and so not come across fake pred edges. eprime will generally only be NULL if the
value of the expression, translated
through the PHI for this predecessor, is
undefined. If that is the case, we can't
make the expression fully redundant,
because its value is undefined along a
predecessor path. We can thus break out
early because it doesn't matter what the
rest of the results are. If we can insert it, it's not the same value
already existing along every predecessor, and
it's defined by some predecessor, it is
partially redundant. Insert only if we can remove a later expression on a path
that we want to optimize for speed.
The phi node that we will be inserting in BLOCK is not free,
and inserting it for the sake of !optimize_for_speed successor
may cause regressions on the speed path.
References add_to_value(), bitmap_insert_into_set(), bitmap_set_copy(), bitmap_value_insert_into_set(), CDI_DOMINATORS, dom, dump_file, dump_flags, first_dom_son(), get_expr_value_id(), get_immediate_dominator(), get_or_alloc_expr_for_name(), gimple_call_flags(), gimple_has_side_effects(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), has_zero_uses(), is_gimple_call(), is_gimple_debug(), next_dom_son(), print_bitmap_set(), ssa_undefined_value_p(), stmt_could_throw_p(), stmt_ends_bb_p(), virtual_operand_p(), and worklist.
|
static |
Gate and execute functions for PRE.
This has to happen before SCCVN runs because
loop_optimizer_init may create new phis, etc. Collect and value number expressions computed in each basic block.
Insert can get quite slow on an incredibly large number of basic
blocks due to some quadratic behavior. Until this behavior is
fixed, don't run it when he have an incredibly large number of
bb's. If we aren't going to run insert, there is no point in
computing ANTIC, either, even though it's plenty fast. Make sure to remove fake edges before committing our inserts.
This makes sure we don't end up with extra critical edges that
we would need to split. Remove all the redundant expressions.
TODO: tail_merge_optimize may merge all predecessors of a block, in which
case we can merge the block with the remaining predecessor of the block.
It should either:
- call merge_blocks after each tail merge iteration
- call merge_blocks after all tail merge iterations
- mark TODO_cleanup_cfg when necessary
- share the cfg cleanup with fini_pre. Tail merging invalidates the virtual SSA web, together with
cfg-cleanup opportunities exposed by PRE this will wreck the
SSA updating machinery. So make sure to run update-ssa
manually, before eventually scheduling cfg-cleanup as part of
the todo.
Referenced by mark_operand_necessary().
|
static |
@verbatim
Perform insertion of partially redundant values. For BLOCK, do the following:
Steps 1, 2a, and 3 are done by insert_aux. 2b, 2c and 2d are done by do_regular_insertion and do_partial_insertion.
We should never run insertion for the exit block
and so not come across fake pred edges. eprime will generally only be NULL if the
value of the expression, translated
through the PHI for this predecessor, is
undefined. If that is the case, we can't
make the expression fully redundant,
because its value is undefined along a
predecessor path. We can thus break out
early because it doesn't matter what the
rest of the results are. We want to perform insertions to remove a redundancy on
a path in the CFG we want to optimize for speed. If we can insert it, it's not the same value
already existing along every predecessor, and
it's defined by some predecessor, it is
partially redundant. If all edges produce the same value and that value is
an invariant, then the PHI has the same value on all
edges. Note this.
|
static |
Eliminate fully redundant computations.
We cannot remove stmts during BB walk, especially not release SSA
names there as this confuses the VN machinery. The stmts ending
up in el_to_remove are either stores or simple copies. If there is a single use only, propagate the equivalency
instead of keeping the copy. If this is a store or a now unused copy, remove it.
We cannot update call statements with virtual operands during
SSA walk. This might remove them which in turn makes our
VN lattice invalid.
|
static |
Return a leader for OP that is available at the current point of the eliminate domwalk.
References dump_file, dump_flags, is_gimple_call(), print_generic_expr(), print_gimple_expr(), and stmt_can_make_abnormal_goto().
|
static |
Insert the expression recorded by SCCVN for VAL at *GSI. Returns the leader for the expression if insertion was successful.
|
static |
At the current point of the eliminate domwalk make OP available.
|
static |
Gate and execute functions for FRE.
Remove all the redundant expressions.
|
inlinestatic |
Return the expression that has expression id ID
References pre_expr_d::id, pre_expr_d::kind, lookup_expression_id(), and NAME.
Referenced by bitmap_insert_into_set_1(), and debug_bitmap_set().
|
inlinestatic |
Like bitmap_find_leader, but checks for the value existing in SET1 *or* SET2. This is used to avoid making a set consisting of the union of PA_IN and ANTIC_IN during insert.
Referenced by get_expr_type(), and phi_translate_1().
|
static |
Referenced by create_component_ref_by_pieces_1().
|
static |
Find a simple leader for an expression, or generate one using create_expression_by_pieces from a NARY expression for the value. BLOCK is the basic_block we are looking for leaders in. OP is the tree expression to find a leader for or generate. Returns the leader or NULL_TREE on failure.
Defer.
It must be a complex expression, so generate it recursively. Note
that this is only necessary to handle gcc.dg/tree-ssa/ssa-pre28.c
where the insert algorithm fails to insert a required expression. We cannot insert random REFERENCE expressions at arbitrary
places. We can insert NARYs which eventually re-materializes
its operand values. Defer.
|
static |
Perform CFG cleanups made necessary by elimination.
|
static |
Deallocate data structures used by PRE.
|
static |
Return the folded version of T if T, when folded, is a gimple min_invariant. Otherwise, return T.
We have to go from trees to pre exprs to value ids to
constants. We might have simplified the expression to a
SSA_NAME for example from x_1 * 1. But we cannot
insert a PHI for x_1 unconditionally as x_1 might
not be available readily. Fallthrough.
We have to go from trees to pre exprs to value ids to
constants.
|
static |
|
static |
Referenced by mark_operand_necessary().
|
static |
Given a value id V, find the actual tree representing the constant value if there is one, and return it. Return NULL if we can't find a constant.
Referenced by get_or_alloc_expr_for(), and get_or_alloc_expr_for_constant().
|
static |
Get the tree type for our PRE expression e.
References changed, find_leader_in_sets(), get_representative_for(), vn_nary_op_s::length, memcpy(), vn_nary_op_s::op, phi_translate(), sizeof_vn_nary_op(), vn_ssa_aux::value_id, and VN_INFO().
|
static |
|
static |
Return the value id for a PRE expression EXPR.
??? We cannot assert that expr has a value-id (it can be 0), because
we assign value-ids only to expressions that have a result
in set_hashtable_value_ids.
|
inlinestatic |
Return the expression id for tree EXPR.
References hash_table< Descriptor, Allocator >::find_slot(), and pre_expr_d::id.
Referenced by bitmap_set_new(), and phi_translate().
|
static |
Get or allocate a pre_expr for a piece of GIMPLE, and return it. Currently only supports constants and SSA_NAMES.
More complex expressions can result from SCCVN expression
simplification that inserts values for them. As they all
do not have VOPs the get handled by the nary ops struct.
References get_constant_for_value_id(), get_expr_value_id(), get_or_alloc_expr_for_constant(), is_gimple_min_invariant(), vn_nary_op_s::op, and vn_nary_op_s::type.
Referenced by get_or_alloc_expr_for_constant().
|
static |
Given a CONSTANT, allocate a new CONSTANT type PRE_EXPR to represent it.
References CONSTANT, get_constant_for_value_id(), get_expr_value_id(), get_or_alloc_expr_for(), is_gimple_min_invariant(), pre_expr_d::kind, NARY, vn_nary_op_s::op, tcc_binary, and tcc_comparison.
Referenced by get_or_alloc_expr_for().
|
static |
Given an SSA_NAME NAME, get or create a pre_expr to represent it.
References bitmap_set::expressions, and bitmap_set::values.
Referenced by create_component_ref_by_pieces(), and do_partial_partial_insertion().
|
inlinestatic |
Return the existing expression id for EXPR, or create one if one does not exist yet.
Referenced by bitmap_set_contains_expr(), and insert_aux().
|
static |
Get a representative SSA_NAME for a given expression. Since all of our sub-expressions are treated as values, we require them to be SSA_NAME's for simplicity. Prior versions of GVNPRE used to use "value handles" here, so that an expression would be VH.11 + VH.10 instead of d_3 + e_6. In either case, the operands are really values (IE we do not expect them to be usable without finding leaders).
Go through all of the expressions representing this value
and pick out an SSA_NAME. If we reached here we couldn't find an SSA_NAME. This can
happen when we've discovered a value that has never appeared in
the program as set to an SSA_NAME, as the result of phi translation.
Create one here.
??? We should be able to re-use this when we insert the statement
to compute it. ??? For now mark this SSA name for release by SCCVN.
Referenced by get_expr_type(), and phi_translate_1().
|
static |
Returns true if we want to inhibit the insertions of PHI nodes for the given EXPR for basic block BB (a member of a loop). We want to do this, when we fear that the induction variable we create might inhibit vectorization.
If we aren't going to vectorize we don't inhibit anything.
Otherwise we inhibit the insertion when the address of the
memory reference is a simple induction variable. In other
cases the vectorizer won't do anything anyway (either it's
loop invariant or a complicated expression). Calls are not a problem.
Fallthru.
Default defs are loop invariant.
Defined outside this loop, also loop invariant.
If it's a simple induction variable inhibit insertion,
the vectorizer might be interested in this one. No simple IV, vectorizer can't do anything, hence no
reason to inhibit the transformation for this operand.
References bitmap_set_bit(), gimple_get_lhs(), gimple_set_plf(), gsi_end_p(), gsi_insert_seq_on_edge(), gsi_next(), and gsi_stmt().
|
static |
Initialize data structures used by PRE.
|
static |
Perform insertion of partially redundant values.
Clear the NEW sets before the next iteration. We have already
fully propagated its contents.
|
static |
Note that we need to value_replace both NEW_SETS, and
AVAIL_OUT. For both the case of NEW_SETS, the value may be
represented by some non-simple expression here that we want
to replace it with.
References add_to_value(), bitmap_value_insert_into_set(), copy_reference_ops_from_call(), get_expr_value_id(), get_or_alloc_expression_id(), gimple_call_internal_p(), gimple_expr_type(), gimple_vuse(), pre_expr_d::id, pre_expr_d::kind, pool_alloc(), REFERENCE, VN_NOWALK, vn_reference_lookup_pieces(), and vNULL.
|
static |
Insert the to-be-made-available values of expression EXPRNUM for each predecessor, stored in AVAIL, into the predecessors of BLOCK, and merge the result with a phi node, given the same value number as NODE. Return true if we have inserted new stuff.
Make sure we aren't creating an induction variable.
Induction variables only have one edge inside the loop.
Make the necessary insertions.
We cannot insert a PHI node if we failed to insert
on one edge. Constants may not have the right type, fold_convert
should give us back a constant with the right type. We may have to do a conversion because our value
numbering can look through types in certain cases, but
our IL requires all operands of a phi node have the same
type. If we didn't want a phi node, and we made insertions, we still have
inserted new stuff, and thus return true. If we didn't want a phi node,
and didn't make insertions, we haven't added anything new, so return
false. Now build a phi for the new variable.
The value should *not* exist in PHI_GEN, or else we wouldn't be doing
this insertion, since we test for the existence of this value in PHI_GEN
before proceeding with the partial redundancy checks in insert_aux.
The value may exist in AVAIL_OUT, in particular, it could be represented
by the expression we are trying to eliminate, in which case we want the
replacement to occur. If it's not existing in AVAIL_OUT, we want it
inserted there.
Similarly, to the PHI_GEN case, the value should not exist in NEW_SETS of
this block, because if it did, it would have existed in our dominator's
AVAIL_OUT, and would have been skipped due to the full redundancy check.
|
inlinestatic |
Referenced by expression_for_id().
| gimple_opt_pass* make_pass_fre | ( | ) |
| gimple_opt_pass* make_pass_pre | ( | ) |
|
inlinestatic |
Borrow a bit of tree-ssa-dce.c for the moment. XXX: In 4.1, we should be able to just run a DCE pass after PRE, though this may be a bit faster, and we may want critical edges kept split.
If OP's defining statement has not already been determined to be necessary, mark that statement necessary. Return the stmt, if it is newly necessary.
References do_pre(), opt_pass::execute(), opt_pass::gate(), gate_pre(), and gimple_opt_pass::gimple_opt_pass().
|
static |
Determine if OP is valid in SET1 U SET2, which it is when the union contains its value-id.
|
inlinestatic |
Add the tuple mapping from {expression E, basic block PRED} to
the phi translation table and return whether it pre-existed.
|
static |
Wrapper around phi_translate_1 providing caching functionality.
Constants contain no values that need translation.
Don't add translations of NAMEs as those are cheap to translate.
Store NULL for the value we want to return in the case of
recursing. Translate.
Remove failed translations again, they cause insert
iteration to not pick up new opportunities reliably.
References ao_ref_s::base, bitmap_bit_p(), get_expression_id(), gimple_vdef(), gimple_vuse(), gsi_end_p(), gsi_next(), gsi_start_bb(), and gsi_stmt().
Referenced by get_expr_type(), and phi_translate_1().
|
static |
Translate EXPR using phis in PHIBLOCK, so that it has the values of the phis in PRED. Return NULL if we can't find a leader for each part of the translated expression.
We can't possibly insert these.
We may have changed from an SSA_NAME to a constant
If it transforms a non-constant ARRAY_REF into a constant
one, adjust the constant offset. If it transforms from an SSA_NAME to an address, fold with
a preceding indirect reference. We can always insert constants, so if we have a partial
redundant constant load of another type try to translate it
to a constant of appropriate type. If we'd have to convert things we would need to validate
if we can insert the translated expression. So fail
here for now - we cannot insert an alias with a different
type in the VN tables either, as that would assert. If the SSA name is defined by a PHI node in this block,
translate it. Handle constant.
Otherwise return it unchanged - it will get cleaned if its
value is not available in PREDs AVAIL_OUT set of expressions.
References find_leader_in_sets(), get_representative_for(), is_gimple_min_invariant(), phi_translate(), vn_ssa_aux::value_id, and VN_INFO().
|
static |
For each expression in SET, translate the values through phi nodes in PHIBLOCK using edge PHIBLOCK->PRED, and store the resulting expressions in DEST.
We might end up with multiple expressions from SET being
translated to the same value. In this case we do not want
to retain the NARY or REFERENCE expression but prefer a NAME
which would be the leader.
Referenced by valid_in_sets().
|
static |
Print out SET to OUTFILE.
Referenced by do_partial_partial_insertion().
|
static |
Print out EXPR to outfile.
|
static |
Print out the expressions that have VAL to OUTFILE.
|
static |
Clean the set of expressions that are no longer valid in SET because they are clobbered in BLOCK or because they trap and may not be executed.
If the NARY may trap make sure the block does not contain
a possible exit point.
??? This is overly conservative if we translate AVAIL_OUT
as the available expression might be after the exit point.
References edge_def::dest.
|
static |
Because we don't follow exactly the standard PRE algorithm, and decide not to insert PHI nodes sometimes, and because value numbering of casts isn't perfect, we sometimes end up inserting dead code. This simple DCE-like pass removes any insertions we made that weren't actually used.
PHI nodes are somewhat special in that each PHI alternative has
data and control dependencies. All the statements feeding the
PHI node's arguments are always necessary. Propagate through the operands. Examine all the USE, VUSE and
VDEF operands in this statement. Mark all the statements
which feed this statement's uses as necessary. The operands of VDEF expressions are also needed as they
represent potential definitions that may reach this
statement (VDEF operands allow us to follow def-def
links).
|
static |
Return a SCCVN valnum (SSA name or constant) for the PRE value-id VAL.
References bitmap_clear().
Generate an topological-ordered array of bitmap set SET.
Pre-allocate roughly enough space for the array.
The number of expressions having a given value is usually
relatively small. Thus, rather than making a vector of all
the expressions and sorting it by value-id, we walk the values
and check in the reverse mapping that tells us what expressions
have a given value, to filter those in our set. As a result,
the expressions are inserted in value-id order, which means
topological order.
If this is somehow a significant lose for some cases, we can
choose which set to walk based on the set size.
|
static |
Translate the VUSE backwards through phi nodes in PHIBLOCK, so that it has the value it would have in BLOCK. Set *SAME_VALID to true in case the new vuse doesn't change the value id of the OPERANDS.
Use the alias-oracle to find either the PHI node in this block,
the first VUSE used in this block that is equivalent to vuse or
the first VUSE which definition in this block kills the value. Try to find a vuse that dominates this phi node by skipping
non-clobbering statements. If we didn't find any, the value ID can't stay the same,
but return the translated vuse. ??? We would like to return vuse here as this is the canonical
upmost vdef that this reference is associated with. But during
insertion of the references into the hash tables we only ever
directly insert with their direct gimple_vuse, hence returning
something else would make us not find the other expression.
|
static |
Determine if the expression EXPR is valid in SET1 U SET2. ONLY SET2 CAN BE NULL. This means that we have a leader for each part of the expression (if it consists of values), or the expression is an SSA_NAME. For loads/calls, we also see if the vuse is killed in this block.
References bitmap_set_bit(), basic_block_def::index, and phi_translate_set().
|
static |
Determine if EXPR, a memory expression, is ANTIC_IN at the top of BLOCK by seeing if it is not killed in the block. Note that we are only determining whether there is a store that kills it. Because of the order in which clean iterates over values, we are guaranteed that altered operands will have caused us to be eliminated from the ANTIC_IN set already.
Lookup a previously calculated result.
A memory expression {e, VUSE} dies in the block if there is a
statement that may clobber e. If, starting statement walk from the
top of the basic block, a statement uses VUSE there can be no kill
inbetween that use and the original statement that loaded {e, VUSE},
so we can stop walking. Not a memory statement.
Not a may-def.
A load with the same VUSE, we're done.
Init ref only if we really need it.
If the statement may clobber expr, it dies.
Remember the result.
|
static |
We can add and remove elements and entries to and from sets and hash tables, so we use alloc pools for them.
|
static |
List of blocks that may have changed during ANTIC computation and thus need to be iterated over.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Inserted expressions are placed onto this worklist, which is used for performing quick dead code elimination of insertions we made that didn't turn out to be necessary.
|
static |
|
static |
Set of blocks with statements that have had their AB properties changed.
|
static |
Set of blocks with statements that have had their EH properties changed.
|
static |
Next global expression id number.
|
static |
The phi_translate_table caches phi translations for a given expression and predecessor.
|
static |
Basic block list in postorder.
|
static |
Referenced by dom_walker::walk().
|
static |
| struct { ... } pre_stats |
This structure is used to keep track of statistics on what optimization PRE was able to perform.