Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5537)

Issue 6281047: Add flag to enable function pattern match for attributes

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 11 months ago by dehao
Modified:
11 years, 11 months ago
Reviewers:
davidxl
Base URL:
svn+ssh://gcc.gnu.org/svn/gcc/branches/google/gcc-4_6/gcc/
Visibility:
Public.

Description

Add flag to enable function pattern match for attributes

Patch Set 1 #

Patch Set 2 : Using RE to do the matching #

Total comments: 2

Patch Set 3 : add examples to doc #

Unified diffs Side-by-side diffs Delta from patch set Stats (+100 lines, -1 line) Patch
M gcc/ChangeLog.google-4_6 View 1 1 chunk +10 lines, -0 lines 0 comments Download
M gcc/cgraph.c View 1 2 chunks +2 lines, -0 lines 0 comments Download
M gcc/common.opt View 1 1 chunk +4 lines, -0 lines 0 comments Download
M gcc/doc/invoke.texi View 1 2 2 chunks +11 lines, -1 line 0 comments Download
M gcc/opts.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M gcc/opts.c View 1 1 chunk +4 lines, -0 lines 0 comments Download
M gcc/opts-global.c View 1 4 chunks +68 lines, -0 lines 0 comments Download

Messages

Total messages: 3
davidxl
http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c File gcc/opts-global.c (right): http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c#newcode144 gcc/opts-global.c:144: } Also needs to call into the attribute handler ...
11 years, 11 months ago (2012-06-06 04:55:29 UTC) #1
dehao
Example added in invoke.texi Thanks, Dehao http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c File gcc/opts-global.c (right): http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c#newcode144 gcc/opts-global.c:144: } On 2012/06/06 ...
11 years, 11 months ago (2012-06-06 11:22:35 UTC) #2
davidxl
11 years, 11 months ago (2012-06-07 00:23:23 UTC) #3
ok -- good for google branches.

thanks,

David

On Wed, Jun 6, 2012 at 4:22 AM,  <dehao@google.com> wrote:
> Reviewers: davidxl,
>
> Message:
> Example added in invoke.texi
>
> Thanks,
> Dehao
>
>
>
> http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c
> File gcc/opts-global.c (right):
>
> http://codereview.appspot.com/6281047/diff/2001/gcc/opts-global.c#newcode144
> gcc/opts-global.c:144: }
> On 2012/06/06 04:55:29, davidxl wrote:
>>
>> Also needs to call into the attribute handler -- because some
>
> attributes are
>>
>> 'folded' into other attribute bits.
>
>
>> 1) spec = lookup_attribute_spec (...)
>> 2)  (spec->handler)(...)
>
>
> Looks like these are already invoked in decl_attributes...
>
> Example added in invoke.texi
>
> Description:
> Add flag to enable function pattern match for attributes
>
> Please review this at http://codereview.appspot.com/6281047/
>
> Affected files:
>  M     gcc/ChangeLog.google-4_6
>  M     gcc/cgraph.c
>  M     gcc/common.opt
>  M     gcc/doc/invoke.texi
>  M     gcc/opts-global.c
>  M     gcc/opts.c
>  M     gcc/opts.h
>
>
> Index: gcc/doc/invoke.texi
> ===================================================================
> --- gcc/doc/invoke.texi (revision 188050)
> +++ gcc/doc/invoke.texi (working copy)
> @@ -362,7 +362,8 @@
>  -fdelete-null-pointer-checks -fdse -fdevirtualize -fdse @gol
>  -fearly-inlining -fipa-sra -fexpensive-optimizations -ffast-math @gol
>  -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 -fif-conversion -fif-conversion2 -findirect-inlining @gol
>  -finline-functions -finline-functions-called-once -finline-limit=@var{n}
> @gol
> @@ -8585,6 +8586,10 @@
>  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.
> +
>  @item -fbranch-target-load-optimize
>  @opindex fbranch-target-load-optimize
>  Perform branch target register load optimization before prologue / epilogue
> Index: gcc/cgraph.c
> ===================================================================
> --- gcc/cgraph.c        (revision 188050)
> +++ gcc/cgraph.c        (working copy)
> @@ -99,6 +99,7 @@
>  #include "ipa-utils.h"
>  #include "lto-streamer.h"
>  #include "l-ipo.h"
> +#include "opts.h"
>
>  const char * const ld_plugin_symbol_resolution_names[]=
>  {
> @@ -554,6 +555,7 @@
>       node->origin->nested = node;
>     }
>   cgraph_add_assembler_hash_node (node);
> +  pattern_match_function_attributes (decl);
>   return node;
>  }
>
> Index: gcc/opts.c
> ===================================================================
> --- gcc/opts.c  (revision 188050)
> +++ gcc/opts.c  (working copy)
> @@ -1647,6 +1647,10 @@
>       /* 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 188050)
> +++ gcc/opts.h  (working copy)
> @@ -382,4 +382,5 @@
>                                     location_t loc,
>                                     const char *value);
>  extern void write_opts_to_asm (void);
> +extern void pattern_match_function_attributes (tree);
>  #endif
> Index: gcc/ChangeLog.google-4_6
> ===================================================================
> --- gcc/ChangeLog.google-4_6    (revision 188050)
> +++ gcc/ChangeLog.google-4_6    (working copy)
> @@ -1,3 +1,13 @@
> +2012-06-01  Dehao Chen  <dehao@google.com>
> +
> +       * 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.
> +
>  2012-05-30   Cary Coutant  <ccoutant@google.com>
>
>        * gcc/dwarf2out.c (index_location_lists): Don't index location
> Index: gcc/common.opt
> ===================================================================
> --- gcc/common.opt      (revision 188050)
> +++ gcc/common.opt      (working copy)
> @@ -1242,6 +1242,10 @@
>  Common Report Var(flag_function_sections)
>  Place each function into its own section
>
> +ffunction-attribute-list=
> +Common Joined RejectNegative Var(common_deferred_options) Defer
> +-ffunction-attribute-list=attribute:name,...  Add attribute to named
> functions
> +
>  fgcda=
>  Common Joined RejectNegative Var(gcov_da_name)
>  Set the gcov data file name.
> Index: gcc/opts-global.c
> ===================================================================
> --- gcc/opts-global.c   (revision 188050)
> +++ gcc/opts-global.c   (working copy)
> @@ -39,6 +39,7 @@
>  #include "tree-pass.h"
>  #include "params.h"
>  #include "l-ipo.h"
> +#include "xregex.h"
>
>  typedef const char *const_char_p; /* For DEF_VEC_P.  */
>  DEF_VEC_P(const_char_p);
> @@ -50,6 +51,13 @@
>  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 *
> @@ -79,6 +87,62 @@
>   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).  */
>
> @@ -452,6 +516,10 @@
>          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)
>
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b