public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Dump function attributes
@ 2015-09-28 15:07 Tom de Vries
  2015-09-28 15:56 ` Bernd Schmidt
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-09-28 15:07 UTC (permalink / raw)
  To: gcc-patches

Hi,

patch below prints the function attributes in the dump file.

Say we mark a function foo with attributes noinline and noclone like this:
...
int __attribute__((noinline, noclone))
foo (void)
...

Then using this patch, we find in the dump file:
...
;; Function foo (foo, funcdef_no=10, decl_uid=2455, cgraph_uid=10, 
symbol_order=10)

Pass statistics of <pass>: ----------------

foo ()
[ noclone , noinline ]
{
...

Good idea?

If so, do we want one attribute per line?

Thanks,
- Tom

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index cd7a4b4..c724fde 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7384,6 +7384,13 @@ dump_function_to_file (tree fndecl, FILE *file, 
int flags)
      }
    fprintf (file, ")\n");

+  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
+    {
+      fprintf (file, "[ ");
+      print_generic_expr (file, DECL_ATTRIBUTES (fndecl), dump_flags);
+      fprintf (file, "]\n");
+    }
+
    if (flags & TDF_VERBOSE)
      print_node (file, "", fndecl, 2);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Dump function attributes
  2015-09-28 15:07 [RFC] Dump function attributes Tom de Vries
@ 2015-09-28 15:56 ` Bernd Schmidt
  2015-09-29  7:01   ` [patch, committed] " Tom de Vries
  0 siblings, 1 reply; 8+ messages in thread
From: Bernd Schmidt @ 2015-09-28 15:56 UTC (permalink / raw)
  To: Tom de Vries, gcc-patches

On 09/28/2015 04:32 PM, Tom de Vries wrote:
> patch below prints the function attributes in the dump file.

> foo ()
> [ noclone , noinline ]
> {
> ...
>
> Good idea?
>
> If so, do we want one attribute per line?

Only for really long ones I'd think. Patch is ok for now.


Bernd

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch, committed] Dump function attributes
  2015-09-28 15:56 ` Bernd Schmidt
@ 2015-09-29  7:01   ` Tom de Vries
  2015-09-29 11:29     ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-09-29  7:01 UTC (permalink / raw)
  To: Bernd Schmidt, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

[ was: Re: [RFC] Dump function attributes ]

On 28/09/15 17:17, Bernd Schmidt wrote:
> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>> patch below prints the function attributes in the dump file.
>
>> foo ()
>> [ noclone , noinline ]
>> {
>> ...
>>
>> Good idea?
>>
>> If so, do we want one attribute per line?
>
> Only for really long ones I'd think. Patch is ok for now.
>
>

Reposting patch with ChangeLog entry added.

Bootstrapped and reg-tested on x86_64.

Committed to trunk.

Thanks,
- Tom

[-- Attachment #2: 0001-Dump-function-attributes.patch --]
[-- Type: text/x-patch, Size: 714 bytes --]

Dump function attributes

2015-09-29  Tom de Vries  <tom@codesourcery.com>

	* tree-cfg.c (dump_function_to_file): Dump function attributes.
---
 gcc/tree-cfg.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 807d96f..08935ac 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7369,6 +7369,13 @@ dump_function_to_file (tree fndecl, FILE *file, int flags)
     }
   fprintf (file, ")\n");
 
+  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
+    {
+      fprintf (file, "[ ");
+      print_generic_expr (file, DECL_ATTRIBUTES (fndecl), dump_flags);
+      fprintf (file, "]\n");
+    }
+
   if (flags & TDF_VERBOSE)
     print_node (file, "", fndecl, 2);
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch, committed] Dump function attributes
  2015-09-29  7:01   ` [patch, committed] " Tom de Vries
@ 2015-09-29 11:29     ` Richard Biener
  2015-09-29 11:41       ` Tom de Vries
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2015-09-29 11:29 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Bernd Schmidt, gcc-patches

