GCC Middle and Back End API Reference
tree-call-cdce.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "cfghooks.h"
#include "tree-pass.h"
#include "ssa.h"
#include "gimple-pretty-print.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "gimple-iterator.h"
#include "tree-cfg.h"
#include "tree-into-ssa.h"
#include "builtins.h"
#include "internal-fn.h"
#include "tree-dfa.h"
Include dependency graph for tree-call-cdce.cc:

Data Structures

struct  inp_domain
 

Macros

#define MAX_BASE_INT_BIT_SIZE   32
 

Functions

static inp_domain get_domain (int lb, bool has_lb, bool lb_inclusive, int ub, bool has_ub, bool ub_inclusive)
 
static bool check_target_format (tree arg)
 
static bool check_pow (gcall *pow_call)
 
static bool check_builtin_call (gcall *bcall)
 
static bool can_test_argument_range (gcall *call)
 
static bool edom_only_function (gcall *call)
 
static bool can_guard_call_p (gimple *call)
 
static enum tree_code comparison_code_if_no_nans (tree_code code)
 
static void gen_one_condition (tree arg, int lbub, enum tree_code tcode, const char *temp_name1, const char *temp_name2, vec< gimple * > conds, unsigned *nconds)
 
static void gen_conditions_for_domain (tree arg, inp_domain domain, vec< gimple * > conds, unsigned *nconds)
 
static void gen_conditions_for_pow_cst_base (tree base, tree expn, vec< gimple * > conds, unsigned *nconds)
 
static void gen_conditions_for_pow_int_base (tree base, tree expn, vec< gimple * > conds, unsigned *nconds)
 
static void gen_conditions_for_pow (gcall *pow_call, vec< gimple * > conds, unsigned *nconds)
 
static inp_domain get_no_error_domain (enum built_in_function fnc)
 
static void gen_shrink_wrap_conditions (gcall *bi_call, const vec< gimple * > &conds, unsigned int *nconds)
 
static void shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, const vec< gimple * > &conds, unsigned int nconds, gcall *bi_newcall=NULL)
 
static void shrink_wrap_one_built_in_call (gcall *bi_call)
 
static bool can_use_internal_fn (gcall *call)
 
static void use_internal_fn (gcall *call)
 
static void shrink_wrap_conditional_dead_built_in_calls (const vec< gcall * > &calls)
 
gimple_opt_passmake_pass_call_cdce (gcc::context *ctxt)
 

Macro Definition Documentation

◆ MAX_BASE_INT_BIT_SIZE

#define MAX_BASE_INT_BIT_SIZE   32
A helper function to help select calls to pow that are suitable for conditional DCE transformation. It looks for pow calls that can be guided with simple conditions. Such calls either have constant base values or base values converted from integers. Returns true if the pow call POW_CALL is a candidate.
The maximum integer bit size for base argument of a pow call that is suitable for shrink-wrapping transformation.

Referenced by check_pow(), and gen_conditions_for_pow_int_base().

Function Documentation

◆ can_guard_call_p()

static bool can_guard_call_p ( gimple * call)
static
Return true if it is structurally possible to guard CALL.

References find_fallthru_edge(), gimple_bb(), and stmt_ends_bb_p().

◆ can_test_argument_range()

static bool can_test_argument_range ( gcall * call)
static
Return true if built-in function call CALL calls a math function and if we know how to test the range of its arguments to detect _most_ situations in which errno is not set. The test must err on the side of treating non-erroneous values as potentially erroneous.

References CASE_FLT_FN, CASE_FLT_FN_FLOATN_NX, check_builtin_call(), check_pow(), DECL_FUNCTION_CODE(), and gimple_call_fndecl().

Referenced by can_use_internal_fn(), and use_internal_fn().

◆ can_use_internal_fn()

static bool can_use_internal_fn ( gcall * call)
static
Return true if built-in function call CALL could be implemented using a combination of an internal function to compute the result and a separate call to set errno.

References can_test_argument_range(), edom_only_function(), gimple_vdef(), and replacement_internal_fn().

◆ check_builtin_call()

static bool check_builtin_call ( gcall * bcall)
static
A helper function to help select candidate function calls that are suitable for conditional DCE. Candidate functions must have single valid input domain in this implementation except for pow (see check_pow). Returns true if the function call is a candidate.

References check_target_format(), and gimple_call_arg().

Referenced by can_test_argument_range().

◆ check_pow()

◆ check_target_format()

static bool check_target_format ( tree arg)
static
A helper function to check the target format for the argument type. In this implementation, only IEEE formats are supported. ARG is the call argument to be checked. Returns true if the format is supported. To support other target formats, function get_no_error_domain needs to be enhanced to have range bounds properly computed. Since the check is cheap (very small number of candidates to be checked), the result is not cached for each float type.

References ieee_double_format, ieee_extended_intel_128_format, ieee_extended_intel_96_format, ieee_extended_intel_96_round_53_format, ieee_extended_motorola_format, ieee_quad_format, ieee_single_format, mips_double_format, mips_quad_format, mips_single_format, motorola_double_format, motorola_single_format, REAL_MODE_FORMAT, TREE_TYPE, and TYPE_MODE.

