Patchwork [GOOGLE] backport r188371 to google-4_8

login
register
mail settings
Submitter Dehao Chen
Date April 25, 2013, 11:37 p.m.
Message ID <CAO2gOZVmLCwEymS3UoSLrCLuGq_WfjEHUxRTquqWFt3kKnDtXw@mail.gmail.com>
Download mbox | patch
Permalink /patch/239604/
State New
Headers show

Comments

Dehao Chen - April 25, 2013, 11:37 p.m.
The ported patch:

r188371 | dehao | 2012-06-09 18:44:58 -0700 (Sat, 09 Jun 2012) | 13 lines

2012-06-10  Dehao Chen  <dehao@google.com>

Backport r188303 from google-4_7
* gcc/cgraph.c (cgraph_node): Add attribute to function decl.
* gcc/opts-global.c (add_attribute_pattern): New function.
(pattern_match_function_attributes): New function.
(handle_common_deferred_options): Handle new options.
* gcc/opts.c (common_handle_option): Handle new options.
* gcc/opts.h (handle_common_deferred_options): New function.
* gcc/common.opt (ffunction_attribute_list): New option.

The new patch:

bootstrapped and passed regression test.

Is it ok for google-4_8 branch?

Thanks,
Dehao
Xinliang David Li - April 25, 2013, 11:41 p.m.
ok.

David

