GCC Middle and Back End API Reference
|
Data Structures | |
struct | nesting_info |
struct | nesting_copy_body_data |
Variables | |
static struct bitmap_obstack | nesting_info_bitmap_obstack |
static tree | trampoline_type |
tree build_addr | ( | ) |
Take the address of EXP to be used within function CONTEXT. Mark it for addressability as necessary.
Building the ADDR_EXPR will compute a set of properties for that ADDR_EXPR. Those properties are unfortunately context specific, i.e., they are dependent on CURRENT_FUNCTION_DECL. Temporarily set CURRENT_FUNCTION_DECL to the desired context, build the ADDR_EXPR, then restore CURRENT_FUNCTION_DECL. That way the properties are for the ADDR_EXPR are computed properly.
References current_function_decl.
Referenced by create_nesting_tree(), create_phi_for_local_result(), lower_gimple_return(), and remap_vla_decls().
|
static |
We have to check for a fairly pathological case. The operands of function nested function are to be interpreted in the context of the enclosing function. So if any are variably-sized, they will get remapped when the enclosing function is inlined. But that remapping would also have to be done in the types of the PARM_DECLs of the nested function, meaning the argument types of that function will disagree with the arguments in the calls to that function. So we'd either have to make a copy of the nested function corresponding to each time the enclosing function was inlined or add a VIEW_CONVERT_EXPR to each such operand for each call to the nested function. The former is not practical. The latter would still require detecting this case to know when to add the conversions. So, for now at least, we don't inline such an enclosing function. We have to do that check recursively, so here return indicating whether FNDECL has such a nested function. ORIG_FN is the function we were trying to inline to use for checking whether any argument is variably modified by anything in it. It would be better to do this in tree-inline.c so that we could give the appropriate warning for why a function can't be inlined, but that's too late since the nesting structure has already been flattened and adding a flag just to record this fact seems a waste of a flag.
Referenced by walk_all_functions().
|
static |
A helper function for remap_vla_decls. See if *TP contains some remapped variables.
|
static |
Walk the nesting tree starting with ROOT. Convert all trampolines and call expressions. At the same time, determine if a nested function actually uses its static chain; if not, remember that.
First, optimistically clear static_chain for all decls that haven't used the static chain already for variable access.
Walk the functions and perform transformations. Note that these transformations can induce new uses of the static chain, which in turn require re-examining all users of the decl.
??? It would make sense to try to use the call graph to speed this up, but the call graph hasn't really been built yet. Even if it did, we would still need to iterate in this loop since address-of references wouldn't show up in the callgraph anyway.
|
static |
Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_CALLs that reference nested functions to make sure that the static chain is set up properly for the call.
Don't add CHAIN.* or FRAME.* twice.
FALLTHRU
Keep looking for other operands.
References nesting_info::chain_decl, nesting_info::chain_field, nesting_info::context, lang_hooks::decl_printable_name, dump_file, dump_flags, and nesting_info::outer.
|
static |
Called via walk_function+walk_gimple_stmt, rewrite all references to VAR and PARM_DECLs that were referenced by inner nested functions. The rewrite will be a structure reference to the local frame variable.
|
static |
Helper for convert_local_reference. Convert all the references in the chain of clauses at *PCLAUSES. WI is as in convert_local_reference.
FALLTHRU
References nesting_info::context, convert_local_reference_op(), convert_local_reference_stmt(), OMP_CLAUSE_LASTPRIVATE, OMP_CLAUSE_REDUCTION, and walk_body().
|
static |
Non-automatic variables are never processed.
FALLTHRU
If we copied a pointer to the frame, then the original decl is used unchanged in the parent function.
No need to transform anything if no child references the variable.
If we converted anything ...
Then the frame decl is now addressable.
If we are in a context where we only accept values, then compute the address into a temporary.
Go down this entire nest and just look at the final prefix and anything that describes the references. Otherwise, we lose track of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.
We need to re-fold the MEM_REF as component references as part of a ADDR_EXPR address are not allowed. But we cannot fold here, as the chain record type is not yet finalized.
Just request to look at the subtrees, leaving val_only and lhs untouched. This might actually be for !val_only + lhs, in which case we don't want to force a replacement by a temporary.
References current_function_decl.
Referenced by convert_local_omp_clauses().
|
static |
Called via walk_function+walk_gimple_stmt, rewrite all references to VAR and PARM_DECLs that were referenced by inner nested functions. The rewrite will be a structure reference to the local frame variable.
For every other statement that we are not interested in handling here, let the walker traverse the operands.
Indicate that we have handled all the operands ourselves.
Referenced by convert_local_omp_clauses().
|
static |
Called via walk_function+walk_tree, rewrite all GIMPLE_LABELs whose labels are referenced via nonlocal goto from a nested function. The rewrite will involve installing a newly generated DECL_NONLOCAL label, and (potentially) a branch around the rtl gunk that is assumed to be attached to such a label.
If there's any possibility that the previous statement falls through, then we must branch around the new non-local label.
|
static |
Called via walk_function+walk_gimple_stmt, rewrite all GIMPLE_GOTOs that reference labels from outer functions. The rewrite will be a call to __builtin_nonlocal_goto.
The original user label may also be use for a normal goto, therefore we must create a new label that will actually receive the abnormal control transfer. This new label will be marked LABEL_NONLOCAL; this mark will trigger proper behavior in the cfg, as well as cause the (hairy target-specific) non-local goto receiver code to be generated when we expand rtl. Enter this association into var_map so that we can insert the new label into the IL during a second pass.
Build: __builtin_nl_goto(new_label, &chain->nl_goto_field).
We have handled all of STMT's operands, no need to keep going.
|
static |
Helper for convert_nonlocal_references, rewrite all references to VAR and PARM_DECLs that belong to outer functions.
FALLTHRU
Referenced by note_nonlocal_vla_type().
|
static |
Callback for walk_gimple_stmt, rewrite all references to VAR and PARM_DECLs that belong to outer functions. The rewrite will involve some number of structure accesses back up the static chain. E.g. for a variable FOO up one nesting level it'll be CHAIN->FOO. For two levels it'll be CHAIN->__chain->FOO. Further indirections apply to decls for which use_pointer_in_frame is true.
Non-automatic variables are never processed.
FALLTHRU
We're taking the address of a label from a parent function, but this is not itself a non-local goto. Mark the label such that it will not be deleted, much as we would with a label address in static storage.
If we changed anything, we might no longer be directly referencing a decl.
If the callback converted the address argument in a context where we only accept variables (and min_invariant, presumably), then compute the address into a temporary.
Go down this entire nest and just look at the final prefix and anything that describes the references. Otherwise, we lose track of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.
Just request to look at the subtrees, leaving val_only and lhs untouched. This might actually be for !val_only + lhs, in which case we don't want to force a replacement by a temporary.
|
static |
Callback for walk_gimple_stmt. Rewrite all references to VAR and PARM_DECLs that belong to outer functions. This handles statements that are not handled via the standard recursion done in walk_gimple_stmt. STMT is the statement to examine, DATA is as in convert_nonlocal_reference_op. Set *HANDLED_OPS_P to true if all the operands of STMT have been handled by this function.
Don't walk non-local gotos for now.
For every other statement that we are not interested in handling here, let the walker traverse the operands.
We have handled all of STMT operands, no need to traverse the operands.
|
static |
Called via walk_function+walk_stmt, rewrite all references to addresses of nested functions that require the use of trampolines. The rewrite will involve a reference a trampoline generated for the occasion.
Build T.1 = &CHAIN->tramp; T.2 = __builtin_adjust_trampoline (T.1); T.3 = (func_type)T.2;
Only need to process nested functions.
If the nested function doesn't use a static chain, then it doesn't need a trampoline.
If we don't want a trampoline, then don't build one.
Lookup the immediate parent of the callee, as that's where we need to insert the trampoline.
Compute the address of the field holding the trampoline.
Do machine-specific ugliness. Normally this will involve computing extra alignment, but it can really be anything.
Cast back to the proper function type.
|
static |
Called via walk_function+walk_gimple_stmt, rewrite all references to addresses of nested functions that require the use of trampolines. The rewrite will involve a reference a trampoline generated for the occasion.
Only walk call arguments, lest we generate trampolines for direct calls.
References build_omp_clause(), gimple_location(), gimple_omp_taskreg_clauses(), gimple_omp_taskreg_set_clauses(), OMP_CLAUSE_FIRSTPRIVATE, and OMP_CLAUSE_SHARED.
|
staticread |
Construct our local datastructure describing the function nesting tree rooted by CGN.
See discussion at check_for_nested_with_variably_modified for a discussion of why this has to be here.
References build_addr(), and nesting_info::frame_decl.
|
static |
Like create_tmp_var, except record the variable for registration at the given nesting level.
If the type is of variable size or a type which must be created by the frontend, something is wrong. Note that we explicitly allow incomplete types here, since we create them ourselves here.
|
static |
|
static |
Do "everything else" to clean up or complete state collected by the various walking passes -- lay out the types and decls, generate code to initialize the frame decl, store critical expressions in the struct function for rtl to find.
If we created a non-local frame type or decl, we need to lay them out at this time.
In some cases the frame type will trigger the -Wpadded warning. This is not helpful; suppress it.
Remove root->frame_decl from root->new_local_var_chain, so that we can declare it also in the lexical blocks, which helps ensure virtual regs that end up appearing in its RTL expression get substituted in instantiate_virtual_regs().
If any parameters were referenced non-locally, then we need to insert a copy. Likewise, if any variables were referenced by pointer, we need to initialize the address.
If the assignment is from a non-register the stmt is not valid gimple. Make it so by using a temporary instead.
If a chain_field was created, then it needs to be initialized from chain_decl.
If trampolines were created, then we need to initialize them.
If we created initialization statements, insert them.
If a chain_decl was created, then it needs to be registered with struct function so that it gets initialized from the static chain register at the beginning of the function.
Similarly for the non-local goto save area.
Make sure all new local variables get inserted into the proper BIND_EXPR.
If there are any debug decls with variable length types, remap those types using other debug_var_chain variables.
Fold the rewritten MEM_REF trees.
Dump the translated tree function.
References annotate_all_with_location(), gimple_bind_body(), gimple_bind_set_body(), gimple_body(), gimple_seq_add_seq(), and gimple_seq_first_stmt().
|
static |
Fold the MEM_REF *E.
|
static |
Free the data structures allocated during this pass.
|
static |
Build or return the variable that holds the static chain within INFO->CONTEXT. This variable may only be used within INFO->CONTEXT.
Note that this variable is *not* entered into any BIND_EXPR; the construction of this variable is handled specially in expand_function_start and initialize_inlined_parameters. Note also that it's represented as a parameter. This is more close to the truth, since the initial value does come from the caller.
Tell tree-inline.c that we never write to this variable, so it can copy-prop the replacement value immediately.
Referenced by get_frame_field(), and note_nonlocal_vla_type().
|
static |
Build or return the field within the non-local frame state that holds the static chain for INFO->CONTEXT. This is the way to walk back up multiple nesting levels.
Referenced by get_frame_field().
|
static |
Return an expression referencing FIELD from TARGET_CONTEXT's non-local frame as seen from INFO->CONTEXT. Insert any necessary computations before GSI.
Make sure frame_decl gets created.
References nesting_info::context, decl_function_context(), nesting_info::frame_decl, get_chain_decl(), get_chain_field(), get_frame_type(), lookup_field_for_decl(), nesting_info::outer, pointer_map_insert(), use_pointer_in_frame(), and nesting_info::var_map.
Referenced by get_local_debug_decl().
|
static |
Build or return the RECORD_TYPE that describes the frame state that is shared between INFO->CONTEXT and its nested functions. This record will not be complete until finalize_nesting_tree; up until that point we'll be adding fields as necessary. We also build the DECL that represents this frame in the function.
??? Always make it addressable for now, since it is meant to be pointed to by the static chain pointer. This pessimizes when it turns out that no static chains are needed because the nested functions referencing non-local variables are not reachable, but the true pessimization is to create the non- local frame structure in the first place.
Referenced by get_frame_field(), and get_static_chain().
|
static |
A subroutine of convert_local_reference. Create a local variable in the parent function with DECL_VALUE_EXPR set to reference the field in FRAME. This is used both for debug info and in OpenMP lowering.
Make sure frame_decl gets created.
Do not emit debug info twice.
References bitmap_bit_p(), walk_stmt_info::changed, nesting_info::context, get_frame_field(), walk_stmt_info::gsi, init_tmp_var(), walk_stmt_info::is_lhs, lookup_field_for_decl(), save_tmp_var(), nesting_info::suppress_expansion, use_pointer_in_frame(), and walk_stmt_info::val_only.
|
static |
Build or return the field within the non-local frame state that holds the non-local goto "jmp_buf". The buffer itself is maintained by the rtl middle-end as dynamic stack space is allocated.
For __builtin_nonlocal_goto, we need N words. The first is the frame pointer, the rest is for the target's stack pointer save area. The number of words is controlled by STACK_SAVEAREA_MODE; not the best interface, but it'll do for now.
|
static |
A subroutine of convert_nonlocal_reference_op. Create a local variable in the nested function with DECL_VALUE_EXPR set to reference the true variable in the parent function. This is used both for debug info and in OpenMP lowering.
A copy of the code in get_frame_field, but without the temporaries.
Make sure frame_decl gets created.
??? We should be remapping types as well, surely.
|
static |
Return an expression computing the static chain for TARGET_CONTEXT from INFO->CONTEXT. Insert any necessary computations before TSI.
References nesting_info::frame_decl, and get_frame_type().
|
static |
If we won't be able to guarantee alignment simply via TYPE_ALIGN, then allocate extra space so that we can do dynamic alignment.
|
static |
Gimplify a function and all its nested functions.
|
static |
Similarly, but only do so to force EXP to satisfy is_gimple_val.
|
static |
Copy EXP into a temporary. Allocate the temporary in the context of INFO and insert the initialization statement before GSI.
Referenced by get_local_debug_decl(), and remap_vla_decls().
|
static |
Initialize a new temporary with the GIMPLE_CALL STMT.
void insert_field_into_struct | ( | ) |
Insert FIELD into TYPE, sorted by alignment requirements.
Set correct alignment for frame struct type.
|
staticread |
|
staticread |
Iterate over the nesting tree, starting with ROOT, depth first.
|
static |
Given DECL, a non-locally accessed variable, find or create a field in the non-local frame structure for the given nesting context.
References build_pointer_type().
Referenced by get_frame_field(), get_local_debug_decl(), and remap_vla_decls().
|
static |
Given DECL, a nested function, find or create a field in the non-local frame structure for a trampoline for this function.
References build_array_type(), build_index_type(), get_identifier(), nesting_info::nl_goto_field, ptr_mode, SAVE_NONLOCAL, type(), lang_hooks_for_types::type_for_mode, and lang_hooks::types.
Referenced by remap_vla_decls().
void lower_nested_functions | ( | ) |
Main entry point for this pass. Process FNDECL and all of its nested subroutines and turn them into something less tightly bound.
If there are no nested functions, there's nothing to do.
|
static |
A helper subroutine for debug_var_chain type remapping.
|
static |
Create nonlocal debug decls for nonlocal VLA array bounds for VLAs in BLOCK.
|
static |
|
static |
Create nonlocal debug decls for nonlocal VLA array bounds.
References build_omp_clause(), convert_nonlocal_omp_clauses(), get_chain_decl(), gimple_goto_dest(), gimple_location(), gimple_omp_taskreg_clauses(), gimple_omp_taskreg_clauses_ptr(), gimple_omp_taskreg_set_clauses(), gsi_stmt(), walk_stmt_info::info, walk_stmt_info::is_lhs, OMP_CLAUSE_FIRSTPRIVATE, nesting_info::suppress_expansion, and walk_stmt_info::val_only.
|
static |
Remap VLA decls in BLOCK and subblocks if remapped variables are involved.
Fully expand value expressions. This avoids having debug variables only referenced from them and that can be swept during GC.
References nesting_info::any_parm_remapped, nesting_info::any_tramp_created, build_addr(), nesting_info::chain_field, nesting_info::context, declare_vars(), nesting_info::frame_decl, nesting_info::frame_type, gimple_assign_set_rhs1(), gimple_body(), gimple_seq_add_stmt(), gimple_seq_first_stmt(), init_tmp_var(), nesting_info::inner, is_gimple_reg(), is_gimple_reg_type(), layout_decl(), layout_type(), lookup_field_for_decl(), lookup_tramp_for_decl(), nesting_info::new_local_var_chain, nesting_info::next, and use_pointer_in_frame().
|
static |
Similarly, but copy from the temporary and insert the statement after the iterator.
Referenced by get_local_debug_decl().
|
static |
|
static |
Unnest the nodes and pass them to cgraph.
For nested functions update the cgraph to reflect unnesting. We also delay finalizing of these functions up to this point.
|
static |
Return true if DECL should be referenced by pointer in the non-local frame structure.
It's illegal to copy TREE_ADDRESSABLE, impossible to copy variable sized decls, and inefficient to copy large aggregates. Don't bother moving anything but scalar variables.
Variable sized types make things "interesting" in the frame.
Referenced by get_frame_field(), get_local_debug_decl(), and remap_vla_decls().
|
static |
Similarly for ROOT and all functions nested underneath, depth first.
References cgraph_get_node(), check_for_nested_with_variably_modified(), symtab_node_base::decl, cgraph_node::nested, cgraph_node::next_nested, and variably_modified_type_p().
|
static |
Invoke CALLBACK on all statements of GIMPLE sequence *PSEQ.
Referenced by convert_local_omp_clauses().
|
inlinestatic |
Invoke CALLBACK_STMT/CALLBACK_OP on all statements of INFO->CONTEXT.
|
static |
Invoke CALLBACK on a GIMPLE_OMP_FOR's init, cond, incr and pre-body.
|
static |
Obstack used for the bitmaps in the struct above.
|
static |
Build or return the type used to represent a nested function trampoline.