From e52a8b712b7e831d71d208aadae7be74ee19b1f5 Mon Sep 17 00:00:00 2001 From: Georg-Johann Lay Date: Thu, 17 Jan 2013 17:14:53 +0000 Subject: [PATCH] builtins.def (DEF_BUILTIN): Factor out "__builtin_avr_" from NAME, turn NAME to an uppercase identifier. * config/avr/builtins.def (DEF_BUILTIN): Factor out "__builtin_avr_" from NAME, turn NAME to an uppercase identifier. Factor out 'CODE_FOR_' from ICODE, use 'nothing' instead of '-1'. Remove ID. Adjust comments. * config/avr/avr-c.c (avr_builtin_name): Remove. (avr_cpu_cpp_builtins): Use DEF_BUILTIN instead of for-loop. * config/avr/avr.c (avr_tolower): New static function. (DEF_BUILTIN): Remove parameter ID. Prefix ICODE by 'CODE_FOR_'. Stringify NAME, prefix it with "__builtin_avr_" and lowercase it. (avr_expand_builtin): Assert insn_code != CODE_FOR_nothing for default expansion. From-SVN: r195276 --- gcc/ChangeLog | 14 ++++++++++ gcc/config/avr/avr-c.c | 19 +++---------- gcc/config/avr/avr.c | 55 ++++++++++++++++++++++++++----------- gcc/config/avr/builtins.def | 34 +++++++++++------------ 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ee6b3f02f5c..d7816844a51 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2013-01-17 Georg-Johann Lay + + * config/avr/builtins.def (DEF_BUILTIN): Factor out + "__builtin_avr_" from NAME, turn NAME to an uppercase identifier. + Factor out 'CODE_FOR_' from ICODE, use 'nothing' instead of '-1'. + Remove ID. Adjust comments. + * config/avr/avr-c.c (avr_builtin_name): Remove. + (avr_cpu_cpp_builtins): Use DEF_BUILTIN instead of for-loop. + * config/avr/avr.c (avr_tolower): New static function. + (DEF_BUILTIN): Remove parameter ID. Prefix ICODE by 'CODE_FOR_'. + Stringify NAME, prefix it with "__builtin_avr_" and lowercase it. + (avr_expand_builtin): Assert insn_code != CODE_FOR_nothing for + default expansion. + 2013-01-17 Jan Hubicka PR tree-optimization/55273 diff --git a/gcc/config/avr/avr-c.c b/gcc/config/avr/avr-c.c index 2685f4b3d73..075d9ef791b 100644 --- a/gcc/config/avr/avr-c.c +++ b/gcc/config/avr/avr-c.c @@ -70,14 +70,6 @@ avr_toupper (char *up, const char *lo) /* Worker function for TARGET_CPU_CPP_BUILTINS. */ -static const char *const avr_builtin_name[] = - { -#define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) NAME, -#include "builtins.def" -#undef DEF_BUILTIN - NULL - }; - void avr_cpu_cpp_builtins (struct cpp_reader *pfile) { @@ -176,13 +168,10 @@ avr_cpu_cpp_builtins (struct cpp_reader *pfile) /* Define builtin macros so that the user can easily query whether or not a specific builtin is available. */ - for (i = 0; avr_builtin_name[i]; i++) - { - const char *name = avr_builtin_name[i]; - char *Name = (char*) alloca (1 + strlen (name)); - - cpp_define (pfile, avr_toupper (Name, name)); - } +#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE) \ + cpp_define (pfile, "__BUILTIN_AVR_" #NAME); +#include "builtins.def" +#undef DEF_BUILTIN /* Builtin macros for the __int24 and __uint24 type. */ diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c index 440ca690795..9c7f00aaae7 100644 --- a/gcc/config/avr/avr.c +++ b/gcc/config/avr/avr.c @@ -205,6 +205,22 @@ bool avr_need_clear_bss_p = false; bool avr_need_copy_data_p = false; +/* Transform UP into lowercase and write the result to LO. + You must provide enough space for LO. Return LO. */ + +static char* +avr_tolower (char *lo, const char *up) +{ + char *lo0 = lo; + + for (; *up; up++, lo++) + *lo = TOLOWER (*up); + + *lo = '\0'; + + return lo0; +} + /* Custom function to count number of set bits. */ @@ -11368,7 +11384,8 @@ avr_out_insert_bits (rtx *op, int *plen) enum avr_builtin_id { -#define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) ID, +#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE) \ + AVR_BUILTIN_ ## NAME, #include "builtins.def" #undef DEF_BUILTIN @@ -11378,7 +11395,6 @@ enum avr_builtin_id struct GTY(()) avr_builtin_description { enum insn_code icode; - const char *name; int n_args; tree fndecl; }; @@ -11391,9 +11407,8 @@ struct GTY(()) avr_builtin_description static GTY(()) struct avr_builtin_description avr_bdesc[AVR_BUILTIN_COUNT] = { - -#define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, ICODE) \ - { (enum insn_code) ICODE, NAME, N_ARGS, NULL_TREE }, +#define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE) \ + { (enum insn_code) CODE_FOR_ ## ICODE, N_ARGS, NULL_TREE }, #include "builtins.def" #undef DEF_BUILTIN }; @@ -11462,22 +11477,29 @@ avr_init_builtins (void) NULL_TREE); tree const_memx_void_node - = build_qualified_type (void_type_node, - TYPE_QUAL_CONST - | ENCODE_QUAL_ADDR_SPACE (ADDR_SPACE_MEMX)); + = build_qualified_type (void_type_node, + TYPE_QUAL_CONST + | ENCODE_QUAL_ADDR_SPACE (ADDR_SPACE_MEMX)); tree const_memx_ptr_type_node - = build_pointer_type_for_mode (const_memx_void_node, PSImode, false); + = build_pointer_type_for_mode (const_memx_void_node, PSImode, false); tree char_ftype_const_memx_ptr - = build_function_type_list (char_type_node, - const_memx_ptr_type_node, - NULL); + = build_function_type_list (char_type_node, + const_memx_ptr_type_node, + NULL); -#define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) \ - gcc_assert (ID < AVR_BUILTIN_COUNT); \ - avr_bdesc[ID].fndecl \ - = add_builtin_function (NAME, TYPE, ID, BUILT_IN_MD, NULL, NULL_TREE); +#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE) \ + { \ + int id = AVR_BUILTIN_ ## NAME; \ + const char *Name = "__builtin_avr_" #NAME; \ + char *name = (char*) alloca (1 + strlen (Name)); \ + \ + gcc_assert (id < AVR_BUILTIN_COUNT); \ + avr_bdesc[id].fndecl \ + = add_builtin_function (avr_tolower (name, Name), TYPE, id, \ + BUILT_IN_MD, NULL, NULL_TREE); \ + } #include "builtins.def" #undef DEF_BUILTIN @@ -11604,6 +11626,7 @@ avr_expand_builtin (tree exp, rtx target, /* No special treatment needed: vanilla expand. */ + gcc_assert (d->icode != CODE_FOR_nothing); gcc_assert (d->n_args == call_expr_nargs (exp)); if (d->n_args == 0) diff --git a/gcc/config/avr/builtins.def b/gcc/config/avr/builtins.def index d2675a5c32a..c8314acc767 100644 --- a/gcc/config/avr/builtins.def +++ b/gcc/config/avr/builtins.def @@ -20,35 +20,35 @@ builtins defined in the AVR part of the GNU compiler. Befor including this file, define a macro - DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, ICODE) + DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE) - NAME: The name as visible by the user as a C string. + NAME: `__builtin_avr_name' will be the user-level name of the builtin. + `AVR_BUILTIN_NAME' will be the internal builtin's id. N_ARGS: Number of input arguments. If special treatment is needed, set to -1 and handle it by hand, see avr.c:avr_expand_builtin(). - ID: An integer to identify the built-in. TYPE: A tree node describing the prototype of the built-in. - ICODE: Insn code number for the insn attached to the built-in. - If special treatment is needed to expand the built-in, set to -1. + ICODE: Name of attached insn or expander. If special treatment in avr.c + is needed to expand the built-in, use `nothing'. */ /* Mapped to respective instruction. */ -DEF_BUILTIN ("__builtin_avr_nop", -1, AVR_BUILTIN_NOP, void_ftype_void, -1) -DEF_BUILTIN ("__builtin_avr_sei", 0, AVR_BUILTIN_SEI, void_ftype_void, CODE_FOR_enable_interrupt) -DEF_BUILTIN ("__builtin_avr_cli", 0, AVR_BUILTIN_CLI, void_ftype_void, CODE_FOR_disable_interrupt) -DEF_BUILTIN ("__builtin_avr_wdr", 0, AVR_BUILTIN_WDR, void_ftype_void, CODE_FOR_wdr) -DEF_BUILTIN ("__builtin_avr_sleep", 0, AVR_BUILTIN_SLEEP, void_ftype_void, CODE_FOR_sleep) +DEF_BUILTIN (NOP, -1, void_ftype_void, nothing) +DEF_BUILTIN (SEI, 0, void_ftype_void, enable_interrupt) +DEF_BUILTIN (CLI, 0, void_ftype_void, disable_interrupt) +DEF_BUILTIN (WDR, 0, void_ftype_void, wdr) +DEF_BUILTIN (SLEEP, 0, void_ftype_void, sleep) /* Mapped to respective instruction but might also be folded away or emit as libgcc call if ISA does not provide the instruction. */ -DEF_BUILTIN ("__builtin_avr_swap", 1, AVR_BUILTIN_SWAP, uchar_ftype_uchar, CODE_FOR_rotlqi3_4) -DEF_BUILTIN ("__builtin_avr_fmul", 2, AVR_BUILTIN_FMUL, uint_ftype_uchar_uchar, CODE_FOR_fmul) -DEF_BUILTIN ("__builtin_avr_fmuls", 2, AVR_BUILTIN_FMULS, int_ftype_char_char, CODE_FOR_fmuls) -DEF_BUILTIN ("__builtin_avr_fmulsu", 2, AVR_BUILTIN_FMULSU, int_ftype_char_uchar, CODE_FOR_fmulsu) +DEF_BUILTIN (SWAP, 1, uchar_ftype_uchar, rotlqi3_4) +DEF_BUILTIN (FMUL, 2, uint_ftype_uchar_uchar, fmul) +DEF_BUILTIN (FMULS, 2, int_ftype_char_char, fmuls) +DEF_BUILTIN (FMULSU, 2, int_ftype_char_uchar, fmulsu) /* More complex stuff that cannot be mapped 1:1 to an instruction. */ -DEF_BUILTIN ("__builtin_avr_delay_cycles", -1, AVR_BUILTIN_DELAY_CYCLES, void_ftype_ulong, -1) -DEF_BUILTIN ("__builtin_avr_insert_bits", 3, AVR_BUILTIN_INSERT_BITS, uchar_ftype_ulong_uchar_uchar, CODE_FOR_insert_bits) -DEF_BUILTIN ("__builtin_avr_flash_segment", 1, AVR_BUILTIN_FLASH_SEGMENT, char_ftype_const_memx_ptr, CODE_FOR_flash_segment) +DEF_BUILTIN (DELAY_CYCLES, -1, void_ftype_ulong, nothing) +DEF_BUILTIN (INSERT_BITS, 3, uchar_ftype_ulong_uchar_uchar, insert_bits) +DEF_BUILTIN (FLASH_SEGMENT, 1, char_ftype_const_memx_ptr, flash_segment)