GCC Middle and Back End API Reference
tree-nrv.c File Reference

Data Structures

struct  nrv_data

Functions

static tree finalize_nrv_r (tree *, int *, void *)
static tree finalize_nrv_r ()
static unsigned int tree_nrv ()
static bool gate_pass_return_slot ()
gimple_opt_passmake_pass_nrv ()
static bool dest_safe_for_nrv_p ()
static unsigned int execute_return_slot_opt ()
gimple_opt_passmake_pass_return_slot ()

Function Documentation

static bool dest_safe_for_nrv_p ( )
static
Determine (pessimistically) whether DEST is available for NRV
   optimization, where DEST is expected to be the LHS of a modify
   expression where the RHS is a function returning an aggregate.

   DEST is available if it is not clobbered or used by the call.   

References call_may_clobber_ref_p(), get_base_address(), gimple_call_lhs(), and ref_maybe_used_by_stmt_p().

Referenced by execute_return_slot_opt().

static unsigned int execute_return_slot_opt ( )
static
Walk through the function looking for GIMPLE_ASSIGNs with calls that
   return in memory on the RHS.  For each of these, determine whether it is
   safe to pass the address of the LHS as the return slot, and mark the
   call appropriately if so.

   The NRV shares the return slot with a local variable in the callee; this
   optimization shares the return slot with the target of the call within
   the caller.  If the NRV is performed (which we can't know in general),
   this optimization is safe if the address of the target has not
   escaped prior to the call.  If it has, modifications to the local
   variable will produce visible changes elsewhere, as in PR c++/19317.   

References aggregate_value_p(), dest_safe_for_nrv_p(), gimple_call_fndecl(), gimple_call_lhs(), gimple_call_return_slot_opt_p(), gimple_call_set_return_slot_opt(), walk_stmt_info::gsi, gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), and is_gimple_call().

static tree finalize_nrv_r ( tree ,
int *  ,
void *   
)
static

Referenced by tree_nrv().

static tree finalize_nrv_r ( )
static
Callback for the tree walker.

   If TP refers to a RETURN_EXPR, then set the expression being returned
   to nrv_data->result.

   If TP refers to nrv_data->var, then replace nrv_data->var with
   nrv_data->result.

   If we reach a node where we know all the subtrees are uninteresting,
   then set *WALK_SUBTREES to zero.   

References walk_stmt_info::info, nrv_data::modified, nrv_data::result, and nrv_data::var.

static bool gate_pass_return_slot ( )
static
gimple_opt_pass* make_pass_nrv ( )
gimple_opt_pass* make_pass_return_slot ( )
static unsigned int tree_nrv ( )
static
Main entry point for return value optimizations.

   If this function always returns the same local variable, and that
   local variable is an aggregate type, then replace the variable with
   the function's DECL_RESULT.

   This is the equivalent of the C++ named return value optimization
   applied to optimized trees in a language independent form.  If we
   ever encounter languages which prevent this kind of optimization,
   then we could either have the languages register the optimization or
   we could change the gating function to check the current language.   

References aggregate_value_p(), current_function_decl, dump_file, dump_flags, finalize_nrv_r(), get_base_address(), gimple_assign_copy_p(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_get_lhs(), gimple_has_lhs(), gimple_return_retval(), gsi_end_p(), gsi_next(), gsi_remove(), gsi_start_bb(), gsi_stmt(), walk_stmt_info::info, is_gimple_reg_type(), memset(), nrv_data::modified, print_generic_expr(), release_defs(), nrv_data::result, unlink_stmt_vdef(), update_stmt(), useless_type_conversion_p(), nrv_data::var, and walk_gimple_op().