From: aesok Date: Sat, 25 Apr 2009 04:34:27 +0000 (+0000) Subject: * target.h (struct gcc_target): Add case_values_threshold field. X-Git-Tag: upstream/4.9.2~36425 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=906bb5c363f525c69bf1611dc6489036796cd154;p=platform%2Fupstream%2Flinaro-gcc.git * target.h (struct gcc_target): Add case_values_threshold field. * target-def.h (TARGET_CASE_VALUES_THRESHOLD): New. (TARGET_INITIALIZER): Use TARGET_CASE_VALUES_THRESHOLD. * targhooks.c (default_case_values_threshold): New function. * targhooks.h (default_case_values_threshold): Declare function. * stmt.c (expand_case): Use case_values_threshold target hook. * expr.h (case_values_threshold): Remove declartation. * expr.c (case_values_threshold): Remove function. * doc/tm.texi (CASE_VALUES_THRESHOLD): Revise documentation. * config/avr/avr.h (CASE_VALUES_THRESHOLD): Remove macro. * config/avr/avr.c (TARGET_CASE_VALUES_THRESHOLD): Define macro. (avr_case_values_threshold): Declare as static. * config/avr/avr-protos.h (avr_case_values_threshold): Remove. * config/avr/mn10300.h (CASE_VALUES_THRESHOLD): Remove macro. * config/avr/mn10300.c (TARGET_CASE_VALUES_THRESHOLD): Define macro. (mn10300_case_values_threshold): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146756 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2776197..3af998b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,24 @@ +2009-04-25 Anatoly Sokolov + + * target.h (struct gcc_target): Add case_values_threshold field. + * target-def.h (TARGET_CASE_VALUES_THRESHOLD): New. + (TARGET_INITIALIZER): Use TARGET_CASE_VALUES_THRESHOLD. + * targhooks.c (default_case_values_threshold): New function. + * targhooks.h (default_case_values_threshold): Declare function. + * stmt.c (expand_case): Use case_values_threshold target hook. + * expr.h (case_values_threshold): Remove declartation. + * expr.c (case_values_threshold): Remove function. + * doc/tm.texi (CASE_VALUES_THRESHOLD): Revise documentation. + + * config/avr/avr.h (CASE_VALUES_THRESHOLD): Remove macro. + * config/avr/avr.c (TARGET_CASE_VALUES_THRESHOLD): Define macro. + (avr_case_values_threshold): Declare as static. + * config/avr/avr-protos.h (avr_case_values_threshold): Remove. + + * config/avr/mn10300.h (CASE_VALUES_THRESHOLD): Remove macro. + * config/avr/mn10300.c (TARGET_CASE_VALUES_THRESHOLD): Define macro. + (mn10300_case_values_threshold): New function. + 2009-04-24 H.J. Lu * ira.c (setup_cover_and_important_classes): Add enum cast. diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h index cb936ef..2df4a16 100644 --- a/gcc/config/avr/avr-protos.h +++ b/gcc/config/avr/avr-protos.h @@ -39,7 +39,6 @@ extern int avr_simple_epilogue (void); extern void gas_output_limited_string (FILE *file, const char *str); extern void gas_output_ascii (FILE *file, const char *str, size_t length); extern int avr_hard_regno_rename_ok (unsigned int, unsigned int); -extern unsigned int avr_case_values_threshold (void); #ifdef TREE_CODE extern void asm_output_external (FILE *file, tree decl, char *name); diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c index e868a97..40835c7 100644 --- a/gcc/config/avr/avr.c +++ b/gcc/config/avr/avr.c @@ -87,6 +87,7 @@ static bool avr_return_in_memory (const_tree, const_tree); static struct machine_function * avr_init_machine_status (void); static rtx avr_builtin_setjmp_frame_value (void); static bool avr_hard_regno_scratch_ok (unsigned int); +static unsigned int avr_case_values_threshold (void); /* Allocate registers from r25 to r8 for parameters for function calls. */ #define FIRST_CUM_REG 26 @@ -359,6 +360,8 @@ static const struct mcu_type_s avr_mcu_types[] = { #undef TARGET_HARD_REGNO_SCRATCH_OK #define TARGET_HARD_REGNO_SCRATCH_OK avr_hard_regno_scratch_ok +#undef TARGET_CASE_VALUES_THRESHOLD +#define TARGET_CASE_VALUES_THRESHOLD avr_case_values_threshold struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h index 32508df..5d50827 100644 --- a/gcc/config/avr/avr.h +++ b/gcc/config/avr/avr.h @@ -732,8 +732,6 @@ fprintf (STREAM, "\t.skip %lu,0\n", (unsigned long)(N)) #define CASE_VECTOR_MODE HImode -#define CASE_VALUES_THRESHOLD avr_case_values_threshold () - #undef WORD_REGISTER_OPERATIONS #define MOVE_MAX 4 diff --git a/gcc/config/mn10300/mn10300.c b/gcc/config/mn10300/mn10300.c index 7ee7269..1eb80ec 100644 --- a/gcc/config/mn10300/mn10300.c +++ b/gcc/config/mn10300/mn10300.c @@ -1,6 +1,6 @@ /* Subroutines for insn-output.c for Matsushita MN10300 series Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Contributed by Jeff Law (law@cygnus.com). This file is part of GCC. @@ -80,6 +80,7 @@ static bool mn10300_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode, const_tree, bool); static int mn10300_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode, tree, bool); +static unsigned int mn10300_case_values_threshold (void); /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP @@ -119,6 +120,9 @@ static int mn10300_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode, #undef TARGET_EXPAND_BUILTIN_VA_START #define TARGET_EXPAND_BUILTIN_VA_START mn10300_va_start +#undef TARGET_CASE_VALUES_THRESHOLD +#define TARGET_CASE_VALUES_THRESHOLD mn10300_case_values_threshold + static void mn10300_encode_section_info (tree, rtx, int); struct gcc_target targetm = TARGET_INITIALIZER; @@ -2126,3 +2130,15 @@ mn10300_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) if (flag_pic) SYMBOL_REF_FLAG (symbol) = (*targetm.binds_local_p) (decl); } + +/* Dispatch tables on the mn10300 are extremely expensive in terms of code + and readonly data size. So we crank up the case threshold value to + encourage a series of if/else comparisons to implement many small switch + statements. In theory, this value could be increased much more if we + were solely optimizing for space, but we keep it "reasonable" to avoid + serious code efficiency lossage. */ + +unsigned int mn10300_case_values_threshold (void) +{ + return 6; +} diff --git a/gcc/config/mn10300/mn10300.h b/gcc/config/mn10300/mn10300.h index 7bd7f33..b6486d9 100644 --- a/gcc/config/mn10300/mn10300.h +++ b/gcc/config/mn10300/mn10300.h @@ -1,7 +1,7 @@ /* Definitions of target machine for GNU compiler. Matsushita MN10300 series Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2007, 2008 Free Software Foundation, Inc. + 2007, 2008, 2009 Free Software Foundation, Inc. Contributed by Jeff Law (law@cygnus.com). This file is part of GCC. @@ -810,14 +810,6 @@ while (0) than accessing full words. */ #define SLOW_BYTE_ACCESS 1 -/* Dispatch tables on the mn10300 are extremely expensive in terms of code - and readonly data size. So we crank up the case threshold value to - encourage a series of if/else comparisons to implement many small switch - statements. In theory, this value could be increased much more if we - were solely optimizing for space, but we keep it "reasonable" to avoid - serious code efficiency lossage. */ -#define CASE_VALUES_THRESHOLD 6 - #define NO_FUNCTION_CSE /* According expr.c, a value of around 6 should minimize code size, and diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 5718eb9..ae2ee51 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -9712,12 +9712,12 @@ contain relative addresses only when @option{-fPIC} or @option{-fPIC} is in effect. @end defmac -@defmac CASE_VALUES_THRESHOLD -Define this to be the smallest number of different values for which it +@deftypefn {Target Hook} unsigned int TARGET_CASE_VALUES_THRESHOLD (void) +This function return the smallest number of different values for which it is best to use a jump-table instead of a tree of conditional branches. The default is four for machines with a @code{casesi} instruction and five otherwise. This is best for most machines. -@end defmac +@end deftypefn @defmac CASE_USE_BIT_TESTS Define this macro to be a C expression to indicate whether C switch diff --git a/gcc/expr.c b/gcc/expr.c index 7935c67..fd0c437 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9865,19 +9865,6 @@ do_store_flag (tree exp, rtx target, enum machine_mode mode) # define CODE_FOR_casesi CODE_FOR_nothing #endif -/* If the machine does not have a case insn that compares the bounds, - this means extra overhead for dispatch tables, which raises the - threshold for using them. */ -#ifndef CASE_VALUES_THRESHOLD -#define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5) -#endif /* CASE_VALUES_THRESHOLD */ - -unsigned int -case_values_threshold (void) -{ - return CASE_VALUES_THRESHOLD; -} - /* Attempt to generate a casesi instruction. Returns 1 if successful, 0 otherwise (i.e. if there is no casesi instruction). */ int diff --git a/gcc/expr.h b/gcc/expr.h index 7e7e088..e3c3837 100644 --- a/gcc/expr.h +++ b/gcc/expr.h @@ -583,10 +583,6 @@ extern void do_compare_rtx_and_jump (rtx, rtx, enum rtx_code, int, extern int try_casesi (tree, tree, tree, tree, rtx, rtx, rtx); extern int try_tablejump (tree, tree, tree, tree, rtx, rtx); -/* Smallest number of adjacent cases before we use a jump table. - XXX Should be a target hook. */ -extern unsigned int case_values_threshold (void); - /* Functions from alias.c */ #include "alias.h" diff --git a/gcc/stmt.c b/gcc/stmt.c index 96e63fa..e2688ef 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -2320,7 +2320,7 @@ expand_case (tree exp) If the switch-index is a constant, do it this way because we can optimize it. */ - else if (count < case_values_threshold () + else if (count < targetm.case_values_threshold () || compare_tree_int (range, (optimize_insn_for_size_p () ? 3 : 10) * count) > 0 /* RANGE may be signed, and really large ranges will show up diff --git a/gcc/target-def.h b/gcc/target-def.h index 73e6943..7ff4ed6 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -1,5 +1,5 @@ /* Default initializers for a generic GCC target. - Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -654,6 +654,10 @@ #define TARGET_HARD_REGNO_SCRATCH_OK default_hard_regno_scratch_ok #endif +#ifndef TARGET_CASE_VALUES_THRESHOLD +#define TARGET_CASE_VALUES_THRESHOLD default_case_values_threshold +#endif + /* C specific. */ #ifndef TARGET_C_MODE_FOR_SUFFIX #define TARGET_C_MODE_FOR_SUFFIX default_mode_for_suffix @@ -918,6 +922,7 @@ TARGET_EXPAND_TO_RTL_HOOK, \ TARGET_INSTANTIATE_DECLS, \ TARGET_HARD_REGNO_SCRATCH_OK, \ + TARGET_CASE_VALUES_THRESHOLD, \ TARGET_C, \ TARGET_CXX, \ TARGET_EMUTLS, \ diff --git a/gcc/target.h b/gcc/target.h index f3d3361..ed08a09 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -921,6 +921,10 @@ struct gcc_target in peephole2. */ bool (* hard_regno_scratch_ok) (unsigned int regno); + /* Return the smallest number of different values for which it is best to + use a jump-table instead of a tree of conditional branches. */ + unsigned int (* case_values_threshold) (void); + /* Functions specific to the C family of frontends. */ struct c { /* Return machine mode for non-standard suffix diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 5b7b875..c0bcac0 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1,5 +1,6 @@ /* Default target hook functions. - Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 + Free Software Foundation, Inc. This file is part of GCC. @@ -765,4 +766,17 @@ default_target_option_can_inline_p (tree caller, tree callee) return ret; } +#ifndef HAVE_casesi +# define HAVE_casesi 0 +#endif + +/* If the machine does not have a case insn that compares the bounds, + this means extra overhead for dispatch tables, which raises the + threshold for using them. */ + +unsigned int default_case_values_threshold (void) +{ + return (HAVE_casesi ? 4 : 5); +} + #include "gt-targhooks.h" diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 07ade39..63d419f 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -1,5 +1,6 @@ /* Default target hook functions. - Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 + Free Software Foundation, Inc. This file is part of GCC. @@ -104,3 +105,4 @@ extern bool default_hard_regno_scratch_ok (unsigned int); extern bool default_target_option_valid_attribute_p (tree, tree, tree, int); extern bool default_target_option_pragma_parse (tree, tree); extern bool default_target_option_can_inline_p (tree, tree); +extern unsigned int default_case_values_threshold (void);