On Thu, Apr 25, 2013 at 4:37 PM, Dehao Chen <dehao@google.com> wrote:
> The ported patch:
>
> r188371 | dehao | 2012-06-09 18:44:58 -0700 (Sat, 09 Jun 2012) | 13 lines
>
> 2012-06-10  Dehao Chen  <dehao@google.com>
>
> Backport r188303 from google-4_7
> * gcc/cgraph.c (cgraph_node): Add attribute to function decl.
> * gcc/opts-global.c (add_attribute_pattern): New function.
> (pattern_match_function_attributes): New function.
> (handle_common_deferred_options): Handle new options.
> * gcc/opts.c (common_handle_option): Handle new options.
> * gcc/opts.h (handle_common_deferred_options): New function.
> * gcc/common.opt (ffunction_attribute_list): New option.
>
> The new patch:
>
> bootstrapped and passed regression test.
>
> Is it ok for google-4_8 branch?
>
> Thanks,
> Dehao
>
> Index: gcc/doc/invoke.texi
> ===================================================================
> --- gcc/doc/invoke.texi (revision 198322)
> +++ gcc/doc/invoke.texi (working copy)
> @@ -369,7 +369,8 @@ Objective-C and Objective-C++ Dialects}.
>  -fdelete-null-pointer-checks -fdevirtualize -fdse @gol
>  -fearly-inlining -fipa-sra -fexpensive-optimizations -ffat-lto-objects @gol
>  -ffast-math -ffinite-math-only -ffloat-store
> -fexcess-precision=@var{style} @gol
> --fforward-propagate -ffp-contract=@var{style} -ffunction-sections @gol
> +-fforward-propagate -ffp-contract=@var{style} @gol
> +-ffunction-attribute-list -ffunction-sections @gol
>  -fgcse -fgcse-after-reload -fgcse-las -fgcse-lm -fgraphite-identity @gol
>  -fgcse-sm -fhoist-adjacent-loads -fif-conversion @gol
>  -fif-conversion2 -findirect-inlining @gol
> @@ -9064,6 +9065,15 @@ You cannot use @code{gprof} on all systems if you
>  specify this option, and you may have problems with debugging if
>  you specify both this option and @option{-g}.
>
> +@item -ffunction-attribute-list
> +@opindex ffunction-attribute-list
> +List of function name patterns that will be applied specified attribute.
> +For example, the following command line will add "cold" attribute to
> +functions that has "ErrorMessage" in its name.
> +@smallexample
> +gcc -ffunction-atribute-list=cold:ErrorMessage -c foo.c
> +@end smallexample
> +
>  @item -fbranch-target-load-optimize
>  @opindex fbranch-target-load-optimize
>  Perform branch target register load optimization before prologue / epilogue
> Index: gcc/common.opt
> ===================================================================
> --- gcc/common.opt (revision 198322)
> +++ gcc/common.opt (working copy)
> @@ -1267,6 +1267,10 @@ Enum(fp_contract_mode) String(on) Value(FP_CONTRAC
>  EnumValue
>  Enum(fp_contract_mode) String(fast) Value(FP_CONTRACT_FAST)
>
> +ffunction-attribute-list=
> +Common Joined RejectNegative Var(common_deferred_options) Defer
> +-ffunction-attribute-list=attribute:name,...  Add attribute to named functions
> +
>  ; Nonzero means don't put addresses of constant functions in registers.
>  ; Used for compiling the Unix kernel, where strange substitutions are
>  ; done on the assembly output.
> Index: gcc/cgraph.c
> ===================================================================
> --- gcc/cgraph.c (revision 198322)
> +++ gcc/cgraph.c (working copy)
> @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "ipa-inline.h"
>  #include "cfgloop.h"
>  #include "gimple-pretty-print.h"
> +#include "opts.h"
>
>  /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know
> about this.  */
>  #include "tree-pass.h"
> @@ -535,6 +536,7 @@ cgraph_create_node (tree decl)
>        node->next_nested = node->origin->nested;
>        node->origin->nested = node;
>      }
> +  pattern_match_function_attributes (decl);
>    return node;
>  }
>
> Index: gcc/opts-global.c
> ===================================================================
> --- gcc/opts-global.c (revision 198322)
> +++ gcc/opts-global.c (working copy)
> @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tree-pass.h"
>  #include "params.h"
>  #include "l-ipo.h"
> +#include "xregex.h"
>
>  typedef const char *const_char_p; /* For DEF_VEC_P.  */
>
> @@ -47,6 +48,13 @@ static vec<const_char_p> ignored_options;
>  const char **in_fnames;
>  unsigned num_in_fnames;
>
> +static struct reg_func_attr_patterns
> +{
> +  regex_t r;
> +  const char *attribute;
> +  struct reg_func_attr_patterns *next;
> +} *reg_func_attr_patterns;
> +
>  /* Return a malloced slash-separated list of languages in MASK.  */
>
>  static char *
> @@ -76,6 +84,62 @@ write_langs (unsigned int mask)
>    return result;
>  }
>
> +/* Add strings like attribute_str:pattern... to attribute pattern list.  */
> +
> +static void
> +add_attribute_pattern (const char *arg)
> +{
> +  char *tmp;
> +  char *pattern_str;
> +  struct reg_func_attr_patterns *one_pat;
> +  int ec;
> +
> +  /* We never free this string.  */
> +  tmp = xstrdup (arg);
> +
> +  pattern_str = strchr (tmp, ':');
> +  if (!pattern_str)
> +    error ("invalid pattern in -ffunction-attribute-list option: %qs", tmp);
> +
> +  *pattern_str = '\0';
> +  pattern_str ++;
> +
> +  one_pat = XCNEW (struct reg_func_attr_patterns);
> +  one_pat->next = reg_func_attr_patterns;
> +  one_pat->attribute = tmp;
> +  reg_func_attr_patterns = one_pat;
> +  if ((ec= regcomp (&one_pat->r, pattern_str, REG_EXTENDED|REG_NOSUB) != 0))
> +    {
> +      char err[100];
> +      regerror (ec, &one_pat->r, err, 99);
> +      error ("invalid pattern in -ffunction-attribute-list option: %qs: %qs",
> +     pattern_str, err);
> +    }
> +}
> +
> +/* Match FNDECL's name with user specified patterns, and add attributes
> +   to FNDECL.  */
> +
> +void
> +pattern_match_function_attributes (tree fndecl)
> +{
> +  const char *name;
> +  struct reg_func_attr_patterns *one_pat;
> +
> +  if (!fndecl)
> +    return;
> +
> +  if (!reg_func_attr_patterns)
> +    return;
> +
> +  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
> +
> +  for (one_pat = reg_func_attr_patterns; one_pat; one_pat = one_pat->next)
> +    if (regexec (&one_pat->r, name, 0, NULL, 0) == 0)
> +      decl_attributes (&fndecl, tree_cons (
> +  get_identifier (one_pat->attribute), NULL, NULL), 0);
> +}
> +
>  /* Complain that switch DECODED does not apply to this front end (mask
>     LANG_MASK).  */
>
> @@ -477,6 +541,10 @@ handle_common_deferred_options (void)
>    set_random_seed (opt->arg);
>    break;
>
> + case OPT_ffunction_attribute_list_:
> +  add_attribute_pattern (opt->arg);
> +  break;
> +
>   case OPT_fstack_limit:
>    /* The real switch is -fno-stack-limit.  */
>    if (!opt->value)
> Index: gcc/opts.c
> ===================================================================
> --- gcc/opts.c (revision 198322)
> +++ gcc/opts.c (working copy)
> @@ -1648,6 +1648,10 @@ common_handle_option (struct gcc_options *opts,
>        /* Deferred.  */
>        break;
>
> +    case OPT_ffunction_attribute_list_:
> +      /* Deferred.  */
> +      break;
> +
>      case OPT_fsched_verbose_:
>  #ifdef INSN_SCHEDULING
>        /* Handled with Var in common.opt.  */
> Index: gcc/opts.h
> ===================================================================
> --- gcc/opts.h (revision 198322)
> +++ gcc/opts.h (working copy)
> @@ -415,4 +415,5 @@ extern void set_struct_debug_option (struct gcc_op
>  extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
>     int *value, unsigned int lang_mask);
>  extern void write_opts_to_asm (void);
> +extern void pattern_match_function_attributes (tree);
>  #endif

Patch

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 198322)
+++ gcc/doc/invoke.texi (working copy)
@@ -369,7 +369,8 @@  Objective-C and Objective-C++ Dialects}.
 -fdelete-null-pointer-checks -fdevirtualize -fdse @gol
 -fearly-inlining -fipa-sra -fexpensive-optimizations -ffat-lto-objects @gol
 -ffast-math -ffinite-math-only -ffloat-store
