GCC Middle and Back End API 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"
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_pass * | make_pass_call_cdce (gcc::context *ctxt) |
#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().
Return true if it is structurally possible to guard CALL.
References find_fallthru_edge(), gimple_bb(), and stmt_ends_bb_p().
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().
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().
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().
References check_target_format(), dconst1, gimple_assign_rhs1(), gimple_assign_rhs_code(), gimple_call_arg(), gimple_call_num_args(), MAX_BASE_INT_BIT_SIZE, real_equal(), real_from_integer(), real_less(), REAL_VALUE_TYPE, SSA_NAME_DEF_STMT, TREE_CODE, TREE_REAL_CST, TREE_TYPE, type(), TYPE_MODE, TYPE_PRECISION, and UNSIGNED.
Referenced by can_test_argument_range(), and gen_conditions_for_pow().
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, type(), and TYPE_MODE.
Referenced by check_builtin_call(), and check_pow().
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().
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
gimple_opt_pass * make_pass_call_cdce | ( | gcc::context * | ctxt | ) |
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().
|
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().
|
static |
Shrink-wrap BI_CALL so that it is only called when one of the NCONDS conditions in CONDS is false. Also move BI_NEWCALL to a new basic block when it is non-null, it is called while all of the CONDS are true.
References add_phi_arg(), profile_probability::always(), CDI_DOMINATORS, copy_ssa_name(), basic_block_def::count, create_phi_node(), dom_info_available_p(), dump_file, dump_flags, EDGE_COUNT, EDGE_SUCC, find_fallthru_edge(), FOR_EACH_IMM_USE_ON_STMT, FOR_EACH_IMM_USE_STMT, gcc_assert, gimple_bb(), gimple_call_lhs(), gimple_call_set_lhs(), gimple_location(), gimple_phi_arg_def(), gimple_phi_result(), gsi_end_p(), gsi_for_stmt(), gsi_insert_before(), gsi_move_before(), GSI_SAME_STMT, gsi_start_bb(), gsi_start_phis(), i, LOCATION_FILE, LOCATION_LINE, make_edge(), NULL, PHI_RESULT, remove_phi_node(), replace_uses_by(), set_immediate_dominator(), SET_USE, split_block(), split_edge(), SSA_NAME_DEF_STMT, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, stmt_ends_bb_p(), basic_block_def::succs, TDF_DETAILS, profile_probability::very_unlikely(), and profile_count::zero().
Referenced by shrink_wrap_one_built_in_call(), and use_internal_fn().
|
static |
Implement built-in function call CALL using an internal function.
References can_test_argument_range(), edom_only_function(), gcc_assert, gen_shrink_wrap_conditions(), gimple_build_call_internal(), gimple_build_call_internal_vec(), gimple_build_cond(), gimple_call_arg(), gimple_call_lhs(), gimple_call_nothrow_p(), gimple_call_num_args(), gimple_call_set_lhs(), gimple_call_set_nothrow(), gimple_location(), gimple_move_vops(), gimple_set_location(), gsi_for_stmt(), gsi_insert_before(), gsi_replace(), GSI_SAME_STMT, i, NULL, NULL_TREE, replace_abnormal_ssa_names(), replacement_internal_fn(), set_edom_supported_p(), shrink_wrap_one_built_in_call_with_conds(), SSA_NAME_DEF_STMT, and stmt_ends_bb_p().
Referenced by shrink_wrap_conditional_dead_built_in_calls().