Referenced by check_builtin_call(), and check_pow().

◆ comparison_code_if_no_nans()

static enum tree_code comparison_code_if_no_nans ( tree_code code)
static
For a comparison code return the comparison code we should use if we don't HONOR_NANS.

References gcc_unreachable.

Referenced by gen_one_condition().

◆ edom_only_function()

static bool edom_only_function ( gcall * call)
static
Return true if CALL can produce a domain error (EDOM) but can never produce a pole, range overflow or range underflow error (all ERANGE). This means that we can tell whether a function would have set errno by testing whether the result is a NaN.

References CASE_FLT_FN, CASE_FLT_FN_FLOATN_NX, DECL_FUNCTION_CODE(), and gimple_call_fndecl().

Referenced by can_use_internal_fn(), and use_internal_fn().

◆ gen_conditions_for_domain()

static void gen_conditions_for_domain ( tree arg,
inp_domain domain,
vec< gimple * > conds,
unsigned * nconds )
static
A helper function to generate GIMPLE statements for out of input domain check. ARG is the call argument to be runtime checked, DOMAIN holds the valid domain for the given function, CONDS points to the vector holding the result GIMPLE statements. *NCONDS is the number of logical comparisons. This function produces no more than two logical comparisons, one for lower bound check, one for upper bound check.

References gen_one_condition(), inp_domain::has_lb, inp_domain::has_ub, inp_domain::is_lb_inclusive, inp_domain::is_ub_inclusive, inp_domain::lb, NULL, and inp_domain::ub.

Referenced by gen_conditions_for_pow_cst_base(), gen_conditions_for_pow_int_base(), and gen_shrink_wrap_conditions().

◆ gen_conditions_for_pow()

static void gen_conditions_for_pow ( gcall * pow_call,
vec< gimple * > conds,
unsigned * nconds )
static
Method to generate conditional statements for guarding conditionally dead calls to pow. One or more statements can be generated for each logical condition. Statement groups of different conditions are separated by a NULL tree and they are stored in the vec conds. The number of logical conditions are stored in *nconds. See C99 standard, 7.12.7.4:2, for description of pow (x, y). The precise condition for domain errors are complex. In this implementation, a simplified (but conservative) valid domain for x and y are used: x is positive to avoid dom errors, while y is smaller than a upper bound (depending on x) to avoid range errors. Runtime code is generated to check x (if not constant) and y against the valid domain. If it is out, jump to the call, otherwise the call is bypassed. POW_CALL is the call statement, *CONDS is a vector holding the resulting condition statements, and *NCONDS is the number of logical conditions.

References check_pow(), gcc_checking_assert, gcc_unreachable, gen_conditions_for_pow_cst_base(), gen_conditions_for_pow_int_base(), gimple_call_arg(), and TREE_CODE.

Referenced by gen_shrink_wrap_conditions().

◆ gen_conditions_for_pow_cst_base()

static void gen_conditions_for_pow_cst_base ( tree base,
tree expn,
vec< gimple * > conds,
unsigned * nconds )
static
A helper function to generate condition code for the y argument in call pow (some_const, y). See candidate selection in check_pow. Since the candidates' base values have a limited range, the guarded code generated for y are simple: if (__builtin_isgreater (y, max_y)) pow (const, y); Note max_y can be computed separately for each const base, but in this implementation, we choose to compute it using the max base in the allowed range for the purpose of simplicity. BASE is the constant base value, EXPN is the expression for the exponent argument, *CONDS is the vector to hold resulting statements, and *NCONDS is the number of logical conditions.

References dconst1, gcc_assert, gen_conditions_for_domain(), get_domain(), real_equal(), real_from_integer(), real_less(), REAL_VALUE_TYPE, TREE_REAL_CST, TREE_TYPE, TYPE_MODE, and UNSIGNED.

Referenced by gen_conditions_for_pow().

◆ gen_conditions_for_pow_int_base()

static void gen_conditions_for_pow_int_base ( tree base,
tree expn,
vec< gimple * > conds,
unsigned * nconds )
static
Generate error condition code for pow calls with non constant base values. The candidates selected have their base argument value converted from integer (see check_pow) value (1, 2, 4 bytes), and the max exp value is computed based on the size of the integer type (i.e. max possible base value). The resulting input domain for exp argument is thus conservative (smaller than the max value allowed by the runtime value of the base). BASE is the integer base value, EXPN is the expression for the exponent argument, *CONDS is the vector to hold resulting statements, and *NCONDS is the number of logical conditions.

References build_int_cst(), create_tmp_var, gcc_assert, gen_conditions_for_domain(), get_domain(), gimple_assign_rhs1(), gimple_assign_set_lhs(), gimple_build_assign(), gimple_build_cond(), make_ssa_name(), MAX_BASE_INT_BIT_SIZE, NULL, NULL_TREE, SSA_NAME_DEF_STMT, TREE_TYPE, and TYPE_PRECISION.

