public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [statistics.cc] Emit asm name of function with -fdump-statistics-asmname
@ 2022-06-16 15:04 Prathamesh Kulkarni
  2022-06-20  7:21 ` Richard Biener
  2022-06-26 19:39 ` Jeff Law
  0 siblings, 2 replies; 5+ messages in thread
From: Prathamesh Kulkarni @ 2022-06-16 15:04 UTC (permalink / raw)
  To: gcc Patches

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

Hi,
I just noticed -fdump-statistics supports asmname sub-option, which
according to the doc states:
"If DECL_ASSEMBLER_NAME has been set for a given decl, use that in the dump
instead of DECL_NAME. Its primary use is ease of use working backward from
mangled names in the assembly file."

When passed -fdump-statistics-asmname, the dump however still contains the
original name of functions. The patch modifies statistics.cc to emit asm
name of function instead. Also for C++, it helps to better disambiguate
overloaded function names in the stats dump file.
I have attached stats dump for a simple test-case.

Does it look OK ?

Thanks,
Prathamesh

[-- Attachment #2: stats-asmname-1.txt --]
[-- Type: text/plain, Size: 2074 bytes --]

diff --git a/gcc/statistics.cc b/gcc/statistics.cc
index 0d596e34189..ff4f9cc7fb6 100644
--- a/gcc/statistics.cc
+++ b/gcc/statistics.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "context.h"
 #include "pass_manager.h"
+#include "tree.h"
 
 static int statistics_dump_nr;
 static dump_flags_t statistics_dump_flags;
@@ -113,6 +114,21 @@ curr_statistics_hash (void)
   return statistics_hashes[idx];
 }
 
+/* Helper function to return asmname or name of FN
+   depending on whether asmname option is set.  */
+
+static const char *
+get_function_name (struct function *fn)
+{
+  if (statistics_dump_flags & TDF_ASMNAME)
+    {
+      tree asmname = decl_assembler_name (fn->decl);
+      if (asmname)
+	return IDENTIFIER_POINTER (asmname);
+    }
+  return function_name (fn);
+}
+
 /* Helper for statistics_fini_pass.  Print the counter difference
    since the last dump for the pass dump files.  */
 
@@ -152,7 +168,7 @@ statistics_fini_pass_2 (statistics_counter **slot,
 	     current_pass->static_pass_number,
 	     current_pass->name,
 	     counter->id, counter->val,
-	     current_function_name (),
+	     get_function_name (cfun),
 	     count);
   else
     fprintf (statistics_dump_file,
@@ -160,7 +176,7 @@ statistics_fini_pass_2 (statistics_counter **slot,
 	     current_pass->static_pass_number,
 	     current_pass->name,
 	     counter->id,
-	     current_function_name (),
+	     get_function_name (cfun),
 	     count);
   counter->prev_dumped_count = counter->count;
   return 1;
@@ -329,7 +345,7 @@ statistics_counter_event (struct function *fn, const char *id, int incr)
 	   current_pass ? current_pass->static_pass_number : -1,
 	   current_pass ? current_pass->name : "none",
 	   id,
-	   function_name (fn),
+	   get_function_name (fn),
 	   incr);
 }
 
@@ -359,5 +375,5 @@ statistics_histogram_event (struct function *fn, const char *id, int val)
 	   current_pass->static_pass_number,
 	   current_pass->name,
 	   id, val,
-	   function_name (fn));
+	   get_function_name (fn));
 }

