GCC Middle and Back End API Reference
tree-stdarg.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "tree.h"
#include "gimple.h"
#include "tree-pass.h"
#include "ssa.h"
#include "gimple-pretty-print.h"
#include "fold-const.h"
#include "langhooks.h"
#include "gimple-iterator.h"
#include "gimple-walk.h"
#include "gimplify.h"
#include "tree-into-ssa.h"
#include "tree-cfg.h"
#include "tree-stdarg.h"
Include dependency graph for tree-stdarg.cc:

Functions

static bool reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb)
 
static unsigned HOST_WIDE_INT va_list_counter_bump (struct stdarg_info *si, tree counter, tree rhs, bool gpr_p)
 
static tree find_va_list_reference (tree *tp, int *walk_subtrees, void *data)
 
static void va_list_counter_op (struct stdarg_info *si, tree ap, tree var, bool gpr_p, bool write_p)
 
static bool va_list_counter_struct_op (struct stdarg_info *si, tree ap, tree var, bool write_p)
 
static bool va_list_ptr_read (struct stdarg_info *si, tree ap, tree tem)
 
static bool va_list_ptr_write (struct stdarg_info *si, tree ap, tree tem2)
 
static void check_va_list_escapes (struct stdarg_info *si, tree lhs, tree rhs)
 
static bool check_all_va_list_escapes (struct stdarg_info *si)
 
static void optimize_va_list_gpr_fpr_size (function *fun)
 
static void expand_ifn_va_arg_1 (function *fun)
 
static void expand_ifn_va_arg (function *fun)
 
gimple_opt_passmake_pass_stdarg (gcc::context *ctxt)
 
gimple_opt_passmake_pass_lower_vaarg (gcc::context *ctxt)
 

Function Documentation

◆ check_all_va_list_escapes()

◆ check_va_list_escapes()

static void check_va_list_escapes ( struct stdarg_info * si,
tree lhs,
tree rhs )
static
If RHS is X, (some type *) X or X + CST for X a temporary variable
containing value of some va_list variable plus optionally some constant,
either set si->va_list_escapes or add LHS to si->va_list_escape_vars,
depending whether LHS is a function local temporary.   

References bitmap_bit_p, bitmap_set_bit, dump_file, dump_flags, ggc_alloc(), HOST_WIDE_INT_M1U, POINTER_TYPE_P, reachable_at_most_once(), si, SSA_NAME_VERSION, TDF_DETAILS, TREE_CODE, TREE_OPERAND, TREE_TYPE, and va_list_counter_bump().

Referenced by optimize_va_list_gpr_fpr_size().

◆ expand_ifn_va_arg()

◆ expand_ifn_va_arg_1()

◆ find_va_list_reference()

static tree find_va_list_reference ( tree * tp,
int * walk_subtrees,
void * data )
static
Called by walk_tree to look for references to va_list variables.   

References bitmap_bit_p, DECL_UID, NULL_TREE, num_ssa_names, SSA_NAME_VERSION, TREE_CODE, and VAR_P.

Referenced by optimize_va_list_gpr_fpr_size().

◆ make_pass_lower_vaarg()

gimple_opt_pass * make_pass_lower_vaarg ( gcc::context * ctxt)

References ggc_alloc().

◆ make_pass_stdarg()

gimple_opt_pass * make_pass_stdarg ( gcc::context * ctxt)

References ggc_alloc().

◆ optimize_va_list_gpr_fpr_size()

static void optimize_va_list_gpr_fpr_size ( function * fun)
static
Optimize FUN->va_list_gpr_size and FUN->va_list_fpr_size.   

References ap, BITMAP_ALLOC, bitmap_empty_p(), BITMAP_FREE, bitmap_set_bit, BUILT_IN_NORMAL, calculate_dominance_info(), CDI_DOMINATORS, cfun, char_type_node, check_all_va_list_escapes(), check_va_list_escapes(), CONVERT_EXPR_CODE_P, current_function_decl, function::decl, DECL_FUNCTION_CODE(), lang_hooks::decl_printable_name, DECL_UID, dump_file, dump_flags, find_va_list_reference(), fndecl_built_in_p(), FOR_EACH_BB_FN, FOR_EACH_PHI_ARG, fputc(), free(), gcc_assert, get_gimple_rhs_class(), ggc_alloc(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_call_arg(), gimple_call_fndecl(), gimple_phi_arg_def(), gimple_phi_arg_def_ptr(), gimple_phi_num_args(), GIMPLE_SINGLE_RHS, gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), gsi_stmt(), i, integer_zerop(), is_gimple_assign(), is_gimple_call(), is_gimple_debug(), is_gimple_reg_type(), is_global_var(), NULL, NULL_TREE, num_ssa_names, PHI_RESULT, POINTER_TYPE_P, print_gimple_stmt(), si, SSA_OP_USE, walk_stmt_info::stmt, targetm, TDF_DETAILS, TREE_CLOBBER_P, TREE_CODE, TREE_OPERAND, TREE_TYPE, TYPE_MAIN_VARIANT, USE_FROM_PTR, va_list_counter_struct_op(), va_list_fpr_counter_field, function::va_list_fpr_size, va_list_gpr_counter_field, function::va_list_gpr_size, VA_LIST_MAX_FPR_SIZE, VA_LIST_MAX_GPR_SIZE, va_list_ptr_read(), va_list_ptr_write(), VAR_P, virtual_operand_p(), void_type_node, walk_gimple_op(), and walk_tree.

