GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "rtl.h"
#include "tm_p.h"
#include "basic-block.h"
#include "function.h"
#include "expr.h"
#include "langhooks.h"
#include "bitmap.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "cgraph.h"
#include "tree-cfg.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-ssanames.h"
#include "tree-dfa.h"
#include "tree-ssa.h"
#include "tree-pass.h"
#include "except.h"
#include "flags.h"
#include "diagnostic.h"
#include "gimple-pretty-print.h"
#include "toplev.h"
#include "debug.h"
#include "params.h"
#include "tree-inline.h"
#include "value-prof.h"
#include "target.h"
#include "tree-ssa-live.h"
#include "tree-outof-ssa.h"
#include "sbitmap.h"
#include "cfgloop.h"
#include "regs.h"
#include "insn-attr.h"
#include "asan.h"
#include "tree-ssa-address.h"
Data Structures | |
struct | stack_var |
struct | stack_vars_data |
Macros | |
#define | STACK_ALIGNMENT_NEEDED 1 |
#define | SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x) |
#define | EOC ((size_t)-1) |
#define | SPCT_HAS_LARGE_CHAR_ARRAY 1 |
#define | SPCT_HAS_SMALL_CHAR_ARRAY 2 |
#define | SPCT_HAS_ARRAY 4 |
#define | SPCT_HAS_AGGREGATE 8 |
Enumerations | |
enum | { SPCT_FLAG_DEFAULT = 1, SPCT_FLAG_ALL = 2, SPCT_FLAG_STRONG = 3 } |
Variables | |
struct ssaexpand | SA |
gimple | currently_expanding_gimple_stmt |
static struct stack_var * | stack_vars |
static size_t | stack_vars_alloc |
static size_t | stack_vars_num |
static struct pointer_map_t * | decl_to_stack_part |
static bitmap_obstack | stack_var_bitmap_obstack |
static size_t * | stack_vars_sorted |
static int | frame_phase |
static bool | has_protected_decls |
static bool | has_short_buffer |
static struct pointer_map_t * | lab_rtx_for_bb |
#define EOC ((size_t)-1) |
Referenced by expand_stack_vars(), and partition_stack_vars().
#define SPCT_HAS_AGGREGATE 8 |
Referenced by expand_used_vars_for_block().
#define SPCT_HAS_ARRAY 4 |
Referenced by expand_used_vars_for_block().
#define SPCT_HAS_LARGE_CHAR_ARRAY 1 |
Examine TYPE and determine a bit mask of the following features.
Referenced by expand_used_vars_for_block().
#define SPCT_HAS_SMALL_CHAR_ARRAY 2 |
#define SSAVAR | ( | x | ) | (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x) |
#define STACK_ALIGNMENT_NEEDED 1 |
|
static |
Take into account all sizes of partitions and reset DECL_RTLs.
Skip variables that aren't partition representatives, for now.
|
static |
If the points-to solution *PI points to variables that are in a partition together with other variables add all partition members to the pointed-to variables bitmap.
The pointed-to vars bitmap is shared, it is enough to visit it once.
By using a temporary bitmap to store all members of the partitions we have to add we make sure to visit each of the partitions only once.
References cfun, and pointer_map_create().
Referenced by update_alias_info_with_stack_vars().
|
static |
Generate stack partition conflicts between all partitions that are simultaneously live.
We approximate the live range of a stack variable by taking the first mention of its name as starting point(s), and by the end-of-scope death clobber added by gimplify as ending point(s) of the range. This overapproximates in the case we for instance moved an address-taken operation upward, without also moving a dereference to it upwards. But it's conservatively correct as a variable never can hold values before its name is mentioned at least once.
We then do a mostly classical bitmap liveness algorithm.
References stack_var::alignb, BITS_PER_UNIT, stack_var::decl, HOST_WIDE_INT, MAX_SUPPORTED_STACK_ALIGNMENT, stack_var::size, SSA_NAME_VERSION, and TREE_CODE.
|
static |
Helper routine for add_scope_conflicts, calculating the active partitions at the end of BB, leaving the result in WORK. We're called to generate conflicts when FOR_CONFLICT is true, otherwise we're just tracking liveness.
Nested function lowering might introduce LHSs that are COMPONENT_REFs.
If this is the first real instruction in this BB we need to add conflicts for everything live at this point now. Unlike classical liveness for named objects we can't rely on seeing a def/use of the names we're interested in. There might merely be indirect loads/stores. We'd not add any conflicts for such partitions.
References BITMAP_ALLOC, bitmap_ior_into(), stack_var::conflicts, EXECUTE_IF_SET_IN_BITMAP, visit, and visit_conflict().
|
static |
Ensure that variables in different stack protection phases conflict so that they are not merged and share the same stack slot.
|
static |
Accumulate DECL into STACK_VARS.
Ensure that all variables have size, so that &a != &b for any two variables that are simultaneously live.
An alignment of zero can mightily confuse us later.
All variables are initially in their own partition.
All variables initially conflict with no other.
Ensure that this decl doesn't get put onto the list twice.
|
static |
Make the decls associated with luid's X and Y conflict.
References bitmap_set_bit, DECL_P, DECL_RTL_IF_SET, get_base_address(), pc_rtx, and pointer_map_contains().
Referenced by stack_protect_classify_type().
|
static |
Compute the byte alignment to use for DECL. Ignore alignment we can't do with expected alignment of the stack boundary.
References frame_phase.
|
static |
Allocate SIZE bytes at byte alignment ALIGN from the stack frame. Return the frame offset.
Referenced by expand_stack_vars().
|
static |
And helper function that checks for asan phase (with stack protector it is phase 3). This is used as callback for expand_stack_vars. Returns true if any of the vars in the partition need to be protected.
References DECL_CHAIN, field_type(), record_or_union_type_has_array_p(), RECORD_OR_UNION_TYPE_P, TREE_CODE, TREE_TYPE, and TYPE_FIELDS.
|
static |
Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity. Allow 4 levels of rtl nesting for most rtl codes, and if we see anything deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN.
Create DEBUG_EXPR (and DEBUG_EXPR_DECL).
Emit a debug bind insn before INSN.
References DECL_ARTIFICIAL, DECL_MODE, DECL_P, emit_debug_insn(), FOR_EACH_IMM_USE_FAST, FOR_EACH_IMM_USE_ON_STMT, FOR_EACH_IMM_USE_STMT, gimple_assign_rhs_to_tree(), gimple_debug_bind_p(), gimple_location(), make_node, set_curr_insn_location(), SET_USE, TREE_TYPE, TYPE_MODE, update_stmt(), USE_STMT, and VAR_INIT_STATUS_INITIALIZED.
|
static |
Return the difference between the ceil and the truncated result of a signed division by OP1 with remainder MOD.
(mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0)
References NULL_RTX, separate_ops::op2, tcc_expression, TREE_CODE, TREE_CODE_CLASS, TREE_TYPE, TYPE_MODE, and TYPE_UNSIGNED.
|
static |
Return the difference between the ceil and the truncated result of an unsigned division by OP1 with remainder MOD.
(mod != 0 ? 1 : 0)
|
static |
A subroutine of expand_used_vars. Walk down through the BLOCK tree and clear TREE_USED on all local variables.
if (!TREE_STATIC (t) && !DECL_EXTERNAL (t))
References stack_protect_decl_phase().
|
static |
Create a block containing landing pads and similar stuff.
Make sure the locus is set to the end of the function, so that epilogue line numbers and warnings are set properly.
Generate rtl for function exit.
While emitting the function end we could move end of the last basic block.
References targetm.
|
static |
Create a basic block for initialization code.
Multiple entry points not supported yet.
When entry edge points to first basic block, we don't need jump, otherwise we have to jump into proper target.
|
static |
Convert X to MODE, that must be Pmode or ptr_mode, without emitting any rtl.
References gen_rtx_MEM(), NULL_RTX, separate_ops::op0, set_mem_attributes(), TREE_STRING_LENGTH, and TREE_STRING_POINTER.
|
static |
Create a decl for the guard at the top of the stack frame.
|
static |
A subroutine of expand_one_var. VAR is a variable that will be allocated to the local stack frame. Return true if we wish to add VAR to STACK_VARS so that it will be coalesced with other variables. Return false to allocate VAR immediately.
This function is used to reduce the number of variables considered for coalescing, which reduces the size of the quadratic problem.
If stack protection is enabled, <em>all</em> stack variables must be deferred, so that we can re-order the strings to the top of the frame. Similarly for Address Sanitizer.
We handle "large" alignment via dynamic allocation. We want to handle this extra complication in only one place, so defer them.
Variables in the outermost scope automatically conflict with every other variable. The only reason to want to defer them at all is that, after sorting, we can more efficiently pack small variables in the stack frame. Continue to defer at -O2.
Without optimization, *most* variables are allocated from the stack, which makes the quadratic problem large exactly when we want compilation to proceed as quickly as possible. On the other hand, we don't want the function's stack frame size to get completely out of hand. So we avoid adding scalars and "small" aggregates to the list at all.
|
static |
RTL expansion is not able to compile array references with variable offsets for arrays stored in single register. Discover such expressions and mark variables as addressable to avoid this scenario.
|
static |
Helper function for discover_nonconstant_array_refs. Look for ARRAY_REF nodes with non-constant indexes and mark them addressable.
References MEM_P, ssaexpand::partition_to_pseudo, SA, and set_mem_expr().
|
static |
A debugging aid for expand_used_vars. Dump the generated partitions.
Skip variables that aren't partition representatives, for now.
HOST_WIDE_INT estimated_stack_frame_size | ( | ) |
Make a fair guess for the size of the stack frame of the function in NODE. This doesn't have to be exact, the result is only used in the inline heuristics. So we don't want to run the full stack var packing algorithm (which is quadratic in the number of stack vars). Instead, we calculate the total size of all stack vars. This turns out to be a pretty fair estimate – packing of stack vars doesn't happen very often.
Fake sorting the stack vars for account_stack_vars ().
|
static |
A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL statement STMT.
If this is not a builtin function, the function type through which the call is made may be different from the type of the function.
TER addresses into arguments of builtin functions so we have a chance to infer more correct alignment information. See PR39954.
Ensure RTL is created for debug args.
|
static |
Return an RTX equivalent to the value of the tree expression EXP.
Fall through.
Fall through.
Fall through...
This decl was probably optimized away.
If op0 is not BLKmode, but BLKmode is, adjust_mode below would ICE. While it is likely a FE bug, try to be robust here. See PR43166.
Fall through.
FALLTHROUGH
(mem (debug_implicit_ptr)) might confuse aliasing. Instead just use get_inner_reference.
Don't use offset_address here, we don't need a recognizable address, and we don't want to generate code.
Bitfield.
This condition may hold if we're expanding the address right past the end of an array that turned out not to be addressable (i.e., the address was only computed in debug stmts). The gen_subreg below would rightfully crash, and the address doesn't really exist, so just drop it.
For the rare target where pointers are not the same size as size_t, we need to check for mis-matched modes and correct the addend.
If OP0 is a partial mode, then we must truncate, even if it has the same bitsize as OP1 as GCC's representation of partial modes is opaque.
We always sign-extend, regardless of the signedness of the operand, because the operand is always unsigned here even if the original C expression is signed.
Fall through.
??? Maybe handle some builtins?
If this is a reference to an incoming value of parameter that is never used in the code or where the incoming value is never used in the code, use PARM_DECL's DECL_RTL if set.
Vector stuff. For most of the codes we don't have rtl codes.
Misc codes.
??? Similar to the above.
|
static |
Expand the _LOCs in debug insns. We run this after expanding all regular insns, so that any variables referenced in the function will have their DECL_RTLs set.
New alias sets while setting up memory attributes cause -fcompare-debug failures, even though it doesn't bring about any codegen changes.
|
static |
Return an RTX equivalent to the value of the parameter DECL.
References CONSTANT_P, FLOAT_MODE_P, gcc_assert, GET_MODE, GET_MODE_BITSIZE, GET_MODE_PRECISION, separate_ops::op0, simplify_gen_subreg(), simplify_gen_unary(), subreg_lowpart_offset(), tcc_unary, TREE_CODE, TREE_CODE_CLASS, TREE_OPERAND, TREE_TYPE, TYPE_MODE, and TYPE_UNSIGNED.
|
static |
Return an RTX equivalent to the source bind value of the tree expression EXP.
See if this isn't an argument that has been completely optimized out.
|
static |
Expand basic block BB from GIMPLE trees to RTL.
Note that since we are now transitioning from GIMPLE to RTL, we cannot use the gsi_*_bb() routines because they expect the basic block to be in GIMPLE, instead of RTL. Therefore, we need to access the BB sequence directly.
Remove the RETURN_EXPR if we may fall though to the exit instead.
Java emits line number notes in the top of labels. ??? Make this go away once line number notes are obsoleted.
If this statement is a non-debug one, and we generate debug insns, then this one might be the last real use of a TERed SSA_NAME, but where there are still some debug uses further down. Expanding the current SSA name in such further debug uses by their RHS might lead to wrong debug info, as coalescing might make the operands of such RHS be placed into the same pseudo as something else. Like so: a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead use(a_1); a_2 = ... #DEBUG ... => a_1 As a_0 and a_2 don't overlap in lifetime, assume they are coalesced. If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use, the write to a_2 would actually have clobbered the place which formerly held a_0. So, instead of that, we recognize the situation, and generate debug temporaries at the last real use of TERed SSA names: a_1 = a_0 + 1; #DEBUG #D1 => a_1 use(a_1); a_2 = ... #DEBUG ... => #D1
Look for SSA names that have their last use here (TERed names always have only one real use).
OP is a TERed SSA name, with DEF it's defining statement, and where OP is used in further debug instructions. Generate a debug temporary, and replace all uses of OP in debug insns with that temporary.
Expand this statement, then evaluate the resulting RTL and fixup the CFG accordingly.
We can't dump the insn with a TREE where an RTX is expected.
In order not to generate too many debug temporaries, we delink all uses of debug statements we already expanded. Therefore debug statements between definition and real use of TERed SSA names will continue to use the SSA name, and not be replaced with debug temps.
We can't dump the insn with a TREE where an RTX is expected.
Ignore this stmt if it is in the list of replaceable expressions.
Expand implicit goto and convert goto_locus.
Expanded RTL can create a jump in the last instruction of block. This later might be assumed to be a jump to successor and break edge insertion. We need to insert dummy move to prevent this. PR41440.
Find the block tail. The last insn in the block is the insn before a barrier and/or table jump insn.
|
static |
A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND. Returns a new basic block if we've terminated the current basic block and created a new one.
We're sometimes presented with such code: D.123_1 = x < y; if (D.123_1 != 0) ... This would expand to two comparisons which then later might be cleaned up by combine. But some pattern matchers like if-conversion work better when there's only one compare, so make up for this here as special exception if TER would have made the same change.
If jumps are cheap turn some more codes into jumpy sequences.
These flags have no purpose in RTL land.
We can either have a pure conditional jump with one fallthru edge or two-way jump that needs to be decomposed into two basic blocks.
|
static |
Expand one gimple statement STMT and return the last RTL instruction before any of the newly generated ones.
In addition to generating the necessary RTL instructions this also sets REG_EH_REGION notes if necessary and sets the current source location for diagnostics.
We need to save and restore the current source location so that errors discovered during expansion are emitted with the right location. But it would be better if the diagnostic routines used the source location embedded in the tree nodes rather than globals.
Free any temporaries used to evaluate this statement.
Mark all insns that may trap.
If we want exceptions for non-call insns, any may_trap_p instruction may throw.
References const0_rtx, and const1_rtx.
|
static |
A subroutine of expand_gimple_stmt, expanding one gimple statement STMT that doesn't require special handling for outgoing edges. That is no tailcalls and no GIMPLE_COND.
If we are not returning the current function's RESULT_DECL, build an assignment to it.
I believe that a function's RESULT_DECL is unique.
??? We'd like to use simply expand_assignment here, but this fails if the value is of BLKmode but the return decl is a register. expand_return has special handling for this combination, which eventually should move to common code. See comments there. Until then, let's build a modify expression :-/
Tree expand used to fiddle with |= and &= of two bitfield COMPONENT_REFs here. This can't happen with gimple, the LHS of binary assigns must be a gimple reg.
This is a clobber to mark the going out of scope for this LHS.
Fallthru
Fallthru
If we want to use a nontemporal store, force the value to register first. If we store into a promoted register, don't directly expand to target.
If TEMP is a VOIDmode constant, use convert_modes to make sure that we properly convert it.
|
static |
A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL that has CALL_EXPR_TAILCALL set. Returns non-null if we actually generated a tail call (something that might be denied by the ABI rules governing the call; see calls.c).
Sets CAN_FALLTHRU if we generated a conditional tail call, and can still reach the rest of BB. The case here is __builtin_sqrt, where the NaN result goes through the external function (with a tailcall) and the normal result happens via a sqrt instruction.
??? Wouldn't it be better to just reset any pending stack adjust? Any instructions emitted here are about to be deleted.
Remove any non-eh, non-abnormal edges that don't go to exit.
??? I.e. the fallthrough edge. HOWEVER! If there were to be EH or abnormal edges, we shouldn't have created a tail call in the first place. So it seems to me we should just be removing all edges here, or redirecting the existing fallthru edge to the exit block.
This is somewhat ugly: the call_expr expander often emits instructions after the sibcall (to perform the function return). These confuse the find_many_sub_basic_blocks code, so we need to get rid of these.
For instance an sqrt builtin expander expands if with sibcall in the then and label for `else`.
References targetm.
|
static |
A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that has some associated error, e.g. its type is error-mark. We just need to pick something that won't crash the rest of the compiler.
|
static |
A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that will reside in a hard register.
References BITS_PER_UNIT.
|
static |
A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that will reside in a pseudo register.
Note if the object is a user variable.
|
static |
A subroutine of expand_one_var. Called to immediately assign rtl to a variable to be allocated in the stack frame.
We handle highly aligned variables in expand_stack_vars.
|
static |
Assign rtl to DECL at BASE + OFFSET.
If this fails, we've overflowed the stack frame. Error nicely?
Set alignment we actually gave this decl if it isn't an SSA name. If it is we generate stack slots only accidentally so it isn't as important, we'll simply use the alignment that is already set.
One would think that we could assert that we're not decreasing alignment here, but (at least) the i386 port does exactly this via the MINIMUM_ALIGNMENT hook.
|
static |
A subroutine of expand_used_vars. Expand one variable according to its flavor. Variables to be placed on the stack are not actually expanded yet, merely recorded. When REALLY_EXPAND is false, only add stack values to be allocated. Return stack usage this variable is supposed to take.
Because we don't know if VAR will be in register or on stack, we conservatively assume it will be on stack even if VAR is eventually put into register after RA pass. For non-automatic variables, which won't be on stack, we collect alignment of type and ignore user specified alignment.
Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set or variables which were assigned a stack slot already by expand_one_stack_var_at - in the latter case DECL_ALIGN has been changed from the offset chosen to it.
If the variable alignment is very large we'll dynamicaly allocate it, which means that in-frame portion is just a pointer.
stack_alignment_estimated shouldn't change after stack realign decision made
stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted. So here we only make sure stack_alignment_needed >= align.
Reject variables which cover more than half of the address-space.
Referenced by fini_vars_expansion().
|
static |
This function sets crtl->args.internal_arg_pointer to a virtual register if DRAP is needed. Local register allocator will replace virtual_incoming_args_rtx with the virtual register.
Call update_stack_boundary here again to update incoming stack boundary. It may set incoming stack alignment to a different value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may use the minimum incoming stack alignment to check if it is OK to perform sibcall optimization since sibcall optimization will only align the outgoing stack to incoming stack boundary.
The incoming stack frame has to be aligned at least at parm_stack_boundary.
Update crtl->stack_alignment_estimated and use it later to align stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call exceptions since callgraph doesn't collect incoming stack alignment in this case.
Target has to redefine TARGET_GET_DRAP_RTX to support stack alignment.
stack_realign_drap and drap_rtx must match.
Do nothing if NULL is returned, which means DRAP is not needed.
Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is needed.
|
static |
A subroutine of expand_used_vars. Give each partition representative a unique location within the stack frame. Update each partition member with that location.
Determine if there are any variables requiring "large" alignment. Since these are dynamically allocated, we only process these if no predicate involved.
Find the total size of these variables.
Stop when we get to the first decl with "small" alignment.
Skip variables that aren't partition representatives.
Skip variables that have already had rtl assigned. See also add_stack_var where we perpetrate this pc_rtx hack.
If there were any, allocate space.
Skip variables that aren't partition representatives, for now.
Skip variables that have already had rtl assigned. See also add_stack_var where we perpetrate this pc_rtx hack.
Check the predicate to see whether this variable should be allocated in this pass.
Find best representative of the partition. Prefer those with DECL_NAME, even better satisfying asan_protect_stack_decl predicate.
Large alignment is only processed in the last pass.
Create rtl for each variable based on their location within the partition.
References alloc_stack_frame_space(), stack_vars_data::asan_decl_vec, asan_protect_stack_decl(), ASAN_RED_ZONE_SIZE, stack_vars_data::asan_vec, crtl, stack_var::decl, DECL_NAME, DECL_P, EOC, frame_offset, HOST_WIDE_INT, MAX, stack_var::next, NULL_TREE, SANITIZE_ADDRESS, and virtual_stack_vars_rtx.
|
static |
Expand all variables used in the function.
Compute the phase of the stack frame for this function.
Set TREE_USED on all variables in the local_decls.
Clear TREE_USED on all variables associated with a block scope.
Assign decls to each SSA name partition, share decls for partitions we could have coalesced (those with the same type).
This is a PARM_DECL or RESULT_DECL. For those partitions that contain the default def (representing the parm or result itself) we don't do anything here. But those which don't contain the default def (representing a temporary based on the parm/result) we need to allocate space just like for normal VAR_DECLs.
Examine local referenced variables that have their addresses taken, contain an array, or are arrays.
At this point all variables on the local_decls with TREE_USED set are not associated with any block scope. Lay them out.
Expanded above already.
We didn't set a block for static or extern because it's hard to tell the difference between a global variable (re)declared in a local scope, and one that's really declared there to begin with. And it doesn't really matter much, since we're not giving them stack space. Expand them now.
If the variable is not associated with any block, then it was created by the optimizers, and could be live anywhere in the function.
Finally, mark all variables on the list as used. We'll use this in a moment when we expand those associated with scopes.
Keep artificial non-ignored vars in cfun->local_decls chain until instantiate_decls.
If rtl isn't set yet, which can happen e.g. with -fstack-protector, retry before returning from this function.
We duplicated some of the decls in CFUN->LOCAL_DECLS. +—————–+—————–+ | ...processed... | ...duplicates...| +—————–+—————–+ ^ +– LEN points here. We just want the duplicates, as those are the artificial non-ignored vars that we want to keep until instantiate_decls. Move them down and truncate the array.
At this point, all variables within the block tree with TREE_USED set are actually used by the optimized function. Lay them out.
If stack protection is enabled, we don't share space between vulnerable data and non-vulnerable data.
Now that we have collected all stack variables, and have computed a minimal interference graph, attempt to save some stack space.
Assign rtl to each variable based on these partitions.
Reorder decls to be protected by iterating over the variables array multiple times, and allocating out of each phase in turn.
??? We could probably integrate this into the qsort we did earlier, such that we naturally see these variables first, and thus naturally allocate things in the right order.
Phase 1 contains only character arrays.
Phase 2 contains other kinds of arrays.
Phase 3, any partitions that need asan protection in addition to phase 1 and 2.
If there were any artificial non-ignored vars without rtl found earlier, see if deferred stack allocation hasn't assigned rtl to them.
Keep artificial non-ignored vars in cfun->local_decls chain until instantiate_decls.
If the target requires that FRAME_OFFSET be aligned, do it.
|
static |
A subroutine of expand_used_vars. Walk down through the BLOCK tree expanding variables. Those variables that can be put into registers are allocated pseudos; those that can't are put on the stack.
TOPLEVEL is true if this is the outermost BLOCK.
Expand all variables at this level.
Expand all variables at containing levels.
References SPCT_HAS_AGGREGATE, SPCT_HAS_ARRAY, and SPCT_HAS_LARGE_CHAR_ARRAY.
|
static |
Free up stack variable graph data.
References expand_one_var(), gcc_assert, ssaexpand::partition_to_pseudo, and SA.
|
static |
Return the difference between the floor and the truncated result of a signed division by OP1 with remainder MOD.
(mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0)
tree gimple_assign_rhs_to_tree | ( | ) |
Return an expression tree corresponding to the RHS of GIMPLE statement STMT.
Avoid modifying this tree in place below.
Referenced by avoid_complex_debug_insns().
|
static |
Translate the intermediate representation contained in the CFG from GIMPLE trees to RTL.
We do conversion per basic block and preserve/update the tree CFG. This implies we have to do some magic as the CFG can simultaneously consist of basic blocks containing RTL and GIMPLE trees. This can confuse the CFG hooks, so be careful to not manipulate CFG during the expansion.
Make sure all values used by the optimization passes have sane defaults.
Some backends want to know that we are expanding to RTL.
Dominators are not kept up-to-date as we may create new basic-blocks.
Eventually, all FEs should explicitly set function_start_locus.
Make sure first insn is a note even if we don't want linenums. This makes sure the first insn will never be deleted. Also, final expects a note to appear there.
Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE.
Resovle the function section. Some targets, like ARM EABI rely on knowledge of the function section at exapnsion time to predict distance of calls.
Expand the variables recorded during gimple lowering.
Honor stack protection warnings.
Set up parameters and prepare for return, for the function.
If we emitted any instructions for setting up the variables, emit them before the FUNCTION_START note.
In expand_function_end we'll insert the alloca save/restore before parm_birth_insn. We've just insertted an alloca call. Adjust the pointer to match.
Now that we also have the parameter RTXs, copy them over to our partitions.
If this decl was marked as living in multiple places, reset this now to NULL.
Some RTL parts really want to look at DECL_RTL(x) when x was a decl marked in REG_ATTR or MEM_ATTR. We could use SET_DECL_RTL here making this available, but that would mean to select one of the potentially many RTLs for one DECL. Instead of doing that we simply reset the MEM_EXPR of the RTL in question, then nobody can get at it and hence nobody can call DECL_RTL on it.
If we have a class containing differently aligned pointers we need to merge those into the corresponding RTL pointer alignment.
We might have generated new SSA names in update_alias_info_with_stack_vars. They will have a NULL defining statements, and won't be part of the partitioning, so ignore those.
Adjust all partition members to get the underlying decl of the representative which we might have created in expand_one_var.
If this function is `main', emit a call to `__main' to run global initializers, etc.
Initialize the stack_protect_guard field. This must happen after the call to __main (if any) so that the external decl is initialized.
Register rtl specific functions for cfg.
Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the remaining edges later.
Free stuff we no longer need after GIMPLE optimizations.
We are no longer in SSA form.
Expansion is used by optimization passes too, set maybe_hot_insn_p conservatively to true until they are all profile aware.
Zap the tree EH table.
We need JUMP_LABEL be set in order to redirect jumps, and hence split edges which edge insertions might do.
Put insns after parm birth, but before NOTE_INSNS_FUNCTION_BEG.
We're done expanding trees to RTL.
Clear EDGE_EXECUTABLE. This flag is never used in the backend.
At the moment not all abnormal edges match the RTL representation. It is safe to remove them here as find_many_sub_basic_blocks will rediscover them. In the future we should get this fixed properly.
Fixup REG_EQUIV notes in the prologue if there are tailcalls in this function.
After initial rtl generation, call back to finish generating exception support code. We need to do this before cleaning up the CFG as the code does not expect dead landing pads.
Remove unreachable blocks, otherwise we cannot compute dominators which are needed for loop state verification. As a side-effect this also compacts blocks. ??? We cannot remove trivially dead insns here as for example the DRAP reg on i?86 is not magically live at this point. gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise.
Initialize pseudos allocated for hard registers.
And finally unshare all RTL.
There's no need to defer outputting this function any more; we know we want to output it.
Now that we're done expanding trees to RTL, we shouldn't have any more CONCATs anywhere.
And the pass manager will dump RTL for us.
If we're emitting a nested function, make sure its parent gets emitted as well. Doing otherwise confuses debug info.
We are now committed to emitting code for this function. Do any preparation, such as emitting abstract debug info for the inline before it gets mangled by optimization.
After expanding, the return labels are no longer needed.
After expanding, the tm_restart map is no longer needed.
Tag the blocks with a depth number so that change_scope can find the common parent easily.
References ei_next(), ei_safe_edge(), ei_start, edge_def::flags, and remove_edge().
|
static |
Prepare for expanding variables.
Conflict bitmaps, and a few related temporary bitmaps, go here.
A map from decl to stack partition.
Initialize local stack smashing state.
|
static |
Returns the label_rtx expression for a label starting basic block BB.
Find the tree label if it is present.
rtl_opt_pass* make_pass_expand | ( | ) |
|
static |
Mark all calls that can have a transaction restart.
|
static |
A subroutine of expand_gimple_cond. Given E, a fallthrough edge of a basic block where we just expanded the conditional at the end, possibly clean up the CFG and instruction sequence. LAST is the last instruction before the just emitted jump sequence.
Special case: when jumpif decides that the condition is trivial it emits an unconditional jump (and the necessary barrier). But we still have two edges, the fallthru one is wrong. purge_dead_edges would clean this up later. Unfortunately we have to insert insns (and split edges) before find_many_sub_basic_blocks and hence before purge_dead_edges. But splitting edges might create new blocks which depend on the fact that if there are two edges there's no barrier. So the barrier would get lost and verify_flow_info would ICE. Instead of auditing all edge splitters to care for the barrier (which normally isn't there in a cleaned CFG), fix it here.
Now, we have a single successor block, if we have insns to insert on the remaining edge we potentially will insert it at the end of this block (if the dest block isn't feasible) in order to avoid splitting the edge. This insertion will take place in front of the last jump. But we might have emitted multiple jumps (conditional and one unconditional) to the same destination. Inserting in front of the last one then is a problem. See PR 40021. We fix this by deleting all jumps except the last unconditional one.
Make sure we have an unconditional jump. Otherwise we're confused.
|
static |
If we need to produce a detailed dump, print the tree representation for STMT to the dump file. SINCE is the last RTX after which the RTL generated for STMT should have been appended.
References gimple_assign_rhs1(), gimple_assign_rhs2(), TREE_CODE, TREE_TYPE, and TYPE_PRECISION.
|
static |
A subroutine of expand_used_vars. Binpack the variables into partitions constrained by the interference graph. The overall algorithm used is as follows:
Sort the objects by size in descending order. For each object A { S = size(A) O = 0 loop { Look for the largest non-conflicting object B with size <= S. UNION (A, B) }
Ignore objects that aren't partition representatives. If we see a var that is not a partition representative, it must have been merged earlier.
Ignore objects that aren't partition representatives.
Do not mix objects of "small" (supported) alignment and "large" (unsupported) alignment.
For Address Sanitizer do not mix objects with different sizes, as the shorter vars wouldn't be adequately protected. Don't do that for "large" (unsupported) alignment objects, those aren't protected anyway.
Ignore conflicting objects.
UNION the objects, placing J at OFFSET.
References dump_file, dump_flags, EOC, HOST_WIDE_INT_PRINT_DEC, stack_var::next, print_generic_expr(), si, and stack_vars_num.
|
static |
Helper routine to check if a record or union contains an array field.
Referenced by asan_decl_phase_3().
|
static |
Return the difference between the rounded and the truncated result of a signed division by OP1 with remainder MOD. Halfway cases are rounded away from zero, rather than to the nearest even number.
(abs (mod) >= abs (op1) - abs (mod) ? (op1 / mod > 0 ? 1 : -1) : 0)
|
static |
Return the difference between the rounded and the truncated result of a unsigned division by OP1 with remainder MOD. Halfway cases are rounded away from zero, rather than to the nearest even number.
(mod >= op1 - mod ? 1 : 0)
|
static |
For each lexical block, set BLOCK_NUMBER to the depth at which it is found in the block tree.
|
inlinestatic |
Associate declaration T with storage space X. If T is no SSA name this is exactly SET_DECL_RTL, otherwise make the partition of T associated with X.
For the benefit of debug information at -O0 (where vartracking doesn't run) record the place also in the base DECL if it's a normal variable (not a parameter).
If we don't yet have something recorded, just record it now.
If we have it set already to "multiple places" don't change this.
If we have something recorded and it's not the same place as we want to record now, we have multiple partitions for the same base variable, with different places. We can't just randomly chose one, hence we have to say that we don't know. This only happens with optimization, and there var-tracking will figure out the right thing.
|
static |
References add_stack_var_conflict(), stack_protect_decl_phase(), and stack_vars_num.
|
static |
Return nonzero if DECL should be segregated into the "vulnerable" upper part of the local stack frame. Remember if we ever return nonzero for any variable in this function. The return value is the phase number in which the variable should be allocated.
Referenced by clear_tree_used(), and stack_protect_classify_type().
|
static |
Two helper routines that check for phase 1 and phase 2. These are used as callbacks for expand_stack_vars.
|
static |
|
static |
A subroutine of partition_stack_vars. A comparison function for qsort, sorting an array of indices by the properties of the object.
Primary compare on "large" alignment. Large comes first.
Secondary compare on size, decreasing
Tertiary compare on true alignment, decreasing.
Final compare on ID for sort stability, increasing. Two SSA names are compared by their version, SSA names come before non-SSA names, and two normal decls are compared by their DECL_UID.
|
static |
Check whether the decls associated with luid's X and Y conflict.
Partitions containing an SSA name result from gimple registers with things like unsupported modes. They are top-level and hence conflict with everything else.
Referenced by union_stack_vars().
|
static |
A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND partitioning algorithm. Partitions A and B are known to be non-conflicting. Merge them into a single partition A.
Add B to A's partition.
Update the required alignment of partition A to account for B.
Update the interference graph and merge the conflicts.
References stack_var::alignb, BITS_PER_UNIT, HOST_WIDE_INT, MAX_SUPPORTED_STACK_ALIGNMENT, SANITIZE_ADDRESS, stack_var::size, and stack_var_conflict_p().
|
static |
Update points-to sets based on partition info, so we can use them on RTL. The bitmaps representing stack partitions will be saved until expand, where partitioned decls used as bases in memory expressions will be rewritten.
Not interested in partitions with single variable.
Create an SSA_NAME that points to the partition for use as base during alias-oracle queries on RTL for bases that have been partitioned.
Create bitmaps representing partitions. They will be used for points-to sets later, so use GGC alloc.
Make the SSA name point to all partition members.
Make all points-to sets that contain one member of a partition contain all members of the partition.
References add_partitioned_vars_to_ptset(), BITMAP_ALLOC, BITMAP_FREE, cfun, num_ssa_names, pointer_map_destroy(), pointer_set_create(), pointer_set_destroy(), POINTER_TYPE_P, ptr_info_def::pt, ssa_name, SSA_NAME_PTR_INFO, and TREE_TYPE.
|
static |
Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var record conflicts between it and all currently active other partitions from bitmap DATA.
Referenced by add_scope_conflicts_1().
|
static |
Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var enter its partition number into bitmap DATA.
gimple currently_expanding_gimple_stmt |
This variable holds the currently expanded gimple statement for purposes of comminucating the profile info to the builtin expanders.
|
static |
|
static |
The phase of the stack frame. This is the known misalignment of virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is, (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0.
Referenced by align_local_variable(), and get_stack_local_alignment().
|
static |
Used during expand_used_vars to remember if we saw any decls for which we'd like to enable stack smashing protection.
|
static |
Used during expand_used_vars. Remember if we say a character buffer smaller than our cutoff threshold. Used for -Wstack-protector.
|
static |
Maps the blocks that do not contain tree labels to rtx labels.
struct ssaexpand SA |
A pass for lowering trees to RTL. Copyright (C) 2004-2013 Free Software Foundation, Inc.
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 variable holds information helping the rewriting of SSA trees into RTL.
Referenced by discover_nonconstant_array_refs_r(), fini_vars_expansion(), get_rtx_for_ssa_name(), and insert_rtx_to_part_on_edge().
|
static |
Conflict bitmaps go on this obstack. This allows us to destroy all of them in one big sweep.
|
static |
We have an array of such objects while deciding allocation.
|
static |
|
static |
Referenced by partition_stack_vars(), and stack_protect_classify_type().
|
static |
An array of indices such that stack_vars[stack_vars_sorted[i]].size is non-decreasing.