[-- Attachment #3: foo.cpp --]
[-- Type: application/octet-stream, Size: 130 bytes --]

__attribute__((noipa))
int foo(int x, int y)
{
  return x + y; 
}

__attribute__((noipa))
int foo(int x)
{
  return foo (x, x);
}

[-- Attachment #4: stats-dump.txt --]
[-- Type: text/plain, Size: 2691 bytes --]

29 ssa "unused VAR_DECLs removed" "foo" 1
47 fre "RPO blocks" "foo" 1
47 fre "RPO iterations == 10" "foo" 1
47 fre "RPO blocks visited" "foo" 1
47 fre "RPO blocks executable" "foo" 1
47 fre "RPO block visited times == 1" "foo" 1
47 fre "RPO num avail == 1" "foo" 1
47 fre "RPO num values == 3" "foo" 1
47 fre "RPO num lattice == 3" "foo" 1
47 fre "RPO num values == 2" "foo" 1
47 fre "RPO blocks" "foo" 1
47 fre "RPO iterations == 10" "foo" 1
47 fre "RPO num lattice == 2" "foo" 1
47 fre "RPO blocks visited" "foo" 1
47 fre "RPO blocks executable" "foo" 1
47 fre "RPO block visited times == 1" "foo" 1
47 fre "RPO num avail == 1" "foo" 1
120 fre "RPO blocks" "foo" 1
120 fre "RPO iterations == 10" "foo" 1
120 fre "RPO blocks visited" "foo" 1
120 fre "RPO blocks executable" "foo" 1
120 fre "RPO block visited times == 1" "foo" 1
120 fre "RPO num avail == 1" "foo" 1
120 fre "RPO num values == 3" "foo" 1
120 fre "RPO num lattice == 3" "foo" 1
151 pre "RPO blocks" "foo" 1
151 pre "RPO iterations == 10" "foo" 1
151 pre "compute_antic iterations == 2" "foo" 1
151 pre "RPO blocks visited" "foo" 1
151 pre "RPO blocks executable" "foo" 1
151 pre "RPO block visited times == 1" "foo" 1
151 pre "RPO num avail == 1" "foo" 1
151 pre "RPO num values == 3" "foo" 1
151 pre "RPO num lattice == 3" "foo" 1
151 pre "insert iterations == 1" "foo" 1
201 fre "RPO blocks" "foo" 1
201 fre "RPO iterations == 10" "foo" 1
201 fre "RPO blocks visited" "foo" 1
201 fre "RPO blocks executable" "foo" 1
201 fre "RPO block visited times == 1" "foo" 1
201 fre "RPO num avail == 1" "foo" 1
201 fre "RPO num values == 3" "foo" 1
201 fre "RPO num lattice == 3" "foo" 1
293 combine "two-insn combine" "foo" 2
120 fre "RPO num values == 2" "foo" 1
120 fre "RPO blocks" "foo" 1
120 fre "RPO iterations == 10" "foo" 1
120 fre "RPO num lattice == 2" "foo" 1
120 fre "RPO blocks visited" "foo" 1
120 fre "RPO blocks executable" "foo" 1
120 fre "RPO block visited times == 1" "foo" 1
120 fre "RPO num avail == 1" "foo" 1
151 pre "RPO num values == 2" "foo" 1
151 pre "RPO blocks" "foo" 1
151 pre "RPO iterations == 10" "foo" 1
151 pre "compute_antic iterations == 2" "foo" 1
151 pre "RPO num lattice == 2" "foo" 1
151 pre "RPO blocks visited" "foo" 1
151 pre "RPO blocks executable" "foo" 1
151 pre "RPO block visited times == 1" "foo" 1
151 pre "RPO num avail == 1" "foo" 1
151 pre "insert iterations == 1" "foo" 1
201 fre "RPO num values == 2" "foo" 1
201 fre "RPO blocks" "foo" 1
201 fre "RPO iterations == 10" "foo" 1
201 fre "RPO num lattice == 2" "foo" 1
201 fre "RPO blocks visited" "foo" 1
201 fre "RPO blocks executable" "foo" 1
201 fre "RPO block visited times == 1" "foo" 1
201 fre "RPO num avail == 1" "foo" 1

[-- Attachment #5: stats-dump-asmname.txt --]
[-- Type: text/plain, Size: 3006 bytes --]

29 ssa "unused VAR_DECLs removed" "_Z3fooi" 1
47 fre "RPO blocks" "_Z3fooii" 1
47 fre "RPO iterations == 10" "_Z3fooii" 1
47 fre "RPO blocks visited" "_Z3fooii" 1
47 fre "RPO blocks executable" "_Z3fooii" 1
47 fre "RPO block visited times == 1" "_Z3fooii" 1
47 fre "RPO num avail == 1" "_Z3fooii" 1
47 fre "RPO num values == 3" "_Z3fooii" 1
47 fre "RPO num lattice == 3" "_Z3fooii" 1
47 fre "RPO num values == 2" "_Z3fooi" 1
47 fre "RPO blocks" "_Z3fooi" 1
47 fre "RPO iterations == 10" "_Z3fooi" 1
47 fre "RPO num lattice == 2" "_Z3fooi" 1
47 fre "RPO blocks visited" "_Z3fooi" 1
47 fre "RPO blocks executable" "_Z3fooi" 1
47 fre "RPO block visited times == 1" "_Z3fooi" 1
47 fre "RPO num avail == 1" "_Z3fooi" 1
120 fre "RPO blocks" "_Z3fooii" 1
120 fre "RPO iterations == 10" "_Z3fooii" 1
120 fre "RPO blocks visited" "_Z3fooii" 1
120 fre "RPO blocks executable" "_Z3fooii" 1
120 fre "RPO block visited times == 1" "_Z3fooii" 1
120 fre "RPO num avail == 1" "_Z3fooii" 1
120 fre "RPO num values == 3" "_Z3fooii" 1
120 fre "RPO num lattice == 3" "_Z3fooii" 1
151 pre "RPO blocks" "_Z3fooii" 1
151 pre "RPO iterations == 10" "_Z3fooii" 1
151 pre "compute_antic iterations == 2" "_Z3fooii" 1
151 pre "RPO blocks visited" "_Z3fooii" 1
151 pre "RPO blocks executable" "_Z3fooii" 1
151 pre "RPO block visited times == 1" "_Z3fooii" 1
151 pre "RPO num avail == 1" "_Z3fooii" 1
151 pre "RPO num values == 3" "_Z3fooii" 1
151 pre "RPO num lattice == 3" "_Z3fooii" 1
151 pre "insert iterations == 1" "_Z3fooii" 1
201 fre "RPO blocks" "_Z3fooii" 1
201 fre "RPO iterations == 10" "_Z3fooii" 1
201 fre "RPO blocks visited" "_Z3fooii" 1
201 fre "RPO blocks executable" "_Z3fooii" 1
201 fre "RPO block visited times == 1" "_Z3fooii" 1
201 fre "RPO num avail == 1" "_Z3fooii" 1
201 fre "RPO num values == 3" "_Z3fooii" 1
201 fre "RPO num lattice == 3" "_Z3fooii" 1
293 combine "two-insn combine" "_Z3fooii" 2
120 fre "RPO num values == 2" "_Z3fooi" 1
120 fre "RPO blocks" "_Z3fooi" 1
120 fre "RPO iterations == 10" "_Z3fooi" 1
120 fre "RPO num lattice == 2" "_Z3fooi" 1
120 fre "RPO blocks visited" "_Z3fooi" 1
120 fre "RPO blocks executable" "_Z3fooi" 1
120 fre "RPO block visited times == 1" "_Z3fooi" 1
120 fre "RPO num avail == 1" "_Z3fooi" 1
151 pre "RPO num values == 2" "_Z3fooi" 1
151 pre "RPO blocks" "_Z3fooi" 1
151 pre "RPO iterations == 10" "_Z3fooi" 1
151 pre "compute_antic iterations == 2" "_Z3fooi" 1
151 pre "RPO num lattice == 2" "_Z3fooi" 1
151 pre "RPO blocks visited" "_Z3fooi" 1
151 pre "RPO blocks executable" "_Z3fooi" 1
151 pre "RPO block visited times == 1" "_Z3fooi" 1
151 pre "RPO num avail == 1" "_Z3fooi" 1
151 pre "insert iterations == 1" "_Z3fooi" 1
201 fre "RPO num values == 2" "_Z3fooi" 1
201 fre "RPO blocks" "_Z3fooi" 1
201 fre "RPO iterations == 10" "_Z3fooi" 1
201 fre "RPO num lattice == 2" "_Z3fooi" 1
201 fre "RPO blocks visited" "_Z3fooi" 1
201 fre "RPO blocks executable" "_Z3fooi" 1
201 fre "RPO block visited times == 1" "_Z3fooi" 1
201 fre "RPO num avail == 1" "_Z3fooi" 1

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

* Re: [statistics.cc] Emit asm name of function with -fdump-statistics-asmname
  2022-06-16 15:04 [statistics.cc] Emit asm name of function with -fdump-statistics-asmname Prathamesh Kulkarni
@ 2022-06-20  7:21 ` Richard Biener
  2022-06-27  4:51   ` Prathamesh Kulkarni
  2022-06-26 19:39 ` Jeff Law
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Biener @ 2022-06-20  7:21 UTC (permalink / raw)
  To: Prathamesh Kulkarni; +Cc: gcc Patches

On Thu, Jun 16, 2022 at 5:05 PM Prathamesh Kulkarni via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
> I just noticed -fdump-statistics supports asmname sub-option, which
> according to the doc states:
> "If DECL_ASSEMBLER_NAME has been set for a given decl, use that in the dump
> instead of DECL_NAME. Its primary use is ease of use working backward from
> mangled names in the assembly file."
>
> When passed -fdump-statistics-asmname, the dump however still contains the
> original name of functions. The patch modifies statistics.cc to emit asm
> name of function instead. Also for C++, it helps to better disambiguate
> overloaded function names in the stats dump file.
> I have attached stats dump for a simple test-case.
>
> Does it look OK ?

decl_assembler_name has the side-effect of computing and setting it if it is
not set already - I think that's unwanted.  You probably want to use
it only if DECL_ASSEMBLER_NAME_SET_P which then means when it
gets it later the dump will be split.

Richard.

>
> Thanks,
> Prathamesh

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

* Re: [statistics.cc] Emit asm name of function with -fdump-statistics-asmname
  2022-06-16 15:04 [statistics.cc] Emit asm name of function with -fdump-statistics-asmname Prathamesh Kulkarni
  2022-06-20  7:21 ` Richard Biener
@ 2022-06-26 19:39 ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2022-06-26 19:39 UTC (permalink / raw)
  To: gcc-patches



On 6/16/2022 9:04 AM, Prathamesh Kulkarni via Gcc-patches wrote:
> Hi,
> I just noticed -fdump-statistics supports asmname sub-option, which
> according to the doc states:
> "If DECL_ASSEMBLER_NAME has been set for a given decl, use that in the dump
> instead of DECL_NAME. Its primary use is ease of use working backward from
> mangled names in the assembly file."
>
> When passed -fdump-statistics-asmname, the dump however still contains the
> original name of functions. The patch modifies statistics.cc to emit asm
> name of function instead. Also for C++, it helps to better disambiguate
> overloaded function names in the stats dump file.
> I have attached stats dump for a simple test-case.
>
> Does it look OK ?
Yes.  This is fine for the trunk.
jeff


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

* Re: [statistics.cc] Emit asm name of function with -fdump-statistics-asmname
  2022-06-20  7:21 ` Richard Biener
@ 2022-06-27  4:51   ` Prathamesh Kulkarni
  2022-06-27  5:25     ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Prathamesh Kulkarni @ 2022-06-27  4:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc Patches

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

On Mon, 20 Jun 2022 at 12:52, Richard Biener <richard.guenther@gmail.com> wrote:
>
> On Thu, Jun 16, 2022 at 5:05 PM Prathamesh Kulkarni via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Hi,
> > I just noticed -fdump-statistics supports asmname sub-option, which
> > according to the doc states:
> > "If DECL_ASSEMBLER_NAME has been set for a given decl, use that in the dump
> > instead of DECL_NAME. Its primary use is ease of use working backward from
> > mangled names in the assembly file."
> >
> > When passed -fdump-statistics-asmname, the dump however still contains the
> > original name of functions. The patch modifies statistics.cc to emit asm
> > name of function instead. Also for C++, it helps to better disambiguate
> > overloaded function names in the stats dump file.
> > I have attached stats dump for a simple test-case.
> >
> > Does it look OK ?
>
> decl_assembler_name has the side-effect of computing and setting it if it is
> not set already - I think that's unwanted.  You probably want to use
> it only if DECL_ASSEMBLER_NAME_SET_P which then means when it
> gets it later the dump will be split.
Hi Richard,
Sorry for late reply. In the attached patch, I checked for
DECL_ASSEMBLER_NAME_SET_P before calling
decl_assembler_name.
Does that look OK ?

Thanks,
Prathamesh
>
> Richard.
>
> >
> > Thanks,
> > Prathamesh

[-- Attachment #2: stats-asmname-2.txt --]
[-- Type: text/plain, Size: 2123 bytes --]

diff --git a/gcc/statistics.cc b/gcc/statistics.cc
index 0d596e34189..6c21415bf65 100644
--- a/gcc/statistics.cc
+++ b/gcc/statistics.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "context.h"
 #include "pass_manager.h"
+#include "tree.h"
 
 static int statistics_dump_nr;
 static dump_flags_t statistics_dump_flags;
@@ -113,6 +114,22 @@ curr_statistics_hash (void)
   return statistics_hashes[idx];
 }
 
+/* Helper function to return asmname or name of FN
+   depending on whether asmname option is set.  */
+
+static const char *
+get_function_name (struct function *fn)
+{
+  if ((statistics_dump_flags & TDF_ASMNAME)
+      && DECL_ASSEMBLER_NAME_SET_P (fn->decl))
+    {
+      tree asmname = decl_assembler_name (fn->decl);
+      if (asmname)
+	return IDENTIFIER_POINTER (asmname);
+    }
+  return function_name (fn);
+}
+
 /* Helper for statistics_fini_pass.  Print the counter difference
    since the last dump for the pass dump files.  */
 
@@ -152,7 +169,7 @@ statistics_fini_pass_2 (statistics_counter **slot,
 	     current_pass->static_pass_number,
 	     current_pass->name,
 	     counter->id, counter->val,
-	     current_function_name (),
+	     get_function_name (cfun),
 	     count);
   else
     fprintf (statistics_dump_file,
@@ -160,7 +177,7 @@ statistics_fini_pass_2 (statistics_counter **slot,
 	     current_pass->static_pass_number,
 	     current_pass->name,
 	     counter->id,
-	     current_function_name (),
+	     get_function_name (cfun),
 	     count);
   counter->prev_dumped_count = counter->count;
   return 1;
@@ -329,7 +346,7 @@ statistics_counter_event (struct function *fn, const char *id, int incr)
 	   current_pass ? current_pass->static_pass_number : -1,
 	   current_pass ? current_pass->name : "none",
 	   id,
-	   function_name (fn),
+	   get_function_name (fn),
 	   incr);
 }
 
@@ -359,5 +376,5 @@ statistics_histogram_event (struct function *fn, const char *id, int val)
 	   current_pass->static_pass_number,
 	   current_pass->name,
 	   id, val,
-	   function_name (fn));
+	   get_function_name (fn));
 }

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