◆ reachable_at_most_once()

static bool reachable_at_most_once ( basic_block va_arg_bb,
basic_block va_start_bb )
static
Pass computing data for optimizing stdarg functions.
   Copyright (C) 2004-2024 Free Software Foundation, Inc.
   Contributed by Jakub Jelinek <jakub@redhat.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/>.   
A simple pass that attempts to optimize stdarg functions on architectures
that need to save register arguments to stack on entry to stdarg functions.
If the function doesn't use any va_start macros, no registers need to
be saved.  If va_start macros are used, the va_list variables don't escape
the function, it is only necessary to save registers that will be used
in va_arg macros.  E.g. if va_arg is only used with integral types
in the function, floating point registers don't need to be saved, etc.   
Return true if basic block VA_ARG_BB is dominated by VA_START_BB and
is executed at most as many times as VA_START_BB.   

References bitmap_bit_p, bitmap_clear(), bitmap_set_bit, CDI_DOMINATORS, cfun, dominated_by_p(), EDGE_COMPLEX, ENTRY_BLOCK_PTR_FOR_FN, FOR_EACH_EDGE, gcc_assert, ggc_alloc(), basic_block_def::index, last_basic_block_for_fn, basic_block_def::preds, and visited.

Referenced by check_va_list_escapes(), va_list_counter_op(), and va_list_ptr_read().

◆ va_list_counter_bump()

◆ va_list_counter_op()

static void va_list_counter_op ( struct stdarg_info * si,
tree ap,
tree var,
bool gpr_p,
bool write_p )
static
Helper function of va_list_counter_struct_op.  Compute
cfun->va_list_{g,f}pr_size.  AP is a va_list GPR/FPR counter,
if WRITE_P is true, seen in AP = VAR, otherwise seen in VAR = AP
statement.  GPR_P is true if AP is a GPR counter, false if it is
a FPR counter.   

References ap, cfun, dump_file, dump_flags, ggc_alloc(), reachable_at_most_once(), si, TDF_DETAILS, va_list_counter_bump(), VA_LIST_MAX_FPR_SIZE, and VA_LIST_MAX_GPR_SIZE.

Referenced by va_list_counter_struct_op().

◆ va_list_counter_struct_op()

static bool va_list_counter_struct_op ( struct stdarg_info * si,
tree ap,
tree var,
bool write_p )
static
If AP is a va_list GPR/FPR counter, compute cfun->va_list_{g,f}pr_size.
If WRITE_P is true, AP has been seen in AP = VAR assignment, if WRITE_P
is false, AP has been seen in VAR = AP assignment.
Return true if the AP = VAR (resp. VAR = AP) statement is a recognized
va_arg operation that doesn't cause the va_list variable to escape
current function.   

References ap, bitmap_bit_p, DECL_UID, get_base_address(), ggc_alloc(), num_ssa_names, si, SSA_NAME_VERSION, TREE_CODE, TREE_OPERAND, va_list_counter_op(), va_list_fpr_counter_field, va_list_gpr_counter_field, and VAR_P.

Referenced by optimize_va_list_gpr_fpr_size().

◆ va_list_ptr_read()

static bool va_list_ptr_read ( struct stdarg_info * si,
tree ap,
tree tem )
static
Check for TEM = AP.  Return true if found and the caller shouldn't
search for va_list references in the statement.   

References ap, bitmap_bit_p, bitmap_set_bit, DECL_UID, dump_file, dump_flags, ggc_alloc(), HOST_WIDE_INT_M1U, num_ssa_names, reachable_at_most_once(), si, SSA_NAME_VERSION, TDF_DETAILS, TREE_CODE, va_list_counter_bump(), and VAR_P.

Referenced by optimize_va_list_gpr_fpr_size().

◆ va_list_ptr_write()

static bool va_list_ptr_write ( struct stdarg_info * si,
tree ap,
tree tem2 )
static
Check for:
  tem1 = AP;
  TEM2 = tem1 + CST;
  AP = TEM2;
sequence and update cfun->va_list_gpr_size.  Return true if found.   

References ap, bitmap_bit_p, cfun, DECL_UID, ggc_alloc(), num_ssa_names, si, SSA_NAME_VERSION, TREE_CODE, va_list_counter_bump(), VA_LIST_MAX_GPR_SIZE, and VAR_P.

Referenced by optimize_va_list_gpr_fpr_size().