diff options
author | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-11-08 22:46:16 +0000 |
---|---|---|
committer | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-11-08 22:46:16 +0000 |
commit | 0e80b01daa5ed1a0dcb48f50d8b77e3c390f2a92 (patch) | |
tree | 956d82c4131695b3b703c5ba7a83a02ad61d5928 /gcc/fold-const.c | |
parent | 8d0b865d5de1355485ac6eda9dfd433bedb30649 (diff) | |
download | linaro-gcc-0e80b01daa5ed1a0dcb48f50d8b77e3c390f2a92.tar.gz linaro-gcc-0e80b01daa5ed1a0dcb48f50d8b77e3c390f2a92.tar.bz2 linaro-gcc-0e80b01daa5ed1a0dcb48f50d8b77e3c390f2a92.zip |
Re-factor tree.h - Part 1.
This is the first patch in a series of patches to cleanup tree.h to
reduce the exposure it has all over the compiler.
In this patch, I'm moving functions that are used once into the files
that use them, and make them private to that file. These functions
were declared extern in tree.h and called from exactly one place.
The patch does not move EVERY function. This usually happens
when the function uses private state from its original file, and
moving that private state would mean moving other functions that made
no sense to move.
Additionally, the patch removes functions that were never used.
In subsequent patches, I will be moving out of tree.h extern definitions
that should be grouped in other files (e.g., all functions defined in
some FOO.c will be moved to the corresponding FOO.h). This will allow
me to remove the inclusion of tree.h from some files.
* attribs.c (lookup_scoped_attribute_spec): Make static.
(get_attribute_namespace): Likewise.
* builtins.c (more_const_call_expr_args_p): Move from
tree.h.
(validate_arglist): Move earlier in the file. Make static.
(expand_stack_restore): Move from stmt.c
(expand_stack_save): Move from stmt.c
(rewrite_call_expr_array): Move earlier in the file.
(rewrite_call_expr_valist): Likewise.
* cfgexpand.c: Include hard-reg-set.h before tree.h
Include recog.h.
Include output.h.
(expand_asm_loc): Move from stmt.c.
(n_occurrences): Move from stmt.c.
(check_operand_nalternatives): Move from stmt.c.
(tree_conflicts_with_clobbers_p): Move from stmt.c.
(expand_asm_operands): Move from stmt.c
(expand_asm_stmt): Move from stmt.c
(expand_computed_goto): Move from stmt.c
(expand_goto): Move from stmt.c
(expand_null_return_1): Move from stmt.c
(expand_null_return): Move from stmt.c
(expand_value_return): Move from stmt.c
(expand_return): Move from stmt.c
(expand_main_function): Move from function.c
(stack_protect_prologue): Move from function.c
* cgraphclones.c (build_function_type_skip_args): Move from tree.c.
(build_function_decl_skip_args): Move from tree.c.
* explow.c (tree_expr_size): Move from tree.c.
* expr.c (addr_expr_of_non_mem_decl_p): Remove.
(fields_length): Move from tree.c.
* fold-const.c (size_low_cst): Move from tree.c.
(tree_expr_nonzero_warnv_p): Make static. Move earlier in the file.
(tree_expr_nonzero_p): Make static. Move earlier in the file.
(fold_build3_initializer_loc): Remove.
(tree_invalid_nonnegative_warnv_p): Make static.
* function.c (expand_main_function): Move to cfgexpand.c.
(stack_protect_prologue): Move to cfgexpand.c.
(set_insn_locations): Move earlier in the file.
* gimple-fold.c: Include langhooks.h.
(truth_type_for): Move from tree.c.
* print-tree.c (print_vec_tree): Remove.
* stmt.c (expand_computed_goto): Move to cfgexpand.c.
(expand_goto): Move to cfgexpand.c.
(n_occurrences): Move to cfgexpand.c.
(expand_asm_loc): Move to cfgexpand.c
(tree_conflicts_with_clobbers_p): Move to cfgexpand.c.
(expand_asm_operands): Move to cfgexpand.c.
(expand_asm_stmt): Move to cfgexpand.c.
(check_operand_nalternatives): Move to cfgexpand.c
(expand_null_return): Move to cfgexpand.c.
(expand_value_return): Move to cfgexpand.c.
(expand_null_return_1): Move to cfgexpand.c.
(expand_return): Move to cfgexpand.c.
(expand_stack_save): Move to builtins.c.
(expand_stack_restore): Move to builtins.c
* symtab.c: Include output.h.
(decl_assembler_name_hash): Move from tree.c.
(decl_assembler_name_equal): Move from tree.c.
* trans-mem.c (is_tm_safe_or_pure): Move from tree.h.
* tree-eh.c (in_array_bounds_p): Move from tree.c.
(range_in_array_bounds_p): Move from tree.c.
* tree-object-size.c (fini_object_sizes): Make static.
* tree-ssa-dom.c (iterative_hash_exprs_commutative): Move from tree.h.
* tree-vrp.c (ssa_name_nonnegative_p): Remove.
* tree.c (decl_assembler_name_equal): Move to symtab.c.
(tree_expr_size): Move to explow.c.
(decl_assembler_name_hash): Move to symtab.c.
(real_twop): Remove.
(tree_expr_size): Move to explow.c.
(stabilize_reference_1): Move earlier in the file. Make static.
(omp_remove_redundant_declare_simd_attrs): Remove.
(simple_cst_list_equal): Move earlier in the file. Make static.
(size_low_cst): Move to fold-const.c.
(build_type_no_quals): Remove.
(build_function_type_skip_args): Move to cgraphclones.c.
(build_function_decl_skip_args): Move to cgraphclones.c.
(in_array_bounds_p): Move to tree-eh.c.
(range_in_array_bounds_p): Move to tree-eh.c.
(truth_type_for): Move to gimple-fold.c.
(list_equal_p): remove.
* tree.h (decl_assembler_name_equal): Remove.
(decl_assembler_name_hash): Remove.
(truth_type_for): Remove.
(build_type_no_quals): Remove.
(build_function_decl_skip_args): Remove.
(in_array_bounds_p): Remove.
(range_in_array_bounds_p): Remove.
(size_low_cst): Remove.
(omp_remove_redundant_declare_simd_attrs): Remove.
(tree_expr_size): Remove.
(fields_length): Remove.
(stabilize_reference_1): Remove.
(expand_goto): Remove.
(expand_stack_save): Remove.
(expand_stack_restore): Remove.
(expand_return): Remove.
(fold_build3_initializer_loc): Remove.
(tree_expr_nonzero_p): Remove.
(tree_invalid_nonnegative_warnv_p): Remove.
(tree_expr_nonzero_warnv_p): Remove.
(fold_builtin_snprintf_chk): Remove.
(validate_arglist): Remove.
(iterative_hash_exprs_commutative): Move to tree-ssa-dom.c.
(simple_cst_list_equal): Remove.
(real_twop): Remove.
(expand_main_function): Remove.
(stack_protect_prologue): Remove.
(print_vec_tree): Remove.
(lookup_scoped_attribute_spec): Remove.
(get_attribute_namespace): Remove.
(expand_computed_goto): Remove.
(expand_asm_stmt): Remove.
(list_equal_p): Remove.
(ssa_name_nonnegative_p): Remove.
(fini_object_sizes): Remove.
(addr_expr_of_non_mem_decl_p): Remove.
(is_tm_safe_or_pure): Move to trans-mem.c.
(more_const_call_expr_args_p): Remove.
(save_vtable_map_decl): Remove.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204606 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 248 |
1 files changed, 123 insertions, 125 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c346063f925..3e6f15887db 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8944,6 +8944,17 @@ pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos) return total.low > (unsigned HOST_WIDE_INT) size; } +/* Return the HOST_WIDE_INT least significant bits of T, a sizetype + kind INTEGER_CST. This makes sure to properly sign-extend the + constant. */ + +static HOST_WIDE_INT +size_low_cst (const_tree t) +{ + double_int d = tree_to_double_int (t); + return d.sext (TYPE_PRECISION (TREE_TYPE (t))).low; +} + /* Subroutine of fold_binary. This routine performs all of the transformations that are common to the equality/inequality operators (EQ_EXPR and NE_EXPR) and the ordering operators @@ -9951,6 +9962,117 @@ mask_with_tz (tree type, double_int x, double_int y) return x; } +/* Return true when T is an address and is known to be nonzero. + For floating point we further ensure that T is not denormal. + Similar logic is present in nonzero_address in rtlanal.h. + + If the return value is based on the assumption that signed overflow + is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't + change *STRICT_OVERFLOW_P. */ + +static bool +tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p) +{ + tree type = TREE_TYPE (t); + enum tree_code code; + + /* Doing something useful for floating point would need more work. */ + if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) + return false; + + code = TREE_CODE (t); + switch (TREE_CODE_CLASS (code)) + { + case tcc_unary: + return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0), + strict_overflow_p); + case tcc_binary: + case tcc_comparison: + return tree_binary_nonzero_warnv_p (code, type, + TREE_OPERAND (t, 0), + TREE_OPERAND (t, 1), + strict_overflow_p); + case tcc_constant: + case tcc_declaration: + case tcc_reference: + return tree_single_nonzero_warnv_p (t, strict_overflow_p); + + default: + break; + } + + switch (code) + { + case TRUTH_NOT_EXPR: + return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0), + strict_overflow_p); + + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + case TRUTH_XOR_EXPR: + return tree_binary_nonzero_warnv_p (code, type, + TREE_OPERAND (t, 0), + TREE_OPERAND (t, 1), + strict_overflow_p); + + case COND_EXPR: + case CONSTRUCTOR: + case OBJ_TYPE_REF: + case ASSERT_EXPR: + case ADDR_EXPR: + case WITH_SIZE_EXPR: + case SSA_NAME: + return tree_single_nonzero_warnv_p (t, strict_overflow_p); + + case COMPOUND_EXPR: + case MODIFY_EXPR: + case BIND_EXPR: + return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 1), + strict_overflow_p); + + case SAVE_EXPR: + return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 0), + strict_overflow_p); + + case CALL_EXPR: + { + tree fndecl = get_callee_fndecl (t); + if (!fndecl) return false; + if (flag_delete_null_pointer_checks && !flag_check_new + && DECL_IS_OPERATOR_NEW (fndecl) + && !TREE_NOTHROW (fndecl)) + return true; + if (flag_delete_null_pointer_checks + && lookup_attribute ("returns_nonnull", + TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))) + return true; + return alloca_call_p (t); + } + + default: + break; + } + return false; +} + +/* Return true when T is an address and is known to be nonzero. + Handle warnings about undefined signed overflow. */ + +static bool +tree_expr_nonzero_p (tree t) +{ + bool ret, strict_overflow_p; + + strict_overflow_p = false; + ret = tree_expr_nonzero_warnv_p (t, &strict_overflow_p); + if (strict_overflow_p) + fold_overflow_warning (("assuming signed overflow does not occur when " + "determining that expression is always " + "non-zero"), + WARN_STRICT_OVERFLOW_MISC); + return ret; +} + /* Fold a binary expression of code CODE and type TYPE with operands OP0 and OP1. LOC is the location of the resulting expression. Return the folded expression if folding is successful. Otherwise, @@ -15244,19 +15366,6 @@ fold_build2_initializer_loc (location_t loc, enum tree_code code, } tree -fold_build3_initializer_loc (location_t loc, enum tree_code code, - tree type, tree op0, tree op1, tree op2) -{ - tree result; - START_FOLD_INIT; - - result = fold_build3_loc (loc, code, type, op0, op1, op2); - - END_FOLD_INIT; - return result; -} - -tree fold_build_call_array_initializer_loc (location_t loc, tree type, tree fn, int nargs, tree *argarray) { @@ -15777,7 +15886,7 @@ tree_call_nonnegative_warnv_p (tree type, tree fndecl, set *STRICT_OVERFLOW_P to true; otherwise, don't change *STRICT_OVERFLOW_P. */ -bool +static bool tree_invalid_nonnegative_warnv_p (tree t, bool *strict_overflow_p) { enum tree_code code = TREE_CODE (t); @@ -16146,117 +16255,6 @@ tree_single_nonzero_warnv_p (tree t, bool *strict_overflow_p) return false; } -/* Return true when T is an address and is known to be nonzero. - For floating point we further ensure that T is not denormal. - Similar logic is present in nonzero_address in rtlanal.h. - - If the return value is based on the assumption that signed overflow - is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't - change *STRICT_OVERFLOW_P. */ - -bool -tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p) -{ - tree type = TREE_TYPE (t); - enum tree_code code; - - /* Doing something useful for floating point would need more work. */ - if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) - return false; - - code = TREE_CODE (t); - switch (TREE_CODE_CLASS (code)) - { - case tcc_unary: - return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0), - strict_overflow_p); - case tcc_binary: - case tcc_comparison: - return tree_binary_nonzero_warnv_p (code, type, - TREE_OPERAND (t, 0), - TREE_OPERAND (t, 1), - strict_overflow_p); - case tcc_constant: - case tcc_declaration: - case tcc_reference: - return tree_single_nonzero_warnv_p (t, strict_overflow_p); - - default: - break; - } - - switch (code) - { - case TRUTH_NOT_EXPR: - return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0), - strict_overflow_p); - - case TRUTH_AND_EXPR: - case TRUTH_OR_EXPR: - case TRUTH_XOR_EXPR: - return tree_binary_nonzero_warnv_p (code, type, - TREE_OPERAND (t, 0), - TREE_OPERAND (t, 1), - strict_overflow_p); - - case COND_EXPR: - case CONSTRUCTOR: - case OBJ_TYPE_REF: - case ASSERT_EXPR: - case ADDR_EXPR: - case WITH_SIZE_EXPR: - case SSA_NAME: - return tree_single_nonzero_warnv_p (t, strict_overflow_p); - - case COMPOUND_EXPR: - case MODIFY_EXPR: - case BIND_EXPR: - return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 1), - strict_overflow_p); - - case SAVE_EXPR: - return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 0), - strict_overflow_p); - - case CALL_EXPR: - { - tree fndecl = get_callee_fndecl (t); - if (!fndecl) return false; - if (flag_delete_null_pointer_checks && !flag_check_new - && DECL_IS_OPERATOR_NEW (fndecl) - && !TREE_NOTHROW (fndecl)) - return true; - if (flag_delete_null_pointer_checks - && lookup_attribute ("returns_nonnull", - TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))) - return true; - return alloca_call_p (t); - } - - default: - break; - } - return false; -} - -/* Return true when T is an address and is known to be nonzero. - Handle warnings about undefined signed overflow. */ - -bool -tree_expr_nonzero_p (tree t) -{ - bool ret, strict_overflow_p; - - strict_overflow_p = false; - ret = tree_expr_nonzero_warnv_p (t, &strict_overflow_p); - if (strict_overflow_p) - fold_overflow_warning (("assuming signed overflow does not occur when " - "determining that expression is always " - "non-zero"), - WARN_STRICT_OVERFLOW_MISC); - return ret; -} - /* Given the components of a binary expression CODE, TYPE, OP0 and OP1, attempt to fold the expression to a constant without modifying TYPE, OP0 or OP1. |