GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.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 "timevar.h"
#include "dumpfile.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-ssa-propagate.h"
#include "tree-ssa-threadupdate.h"
#include "langhooks.h"
#include "params.h"
#include "tree-ssa-threadedge.h"
Variables | |
static int | stmt_count |
vec< tree > | ssa_name_values |
|
static |
Return TRUE if the statement at the end of e->dest depends on the output of any statement in BB. Otherwise return FALSE.
This is used when we are threading a backedge and need to ensure that temporary equivalences from BB do not affect the condition in e->dest.
E->dest does not have to end with a control transferring instruction. This can occur when we try to extend a jump threading opportunity deeper into the CFG. In that case it is safe for this check to return false.
|
static |
Fold the RHS of an assignment statement and return it as a tree. May return NULL_TREE if no simplification is possible.
Sadly, we have to handle conditional assignments specially here, because fold expects all the operands of an expression to be folded before the expression itself is folded, but we can't just substitute the folded condition here.
|
static |
Return the LHS of any ASSERT_EXPR where OP appears as the first argument to the ASSERT_EXPR and in which the ASSERT_EXPR dominates BB. If no such ASSERT_EXPR is found, return OP.
References gimple_assign_lhs().
bool potentially_threadable_block | ( | ) |
Return TRUE if we may be able to thread an incoming edge into BB to an outgoing edge from BB. Return FALSE otherwise.
If BB has a single successor or a single predecessor, then there is no threading opportunity.
If BB does not end with a conditional, switch or computed goto, then there is no threading opportunity.
Referenced by simplify_cond_using_ranges().
void propagate_threaded_block_debug_into | ( | ) |
Copy debug stmts from DEST's chain of single predecessors up to SRC, so that we don't lose the bindings as PHI nodes are introduced when DEST gains new predecessors.
Estimate the number of debug vars overridden in the beginning of DEST, to tell how many we're going to need to begin with.
If we're already starting with 3/4 of alloc_count, go for a pointer_set, otherwise start with an unordered stack-allocated VEC.
Now go through the initial debug stmts in DEST again, this time actually inserting in VARS or FEWVARS. Don't bother checking for duplicates in FEWVARS.
Discard debug bind overlaps. ??? Unlike stmts from src, copied into a new block that will precede BB, debug bind stmts in bypassed BBs may actually be discarded if they're overwritten by subsequent debug bind stmts, which might be a problem once we introduce stmt frontier notes or somesuch. Adding `&& bb == src' to the condition below will preserve all potentially relevant debug notes.
??? Should we drop the location of the copy to denote they're artificial bindings?
|
static |
Record a temporary equivalence, saving enough information so that we can restore the state of recorded equivalences when we're done processing the current edge.
|
static |
Record temporary equivalences created by PHIs at the target of the edge E. Record unwind information for the equivalences onto STACK.
If a PHI which prevents threading is encountered, then return FALSE indicating we should not thread this edge, else return TRUE.
Each PHI creates a temporary equivalence, record them. These are context sensitive equivalences and will be removed later.
If the desired argument is not the same as this PHI's result and it is set by a PHI in E->dest, then we can not thread through E->dest.
We consider any non-virtual PHI as a statement since it count result in a constant assignment or copy operation.
|
static |
Try to simplify each statement in E->dest, ultimately leading to a simplification of the COND_EXPR at the end of E->dest.
Record unwind information for temporary equivalences onto STACK.
Use SIMPLIFY (a pointer to a callback function) to further simplify statements using pass specific information.
We might consider marking just those statements which ultimately feed the COND_EXPR. It's not clear if the overhead of bookkeeping would be recovered by trying to simplify fewer statements.
If we are able to simplify a statement into the form SSA_NAME = (SSA_NAME | gimple invariant), then we can record a context sensitive equivalence which may help us simplify later statements in E->dest.
Walk through each statement in the block recording equivalences we discover. Note any equivalences we discover are context sensitive (ie, are dependent on traversing E) and must be unwound when we're finished processing E.
Ignore empty statements and labels.
If the statement has volatile operands, then we assume we can not thread through this block. This is overly conservative in some ways.
If duplicating this block is going to cause too much code expansion, then do not thread through this block.
If this is not a statement that sets an SSA_NAME to a new value, then do not try to simplify this statement as it will not simplify in any way that is helpful for jump threading.
The result of __builtin_object_size depends on all the arguments of a phi node. Temporarily using only one edge produces invalid results. For example if (x < 6) goto l; else goto l; l: r = PHI <&w[2].a[1](2), &a.a[6](3)> __builtin_object_size (r, 0) The result of __builtin_object_size is defined to be the maximum of remaining bytes. If we use only one edge on the phi, the result will change to be the remaining bytes for the corresponding phi argument. Similarly for __builtin_constant_p: r = PHI <1(2), 2(3)> __builtin_constant_p (r) Both PHI arguments are constant, but x ? 1 : 2 is still not constant.
At this point we have a statement which assigns an RHS to an SSA_VAR on the LHS. We want to try and simplify this statement to expose more context sensitive equivalences which in turn may allow us to simplify the condition at the end of the loop. Handle simple copy operations as well as implied copies from ASSERT_EXPRs.
A statement that is not a trivial copy or ASSERT_EXPR. We're going to temporarily copy propagate the operands and see if that allows us to simplify this statement.
Make a copy of the uses & vuses into USES_COPY, then cprop into the operands.
Try to fold/lookup the new expression. Inserting the expression into the hash table is unlikely to help.
Restore the statement's original uses/defs.
Record the context sensitive equivalence if we were able to simplify this statement.
References DECL_FUNCTION_CODE, and gimple_call_fndecl().
|
static |
We record temporary equivalences created by PHI nodes or statements within the target block. Doing so allows us to identify more jump threading opportunities, even in blocks with side effects.
We keep track of those temporary equivalences in a stack structure so that we can unwind them when we're done processing a particular edge. This routine handles unwinding the data structures.
A NULL value indicates we should stop unwinding, otherwise pop off the next entry as they're recorded in pairs.
void set_ssa_name_value | ( | ) |
Set the value for the SSA name NAME to VALUE.
Referenced by eliminate_redundant_computations().
|
static |
Simplify the control statement at the end of the block E->dest.
To avoid allocating memory unnecessarily, a scratch GIMPLE_COND is available to use/clobber in DUMMY_COND.
Use SIMPLIFY (a pointer to a callback function) to further simplify a condition using pass specific information.
Return the simplified condition or NULL if simplification could not be performed.
For comparisons, we have to update both operands, then try to simplify the comparison.
Get the current value of both operands.
Now see if the operand was consumed by an ASSERT_EXPR which dominates E->src. If so, we want to replace the operand with the LHS of the ASSERT_EXPR.
We may need to canonicalize the comparison. For example, op0 might be a constant while op1 is an SSA_NAME. Failure to canonicalize will cause us to miss threading opportunities.
Stuff the operator and operands into our dummy conditional expression.
We absolutely do not care about any type conversions we only care about a zero/nonzero value.
If we have not simplified the condition down to an invariant, then use the pass specific callback to simplify the condition.
We can have conditionals which just test the state of a variable rather than use a relational operator. These are simpler to handle.
Get the variable's current value from the equivalence chains. It is possible to get loops in the SSA_NAME_VALUE chains (consider threading the backedge of a loop where we have a loop invariant SSA_NAME used in the condition.
If we're dominated by a suitable ASSERT_EXPR, then update CACHED_LHS appropriately.
If we haven't simplified to an invariant yet, then use the pass specific callback to try and simplify it further.
void thread_across_edge | ( | gimple | dummy_cond, |
edge | e, | ||
bool | handle_dominating_asserts, | ||
vec< tree > * | stack, | ||
tree(*)(gimple, gimple) | simplify | ||
) |
We are exiting E->src, see if E->dest ends with a conditional jump which has a known value when reached via E.
Special care is necessary if E is a back edge in the CFG as we may have already recorded equivalences for E->dest into our various tables, including the result of the conditional at the end of E->dest. Threading opportunities are severely limited in that case to avoid short-circuiting the loop incorrectly.
Note it is quite common for the first block inside a loop to end with a conditional which is either always true or always false when reached via the loop backedge. Thus we do not want to blindly disable threading across a loop backedge.
DUMMY_COND is a shared cond_expr used by condition simplification as scratch, to avoid allocating memory.
HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of the simplified condition with left-hand sides of ASSERT_EXPRs they are used in.
STACK is used to undo temporary equivalences created during the walk of E->dest.
SIMPLIFY is a pass-specific function used to simplify statements.
There should be no edges on the path, so no need to walk through the vector entries.
We were unable to determine what out edge from E->dest is taken. However, we might still be able to thread through successors of E->dest. This often occurs when E->dest is a joiner block which then fans back out based on redundant tests. If so, we'll copy E->dest and redirect the appropriate predecessor to the copy. Within the copy of E->dest, we'll thread one or more edges to points deeper in the CFG. This is a stopgap until we have a more structured approach to path isolation. If E->dest has abnormal outgoing edges, then there's no guarantee we can safely redirect any of the edges. Just punt those cases.
Look at each successor of E->dest to see if we can thread through it.
Avoid threading to any block we have already visited.
Record whether or not we were able to thread through a successor of E->dest.
If we were able to thread through a successor of E->dest, then record the jump threading opportunity.
Referenced by simplify_cond_using_ranges().
|
static |
See if TAKEN_EDGE->dest is a threadable block with no side effecs (ie, it need not be duplicated as part of the CFG/SSA updating process).
If it is threadable, add it to PATH and VISITED and recurse, ultimately returning TRUE from the toplevel call. Otherwise do nothing and return false.
DUMMY_COND, HANDLE_DOMINATING_ASSERTS and SIMPLIFY are used to try and simplify the condition at the end of TAKEN_EDGE->dest.
The key property of these blocks is that they need not be duplicated when threading. Thus they can not have visible side effects such as PHI nodes.
Skip over DEBUG statements at the start of the block.
If the block has no statements, but does have a single successor, then it's just a forwarding block and we can thread through it trivially. However, note that just threading through empty blocks with single successors is not inherently profitable. For the jump thread to be profitable, we must avoid a runtime conditional. By taking the return value from the recursive call, we get the desired effect of returning TRUE when we found a profitable jump threading opportunity and FALSE otherwise. This is particularly important when this routine is called after processing a joiner block. Returning TRUE too aggressively in that case results in pointless duplication of the joiner block.
We have a block with no statements, but multiple successors?
The only real statements this block can have are a control flow altering statement. Anything else stops the thread.
Extract and simplify the condition.
If the condition can be statically computed and we have not already visited the destination edge, then add the taken edge to our thread path.
Referenced by thread_through_normal_block().
|
static |
We are exiting E->src, see if E->dest ends with a conditional jump which has a known value when reached via E.
E->dest can have arbitrary side effects which, if threading is successful, will be maintained.
Special care is necessary if E is a back edge in the CFG as we may have already recorded equivalences for E->dest into our various tables, including the result of the conditional at the end of E->dest. Threading opportunities are severely limited in that case to avoid short-circuiting the loop incorrectly.
DUMMY_COND is a shared cond_expr used by condition simplification as scratch, to avoid allocating memory.
HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of the simplified condition with left-hand sides of ASSERT_EXPRs they are used in.
STACK is used to undo temporary equivalences created during the walk of E->dest.
SIMPLIFY is a pass-specific function used to simplify statements.
Our caller is responsible for restoring the state of the expression and const_and_copies stacks.
If E is a backedge, then we want to verify that the COND_EXPR, SWITCH_EXPR or GOTO_EXPR at the end of e->dest is not affected by any statements in e->dest. If it is affected, then it is not safe to thread this edge.
PHIs create temporary equivalences.
Now walk each statement recording any context sensitive temporary equivalences we can detect.
If we stopped at a COND_EXPR or SWITCH_EXPR, see if we know which arm will be taken.
Extract and simplify the condition.
DEST could be NULL for a computed jump to an absolute address.
See if we can thread through DEST as well, this helps capture secondary effects of threading without having to re-run DOM or VRP.
We don't want to thread back to a block we have already visited. This may be overly conservative.
References bitmap_set_bit, edge_def::dest, basic_block_def::index, and thread_around_empty_blocks().
void threadedge_finalize_values | ( | void | ) |
Free the per SSA_NAME value-handle array.
References single_pred_p(), and single_succ_p().
void threadedge_initialize_values | ( | void | ) |
Initialize the per SSA_NAME value-handles array. Returns it.
|
static |
SSA Jump Threading Copyright (C) 2005-2013 Free Software Foundation, Inc. Contributed by Jeff Law law@r edha t.com
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/. To avoid code explosion due to jump threading, we limit the number of statements we are going to copy. This variable holds the number of statements currently seen that we'll have to copy as part of the jump threading process.