-fexcess-precision=@var{style} @gol
--fforward-propagate -ffp-contract=@var{style} -ffunction-sections @gol
+-fforward-propagate -ffp-contract=@var{style} @gol
+-ffunction-attribute-list -ffunction-sections @gol
 -fgcse -fgcse-after-reload -fgcse-las -fgcse-lm -fgraphite-identity @gol
 -fgcse-sm -fhoist-adjacent-loads -fif-conversion @gol
 -fif-conversion2 -findirect-inlining @gol
@@ -9064,6 +9065,15 @@  You cannot use @code{gprof} on all systems if you
 specify this option, and you may have problems with debugging if
 you specify both this option and @option{-g}.

+@item -ffunction-attribute-list
+@opindex ffunction-attribute-list
+List of function name patterns that will be applied specified attribute.
+For example, the following command line will add "cold" attribute to
+functions that has "ErrorMessage" in its name.
+@smallexample
+gcc -ffunction-atribute-list=cold:ErrorMessage -c foo.c
+@end smallexample
+
 @item -fbranch-target-load-optimize
 @opindex fbranch-target-load-optimize
 Perform branch target register load optimization before prologue / epilogue
Index: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 198322)
+++ gcc/common.opt (working copy)
@@ -1267,6 +1267,10 @@  Enum(fp_contract_mode) String(on) Value(FP_CONTRAC
 EnumValue
 Enum(fp_contract_mode) String(fast) Value(FP_CONTRACT_FAST)

+ffunction-attribute-list=
+Common Joined RejectNegative Var(common_deferred_options) Defer
+-ffunction-attribute-list=attribute:name,...  Add attribute to named functions
+
 ; Nonzero means don't put addresses of constant functions in registers.
 ; Used for compiling the Unix kernel, where strange substitutions are
 ; done on the assembly output.
Index: gcc/cgraph.c
===================================================================
--- gcc/cgraph.c (revision 198322)
+++ gcc/cgraph.c (working copy)
@@ -53,6 +53,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "ipa-inline.h"
 #include "cfgloop.h"
 #include "gimple-pretty-print.h"
+#include "opts.h"

 /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know
about this.  */
 #include "tree-pass.h"
@@ -535,6 +536,7 @@  cgraph_create_node (tree decl)
       node->next_nested = node->origin->nested;
       node->origin->nested = node;
     }
