GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "gimple.h"
#include "target.h"
#include "ipa-prop.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 "tree-dfa.h"
#include "tree-pass.h"
#include "flags.h"
#include "diagnostic.h"
#include "tree-dump.h"
#include "tree-inline.h"
#include "params.h"
#include "gimple-pretty-print.h"
#include "ipa-inline.h"
#include "cfgloop.h"
Data Structures | |
struct | bb_info |
struct | split_point |
struct | stack_entry |
Functions | |
static tree | find_retval (basic_block return_bb) |
static bool | test_nonssa_use () |
static void | dump_split_point () |
static bool | verify_non_ssa_vars (struct split_point *current, bitmap non_ssa_vars, basic_block return_bb) |
static void | check_forbidden_calls () |
static bool | dominated_by_forbidden () |
static void | consider_split (struct split_point *current, bitmap non_ssa_vars, basic_block return_bb) |
static basic_block | find_return_bb () |
static tree | find_retval () |
static bool | mark_nonssa_use () |
static bool | visit_bb (basic_block bb, basic_block return_bb, bitmap set_ssa_names, bitmap used_ssa_names, bitmap non_ssa_vars) |
static void | find_split_points () |
static void | split_function () |
static unsigned int | execute_split_functions () |
static bool | gate_split_functions () |
gimple_opt_pass * | make_pass_split_functions () |
static bool | gate_feedback_split_functions () |
static unsigned int | execute_feedback_split_functions () |
gimple_opt_pass * | make_pass_feedback_split_functions () |
Variables | |
static vec< bb_info > | bb_info_vec |
struct split_point | best_split_point |
static bitmap | forbidden_dominators |
|
static |
If STMT is a call, check the callee against a list of forbidden predicate functions. If a match is found, look for uses of the call result in condition statements that compare against zero. For each such use, find the block targeted by the condition statement for the nonzero result, and set the bit for this block in the forbidden dominators bitmap. The purpose of this is to avoid selecting a split point where we are likely to lose the chance to optimize away an unused function call.
At the moment, __builtin_constant_p is the only forbidden predicate function call (see PR49642).
Assuming canonical form for GIMPLE_COND here, with constant in second position.
We're only interested in comparisons that distinguish unambiguously from zero.
References bitmap_set_bit, edge_def::dest, extract_true_false_edges_from_block(), gimple_bb(), gimple_cond_code(), gimple_cond_rhs(), basic_block_def::index, integer_zerop(), and USE_STMT.
|
static |
We found an split_point CURRENT. NON_SSA_VARS is bitmap of all non ssa variables used and RETURN_BB is return basic block. See if we can split function here.
Do not split when we would end up calling function anyway.
When profile is guessed, we can not expect it to give us realistic estimate on likelyness of function taking the complex path. As a special case, when tail of the function is a loop, enable splitting since inlining code skipping the loop is likely noticeable win.
Verify that PHI args on entry are either virtual or all their operands incoming from header are the same.
See what argument we will pass to the split function and compute call overhead.
FIXME: we currently can pass only SSA function parameters to the split arguments. Once parm_adjustment infrastructure is supported by cloning, we can pass more than that.
When there are non-ssa vars used in the split region, see if they are used in the header region. If so, reject the split. FIXME: we can use nested function support to access both.
If the split point is dominated by a forbidden block, reject the split.
See if retval used by return bb is computed by header or split part. When it is computed by split part, we need to produce return statement in the split part and add code to header to pass it around. This is bit tricky to test: 1) When there is no return_bb or no return value, we always pass value around. 2) Invariants are always computed by caller. 3) For SSA we need to look if defining statement is in header or split part 4) For non-SSA we need to look where the var is computed.
Special case is value returned by reference we record as if it was non-ssa set to result_decl.
split_function fixes up at most one PHI non-virtual PHI node in return_bb, for the return value. If there are other PHIs, give up.
At the moment chose split point with lowest frequency and that leaves out smallest size of header. In future we might re-consider this heuristics.
|
static |
If BB is dominated by any block in the forbidden dominators set, return TRUE; else FALSE.
References dump_file, dump_flags, dump_split_point(), split_point::entry_bb, edge_def::flags, FOR_EACH_EDGE, basic_block_def::preds, and TDF_DETAILS.
|
static |
Dump split point CURRENT.
References BITMAP_ALLOC, bitmap_bit_p, bitmap_set_bit, split_point::entry_bb, ENTRY_BLOCK_PTR, FOR_EACH_EDGE, basic_block_def::index, NULL, basic_block_def::preds, split_point::split_bbs, edge_def::src, vNULL, and worklist.
Referenced by dominated_by_forbidden().
|
static |
Execute function splitting pass.
|
static |
Execute function splitting pass.
This can be relaxed; function might become inlinable after splitting away the uninlinable part.
This can be relaxed; most of versioning tests actually prevents a duplication.
FIXME: we could support this.
See if it makes sense to try to split. It makes sense to split if we inline, that is if we have direct calls to handle or direct calls are possibly going to appear as result of indirect inlining or LTO. Also handle -fprofile-generate as LTO to allow non-LTO training for LTO -fprofile-use build. Note that we are not completely conservative about disqualifying functions called once. It is possible that the caller is called more then once and then inlining would still benefit.
Local functions called once will be completely inlined most of time.
FIXME: We can actually split if splitting reduces call overhead.
We enforce splitting after loop headers when profile info is not available.
Initialize bitmap to track forbidden calls.
Compute local info about basic blocks and determine function size/time.
|
static |
Return basic block containing RETURN statement. We allow basic blocks of the form: <retval> = tmp_var; return <retval> but return_bb can not be more complex than this. If nothing is found, return EXIT_BLOCK_PTR.
When there are multiple RETURN statement, chose one with return value, since that one is more likely shared by multiple code paths.
Return BB is special, because for function splitting it is the only basic block that is duplicated in between header and split part of the function.
TODO: We might support multiple return blocks.
|
static |
|
static |
Given return basic block RETURN_BB, see where return value is really stored.
|
static |
Find all articulations and call consider_split on them. OVERALL_TIME and OVERALL_SIZE is time and size of the function.
We perform basic algorithm for finding an articulation in a graph created from CFG by considering it to be an unoriented graph.
The articulation is discovered via DFS walk. We collect earliest basic block on stack that is reachable via backward edge. Articulation is any basic block such that there is no backward edge bypassing it. To reduce stack usage we maintain heap allocated stack in STACK vector. AUX pointer of BB is set to index it appears in the stack or -1 once it is visited and popped off the stack.
The algorithm finds articulation after visiting the whole component reachable by it. This makes it convenient to collect information about the component used by consider_split.
We are walking an acyclic graph, so edge_num counts succ and pred edges together. However when considering articulation, we want to have processed everything reachable from articulation but nothing that reaches into it.
Do actual DFS walk.
New BB to visit, push it to the stack.
Back edge found, record the earliest point.
We are done with examining the edges. Pop off the value from stack and merge stuff we accumulate during the walk.
|
static |
Gate feedback driven function splitting pass. We don't need to split when profiling at all, we are producing lousy code anyway.
|
static |
Gate function splitting pass. When doing profile feedback, we want to execute the pass after profiling is read. So disable one in early optimization.
gimple_opt_pass* make_pass_feedback_split_functions | ( | ) |
gimple_opt_pass* make_pass_split_functions | ( | ) |
|
static |
Callback for walk_stmt_load_store_addr_ops. If T is non-SSA automatic variable, mark it as used in bitmap passed via DATA. Return true when access to T prevents splitting the function.
At present we can't pass non-SSA arguments to split function. FIXME: this can be relaxed by passing references to arguments.
For DECL_BY_REFERENCE, the return value is actually a pointer. We want to pretend that the value pointed to is actual result decl.
|
static |
Split function at SPLIT_POINT.
Collect the parameters of new function and args_to_skip bitmap.
This parm might not have been used up to now, but is going to be used, hence register it.
See if the split function will return.
Add return block to what will become the split function. We do not return; no return block is needed.
We have no return block, so nothing is needed.
When we do not want to return value, we need to construct new return block with empty return statement. FIXME: Once we are able to change return type, we should change function to return void instead of just outputting function with undefined return value. For structures this affects quality of codegen.
When we pass around the value, use existing return block.
If RETURN_BB has virtual operand PHIs, they must be removed and the virtual operand marked for renaming as we change the CFG in a way that tree-inline is not able to compensate for. Note this can happen whether or not we have a return value. If we have a return value, then RETURN_BB may have PHIs for real operands too.
In reality we have to rename the reaching definition of the virtual operand at return_bb as we will eventually release it when we remove the code region we outlined. So we have to rename all immediate virtual uses of that region if we didn't see a PHI definition yet.
??? In real reality we want to set the reaching vdef of the entry of the SESE region as the vuse of the call and the reaching vdef of the exit of the SESE region as the vdef of the call.
Now create the actual clone.
For usual cloning it is enough to clear builtin only when signature changes. For partial inlining we however can not expect the part of builtin implementation to have same semantic as the whole.
If the original function is declared inline, there is no point in issuing a warning for the non-inlinable part.
Create the basic block we place call into. It is the entry basic block split after last label.
Produce the call statement.
For optimized away parameters, add on the caller side before the call DEBUG D#X => parm_Y(D) stmts and associate D#X with parm in decl_debug_args_lookup vector to say for debug info that if parameter parm had been passed, it would have value parm_Y(D).
This needs to be done even without MAY_HAVE_DEBUG_STMTS, otherwise if it didn't exist before, we'd end up with different SSA_NAME_VERSIONs between -g and -g0.
And on the callee side, add DEBUG D#Y s=> parm DEBUG var => D#Y stmts to the first bb where var is a VAR_DECL created for the optimized away parameter in DECL_INITIAL block. This hints in the debug info that var (whole DECL_ORIGIN is the parm PARM_DECL) is optimized away, but could be looked up at the call site as value of D#X there.
We avoid address being taken on any variable used by split part, so return slot optimization is always possible. Moreover this is required to make DECL_BY_REFERENCE work.
Update return value. This is bit tricky. When we do not return, do nothing. When we return we might need to update return_bb or produce a new return statement.
If there is return basic block, see what value we need to store return value into and put call just before it.
See if we need new SSA_NAME for the result. When DECL_BY_REFERENCE is true, retval is actually pointer to return value and it is constant in whole function.
See if there is PHI defining return value.
When there is PHI, just update its value.
Otherwise update the return BB itself. find_return_bb allows at most one assignment to return value, so update first statement.
We don't use return block (there is either no return in function or multiple of them). So create new basic block with return statement.
We use temporary register to hold value when aggregate_value_p is false. Similarly for DECL_BY_REFERENCE we must avoid extra copy.
When returning by reference, there is only one SSA name assigned to RESULT_DECL (that is pointer to return value). Look it up or create new one if it is missing.
Otherwise produce new SSA name for return value.
References add_bb_to_loop(), bitmap_bit_p, bitmap_set_bit, edge_def::count, basic_block_def::count, create_basic_block(), current_loops, EDGE_FREQUENCY, FOR_EACH_EDGE, basic_block_def::frequency, gimple_build_return(), gsi_insert_after(), GSI_NEW_STMT, gsi_start_bb(), basic_block_def::index, make_edge(), edge_def::probability, redirect_edge_and_branch(), REG_BR_PROB_BASE, and edge_def::src.
|
static |
Callback for walk_stmt_load_store_addr_ops. If T is non-SSA automatic variable, check it if it is present in bitmap passed via DATA.
For DECL_BY_REFERENCE, the return value is actually a pointer. We want to pretend that the value pointed to is actual result decl.
|
static |
Look for all BBs in header that might lead to the split part and verify that they are not defining any non-SSA var used by the split part. Parameters are the same as for consider_split.
|
static |
Compute local properties of basic block BB we collect when looking for split points. We look for ssa defs and store them in SET_SSA_NAMES, for ssa uses and store them in USED_SSA_NAMES and for any non-SSA automatic vars stored in NON_SSA_VARS.
When BB has edge to RETURN_BB, collect uses in RETURN_BB too.
Return false when BB contains something that prevents it from being put into split function.
FIXME: We can split regions containing EH. We can not however split RESX, EH_DISPATCH and EH_POINTER referring to same region into different partitions. This would require tracking of EH regions and checking in consider_split_point if they are not used elsewhere.
Check builtins that prevent splitting.
FIXME: once we will allow passing non-parm values to split part, we need to be sure to handle correct builtin_stack_save and builtin_stack_restore. At the moment we are safe; there is no way to store builtin_stack_save result in non-SSA variable since all calls to those are compiler generated.
Record also uses coming from PHI operand in return BB.
struct split_point best_split_point |
Best split point found.
|
static |
Set of basic blocks that are not allowed to dominate a split point.