* Re: [statistics.cc] Emit asm name of function with -fdump-statistics-asmname
  2022-06-27  4:51   ` Prathamesh Kulkarni
@ 2022-06-27  5:25     ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2022-06-27  5:25 UTC (permalink / raw)
  To: Prathamesh Kulkarni; +Cc: gcc Patches



> Am 27.06.2022 um 06:51 schrieb Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>:
> 
> On Mon, 20 Jun 2022 at 12:52, Richard Biener <richard.guenther@gmail.com> wrote:
>> 
>>> On Thu, Jun 16, 2022 at 5:05 PM Prathamesh Kulkarni via Gcc-patches
>>> <gcc-patches@gcc.gnu.org> wrote:
>>> 
>>> Hi,
>>> I just noticed -fdump-statistics supports asmname sub-option, which
>>> according to the doc states:
>>> "If DECL_ASSEMBLER_NAME has been set for a given decl, use that in the dump
>>> instead of DECL_NAME. Its primary use is ease of use working backward from
>>> mangled names in the assembly file."
>>> 
>>> When passed -fdump-statistics-asmname, the dump however still contains the
>>> original name of functions. The patch modifies statistics.cc to emit asm
>>> name of function instead. Also for C++, it helps to better disambiguate
>>> overloaded function names in the stats dump file.
>>> I have attached stats dump for a simple test-case.
>>> 
>>> Does it look OK ?
>> 
>> decl_assembler_name has the side-effect of computing and setting it if it is
>> not set already - I think that's unwanted.  You probably want to use
>> it only if DECL_ASSEMBLER_NAME_SET_P which then means when it
>> gets it later the dump will be split.
> Hi Richard,
> Sorry for late reply. In the attached patch, I checked for
> DECL_ASSEMBLER_NAME_SET_P before calling
> decl_assembler_name.
> Does that look OK ?

Ok.

Richard 


> Thanks,
> Prathamesh
>> 
>> Richard.
>> 
>>> 
>>> Thanks,
>>> Prathamesh
> <stats-asmname-2.txt>

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

end of thread, other threads:[~2022-06-27  5:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 15:04 [statistics.cc] Emit asm name of function with -fdump-statistics-asmname Prathamesh Kulkarni
2022-06-20  7:21 ` Richard Biener
2022-06-27  4:51   ` Prathamesh Kulkarni
2022-06-27  5:25     ` Richard Biener
2022-06-26 19:39 ` Jeff Law

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).