From: James Greenhalgh Date: Mon, 22 Apr 2013 14:50:32 +0000 (+0000) Subject: [Mid-end] Add TARGET_GIMPLE_FOLD_BUILTIN target hook. X-Git-Tag: releases/gcc-4.9.0~6334 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea679d553f0c8791b2df470c138c6505a3be1cfc;p=thirdparty%2Fgcc.git [Mid-end] Add TARGET_GIMPLE_FOLD_BUILTIN target hook. gcc/ * coretypes.h (gimple_stmt_iterator_d): Forward declare. (gimple_stmt_iterator): New typedef. * gimple.h (gimple_stmt_iterator): Rename to... (gimple_stmt_iterator_d): ... This. * doc/tm.texi.in (TARGET_FOLD_BUILTIN): Detail restriction that trees be valid for GIMPLE and GENERIC. (TARGET_GIMPLE_FOLD_BUILTIN): New. * gimple-fold.c (gimple_fold_call): Call target hook gimple_fold_builtin. * hooks.c (hook_bool_gsiptr_false): New. * hooks.h (hook_bool_gsiptr_false): New. * target.def (fold_stmt): New. * doc/tm.texi: Regenerate. From-SVN: r198142 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3e930b47039a..6932a535fd69 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2013-04-22 James Greenhalgh + + * coretypes.h (gimple_stmt_iterator_d): Forward declare. + (gimple_stmt_iterator): New typedef. + * gimple.h (gimple_stmt_iterator): Rename to... + (gimple_stmt_iterator_d): ... This. + * doc/tm.texi.in (TARGET_FOLD_BUILTIN): Detail restriction that + trees be valid for GIMPLE and GENERIC. + (TARGET_GIMPLE_FOLD_BUILTIN): New. + * gimple-fold.c (gimple_fold_call): Call target hook + gimple_fold_builtin. + * hooks.c (hook_bool_gsiptr_false): New. + * hooks.h (hook_bool_gsiptr_false): New. + * target.def (fold_stmt): New. + * doc/tm.texi: Regenerate. + 2013-04-22 Vladimir Makarov PR target/57018 diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 320b4dd5d605..76fc4aabc8ad 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -62,6 +62,8 @@ union gimple_statement_d; typedef union gimple_statement_d *gimple; typedef const union gimple_statement_d *const_gimple; typedef gimple gimple_seq; +struct gimple_stmt_iterator_d; +typedef gimple_stmt_iterator_d gimple_stmt_iterator; union section; typedef union section section; struct gcc_options; diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index c88a89f28c3a..ec7ef758086f 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10931,8 +10931,16 @@ Fold a call to a machine specific built-in function that was set up by @samp{TARGET_INIT_BUILTINS}. @var{fndecl} is the declaration of the built-in function. @var{n_args} is the number of arguments passed to the function; the arguments themselves are pointed to by @var{argp}. -The result is another tree containing a simplified expression for the -call's result. If @var{ignore} is true the value will be ignored. +The result is another tree, valid for both GIMPLE and GENERIC, +containing a simplified expression for the call's result. If +@var{ignore} is true the value will be ignored. +@end deftypefn + +@deftypefn {Target Hook} bool TARGET_GIMPLE_FOLD_BUILTIN (gimple_stmt_iterator *@var{gsi}) +Fold a call to a machine specific built-in function that was set up +by @samp{TARGET_INIT_BUILTINS}. @var{gsi} points to the gimple +statement holding the function call. Returns true if any change +was made to the GIMPLE stream. @end deftypefn @deftypefn {Target Hook} int TARGET_COMPARE_VERSION_PRIORITY (tree @var{decl1}, tree @var{decl2}) diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index d70ce4cfd369..a4187335b627 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -10775,10 +10775,13 @@ Fold a call to a machine specific built-in function that was set up by @samp{TARGET_INIT_BUILTINS}. @var{fndecl} is the declaration of the built-in function. @var{n_args} is the number of arguments passed to the function; the arguments themselves are pointed to by @var{argp}. -The result is another tree containing a simplified expression for the -call's result. If @var{ignore} is true the value will be ignored. +The result is another tree, valid for both GIMPLE and GENERIC, +containing a simplified expression for the call's result. If +@var{ignore} is true the value will be ignored. @end deftypefn +@hook TARGET_GIMPLE_FOLD_BUILTIN + @hook TARGET_COMPARE_VERSION_PRIORITY This hook is used to compare the target attributes in two functions to determine which function's features get higher priority. This is used diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index b9211a9add27..738d7fddd4c9 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -1143,6 +1143,8 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) gimplify_and_update_call_from_tree (gsi, result); changed = true; } + else if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_MD) + changed |= targetm.gimple_fold_builtin (gsi); } return changed; diff --git a/gcc/gimple.h b/gcc/gimple.h index 3a65e3ccace7..76da6d2bcd7d 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -139,7 +139,7 @@ enum plf_mask { /* Iterator object for GIMPLE statement sequences. */ -typedef struct +struct gimple_stmt_iterator_d { /* Sequence node holding the current statement. */ gimple_seq_node ptr; @@ -150,8 +150,7 @@ typedef struct block/sequence is removed. */ gimple_seq *seq; basic_block bb; -} gimple_stmt_iterator; - +}; /* Data structure definitions for GIMPLE tuples. NOTE: word markers are for 64 bit hosts. */ diff --git a/gcc/hooks.c b/gcc/hooks.c index 3b54dfa5430d..3259658e4f4f 100644 --- a/gcc/hooks.c +++ b/gcc/hooks.c @@ -147,6 +147,14 @@ hook_bool_FILEptr_rtx_false (FILE *a ATTRIBUTE_UNUSED, return false; } +/* Generic hook that takes (gimple_stmt_iterator *) and returns + false. */ +bool +hook_bool_gsiptr_false (gimple_stmt_iterator *a ATTRIBUTE_UNUSED) +{ + return false; +} + /* Used for the TARGET_ASM_CAN_OUTPUT_MI_THUNK hook. */ bool hook_bool_const_tree_hwi_hwi_const_tree_false (const_tree a ATTRIBUTE_UNUSED, diff --git a/gcc/hooks.h b/gcc/hooks.h index 50bcc6afc7e8..eaf4b03ebbb9 100644 --- a/gcc/hooks.h +++ b/gcc/hooks.h @@ -42,6 +42,7 @@ extern bool hook_bool_tree_false (tree); extern bool hook_bool_const_tree_false (const_tree); extern bool hook_bool_tree_true (tree); extern bool hook_bool_const_tree_true (const_tree); +extern bool hook_bool_gsiptr_false (gimple_stmt_iterator *); extern bool hook_bool_const_tree_hwi_hwi_const_tree_false (const_tree, HOST_WIDE_INT, HOST_WIDE_INT, diff --git a/gcc/target.def b/gcc/target.def index db742732e340..a8306b258897 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -1289,13 +1289,24 @@ DEFHOOK "", tree, (unsigned int /*location_t*/ loc, tree fndecl, void *arglist), NULL) -/* Fold a target-specific builtin. */ +/* Fold a target-specific builtin to a tree valid for both GIMPLE + and GENERIC. */ DEFHOOK (fold_builtin, "", tree, (tree fndecl, int n_args, tree *argp, bool ignore), hook_tree_tree_int_treep_bool_null) +/* Fold a target-specific builtin to a valid GIMPLE tree. */ +DEFHOOK +(gimple_fold_builtin, + "Fold a call to a machine specific built-in function that was set up\n\ +by @samp{TARGET_INIT_BUILTINS}. @var{gsi} points to the gimple\n\ +statement holding the function call. Returns true if any change\n\ +was made to the GIMPLE stream.", + bool, (gimple_stmt_iterator *gsi), + hook_bool_gsiptr_false) + /* Target hook is used to compare the target attributes in two functions to determine which function's features get higher priority. This is used during function multi-versioning to figure out the order in which two