On Tue, Sep 29, 2015 at 7:43 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> [ was: Re: [RFC] Dump function attributes ]
>
> On 28/09/15 17:17, Bernd Schmidt wrote:
>>
>> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>>>
>>> patch below prints the function attributes in the dump file.
>>
>>
>>> foo ()
>>> [ noclone , noinline ]
>>> {
>>> ...
>>>
>>> Good idea?
>>>
>>> If so, do we want one attribute per line?
>>
>>
>> Only for really long ones I'd think. Patch is ok for now.
>>
>>
>
> Reposting patch with ChangeLog entry added.
>
> Bootstrapped and reg-tested on x86_64.
>
> Committed to trunk.

Hmpf.  I always like to make the dump-files as much copy&past-able to testcases
as possible.  So why did you invent a new syntax for attributes instead of using
the existing __attribute__(("noclone", "noinline")) (in this case)?
Did you verify
how attributes with arguments get printed?

Thanks,
Richard.

>
> Thanks,
> - Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch, committed] Dump function attributes
  2015-09-29 11:29     ` Richard Biener
@ 2015-09-29 11:41       ` Tom de Vries
  2015-09-29 11:42         ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-09-29 11:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: Bernd Schmidt, gcc-patches

On 29/09/15 12:36, Richard Biener wrote:
> On Tue, Sep 29, 2015 at 7:43 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> [ was: Re: [RFC] Dump function attributes ]
>>
>> On 28/09/15 17:17, Bernd Schmidt wrote:
>>>
>>> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>>>>
>>>> patch below prints the function attributes in the dump file.
>>>
>>>
>>>> foo ()
>>>> [ noclone , noinline ]
>>>> {
>>>> ...
>>>>
>>>> Good idea?
>>>>
>>>> If so, do we want one attribute per line?
>>>
>>>
>>> Only for really long ones I'd think. Patch is ok for now.
>>>
>>>
>>
>> Reposting patch with ChangeLog entry added.
>>
>> Bootstrapped and reg-tested on x86_64.
>>
>> Committed to trunk.
>
> Hmpf.  I always like to make the dump-files as much copy&past-able to testcases
> as possible.

Hmm, interesting. Not something I use, but I can imagine it's useful.

> So why did you invent a new syntax for attributes instead of using
> the existing __attribute__(("noclone", "noinline")) (in this case)?

My main concerns were:
- being able to see in dump files what the actual attributes of a
   function are (rather than having to figure it out in a debug session).
- being able to write testcases that can test for the presence of those
   attributes in dump files

> Did you verify
> how attributes with arguments get printed?

F.i. an oacc offload function compiled by the host compiler is annotated 
as follows:

before pass_oacc_transform (in the gomp-4_0-branch):
...
[ oacc function 32, , , omp target entrypoint ]
...

after pass_oacc_transform:
....
[ oacc function 1, 1, 1, omp target entrypoint ]
...

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch, committed] Dump function attributes
  2015-09-29 11:41       ` Tom de Vries
@ 2015-09-29 11:42         ` Richard Biener
  2015-09-30 10:41           ` Tom de Vries
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2015-09-29 11:42 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Bernd Schmidt, gcc-patches

On Tue, Sep 29, 2015 at 1:23 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> On 29/09/15 12:36, Richard Biener wrote:
>>
>> On Tue, Sep 29, 2015 at 7:43 AM, Tom de Vries <Tom_deVries@mentor.com>
>> wrote:
>>>
>>> [ was: Re: [RFC] Dump function attributes ]
>>>
>>> On 28/09/15 17:17, Bernd Schmidt wrote:
>>>>
>>>>
>>>> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>>>>>
>>>>>
>>>>> patch below prints the function attributes in the dump file.
>>>>
>>>>
>>>>
>>>>> foo ()
>>>>> [ noclone , noinline ]
>>>>> {
>>>>> ...
>>>>>
>>>>> Good idea?
>>>>>
>>>>> If so, do we want one attribute per line?
>>>>
>>>>
>>>>
>>>> Only for really long ones I'd think. Patch is ok for now.
>>>>
>>>>
>>>
>>> Reposting patch with ChangeLog entry added.
>>>
>>> Bootstrapped and reg-tested on x86_64.
>>>
>>> Committed to trunk.
>>
>>
>> Hmpf.  I always like to make the dump-files as much copy&past-able to
>> testcases
>> as possible.
>
>
> Hmm, interesting. Not something I use, but I can imagine it's useful.
>
>> So why did you invent a new syntax for attributes instead of using
>> the existing __attribute__(("noclone", "noinline")) (in this case)?
>
>
> My main concerns were:
> - being able to see in dump files what the actual attributes of a
>   function are (rather than having to figure it out in a debug session).
> - being able to write testcases that can test for the presence of those
>   attributes in dump files
>
>> Did you verify
>> how attributes with arguments get printed?
>
>
> F.i. an oacc offload function compiled by the host compiler is annotated as
> follows:
>
> before pass_oacc_transform (in the gomp-4_0-branch):
> ...
> [ oacc function 32, , , omp target entrypoint ]
> ...
>
> after pass_oacc_transform:
> ....
> [ oacc function 1, 1, 1, omp target entrypoint ]
> .

Hmm, ok.  So without some extra dump_attribute_list wrapping
__attribute_(( ... )) around the above doesn't make it more amenable
for cut&pasting.

Richard.

>
> Thanks,
> - Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch, committed] Dump function attributes
  2015-09-29 11:42         ` Richard Biener
