diff options
author | Diego Novillo <dnovillo@google.com> | 2013-11-08 17:46:16 -0500 |
---|---|---|
committer | Diego Novillo <dnovillo@gcc.gnu.org> | 2013-11-08 17:46:16 -0500 |
commit | 862d0b359fb98790d5fad654eecf471228d8bb77 (patch) | |
tree | 956d82c4131695b3b703c5ba7a83a02ad61d5928 /gcc/builtins.c | |
parent | f0e56cd667259c3bc4234cb75c5137136af7b25d (diff) | |
download | gcc-862d0b359fb98790d5fad654eecf471228d8bb77.zip gcc-862d0b359fb98790d5fad654eecf471228d8bb77.tar.gz gcc-862d0b359fb98790d5fad654eecf471228d8bb77.tar.bz2 |
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.
From-SVN: r204606
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 297 |
1 files changed, 165 insertions, 132 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index f84789e..7a04664 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1050,6 +1050,63 @@ expand_builtin_longjmp (rtx buf_addr, rtx value) } } +static inline bool +more_const_call_expr_args_p (const const_call_expr_arg_iterator *iter) +{ + return (iter->i < iter->n); +} + +/* This function validates the types of a function call argument list + against a specified list of tree_codes. If the last specifier is a 0, + that represents an ellipses, otherwise the last specifier must be a + VOID_TYPE. */ + +static bool +validate_arglist (const_tree callexpr, ...) +{ + enum tree_code code; + bool res = 0; + va_list ap; + const_call_expr_arg_iterator iter; + const_tree arg; + + va_start (ap, callexpr); + init_const_call_expr_arg_iterator (callexpr, &iter); + + do + { + code = (enum tree_code) va_arg (ap, int); + switch (code) + { + case 0: + /* This signifies an ellipses, any further arguments are all ok. */ + res = true; + goto end; + case VOID_TYPE: + /* This signifies an endlink, if no arguments remain, return + true, otherwise return false. */ + res = !more_const_call_expr_args_p (&iter); + goto end; + default: + /* If no parameters remain or the parameter's code does not + match the specified code, return false. Otherwise continue + checking any remaining arguments. */ + arg = next_const_call_expr_arg (&iter); + if (!validate_arg (arg, code)) + goto end; + break; + } + } + while (1); + + /* We need gotos here since we can only have one VA_CLOSE in a + function. */ + end: ; + va_end (ap); + + return res; +} + /* Expand a call to __builtin_nonlocal_goto. We're passed the target label and the address of the save area. */ @@ -5581,6 +5638,33 @@ expand_builtin_set_thread_pointer (tree exp) } +/* Emit code to restore the current value of stack. */ + +static void +expand_stack_restore (tree var) +{ + rtx prev, sa = expand_normal (var); + + sa = convert_memory_address (Pmode, sa); + + prev = get_last_insn (); + emit_stack_restore (SAVE_BLOCK, sa); + fixup_args_size_notes (prev, get_last_insn (), 0); +} + + +/* Emit code to save the current value of stack. */ + +static rtx +expand_stack_save (void) +{ + rtx ret = NULL_RTX; + + do_pending_stack_adjust (); + emit_stack_save (SAVE_BLOCK, &ret); + return ret; +} + /* Expand an expression EXP that calls a built-in function, with result going to TARGET if that's convenient (and in mode MODE if that's convenient). @@ -10962,47 +11046,51 @@ fold_builtin_n (location_t loc, tree fndecl, tree *args, int nargs, bool ignore) return NULL_TREE; } -/* Builtins with folding operations that operate on "..." arguments - need special handling; we need to store the arguments in a convenient - data structure before attempting any folding. Fortunately there are - only a few builtins that fall into this category. FNDECL is the - function, EXP is the CALL_EXPR for the call, and IGNORE is true if the - result of the function call is ignored. */ +/* Construct a new CALL_EXPR to FNDECL using the tail of the argument + list ARGS along with N new arguments in NEWARGS. SKIP is the number + of arguments in ARGS to be omitted. OLDNARGS is the number of + elements in ARGS. */ static tree -fold_builtin_varargs (location_t loc, tree fndecl, tree exp, - bool ignore ATTRIBUTE_UNUSED) +rewrite_call_expr_valist (location_t loc, int oldnargs, tree *args, + int skip, tree fndecl, int n, va_list newargs) { - enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); - tree ret = NULL_TREE; + int nargs = oldnargs - skip + n; + tree *buffer; - switch (fcode) + if (n > 0) { - case BUILT_IN_SPRINTF_CHK: - case BUILT_IN_VSPRINTF_CHK: - ret = fold_builtin_sprintf_chk (loc, exp, fcode); - break; + int i, j; - case BUILT_IN_SNPRINTF_CHK: - case BUILT_IN_VSNPRINTF_CHK: - ret = fold_builtin_snprintf_chk (loc, exp, NULL_TREE, fcode); - break; + buffer = XALLOCAVEC (tree, nargs); + for (i = 0; i < n; i++) + buffer[i] = va_arg (newargs, tree); + for (j = skip; j < oldnargs; j++, i++) + buffer[i] = args[j]; + } + else + buffer = args + skip; - case BUILT_IN_FPCLASSIFY: - ret = fold_builtin_fpclassify (loc, exp); - break; + return build_call_expr_loc_array (loc, fndecl, nargs, buffer); +} - default: - break; - } - if (ret) - { - ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); - SET_EXPR_LOCATION (ret, loc); - TREE_NO_WARNING (ret) = 1; - return ret; - } - return NULL_TREE; +/* Construct a new CALL_EXPR to FNDECL using the tail of the argument + list ARGS along with N new arguments specified as the "..." + parameters. SKIP is the number of arguments in ARGS to be omitted. + OLDNARGS is the number of elements in ARGS. */ + +static tree +rewrite_call_expr_array (location_t loc, int oldnargs, tree *args, + int skip, tree fndecl, int n, ...) +{ + va_list ap; + tree t; + + va_start (ap, n); + t = rewrite_call_expr_valist (loc, oldnargs, args, skip, fndecl, n, ap); + va_end (ap); + + return t; } /* Return true if FNDECL shouldn't be folded right now. @@ -11193,53 +11281,6 @@ fold_builtin_call_array (location_t loc, tree type, return build_call_array_loc (loc, type, fn, n, argarray); } -/* Construct a new CALL_EXPR to FNDECL using the tail of the argument - list ARGS along with N new arguments in NEWARGS. SKIP is the number - of arguments in ARGS to be omitted. OLDNARGS is the number of - elements in ARGS. */ - -static tree -rewrite_call_expr_valist (location_t loc, int oldnargs, tree *args, - int skip, tree fndecl, int n, va_list newargs) -{ - int nargs = oldnargs - skip + n; - tree *buffer; - - if (n > 0) - { - int i, j; - - buffer = XALLOCAVEC (tree, nargs); - for (i = 0; i < n; i++) - buffer[i] = va_arg (newargs, tree); - for (j = skip; j < oldnargs; j++, i++) - buffer[i] = args[j]; - } - else - buffer = args + skip; - - return build_call_expr_loc_array (loc, fndecl, nargs, buffer); -} - -/* Construct a new CALL_EXPR to FNDECL using the tail of the argument - list ARGS along with N new arguments specified as the "..." - parameters. SKIP is the number of arguments in ARGS to be omitted. - OLDNARGS is the number of elements in ARGS. */ - -static tree -rewrite_call_expr_array (location_t loc, int oldnargs, tree *args, - int skip, tree fndecl, int n, ...) -{ - va_list ap; - tree t; - - va_start (ap, n); - t = rewrite_call_expr_valist (loc, oldnargs, args, skip, fndecl, n, ap); - va_end (ap); - - return t; -} - /* Construct a new CALL_EXPR using the tail of the argument list of EXP along with N new arguments specified as the "..." parameters. SKIP is the number of arguments in EXP to be omitted. This function is used @@ -11329,57 +11370,6 @@ validate_gimple_arglist (const_gimple call, ...) return res; } -/* This function validates the types of a function call argument list - against a specified list of tree_codes. If the last specifier is a 0, - that represents an ellipses, otherwise the last specifier must be a - VOID_TYPE. */ - -bool -validate_arglist (const_tree callexpr, ...) -{ - enum tree_code code; - bool res = 0; - va_list ap; - const_call_expr_arg_iterator iter; - const_tree arg; - - va_start (ap, callexpr); - init_const_call_expr_arg_iterator (callexpr, &iter); - - do - { - code = (enum tree_code) va_arg (ap, int); - switch (code) - { - case 0: - /* This signifies an ellipses, any further arguments are all ok. */ - res = true; - goto end; - case VOID_TYPE: - /* This signifies an endlink, if no arguments remain, return - true, otherwise return false. */ - res = !more_const_call_expr_args_p (&iter); - goto end; - default: - /* If no parameters remain or the parameter's code does not - match the specified code, return false. Otherwise continue - checking any remaining arguments. */ - arg = next_const_call_expr_arg (&iter); - if (!validate_arg (arg, code)) - goto end; - break; - } - } - while (1); - - /* We need gotos here since we can only have one VA_CLOSE in a - function. */ - end: ; - va_end (ap); - - return res; -} - /* Default target-specific builtin expander that does nothing. */ rtx @@ -13151,7 +13141,7 @@ fold_builtin_snprintf_chk_1 (location_t loc, int nargs, tree *args, BUILT_IN_VSNPRINTF_CHK. If MAXLEN is not NULL, it is maximum length passed as second argument. */ -tree +static tree fold_builtin_snprintf_chk (location_t loc, tree exp, tree maxlen, enum built_in_function fcode) { @@ -13159,6 +13149,49 @@ fold_builtin_snprintf_chk (location_t loc, tree exp, tree maxlen, CALL_EXPR_ARGP (exp), maxlen, fcode); } +/* Builtins with folding operations that operate on "..." arguments + need special handling; we need to store the arguments in a convenient + data structure before attempting any folding. Fortunately there are + only a few builtins that fall into this category. FNDECL is the + function, EXP is the CALL_EXPR for the call, and IGNORE is true if the + result of the function call is ignored. */ + +static tree +fold_builtin_varargs (location_t loc, tree fndecl, tree exp, + bool ignore ATTRIBUTE_UNUSED) +{ + enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); + tree ret = NULL_TREE; + + switch (fcode) + { + case BUILT_IN_SPRINTF_CHK: + case BUILT_IN_VSPRINTF_CHK: + ret = fold_builtin_sprintf_chk (loc, exp, fcode); + break; + + case BUILT_IN_SNPRINTF_CHK: + case BUILT_IN_VSNPRINTF_CHK: + ret = fold_builtin_snprintf_chk (loc, exp, NULL_TREE, fcode); + break; + + case BUILT_IN_FPCLASSIFY: + ret = fold_builtin_fpclassify (loc, exp); + break; + + default: + break; + } + if (ret) + { + ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); + SET_EXPR_LOCATION (ret, loc); + TREE_NO_WARNING (ret) = 1; + return ret; + } + return NULL_TREE; +} + /* Fold a call to the {,v}printf{,_unlocked} and __{,v}printf_chk builtins. FMT and ARG are the arguments to the call; we don't fold cases with more than 2 arguments, and ARG may be null if this is a 1-argument case. |