+  pattern_match_function_attributes (decl);
   return node;
 }

Index: gcc/opts-global.c
===================================================================
--- gcc/opts-global.c (revision 198322)
+++ gcc/opts-global.c (working copy)
@@ -38,6 +38,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "params.h"
 #include "l-ipo.h"
+#include "xregex.h"

 typedef const char *const_char_p; /* For DEF_VEC_P.  */

@@ -47,6 +48,13 @@  static vec<const_char_p> ignored_options;
 const char **in_fnames;
 unsigned num_in_fnames;

+static struct reg_func_attr_patterns
+{
+  regex_t r;
+  const char *attribute;
+  struct reg_func_attr_patterns *next;
+} *reg_func_attr_patterns;
+
 /* Return a malloced slash-separated list of languages in MASK.  */

 static char *
@@ -76,6 +84,62 @@  write_langs (unsigned int mask)
   return result;
 }

+/* Add strings like attribute_str:pattern... to attribute pattern list.  */
+
+static void
+add_attribute_pattern (const char *arg)
+{
+  char *tmp;
+  char *pattern_str;
+  struct reg_func_attr_patterns *one_pat;
+  int ec;
+
+  /* We never free this string.  */
+  tmp = xstrdup (arg);
+
+  pattern_str = strchr (tmp, ':');
+  if (!pattern_str)
+    error ("invalid pattern in -ffunction-attribute-list option: %qs", tmp);
+
+  *pattern_str = '\0';
+  pattern_str ++;
+
+  one_pat = XCNEW (struct reg_func_attr_patterns);
+  one_pat->next = reg_func_attr_patterns;
+  one_pat->attribute = tmp;
+  reg_func_attr_patterns = one_pat;
+  if ((ec= regcomp (&one_pat->r, pattern_str, REG_EXTENDED|REG_NOSUB) != 0))
+    {
+      char err[100];
+      regerror (ec, &one_pat->r, err, 99);
+      error ("invalid pattern in -ffunction-attribute-list option: %qs: %qs",
+     pattern_str, err);
+    }
+}
+
+/* Match FNDECL's name with user specified patterns, and add attributes
+   to FNDECL.  */
+
+void
+pattern_match_function_attributes (tree fndecl)
+{
+  const char *name;
+  struct reg_func_attr_patterns *one_pat;
+
+  if (!fndecl)
+    return;
+
+  if (!reg_func_attr_patterns)
+    return;
+
+  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
+
+  for (one_pat = reg_func_attr_patterns; one_pat; one_pat = one_pat->next)
+    if (regexec (&one_pat->r, name, 0, NULL, 0) == 0)
+      decl_attributes (&fndecl, tree_cons (
+  get_identifier (one_pat->attribute), NULL, NULL), 0);
+}
+
 /* Complain that switch DECODED does not apply to this front end (mask
    LANG_MASK).  */

@@ -477,6 +541,10 @@  handle_common_deferred_options (void)
   set_random_seed (opt->arg);
   break;

+ case OPT_ffunction_attribute_list_:
+  add_attribute_pattern (opt->arg);
+  break;
+
  case OPT_fstack_limit:
   /* The real switch is -fno-stack-limit.  */
   if (!opt->value)
Index: gcc/opts.c
===================================================================
--- gcc/opts.c (revision 198322)
+++ gcc/opts.c (working copy)
@@ -1648,6 +1648,10 @@  common_handle_option (struct gcc_options *opts,
       /* Deferred.  */
       break;

+    case OPT_ffunction_attribute_list_:
+      /* Deferred.  */
+      break;
+
     case OPT_fsched_verbose_:
 #ifdef INSN_SCHEDULING
       /* Handled with Var in common.opt.  */
Index: gcc/opts.h
===================================================================
--- gcc/opts.h (revision 198322)
+++ gcc/opts.h (working copy)
@@ -415,4 +415,5 @@  extern void set_struct_debug_option (struct gcc_op
 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
    int *value, unsigned int lang_mask);
 extern void write_opts_to_asm (void);
+extern void pattern_match_function_attributes (tree);
 #endif