@ 2015-09-30 10:41           ` Tom de Vries
  2015-09-30 12:37             ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-09-30 10:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: Bernd Schmidt, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2702 bytes --]

On 29/09/15 13:29, Richard Biener wrote:
> On Tue, Sep 29, 2015 at 1:23 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> On 29/09/15 12:36, Richard Biener wrote:
>>>
>>> On Tue, Sep 29, 2015 at 7:43 AM, Tom de Vries <Tom_deVries@mentor.com>
>>> wrote:
>>>>
>>>> [ was: Re: [RFC] Dump function attributes ]
>>>>
>>>> On 28/09/15 17:17, Bernd Schmidt wrote:
>>>>>
>>>>>
>>>>> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>>>>>>
>>>>>>
>>>>>> patch below prints the function attributes in the dump file.
>>>>>
>>>>>
>>>>>
>>>>>> foo ()
>>>>>> [ noclone , noinline ]
>>>>>> {
>>>>>> ...
>>>>>>
>>>>>> Good idea?
>>>>>>
>>>>>> If so, do we want one attribute per line?
>>>>>
>>>>>
>>>>>
>>>>> Only for really long ones I'd think. Patch is ok for now.
>>>>>
>>>>>
>>>>
>>>> Reposting patch with ChangeLog entry added.
>>>>
>>>> Bootstrapped and reg-tested on x86_64.
>>>>
>>>> Committed to trunk.
>>>
>>>
>>> Hmpf.  I always like to make the dump-files as much copy&past-able to
>>> testcases
>>> as possible.
>>
>>
>> Hmm, interesting. Not something I use, but I can imagine it's useful.
>>
>>> So why did you invent a new syntax for attributes instead of using
>>> the existing __attribute__(("noclone", "noinline")) (in this case)?
>>
>>
>> My main concerns were:
>> - being able to see in dump files what the actual attributes of a
>>    function are (rather than having to figure it out in a debug session).
>> - being able to write testcases that can test for the presence of those
>>    attributes in dump files
>>
>>> Did you verify
>>> how attributes with arguments get printed?
>>
>>
>> F.i. an oacc offload function compiled by the host compiler is annotated as
>> follows:
>>
>> before pass_oacc_transform (in the gomp-4_0-branch):
>> ...
>> [ oacc function 32, , , omp target entrypoint ]
>> ...
>>
>> after pass_oacc_transform:
>> ....
>> [ oacc function 1, 1, 1, omp target entrypoint ]
>> .
>
> Hmm, ok.  So without some extra dump_attribute_list wrapping
> __attribute_(( ... )) around the above doesn't make it more amenable
> for cut&pasting.
>

With attached untested follow-up patch, for test-case:
...
void __attribute__((noinline)) __attribute__((alias ("bar"), noclone))
foo (void)
{

}

void __attribute__ ((__target__ ("arch=core2", "sse3")))
foo2 (void)
{

}

void __attribute__ ((optimize ((1))))
foo3 (void)
{

}

void __attribute__ ((optimize (("1"))))
foo4 (void)
{

}
...

I get at gimple dump:
...
__attribute__((noclone, alias ("bar"), noinline))
foo ()
{

}


__attribute__((__target__ ("arch=core2", "sse3")))
foo2 ()
{

}


__attribute__((optimize (1)))
foo3 ()
{

}


__attribute__((optimize ("1")))
foo4 ()
{

}
...

OK if bootstrap/regtest succeeds?

Thanks,
- Tom


[-- Attachment #2: 0001-Make-dumping-of-function-attributes-resemble-source-.patch --]
[-- Type: text/x-patch, Size: 1842 bytes --]

Make dumping of function attributes resemble source syntax

---
 gcc/tree-cfg.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e06ee28..735ac46 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -72,6 +72,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfgcleanup.h"
 #include "wide-int-print.h"
 #include "gimplify.h"
+#include "attribs.h"
 
 /* This file contains functions for building the Control Flow Graph (CFG)
    for a function tree.  */
@@ -7352,6 +7353,30 @@ dump_function_to_file (tree fndecl, FILE *file, int flags)
 		  && decl_is_tm_clone (fndecl));
   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
 
+  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
+    {
+      fprintf (file, "__attribute__((");
+
+      bool first = true;
+      tree chain;
+      for (chain = DECL_ATTRIBUTES (fndecl); chain;
+	   first = false, chain = TREE_CHAIN (chain))
+	{
+	  if (!first)
+	    fprintf (file, ", ");
+
+	  print_generic_expr (file, get_attribute_name (chain), dump_flags);
+	  if (TREE_VALUE (chain) != NULL_TREE)
+	    {
+	      fprintf (file, " (");
+	      print_generic_expr (file, TREE_VALUE (chain), dump_flags);
+	      fprintf (file, ")");
+	    }
+	}
+
+      fprintf (file, "))\n");
+    }
+
   current_function_decl = fndecl;
   fprintf (file, "%s %s(", function_name (fun), tmclone ? "[tm-clone] " : "");
 
@@ -7369,13 +7394,6 @@ dump_function_to_file (tree fndecl, FILE *file, int flags)
     }
   fprintf (file, ")\n");
 
-  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
-    {
-      fprintf (file, "[ ");
-      print_generic_expr (file, DECL_ATTRIBUTES (fndecl), dump_flags);
-      fprintf (file, "]\n");
-    }
-
   if (flags & TDF_VERBOSE)
     print_node (file, "", fndecl, 2);
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch, committed] Dump function attributes
  2015-09-30 10:41           ` Tom de Vries