Referenced by gen_conditions_for_pow().

◆ gen_one_condition()

static void gen_one_condition ( tree arg,
int lbub,
enum tree_code tcode,
const char * temp_name1,
const char * temp_name2,
vec< gimple * > conds,
unsigned * nconds )
static
A helper function to generate gimple statements for one bound comparison, so that the built-in function is called whenever TCODE <ARG, LBUB> is *false*. TEMP_NAME1/TEMP_NAME2 are names of the temporaries, CONDS is a vector holding the produced GIMPLE statements, and NCONDS points to the variable holding the number of logical comparisons. CONDS is either empty or a list ended with a null tree.

References boolean_type_node, build_int_cst(), build_real_from_int_cst(), comparison_code_if_no_nans(), create_tmp_var, fold_build2, gimple_assign_set_lhs(), gimple_build_assign(), gimple_build_cond_from_tree(), HONOR_NANS(), integer_type_node, make_ssa_name(), NULL_TREE, and TREE_TYPE.

Referenced by gen_conditions_for_domain().

◆ gen_shrink_wrap_conditions()

static void gen_shrink_wrap_conditions ( gcall * bi_call,
const vec< gimple * > & conds,
unsigned int * nconds )
static
The function to generate shrink wrap conditions for a partially dead builtin call whose return value is not used anywhere, but has to be kept live due to potential error condition. BI_CALL is the builtin call, CONDS is the vector of statements for condition code, NCODES is the pointer to the number of logical conditions. Statements belonging to different logical condition are separated by NULL tree in the vector.

References DECL_FUNCTION_CODE(), fndecl_built_in_p(), gcc_assert, gen_conditions_for_domain(), gen_conditions_for_pow(), get_no_error_domain(), gimple_call_arg(), gimple_call_fndecl(), and is_gimple_call().

Referenced by shrink_wrap_one_built_in_call(), and use_internal_fn().

◆ get_domain()

static inp_domain get_domain ( int lb,
bool has_lb,
bool lb_inclusive,
int ub,
bool has_ub,
bool ub_inclusive )
static
A helper function to construct and return an input domain object. LB is the lower bound, HAS_LB is a boolean flag indicating if the lower bound exists, and LB_INCLUSIVE is a boolean flag indicating if the lower bound is inclusive or not. UB, HAS_UB, and UB_INCLUSIVE have the same meaning, but for upper bound of the domain.

References inp_domain::has_lb, inp_domain::has_ub, inp_domain::is_lb_inclusive, inp_domain::is_ub_inclusive, inp_domain::lb, and inp_domain::ub.

Referenced by gen_conditions_for_pow_cst_base(), gen_conditions_for_pow_int_base(), and get_no_error_domain().

◆ get_no_error_domain()

static inp_domain get_no_error_domain ( enum built_in_function fnc)
static
A helper routine to help computing the valid input domain for a builtin function. See C99 7.12.7 for details. In this implementation, we only handle single region domain. The resulting region can be conservative (smaller) than the actual one and rounded to integers. Some of the bounds are documented in the standard, while other limit constants are computed assuming IEEE floating point format (for SF and DF modes). Since IEEE only sets minimum requirements for long double format, different long double formats exist under different implementations (e.g, 64 bit double precision (DF), 80 bit double-extended precision (XF), and 128 bit quad precision (TF) ). For simplicity, in this implementation, the computed bounds for long double assume 64 bit format (DF) except when it is IEEE quad or extended with the same emax, and are therefore sometimes conservative. Another assumption is that single precision float type is always SF mode, and double type is DF mode. This function is quite implementation specific, so it may not be suitable to be part of builtins.cc. This needs to be revisited later to see if it can be leveraged in x87 assembly expansion.

References CASE_FLT_FN, CASE_FLT_FN_FLOATN_NX, real_format::emax, float64x_type_node, gcc_unreachable, get_domain(), get_no_error_domain(), long_double_type_node, REAL_MODE_FORMAT, and TYPE_MODE.

Referenced by gen_shrink_wrap_conditions(), and get_no_error_domain().

◆ make_pass_call_cdce()

gimple_opt_pass * make_pass_call_cdce ( gcc::context * ctxt)

◆ shrink_wrap_conditional_dead_built_in_calls()

static void shrink_wrap_conditional_dead_built_in_calls ( const vec< gcall * > & calls)
static
The top level function for conditional dead code shrink wrapping transformation.

References gimple_call_lhs(), i, shrink_wrap_one_built_in_call(), and use_internal_fn().

◆ shrink_wrap_one_built_in_call()

static void shrink_wrap_one_built_in_call ( gcall * bi_call)
static
Shrink-wrap BI_CALL so that it is only called when it might set errno (but is always called if it would set errno).

References gcc_assert, gen_shrink_wrap_conditions(), and shrink_wrap_one_built_in_call_with_conds().

Referenced by shrink_wrap_conditional_dead_built_in_calls().

◆ shrink_wrap_one_built_in_call_with_conds()

◆ use_internal_fn()