@ 2015-09-30 12:37             ` Richard Biener
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Biener @ 2015-09-30 12:37 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Bernd Schmidt, gcc-patches

On Wed, Sep 30, 2015 at 12:03 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> On 29/09/15 13:29, Richard Biener wrote:
>>
>> On Tue, Sep 29, 2015 at 1:23 PM, Tom de Vries <Tom_deVries@mentor.com>
>> wrote:
>>>
>>> On 29/09/15 12:36, Richard Biener wrote:
>>>>
>>>>
>>>> On Tue, Sep 29, 2015 at 7:43 AM, Tom de Vries <Tom_deVries@mentor.com>
>>>> wrote:
>>>>>
>>>>>
>>>>> [ was: Re: [RFC] Dump function attributes ]
>>>>>
>>>>> On 28/09/15 17:17, Bernd Schmidt wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 09/28/2015 04:32 PM, Tom de Vries wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> patch below prints the function attributes in the dump file.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> foo ()
>>>>>>> [ noclone , noinline ]
>>>>>>> {
>>>>>>> ...
>>>>>>>
>>>>>>> Good idea?
>>>>>>>
>>>>>>> If so, do we want one attribute per line?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Only for really long ones I'd think. Patch is ok for now.
>>>>>>
>>>>>>
>>>>>
>>>>> Reposting patch with ChangeLog entry added.
>>>>>
>>>>> Bootstrapped and reg-tested on x86_64.
>>>>>
>>>>> Committed to trunk.
>>>>
>>>>
>>>>
>>>> Hmpf.  I always like to make the dump-files as much copy&past-able to
>>>> testcases
>>>> as possible.
>>>
>>>
>>>
>>> Hmm, interesting. Not something I use, but I can imagine it's useful.
>>>
>>>> So why did you invent a new syntax for attributes instead of using
>>>> the existing __attribute__(("noclone", "noinline")) (in this case)?
>>>
>>>
>>>
>>> My main concerns were:
>>> - being able to see in dump files what the actual attributes of a
>>>    function are (rather than having to figure it out in a debug session).
>>> - being able to write testcases that can test for the presence of those
>>>    attributes in dump files
>>>
>>>> Did you verify
>>>> how attributes with arguments get printed?
>>>
>>>
>>>
>>> F.i. an oacc offload function compiled by the host compiler is annotated
>>> as
>>> follows:
>>>
>>> before pass_oacc_transform (in the gomp-4_0-branch):
>>> ...
>>> [ oacc function 32, , , omp target entrypoint ]
>>> ...
>>>
>>> after pass_oacc_transform:
>>> ....
>>> [ oacc function 1, 1, 1, omp target entrypoint ]
>>> .
>>
>>
>> Hmm, ok.  So without some extra dump_attribute_list wrapping
>> __attribute_(( ... )) around the above doesn't make it more amenable
>> for cut&pasting.
>>
>
> With attached untested follow-up patch, for test-case:
> ...
> void __attribute__((noinline)) __attribute__((alias ("bar"), noclone))
> foo (void)
> {
>
> }
>
> void __attribute__ ((__target__ ("arch=core2", "sse3")))
> foo2 (void)
> {
>
> }
>
> void __attribute__ ((optimize ((1))))
> foo3 (void)
> {
>
> }
>
> void __attribute__ ((optimize (("1"))))
> foo4 (void)
> {
>
> }
> ...
>
> I get at gimple dump:
> ...
> __attribute__((noclone, alias ("bar"), noinline))
> foo ()
> {
>
> }
>
>
> __attribute__((__target__ ("arch=core2", "sse3")))
> foo2 ()
> {
>
> }
>
>
> __attribute__((optimize (1)))
> foo3 ()
> {
>
> }
>
>
> __attribute__((optimize ("1")))
> foo4 ()
> {
>
> }
> ...
>
> OK if bootstrap/regtest succeeds?

Ok.

Thanks,
Richard.

> Thanks,
> - Tom
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-09-30 12:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-28 15:07 [RFC] Dump function attributes Tom de Vries
2015-09-28 15:56 ` Bernd Schmidt
2015-09-29  7:01   ` [patch, committed] " Tom de Vries
2015-09-29 11:29     ` Richard Biener
2015-09-29 11:41       ` Tom de Vries
2015-09-29 11:42         ` Richard Biener
2015-09-30 10:41           ` Tom de Vries
2015-09-30 12:37             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).