public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [GSOC] LTO dump tool project
@ 2018-05-29 17:03 Hrishikesh Kulkarni
  2018-05-29 17:17 ` Prathamesh Kulkarni
                   ` (2 more replies)
  0 siblings, 3 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-05-29 17:03 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

My exams have finally ended and I have started working on the GSOC project.
I have forked GCC mirror (https://github.com/hrisearch/gcc) and
created a option for dumping functions and variables used in IL.
Please find the patch attached herewith.

Regards,
Hrishikesh

[-- Attachment #2: symbols-dump.diff --]
[-- Type: text/x-patch, Size: 1638 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 1083f9b..ae66c06 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -66,7 +66,11 @@ Whole program analysis (WPA) mode with number of parallel jobs specified.
 
 fdump
 LTO Var(flag_lto_dump)
-Call the dump function
+Call the dump function.
+
+fdump-lto-list
+LTO Var(flag_lto_dump_list)
+Call the dump function for variables and function in IL.
 
 fresolution=
 LTO Joined
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index b6a8b45..5e4d069 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -38,4 +38,21 @@ along with GCC; see the file COPYING3.  If not see
 void dump()
 {
 	fprintf(stderr, "\nHello World!\n");
+}
+
+void dump_list()
+{
+
+	fprintf (stderr, "Call Graph:\n\n");
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+    cnode->dump (stderr);
+    fprintf(stderr, "\n\n" );
+
+	fprintf (stderr, "Varpool:\n\n");
+	varpool_node *vnode;
+    FOR_EACH_VARIABLE (vnode)
+	vnode->dump (stderr);
+    fprintf(stderr, "\n\n" );
+
 }
\ No newline at end of file
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 4a06217..5ee71c6 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -21,5 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_LTO_DUMP_H_
 
 void dump();
+void dump_list();
 
 #endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 9c79242..93ef52b 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -3360,6 +3360,11 @@ lto_main (void)
     dump();
   }
 
+  if (flag_lto_dump_list)
+  {
+    dump_list();
+  }
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())

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

* Re: [GSOC] LTO dump tool project
  2018-05-29 17:03 [GSOC] LTO dump tool project Hrishikesh Kulkarni
@ 2018-05-29 17:17 ` Prathamesh Kulkarni
  2018-05-29 17:39   ` Martin Liška
  2018-05-29 17:38 ` Martin Liška
  2018-08-01 13:29 ` [GSOC] LTO dump tool project - feedback Martin Liška
  2 siblings, 1 reply; 50+ messages in thread
From: Prathamesh Kulkarni @ 2018-05-29 17:17 UTC (permalink / raw)
  To: Hrishikesh Kulkarni
  Cc: GCC Development, Martin Liška, Jan Hubicka, Richard Biener,
	Martin Jambor

On 29 May 2018 at 22:33, Hrishikesh Kulkarni <hrishikeshparag@gmail.com> wrote:
> Hi,
>
> My exams have finally ended and I have started working on the GSOC project.
> I have forked GCC mirror (https://github.com/hrisearch/gcc) and
> created a option for dumping functions and variables used in IL.
> Please find the patch attached herewith.
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 1083f9b..ae66c06 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -66,7 +66,11 @@ Whole program analysis (WPA) mode with number of
parallel jobs specified.

 fdump
 LTO Var(flag_lto_dump)
-Call the dump function
+Call the dump function.
+
+fdump-lto-list
+LTO Var(flag_lto_dump_list)
+Call the dump function for variables and function in IL.

Instead of making separate options -fdump and -fdump-lto-list,
would it be a good idea to make it a "sub option" to -fdump like
lto1 -fdump,-l which would list all symbols within the LTO object file ?

 fresolution=
 LTO Joined
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index b6a8b45..5e4d069 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -38,4 +38,21 @@ along with GCC; see the file COPYING3.  If not see
 void dump()
 {
  fprintf(stderr, "\nHello World!\n");
+}
+
+void dump_list()
+{
+
+ fprintf (stderr, "Call Graph:\n\n");
+ cgraph_node *cnode;
+ FOR_EACH_FUNCTION (cnode)
+    cnode->dump (stderr);
+    fprintf(stderr, "\n\n" );
+
+ fprintf (stderr, "Varpool:\n\n");
+ varpool_node *vnode;
+    FOR_EACH_VARIABLE (vnode)
+ vnode->dump (stderr);
+    fprintf(stderr, "\n\n" );
+
 }
\ No newline at end of file
Formatting nit - Add comments for the newly added functions.

diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 4a06217..5ee71c6 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -21,5 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_LTO_DUMP_H_

 void dump();
+void dump_list();

 #endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 9c79242..93ef52b 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -3360,6 +3360,11 @@ lto_main (void)
     dump();
   }

+  if (flag_lto_dump_list)
+  {
+    dump_list();
+  }
+
Formatting nit - Avoid braces for single statement within if.
Shouldn't fdump-lto-list be enabled only if fdump is enabled  ?

Thanks,
Prathamesh

   timevar_stop (TV_PHASE_STREAM_IN);

   if (!seen_error ())
>
> Regards,
> Hrishikesh

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

* Re: [GSOC] LTO dump tool project
  2018-05-29 17:03 [GSOC] LTO dump tool project Hrishikesh Kulkarni
  2018-05-29 17:17 ` Prathamesh Kulkarni
@ 2018-05-29 17:38 ` Martin Liška
  2018-05-29 17:43   ` Martin Liška
  2018-08-01 13:29 ` [GSOC] LTO dump tool project - feedback Martin Liška
  2 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-05-29 17:38 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 05/29/2018 07:03 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> My exams have finally ended and I have started working on the GSOC project.
> I have forked GCC mirror (https://github.com/hrisearch/gcc) and
> created a option for dumping functions and variables used in IL.
> Please find the patch attached herewith.

Hello.

Good start. You branched the repository but your forget to push the commit
you sent as attachment. Second issues is that the patch is not against
GCC trunk, but against your local branch. Thus one can't apply that.

About the options:
- once you send a new functionality, it's fine to paste a sample output
- for now I would remove the dummy flag_lto_dump flag
- I would expect for -fdump-lto-list something like what nm does:

$ nm main.o
00000000 T main
00000000 T mystring
00000000 C pole

Then of course you can add some level of verbosity which can print what you have.
Would be also handy during the time to come up with some sorting, but it can wait.

That said, the direction is fine. Please carry on.

Thanks,
Martin

> 
> Regards,
> Hrishikesh
> 

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

* Re: [GSOC] LTO dump tool project
  2018-05-29 17:17 ` Prathamesh Kulkarni
@ 2018-05-29 17:39   ` Martin Liška
  0 siblings, 0 replies; 50+ messages in thread
From: Martin Liška @ 2018-05-29 17:39 UTC (permalink / raw)
  To: Prathamesh Kulkarni, Hrishikesh Kulkarni
  Cc: GCC Development, Jan Hubicka, Richard Biener, Martin Jambor

On 05/29/2018 07:17 PM, Prathamesh Kulkarni wrote:
> Shouldn't fdump-lto-list be enabled only if fdump is enabled  ?

The option is dummy, and eventually all do options will be moved
to a separate tool called lto-dump. Thus all the prefixed '-fdump-lto-foo'
will be replaced with -foo is guess.

Martin

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

* Re: [GSOC] LTO dump tool project
  2018-05-29 17:38 ` Martin Liška
@ 2018-05-29 17:43   ` Martin Liška
  2018-06-01 18:59     ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-05-29 17:43 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 05/29/2018 07:38 PM, Martin Liška wrote:
> $ nm main.o
> 00000000 T main
> 00000000 T mystring
> 00000000 C pole

Or we can be inspired by readelf:

$ readelf -s a.out
[snip]
Symbol table '.symtab' contains 74 entries:
    Num:    Value          Size Type    Bind   Vis      Ndx Name
     66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
     67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
     68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
     69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
     70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fwrite@@GLIBC_2.2.5

Martin

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

* Re: [GSOC] LTO dump tool project
  2018-05-29 17:43   ` Martin Liška
@ 2018-06-01 18:59     ` Hrishikesh Kulkarni
  2018-06-04  8:36       ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-01 18:59 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,
I have pushed the changes to github
(https://github.com/hrisearch/gcc). Added a command line option for
specific dumps of variables and functions used in IL e.g.
-fdump-lto-list=foo will dump:
Call Graph:

foo/1 (foo)
  Type: function
 visibility: default

Regards,
Hrishikesh

On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>
>> $ nm main.o
>> 00000000 T main
>> 00000000 T mystring
>> 00000000 C pole
>
>
> Or we can be inspired by readelf:
>
> $ readelf -s a.out
> [snip]
> Symbol table '.symtab' contains 74 entries:
>    Num:    Value          Size Type    Bind   Vis      Ndx Name
>     66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>     67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>     68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>     69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>     70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
> fwrite@@GLIBC_2.2.5
>
> Martin

[-- Attachment #2: specific-symbols-dump.diff --]
[-- Type: text/x-patch, Size: 7022 bytes --]

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 9a7d54d..b868695 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
     fprintf (f, "  Is instrumented version.\n");
   else if (instrumented_version)
     fprintf (f, "  Has instrumented version.\n");
+
 }
 
 /* Dump call graph node NODE to stderr.  */
diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 4695077..465662e 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -22,7 +22,7 @@
 # The name of the LTO compiler.
 LTO_EXE = lto1$(exeext)
 # The LTO-specific object files inclued in $(LTO_EXE).
-LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
+LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
 lto_OBJS = $(LTO_OBJS)
 
 # this is only useful in a LTO bootstrap, but this does not work right
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 0a408d3..7600840 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -63,6 +63,18 @@ fwpa=
 LTO Driver RejectNegative Joined Var(flag_wpa)
 Whole program analysis (WPA) mode with number of parallel jobs specified.
 
+fdump
+LTO Var(flag_lto_dump)
+Call the dump function.
+
+fdump-lto-list
+LTO Var(flag_lto_dump_list)
+Call the dump function for variables and function in IL.
+
+fdump-lto-list=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
+
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
new file mode 100644
index 0000000..90976cb
--- /dev/null
+++ b/gcc/lto/lto-dump.c
@@ -0,0 +1,105 @@
+/* LTO dump tool
+   Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "function.h"
+#include "basic-block.h"
+#include "tree.h"
+#include "gimple.h"
+#include "cgraph.h"
+#include "lto-streamer.h"
+#include "ipa-utils.h"
+#include "builtins.h"
+#include "alias.h"
+#include "lto-symtab.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "stdio.h"
+
+/*Dump everything*/
+void dump()
+{
+	fprintf(stderr, "\nHello World!\n");
+}
+
+/*Dump variables and functions used in IL*/
+void dump_list()
+{
+
+	fprintf (stderr, "Call Graph:\n");
+	cgraph_node *cnode;
+	
+	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
+  	static const char * const visibility_types[] = {
+    "default", "protected", "hidden", "internal" };
+	FOR_EACH_FUNCTION (cnode)
+	{
+		fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
+		fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
+		fprintf (stderr, "\n visibility: %s\n",
+		visibility_types [DECL_VISIBILITY (cnode->decl)]);
+	}
+
+	fprintf (stderr, "\nVarpool:\n");
+	varpool_node *vnode;
+    FOR_EACH_VARIABLE (vnode)
+    {
+		fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
+		fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
+		fprintf (stderr, "\n visibility:%s\n",
+		visibility_types [DECL_VISIBILITY (vnode->decl)]);
+	}
+}
+
+/*Dump specific variables and functions used in IL*/
+void dump_list2()
+{
+
+	fprintf (stderr, "Call Graph:\n");
+	cgraph_node *cnode;
+	
+	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
+  	static const char * const visibility_types[] = {
+    "default", "protected", "hidden", "internal" };
+	FOR_EACH_FUNCTION (cnode)
+	{
+		if (!strcmp(flag_lto_dump_list2, cnode->name()))
+		{
+			fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
+			fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
+			fprintf (stderr, "\n visibility: %s\n",
+			visibility_types [DECL_VISIBILITY (cnode->decl)]);
+		}
+	}	
+	fprintf (stderr, "\nVarpool:\n");
+	varpool_node *vnode;
+    FOR_EACH_VARIABLE (vnode)
+    {
+    	if (!strcmp(flag_lto_dump_list2, vnode->name()))
+		{	
+			fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
+			fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
+			fprintf (stderr, "\n visibility:%s\n",
+			visibility_types [DECL_VISIBILITY (vnode->decl)]);
+		}
+	}
+}	
\ No newline at end of file
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
new file mode 100644
index 0000000..0aef8d1
--- /dev/null
+++ b/gcc/lto/lto-dump.h
@@ -0,0 +1,27 @@
+/* LTO dump tool
+   Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_LTO_DUMP_H_
+#define GCC_LTO_DUMP_H_
+
+void dump();
+void dump_list();
+void dump_list2();
+
+#endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index d2ccaf6..15a56af 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "attribs.h"
 #include "builtins.h"
-
+#include "lto-dump.h"
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
@@ -3361,6 +3361,18 @@ lto_main (void)
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
+  /*Dump everything*/
+  if (flag_lto_dump)
+    dump();
+
+  /*Dump variables and functions used in IL*/
+  if (flag_lto_dump_list)
+    dump_list();
+
+  /*Dump specific variables and functions used in IL*/
+  if (flag_lto_dump_list2)
+    dump_list2();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 418753c..77f0adb 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
   fprintf (f, "\n");
 }
 
-
 /* Dump given varpool node to stderr.  */
 void varpool_node::debug (void)
 {

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

* Re: [GSOC] LTO dump tool project
  2018-06-01 18:59     ` Hrishikesh Kulkarni
@ 2018-06-04  8:36       ` Martin Liška
  2018-06-04 18:13         ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-04  8:36 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
> Hi,
> I have pushed the changes to github
> (https://github.com/hrisearch/gcc). Added a command line option for
> specific dumps of variables and functions used in IL e.g.
> -fdump-lto-list=foo will dump:
> Call Graph:
> 
> foo/1 (foo)
>   Type: function
>  visibility: default

Hi.

Thanks for the next step. I've got some comments about it:

- -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
  or something similar.

- for -fdump-lto-list I would really prefer to use a format similar to nm:
  print a header with column description and then one line for a symbol

- think about mangling/demangling of C++ symbols, you can take a look at
nm it also has --demangle, --no-demangle

- please learn & try to use an autoformat for your editor in order to
  fulfill GNU coding style. Following checker will help you:

$ ./contrib/check_GNU_style.py /tmp/p
=== ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
gcc/lto/lto-dump.c:38:17:/*Dump everything*/
gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in IL*/
gcc/lto/lto.c:3364:19:  /*Dump everything*/
gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in IL*/

=== ERROR type #2: lines should not exceed 80 characters (11 error(s)) ===
gcc/lto/lto-dump.c:51:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
gcc/lto/lto-dump.c:80:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o

=== ERROR type #3: there should be exactly one space between function name and parenthesis (15 error(s)) ===
gcc/lto/lto-dump.c:39:9:void dump()
gcc/lto/lto-dump.c:41:8:	fprintf(stderr, "\nHello World!\n");
gcc/lto/lto-dump.c:45:14:void dump_list()
gcc/lto/lto-dump.c:74:15:void dump_list2()
gcc/lto/lto-dump.c:85:13:		if (!strcmp(flag_lto_dump_list2, cnode->name()))
gcc/lto/lto-dump.c:97:16:    	if (!strcmp(flag_lto_dump_list2, vnode->name()))
gcc/lto/lto-dump.h:23:9:void dump();
gcc/lto/lto-dump.h:24:14:void dump_list();
gcc/lto/lto-dump.h:25:15:void dump_list2();
gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
gcc/lto/lto.c:3366:8:    dump();
gcc/lto/lto.c:3370:13:    dump_list();
gcc/lto/lto.c:3374:14:    dump_list2();

=== ERROR type #4: there should be no space before a left square bracket (4 error(s)) ===
gcc/lto/lto-dump.c:59:19:		visibility_types [DECL_VISIBILITY (cnode->decl)]);
gcc/lto/lto-dump.c:69:19:		visibility_types [DECL_VISIBILITY (vnode->decl)]);
gcc/lto/lto-dump.c:90:20:			visibility_types [DECL_VISIBILITY (cnode->decl)]);
gcc/lto/lto-dump.c:102:20:			visibility_types [DECL_VISIBILITY (vnode->decl)]);

=== ERROR type #5: trailing whitespace (5 error(s)) ===
gcc/lto/lto-dump.c:50:0:â–ˆ
gcc/lto/lto-dump.c:79:0:â–ˆ
gcc/lto/lto-dump.c:92:2:	}â–ˆ
gcc/lto/lto-dump.c:98:3:		{â–ˆ
gcc/lto/lto-dump.c:105:1:}â–ˆ

And please try to avoid adding blank lines / remove blank lines in files which you don't modify.
Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure, but will help you.

> 
> Regards,
> Hrishikesh
> 
> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>> $ nm main.o
>>> 00000000 T main
>>> 00000000 T mystring
>>> 00000000 C pole
>>
>> Or we can be inspired by readelf:
>>
>> $ readelf -s a.out
>> [snip]
>> Symbol table '.symtab' contains 74 entries:
>>    Num:    Value          Size Type    Bind   Vis      Ndx Name
>>     66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>     67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>     68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>     69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>     70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>> fwrite@@GLIBC_2.2.5
>>
>> Martin
> 
> specific-symbols-dump.diff
> 
> 
> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
> index 9a7d54d..b868695 100644
> --- a/gcc/cgraph.c
> +++ b/gcc/cgraph.c
> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>      fprintf (f, "  Is instrumented version.\n");
>    else if (instrumented_version)
>      fprintf (f, "  Has instrumented version.\n");
> +
>  }
>  
>  /* Dump call graph node NODE to stderr.  */
> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
> index 4695077..465662e 100644
> --- a/gcc/lto/Make-lang.in
> +++ b/gcc/lto/Make-lang.in
> @@ -22,7 +22,7 @@
>  # The name of the LTO compiler.
>  LTO_EXE = lto1$(exeext)
>  # The LTO-specific object files inclued in $(LTO_EXE).
> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>  lto_OBJS = $(LTO_OBJS)
>  
>  # this is only useful in a LTO bootstrap, but this does not work right
> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
> index 0a408d3..7600840 100644
> --- a/gcc/lto/lang.opt
> +++ b/gcc/lto/lang.opt
> @@ -63,6 +63,18 @@ fwpa=
>  LTO Driver RejectNegative Joined Var(flag_wpa)
>  Whole program analysis (WPA) mode with number of parallel jobs specified.
>  
> +fdump
> +LTO Var(flag_lto_dump)
> +Call the dump function.
> +
> +fdump-lto-list
> +LTO Var(flag_lto_dump_list)
> +Call the dump function for variables and function in IL.
> +
> +fdump-lto-list=
> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
> +
> +
>  fresolution=
>  LTO Joined
>  The resolution file.
> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
> new file mode 100644
> index 0000000..90976cb
> --- /dev/null
> +++ b/gcc/lto/lto-dump.c
> @@ -0,0 +1,105 @@
> +/* LTO dump tool
> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +#include "config.h"
> +#include "system.h"
> +#include "coretypes.h"
> +#include "target.h"
> +#include "function.h"
> +#include "basic-block.h"
> +#include "tree.h"
> +#include "gimple.h"
> +#include "cgraph.h"
> +#include "lto-streamer.h"
> +#include "ipa-utils.h"
> +#include "builtins.h"
> +#include "alias.h"
> +#include "lto-symtab.h"
> +#include "stringpool.h"
> +#include "attribs.h"
> +#include "stdio.h"
> +
> +/*Dump everything*/
> +void dump()
> +{
> +	fprintf(stderr, "\nHello World!\n");
> +}
> +
> +/*Dump variables and functions used in IL*/
> +void dump_list()
> +{
> +
> +	fprintf (stderr, "Call Graph:\n");
> +	cgraph_node *cnode;
> +	
> +	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
> +  	static const char * const visibility_types[] = {
> +    "default", "protected", "hidden", "internal" };

We have symbol_node class, this can be refactored into methods.

> +	FOR_EACH_FUNCTION (cnode)
> +	{
> +		fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
> +		fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
> +		fprintf (stderr, "\n visibility: %s\n",
> +		visibility_types [DECL_VISIBILITY (cnode->decl)]);
> +	}
> +
> +	fprintf (stderr, "\nVarpool:\n");
> +	varpool_node *vnode;
> +    FOR_EACH_VARIABLE (vnode)
> +    {
> +		fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
> +		fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
> +		fprintf (stderr, "\n visibility:%s\n",
> +		visibility_types [DECL_VISIBILITY (vnode->decl)]);

Maybe content of the loop body can be a function that will print. Now it's copy&paste.

> +	}
> +}
> +
> +/*Dump specific variables and functions used in IL*/
> +void dump_list2()
> +{
> +
> +	fprintf (stderr, "Call Graph:\n");
> +	cgraph_node *cnode;
> +	
> +	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
> +  	static const char * const visibility_types[] = {
> +    "default", "protected", "hidden", "internal" };
> +	FOR_EACH_FUNCTION (cnode)
> +	{
> +		if (!strcmp(flag_lto_dump_list2, cnode->name()))
> +		{
> +			fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
> +			fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
> +			fprintf (stderr, "\n visibility: %s\n",
> +			visibility_types [DECL_VISIBILITY (cnode->decl)]);
> +		}
> +	}	
> +	fprintf (stderr, "\nVarpool:\n");
> +	varpool_node *vnode;
> +    FOR_EACH_VARIABLE (vnode)
> +    {
> +    	if (!strcmp(flag_lto_dump_list2, vnode->name()))
> +		{	
> +			fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
> +			fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
> +			fprintf (stderr, "\n visibility:%s\n",
> +			visibility_types [DECL_VISIBILITY (vnode->decl)]);
> +		}
> +	}
> +}	

The whole function is copy&paste. Please come up with new methods for symtab_node and use it.

You wrote of the mailing list that you're planning to work on CMD options. But please finish
first dumping of symbols. I would recomment to implement option that will print body
of a function, which should accept similar dumpflags as we use for dump files:

$ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout ~/Programming/testcases/tmp/main.c -c

;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0, symbol_order=2)

main (int argc, char * * argv)
{
  int D.2621;
  int _1;
  int _8;
  int _10;

;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  foo ();
  fwrite (0B, 1, 0, 0B);
  pole[11] = 123;
  if (argc_7(D) == 1)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]
;;    succ:       3
;;                4
...

$ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout ~/Programming/testcases/tmp/main.c -c
int __GIMPLE ()
main (int argc, char * * argv)
{
  int D_2621;
  int _1;
  int _8;
  int _10;

  bb_2:
  foo ();
  fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct FILE * restrict) 0);
  pole[11] = 123;
  if (argc_7(D) == 1)
    goto bb_3;
  else
    goto bb_4;
...

And I would also do a more verbose symbol dump option that will basically call symbol_node::debug.

Thanks,
Martin

> \ No newline at end of file
> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
> new file mode 100644
> index 0000000..0aef8d1
> --- /dev/null
> +++ b/gcc/lto/lto-dump.h
> @@ -0,0 +1,27 @@
> +/* LTO dump tool
> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +#ifndef GCC_LTO_DUMP_H_
> +#define GCC_LTO_DUMP_H_
> +
> +void dump();
> +void dump_list();
> +void dump_list2();
> +
> +#endif
> \ No newline at end of file
> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
> index d2ccaf6..15a56af 100644
> --- a/gcc/lto/lto.c
> +++ b/gcc/lto/lto.c
> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "fold-const.h"
>  #include "attribs.h"
>  #include "builtins.h"
> -
> +#include "lto-dump.h"
>  
>  /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
>  static int lto_parallelism;
> @@ -3361,6 +3361,18 @@ lto_main (void)
>       command line.  */
>    read_cgraph_and_symbols (num_in_fnames, in_fnames);
>  
> +  /*Dump everything*/
> +  if (flag_lto_dump)
> +    dump();
> +
> +  /*Dump variables and functions used in IL*/
> +  if (flag_lto_dump_list)
> +    dump_list();
> +
> +  /*Dump specific variables and functions used in IL*/
> +  if (flag_lto_dump_list2)
> +    dump_list2();
> +
>    timevar_stop (TV_PHASE_STREAM_IN);
>  
>    if (!seen_error ())
> diff --git a/gcc/varpool.c b/gcc/varpool.c
> index 418753c..77f0adb 100644
> --- a/gcc/varpool.c
> +++ b/gcc/varpool.c
> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>    fprintf (f, "\n");
>  }
>  
> -
>  /* Dump given varpool node to stderr.  */
>  void varpool_node::debug (void)
>  {
> 

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

* Re: [GSOC] LTO dump tool project
  2018-06-04  8:36       ` Martin Liška
@ 2018-06-04 18:13         ` Hrishikesh Kulkarni
  2018-06-04 19:08           ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-04 18:13 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

-fdump-lto-list will dump all the symbol list
-fdump-lto-list -demangle will dump all the list with symbol names demangled
-fdump-lto-symbol=foo will dump details of foo

The output(demangled) will be in tabular form like nm:
Symbol Table
        Name         Type         Visibility
              printf            function             default
                   k            variable             default
                main            function             default
                 bar            function             default
                 foo            function             default

I have tried to format the changes according to gnu coding style and
added required methods in symtab_node.

Please find the diff file attached.

Regards,
Hrishikesh

On Mon, Jun 4, 2018 at 2:06 PM, Martin Liška <mliska@suse.cz> wrote:
> On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
>> Hi,
>> I have pushed the changes to github
>> (https://github.com/hrisearch/gcc). Added a command line option for
>> specific dumps of variables and functions used in IL e.g.
>> -fdump-lto-list=foo will dump:
>> Call Graph:
>>
>> foo/1 (foo)
>>   Type: function
>>  visibility: default
>
> Hi.
>
> Thanks for the next step. I've got some comments about it:
>
> - -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
>   or something similar.
>
> - for -fdump-lto-list I would really prefer to use a format similar to nm:
>   print a header with column description and then one line for a symbol
>
> - think about mangling/demangling of C++ symbols, you can take a look at
> nm it also has --demangle, --no-demangle
>
> - please learn & try to use an autoformat for your editor in order to
>   fulfill GNU coding style. Following checker will help you:
>
> $ ./contrib/check_GNU_style.py /tmp/p
> === ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
> gcc/lto/lto-dump.c:38:17:/*Dump everything*/
> gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
> gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in IL*/
> gcc/lto/lto.c:3364:19:  /*Dump everything*/
> gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
> gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in IL*/
>
> === ERROR type #2: lines should not exceed 80 characters (11 error(s)) ===
> gcc/lto/lto-dump.c:51:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
> gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
> gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
> gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
> gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
> gcc/lto/lto-dump.c:80:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
> gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
> gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
> gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
> gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
> gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>
> === ERROR type #3: there should be exactly one space between function name and parenthesis (15 error(s)) ===
> gcc/lto/lto-dump.c:39:9:void dump()
> gcc/lto/lto-dump.c:41:8:        fprintf(stderr, "\nHello World!\n");
> gcc/lto/lto-dump.c:45:14:void dump_list()
> gcc/lto/lto-dump.c:74:15:void dump_list2()
> gcc/lto/lto-dump.c:85:13:               if (!strcmp(flag_lto_dump_list2, cnode->name()))
> gcc/lto/lto-dump.c:97:16:       if (!strcmp(flag_lto_dump_list2, vnode->name()))
> gcc/lto/lto-dump.h:23:9:void dump();
> gcc/lto/lto-dump.h:24:14:void dump_list();
> gcc/lto/lto-dump.h:25:15:void dump_list2();
> gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
> gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
> gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
> gcc/lto/lto.c:3366:8:    dump();
> gcc/lto/lto.c:3370:13:    dump_list();
> gcc/lto/lto.c:3374:14:    dump_list2();
>
> === ERROR type #4: there should be no space before a left square bracket (4 error(s)) ===
> gcc/lto/lto-dump.c:59:19:               visibility_types [DECL_VISIBILITY (cnode->decl)]);
> gcc/lto/lto-dump.c:69:19:               visibility_types [DECL_VISIBILITY (vnode->decl)]);
> gcc/lto/lto-dump.c:90:20:                       visibility_types [DECL_VISIBILITY (cnode->decl)]);
> gcc/lto/lto-dump.c:102:20:                      visibility_types [DECL_VISIBILITY (vnode->decl)]);
>
> === ERROR type #5: trailing whitespace (5 error(s)) ===
> gcc/lto/lto-dump.c:50:0:█
> gcc/lto/lto-dump.c:79:0:█
> gcc/lto/lto-dump.c:92:2:        }█
> gcc/lto/lto-dump.c:98:3:                {█
> gcc/lto/lto-dump.c:105:1:}█
>
> And please try to avoid adding blank lines / remove blank lines in files which you don't modify.
> Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure, but will help you.
>
>>
>> Regards,
>> Hrishikesh
>>
>> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>>> $ nm main.o
>>>> 00000000 T main
>>>> 00000000 T mystring
>>>> 00000000 C pole
>>>
>>> Or we can be inspired by readelf:
>>>
>>> $ readelf -s a.out
>>> [snip]
>>> Symbol table '.symtab' contains 74 entries:
>>>    Num:    Value          Size Type    Bind   Vis      Ndx Name
>>>     66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>>     67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>>     68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>>     69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>>     70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>>> fwrite@@GLIBC_2.2.5
>>>
>>> Martin
>>
>> specific-symbols-dump.diff
>>
>>
>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>> index 9a7d54d..b868695 100644
>> --- a/gcc/cgraph.c
>> +++ b/gcc/cgraph.c
>> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>>      fprintf (f, "  Is instrumented version.\n");
>>    else if (instrumented_version)
>>      fprintf (f, "  Has instrumented version.\n");
>> +
>>  }
>>
>>  /* Dump call graph node NODE to stderr.  */
>> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
>> index 4695077..465662e 100644
>> --- a/gcc/lto/Make-lang.in
>> +++ b/gcc/lto/Make-lang.in
>> @@ -22,7 +22,7 @@
>>  # The name of the LTO compiler.
>>  LTO_EXE = lto1$(exeext)
>>  # The LTO-specific object files inclued in $(LTO_EXE).
>> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
>> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>  lto_OBJS = $(LTO_OBJS)
>>
>>  # this is only useful in a LTO bootstrap, but this does not work right
>> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
>> index 0a408d3..7600840 100644
>> --- a/gcc/lto/lang.opt
>> +++ b/gcc/lto/lang.opt
>> @@ -63,6 +63,18 @@ fwpa=
>>  LTO Driver RejectNegative Joined Var(flag_wpa)
>>  Whole program analysis (WPA) mode with number of parallel jobs specified.
>>
>> +fdump
>> +LTO Var(flag_lto_dump)
>> +Call the dump function.
>> +
>> +fdump-lto-list
>> +LTO Var(flag_lto_dump_list)
>> +Call the dump function for variables and function in IL.
>> +
>> +fdump-lto-list=
>> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>> +
>> +
>>  fresolution=
>>  LTO Joined
>>  The resolution file.
>> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
>> new file mode 100644
>> index 0000000..90976cb
>> --- /dev/null
>> +++ b/gcc/lto/lto-dump.c
>> @@ -0,0 +1,105 @@
>> +/* LTO dump tool
>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>> +
>> +This file is part of GCC.
>> +
>> +GCC is free software; you can redistribute it and/or modify it under
>> +the terms of the GNU General Public License as published by the Free
>> +Software Foundation; either version 3, or (at your option) any later
>> +version.
>> +
>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>> +for more details.
>> +
>> +You should have received a copy of the GNU General Public License
>> +along with GCC; see the file COPYING3.  If not see
>> +<http://www.gnu.org/licenses/>.  */
>> +
>> +#include "config.h"
>> +#include "system.h"
>> +#include "coretypes.h"
>> +#include "target.h"
>> +#include "function.h"
>> +#include "basic-block.h"
>> +#include "tree.h"
>> +#include "gimple.h"
>> +#include "cgraph.h"
>> +#include "lto-streamer.h"
>> +#include "ipa-utils.h"
>> +#include "builtins.h"
>> +#include "alias.h"
>> +#include "lto-symtab.h"
>> +#include "stringpool.h"
>> +#include "attribs.h"
>> +#include "stdio.h"
>> +
>> +/*Dump everything*/
>> +void dump()
>> +{
>> +     fprintf(stderr, "\nHello World!\n");
>> +}
>> +
>> +/*Dump variables and functions used in IL*/
>> +void dump_list()
>> +{
>> +
>> +     fprintf (stderr, "Call Graph:\n");
>> +     cgraph_node *cnode;
>> +
>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> +     static const char * const visibility_types[] = {
>> +    "default", "protected", "hidden", "internal" };
>
> We have symbol_node class, this can be refactored into methods.
>
>> +     FOR_EACH_FUNCTION (cnode)
>> +     {
>> +             fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> +             fprintf (stderr, "\n visibility: %s\n",
>> +             visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> +     }
>> +
>> +     fprintf (stderr, "\nVarpool:\n");
>> +     varpool_node *vnode;
>> +    FOR_EACH_VARIABLE (vnode)
>> +    {
>> +             fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> +             fprintf (stderr, "\n visibility:%s\n",
>> +             visibility_types [DECL_VISIBILITY (vnode->decl)]);
>
> Maybe content of the loop body can be a function that will print. Now it's copy&paste.
>
>> +     }
>> +}
>> +
>> +/*Dump specific variables and functions used in IL*/
>> +void dump_list2()
>> +{
>> +
>> +     fprintf (stderr, "Call Graph:\n");
>> +     cgraph_node *cnode;
>> +
>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> +     static const char * const visibility_types[] = {
>> +    "default", "protected", "hidden", "internal" };
>> +     FOR_EACH_FUNCTION (cnode)
>> +     {
>> +             if (!strcmp(flag_lto_dump_list2, cnode->name()))
>> +             {
>> +                     fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> +                     fprintf (stderr, "\n visibility: %s\n",
>> +                     visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> +             }
>> +     }
>> +     fprintf (stderr, "\nVarpool:\n");
>> +     varpool_node *vnode;
>> +    FOR_EACH_VARIABLE (vnode)
>> +    {
>> +     if (!strcmp(flag_lto_dump_list2, vnode->name()))
>> +             {
>> +                     fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> +                     fprintf (stderr, "\n visibility:%s\n",
>> +                     visibility_types [DECL_VISIBILITY (vnode->decl)]);
>> +             }
>> +     }
>> +}
>
> The whole function is copy&paste. Please come up with new methods for symtab_node and use it.
>
> You wrote of the mailing list that you're planning to work on CMD options. But please finish
> first dumping of symbols. I would recomment to implement option that will print body
> of a function, which should accept similar dumpflags as we use for dump files:
>
> $ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout ~/Programming/testcases/tmp/main.c -c
>
> ;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0, symbol_order=2)
>
> main (int argc, char * * argv)
> {
>   int D.2621;
>   int _1;
>   int _8;
>   int _10;
>
> ;;   basic block 2, loop depth 0
> ;;    pred:       ENTRY
>   foo ();
>   fwrite (0B, 1, 0, 0B);
>   pole[11] = 123;
>   if (argc_7(D) == 1)
>     goto <bb 3>; [INV]
>   else
>     goto <bb 4>; [INV]
> ;;    succ:       3
> ;;                4
> ...
>
> $ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout ~/Programming/testcases/tmp/main.c -c
> int __GIMPLE ()
> main (int argc, char * * argv)
> {
>   int D_2621;
>   int _1;
>   int _8;
>   int _10;
>
>   bb_2:
>   foo ();
>   fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct FILE * restrict) 0);
>   pole[11] = 123;
>   if (argc_7(D) == 1)
>     goto bb_3;
>   else
>     goto bb_4;
> ...
>
> And I would also do a more verbose symbol dump option that will basically call symbol_node::debug.
>
> Thanks,
> Martin
>
>> \ No newline at end of file
>> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
>> new file mode 100644
>> index 0000000..0aef8d1
>> --- /dev/null
>> +++ b/gcc/lto/lto-dump.h
>> @@ -0,0 +1,27 @@
>> +/* LTO dump tool
>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>> +
>> +This file is part of GCC.
>> +
>> +GCC is free software; you can redistribute it and/or modify it under
>> +the terms of the GNU General Public License as published by the Free
>> +Software Foundation; either version 3, or (at your option) any later
>> +version.
>> +
>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>> +for more details.
>> +
>> +You should have received a copy of the GNU General Public License
>> +along with GCC; see the file COPYING3.  If not see
>> +<http://www.gnu.org/licenses/>.  */
>> +
>> +#ifndef GCC_LTO_DUMP_H_
>> +#define GCC_LTO_DUMP_H_
>> +
>> +void dump();
>> +void dump_list();
>> +void dump_list2();
>> +
>> +#endif
>> \ No newline at end of file
>> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
>> index d2ccaf6..15a56af 100644
>> --- a/gcc/lto/lto.c
>> +++ b/gcc/lto/lto.c
>> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>>  #include "fold-const.h"
>>  #include "attribs.h"
>>  #include "builtins.h"
>> -
>> +#include "lto-dump.h"
>>
>>  /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
>>  static int lto_parallelism;
>> @@ -3361,6 +3361,18 @@ lto_main (void)
>>       command line.  */
>>    read_cgraph_and_symbols (num_in_fnames, in_fnames);
>>
>> +  /*Dump everything*/
>> +  if (flag_lto_dump)
>> +    dump();
>> +
>> +  /*Dump variables and functions used in IL*/
>> +  if (flag_lto_dump_list)
>> +    dump_list();
>> +
>> +  /*Dump specific variables and functions used in IL*/
>> +  if (flag_lto_dump_list2)
>> +    dump_list2();
>> +
>>    timevar_stop (TV_PHASE_STREAM_IN);
>>
>>    if (!seen_error ())
>> diff --git a/gcc/varpool.c b/gcc/varpool.c
>> index 418753c..77f0adb 100644
>> --- a/gcc/varpool.c
>> +++ b/gcc/varpool.c
>> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>>    fprintf (f, "\n");
>>  }
>>
>> -
>>  /* Dump given varpool node to stderr.  */
>>  void varpool_node::debug (void)
>>  {
>>
>

[-- Attachment #2: symbols-dump-2.diff --]
[-- Type: text/x-patch, Size: 6327 bytes --]

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index ee7ebb4..ebef347 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -109,6 +109,12 @@ public:
   /* Return dump name with assembler name.  */
   const char *dump_asm_name () const;
 
+  /* Return visibility name.  */
+  const char *dump_visibility () const;
+
+  /* Return type_name name.  */
+  const char *dump_type_name () const;
+
   /* Add node into symbol table.  This function is not used directly, but via
      cgraph/varpool node creation routines.  */
   void register_symbol (void);
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 7600840..a098797 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -71,9 +71,11 @@ fdump-lto-list
 LTO Var(flag_lto_dump_list)
 Call the dump function for variables and function in IL.
 
-fdump-lto-list=
-LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
+fdump-lto-symbol=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 
+demangle
+LTO Var(flag_lto_dump_demangle)
 
 fresolution=
 LTO Joined
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 90976cb..e0becd1 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -34,72 +34,46 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 #include "stdio.h"
+#include "lto.h"
 
-/*Dump everything*/
-void dump()
+/* Dump everything.  */
+void 
+dump ()
 {
 	fprintf(stderr, "\nHello World!\n");
 }
 	
-/*Dump variables and functions used in IL*/
-void dump_list()
+/* Dump variables and functions used in IL.  */
+void
+dump_list ()
 {
 
-	fprintf (stderr, "Call Graph:\n");
-	cgraph_node *cnode;
-	
-	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
-  	static const char * const visibility_types[] = {
-    "default", "protected", "hidden", "internal" };
-	FOR_EACH_FUNCTION (cnode)
+	fprintf (stderr, "Symbol Table\n");
+    symtab_node *node;
+    fprintf (stderr, "\t\tName \t\tType \t\tVisibility\n");
+	FOR_EACH_SYMBOL (node)
 	{
-		fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
-		fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
-		fprintf (stderr, "\n visibility: %s\n",
-		visibility_types [DECL_VISIBILITY (cnode->decl)]);
-	}
-
-	fprintf (stderr, "\nVarpool:\n");
-	varpool_node *vnode;
-    FOR_EACH_VARIABLE (vnode)
-    {
-		fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
-		fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
-		fprintf (stderr, "\n visibility:%s\n",
-		visibility_types [DECL_VISIBILITY (vnode->decl)]);
+		fprintf (stderr, "\n%20s",(flag_lto_dump_demangle) 
+			? node->name (): node->dump_asm_name ());
+		fprintf (stderr, "%20s", node->dump_type_name ());
+		fprintf (stderr, "%20s\n", node->dump_visibility ());
 	}
 }
 
-/*Dump specific variables and functions used in IL*/
-void dump_list2()
+/* Dump specific variables and functions used in IL.  */
+void
+dump_symbol ()
 {
-
-	fprintf (stderr, "Call Graph:\n");
-	cgraph_node *cnode;
-	
-	static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
-  	static const char * const visibility_types[] = {
-    "default", "protected", "hidden", "internal" };
-	FOR_EACH_FUNCTION (cnode)
-	{
-		if (!strcmp(flag_lto_dump_list2, cnode->name()))
-		{
-			fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
-			fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
-			fprintf (stderr, "\n visibility: %s\n",
-			visibility_types [DECL_VISIBILITY (cnode->decl)]);
-		}
-	}	
-	fprintf (stderr, "\nVarpool:\n");
-	varpool_node *vnode;
-    FOR_EACH_VARIABLE (vnode)
+	symtab_node *node;
+    fprintf (stderr, "\t\tName \t\tType \t\tVisibility\n");
+	FOR_EACH_SYMBOL (node)
 	{
-    	if (!strcmp(flag_lto_dump_list2, vnode->name()))
+		if (!strcmp(flag_lto_dump_symbol, node->name()))
 		{
-			fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
-			fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
-			fprintf (stderr, "\n visibility:%s\n",
-			visibility_types [DECL_VISIBILITY (vnode->decl)]);
+			fprintf (stderr, "\n%20s",(flag_lto_dump_demangle) 
+				? node->name (): node->dump_asm_name ());
+		fprintf (stderr, "%20s", node->dump_type_name ());
+		fprintf (stderr, "%20s\n", node->dump_visibility ());
 		}
 	}	
 }	
\ No newline at end of file
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 0aef8d1..352160c 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -20,8 +20,13 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_LTO_DUMP_H_
 #define GCC_LTO_DUMP_H_
 
-void dump();
-void dump_list();
-void dump_list2();
+/* Dump everything.  */
+void dump ();
+
+/*Dump variables and function names used in IL.  */
+void dump_list ();
+
+/*Dump specific variable or function used in IL.  */
+void dump_symbol ();
 
 #endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 15a56af..ab1eed3 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -3361,17 +3361,17 @@ lto_main (void)
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
-  /*Dump everything*/
+  /* Dump everything.  */
   if (flag_lto_dump)
-    dump();
+    dump ();
 
-  /*Dump variables and functions used in IL*/
+  /* Dump variables and functions used in IL.  */
   if (flag_lto_dump_list)
-    dump_list();
+    dump_list ();
 
-  /*Dump specific variables and functions used in IL*/
-  if (flag_lto_dump_list2)
-    dump_list2();
+  /* Dump specific variables and functions used in IL.  */
+  if (flag_lto_dump_symbol)
+    dump_symbol ();
 
   timevar_stop (TV_PHASE_STREAM_IN);
 
diff --git a/gcc/symtab.c b/gcc/symtab.c
index c153308..1d2374f 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -808,6 +808,22 @@ symtab_node::dump_referring (FILE *file)
 
 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
 
+const char *
+symtab_node::dump_visibility () const
+{
+  static const char * const visibility_types[] = {
+    "default", "protected", "hidden", "internal"
+  };
+
+  return visibility_types [DECL_VISIBILITY (decl)];
+}
+
+const char *
+symtab_node::dump_type_name () const
+{
+  return symtab_type_names[type];
+}
+
 /* Dump base fields of symtab nodes to F.  Not to be used directly.  */
 
 void

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

* Re: [GSOC] LTO dump tool project
  2018-06-04 18:13         ` Hrishikesh Kulkarni
@ 2018-06-04 19:08           ` Martin Liška
  2018-06-08 13:41             ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-04 19:08 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/04/2018 08:13 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> -fdump-lto-list will dump all the symbol list

I see extra new lines in the output:

$ lto1 -fdump-lto-list main.o
[..snip..]
Symbol Table
		Name 		Type 		Visibility

            fwrite/15            function             default

               foo/14            function             default

          mystring/12            variable             default

              pole/11            variable             default

              main/13            function             default

> -fdump-lto-list -demangle will dump all the list with symbol names demangled

Good for now. Note that non-demagle version prints function names with order (/$number).
I would not print that.

> -fdump-lto-symbol=foo will dump details of foo

I would really prefer to use symtab_node::debug for now. It presents all details about
symbol instead of current implementation which does: '-fdump-lto-list | grep foo'

> 
> The output(demangled) will be in tabular form like nm:
> Symbol Table
>          Name         Type         Visibility
>                printf            function             default
>                     k            variable             default
>                  main            function             default
>                   bar            function             default
>                   foo            function             default
> 
> I have tried to format the changes according to gnu coding style and
> added required methods in symtab_node.

That's nice that you came up with new symbol_node methods. It's much better.
About the GNU coding style, I still see trailing whitespace:

=== ERROR type #3: there should be no space before a left square bracket (1 error(s)) ===
gcc/symtab.c:818:26:  return visibility_types [DECL_VISIBILITY (decl)];

=== ERROR type #4: trailing whitespace (6 error(s)) ===
gcc/lto/lto-dump.c:40:4:voidâ–ˆ
gcc/lto/lto-dump.c:45:0:â–ˆ
gcc/lto/lto-dump.c:56:52:		fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)â–ˆ
gcc/lto/lto-dump.c:73:53:			fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)â–ˆ
gcc/lto/lto-dump.c:78:2:	}â–ˆ
gcc/lto/lto-dump.c:79:1:}â–ˆ

Martin

> 
> Please find the diff file attached.
> 
> Regards,
> Hrishikesh
> 
> On Mon, Jun 4, 2018 at 2:06 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>> I have pushed the changes to github
>>> (https://github.com/hrisearch/gcc). Added a command line option for
>>> specific dumps of variables and functions used in IL e.g.
>>> -fdump-lto-list=foo will dump:
>>> Call Graph:
>>>
>>> foo/1 (foo)
>>>    Type: function
>>>   visibility: default
>>
>> Hi.
>>
>> Thanks for the next step. I've got some comments about it:
>>
>> - -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
>>    or something similar.
>>
>> - for -fdump-lto-list I would really prefer to use a format similar to nm:
>>    print a header with column description and then one line for a symbol
>>
>> - think about mangling/demangling of C++ symbols, you can take a look at
>> nm it also has --demangle, --no-demangle
>>
>> - please learn & try to use an autoformat for your editor in order to
>>    fulfill GNU coding style. Following checker will help you:
>>
>> $ ./contrib/check_GNU_style.py /tmp/p
>> === ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
>> gcc/lto/lto-dump.c:38:17:/*Dump everything*/
>> gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
>> gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in IL*/
>> gcc/lto/lto.c:3364:19:  /*Dump everything*/
>> gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
>> gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in IL*/
>>
>> === ERROR type #2: lines should not exceed 80 characters (11 error(s)) ===
>> gcc/lto/lto-dump.c:51:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> gcc/lto/lto-dump.c:80:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>
>> === ERROR type #3: there should be exactly one space between function name and parenthesis (15 error(s)) ===
>> gcc/lto/lto-dump.c:39:9:void dump()
>> gcc/lto/lto-dump.c:41:8:        fprintf(stderr, "\nHello World!\n");
>> gcc/lto/lto-dump.c:45:14:void dump_list()
>> gcc/lto/lto-dump.c:74:15:void dump_list2()
>> gcc/lto/lto-dump.c:85:13:               if (!strcmp(flag_lto_dump_list2, cnode->name()))
>> gcc/lto/lto-dump.c:97:16:       if (!strcmp(flag_lto_dump_list2, vnode->name()))
>> gcc/lto/lto-dump.h:23:9:void dump();
>> gcc/lto/lto-dump.h:24:14:void dump_list();
>> gcc/lto/lto-dump.h:25:15:void dump_list2();
>> gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
>> gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
>> gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>> gcc/lto/lto.c:3366:8:    dump();
>> gcc/lto/lto.c:3370:13:    dump_list();
>> gcc/lto/lto.c:3374:14:    dump_list2();
>>
>> === ERROR type #4: there should be no space before a left square bracket (4 error(s)) ===
>> gcc/lto/lto-dump.c:59:19:               visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> gcc/lto/lto-dump.c:69:19:               visibility_types [DECL_VISIBILITY (vnode->decl)]);
>> gcc/lto/lto-dump.c:90:20:                       visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> gcc/lto/lto-dump.c:102:20:                      visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>
>> === ERROR type #5: trailing whitespace (5 error(s)) ===
>> gcc/lto/lto-dump.c:50:0:â–ˆ
>> gcc/lto/lto-dump.c:79:0:â–ˆ
>> gcc/lto/lto-dump.c:92:2:        }â–ˆ
>> gcc/lto/lto-dump.c:98:3:                {â–ˆ
>> gcc/lto/lto-dump.c:105:1:}â–ˆ
>>
>> And please try to avoid adding blank lines / remove blank lines in files which you don't modify.
>> Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure, but will help you.
>>
>>>
>>> Regards,
>>> Hrishikesh
>>>
>>> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>>>> $ nm main.o
>>>>> 00000000 T main
>>>>> 00000000 T mystring
>>>>> 00000000 C pole
>>>>
>>>> Or we can be inspired by readelf:
>>>>
>>>> $ readelf -s a.out
>>>> [snip]
>>>> Symbol table '.symtab' contains 74 entries:
>>>>     Num:    Value          Size Type    Bind   Vis      Ndx Name
>>>>      66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>>>      67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>>>      68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>>>      69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>>>      70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>>>> fwrite@@GLIBC_2.2.5
>>>>
>>>> Martin
>>>
>>> specific-symbols-dump.diff
>>>
>>>
>>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>>> index 9a7d54d..b868695 100644
>>> --- a/gcc/cgraph.c
>>> +++ b/gcc/cgraph.c
>>> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>>>       fprintf (f, "  Is instrumented version.\n");
>>>     else if (instrumented_version)
>>>       fprintf (f, "  Has instrumented version.\n");
>>> +
>>>   }
>>>
>>>   /* Dump call graph node NODE to stderr.  */
>>> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
>>> index 4695077..465662e 100644
>>> --- a/gcc/lto/Make-lang.in
>>> +++ b/gcc/lto/Make-lang.in
>>> @@ -22,7 +22,7 @@
>>>   # The name of the LTO compiler.
>>>   LTO_EXE = lto1$(exeext)
>>>   # The LTO-specific object files inclued in $(LTO_EXE).
>>> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
>>> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>>   lto_OBJS = $(LTO_OBJS)
>>>
>>>   # this is only useful in a LTO bootstrap, but this does not work right
>>> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
>>> index 0a408d3..7600840 100644
>>> --- a/gcc/lto/lang.opt
>>> +++ b/gcc/lto/lang.opt
>>> @@ -63,6 +63,18 @@ fwpa=
>>>   LTO Driver RejectNegative Joined Var(flag_wpa)
>>>   Whole program analysis (WPA) mode with number of parallel jobs specified.
>>>
>>> +fdump
>>> +LTO Var(flag_lto_dump)
>>> +Call the dump function.
>>> +
>>> +fdump-lto-list
>>> +LTO Var(flag_lto_dump_list)
>>> +Call the dump function for variables and function in IL.
>>> +
>>> +fdump-lto-list=
>>> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>>> +
>>> +
>>>   fresolution=
>>>   LTO Joined
>>>   The resolution file.
>>> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
>>> new file mode 100644
>>> index 0000000..90976cb
>>> --- /dev/null
>>> +++ b/gcc/lto/lto-dump.c
>>> @@ -0,0 +1,105 @@
>>> +/* LTO dump tool
>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>> +
>>> +This file is part of GCC.
>>> +
>>> +GCC is free software; you can redistribute it and/or modify it under
>>> +the terms of the GNU General Public License as published by the Free
>>> +Software Foundation; either version 3, or (at your option) any later
>>> +version.
>>> +
>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>> +for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with GCC; see the file COPYING3.  If not see
>>> +<http://www.gnu.org/licenses/>.  */
>>> +
>>> +#include "config.h"
>>> +#include "system.h"
>>> +#include "coretypes.h"
>>> +#include "target.h"
>>> +#include "function.h"
>>> +#include "basic-block.h"
>>> +#include "tree.h"
>>> +#include "gimple.h"
>>> +#include "cgraph.h"
>>> +#include "lto-streamer.h"
>>> +#include "ipa-utils.h"
>>> +#include "builtins.h"
>>> +#include "alias.h"
>>> +#include "lto-symtab.h"
>>> +#include "stringpool.h"
>>> +#include "attribs.h"
>>> +#include "stdio.h"
>>> +
>>> +/*Dump everything*/
>>> +void dump()
>>> +{
>>> +     fprintf(stderr, "\nHello World!\n");
>>> +}
>>> +
>>> +/*Dump variables and functions used in IL*/
>>> +void dump_list()
>>> +{
>>> +
>>> +     fprintf (stderr, "Call Graph:\n");
>>> +     cgraph_node *cnode;
>>> +
>>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>>> +     static const char * const visibility_types[] = {
>>> +    "default", "protected", "hidden", "internal" };
>>
>> We have symbol_node class, this can be refactored into methods.
>>
>>> +     FOR_EACH_FUNCTION (cnode)
>>> +     {
>>> +             fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>>> +             fprintf (stderr, "\n visibility: %s\n",
>>> +             visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>> +     }
>>> +
>>> +     fprintf (stderr, "\nVarpool:\n");
>>> +     varpool_node *vnode;
>>> +    FOR_EACH_VARIABLE (vnode)
>>> +    {
>>> +             fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>>> +             fprintf (stderr, "\n visibility:%s\n",
>>> +             visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>
>> Maybe content of the loop body can be a function that will print. Now it's copy&paste.
>>
>>> +     }
>>> +}
>>> +
>>> +/*Dump specific variables and functions used in IL*/
>>> +void dump_list2()
>>> +{
>>> +
>>> +     fprintf (stderr, "Call Graph:\n");
>>> +     cgraph_node *cnode;
>>> +
>>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>>> +     static const char * const visibility_types[] = {
>>> +    "default", "protected", "hidden", "internal" };
>>> +     FOR_EACH_FUNCTION (cnode)
>>> +     {
>>> +             if (!strcmp(flag_lto_dump_list2, cnode->name()))
>>> +             {
>>> +                     fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>>> +                     fprintf (stderr, "\n visibility: %s\n",
>>> +                     visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>> +             }
>>> +     }
>>> +     fprintf (stderr, "\nVarpool:\n");
>>> +     varpool_node *vnode;
>>> +    FOR_EACH_VARIABLE (vnode)
>>> +    {
>>> +     if (!strcmp(flag_lto_dump_list2, vnode->name()))
>>> +             {
>>> +                     fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>>> +                     fprintf (stderr, "\n visibility:%s\n",
>>> +                     visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>> +             }
>>> +     }
>>> +}
>>
>> The whole function is copy&paste. Please come up with new methods for symtab_node and use it.
>>
>> You wrote of the mailing list that you're planning to work on CMD options. But please finish
>> first dumping of symbols. I would recomment to implement option that will print body
>> of a function, which should accept similar dumpflags as we use for dump files:
>>
>> $ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout ~/Programming/testcases/tmp/main.c -c
>>
>> ;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0, symbol_order=2)
>>
>> main (int argc, char * * argv)
>> {
>>    int D.2621;
>>    int _1;
>>    int _8;
>>    int _10;
>>
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>    foo ();
>>    fwrite (0B, 1, 0, 0B);
>>    pole[11] = 123;
>>    if (argc_7(D) == 1)
>>      goto <bb 3>; [INV]
>>    else
>>      goto <bb 4>; [INV]
>> ;;    succ:       3
>> ;;                4
>> ...
>>
>> $ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout ~/Programming/testcases/tmp/main.c -c
>> int __GIMPLE ()
>> main (int argc, char * * argv)
>> {
>>    int D_2621;
>>    int _1;
>>    int _8;
>>    int _10;
>>
>>    bb_2:
>>    foo ();
>>    fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct FILE * restrict) 0);
>>    pole[11] = 123;
>>    if (argc_7(D) == 1)
>>      goto bb_3;
>>    else
>>      goto bb_4;
>> ...
>>
>> And I would also do a more verbose symbol dump option that will basically call symbol_node::debug.
>>
>> Thanks,
>> Martin
>>
>>> \ No newline at end of file
>>> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
>>> new file mode 100644
>>> index 0000000..0aef8d1
>>> --- /dev/null
>>> +++ b/gcc/lto/lto-dump.h
>>> @@ -0,0 +1,27 @@
>>> +/* LTO dump tool
>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>> +
>>> +This file is part of GCC.
>>> +
>>> +GCC is free software; you can redistribute it and/or modify it under
>>> +the terms of the GNU General Public License as published by the Free
>>> +Software Foundation; either version 3, or (at your option) any later
>>> +version.
>>> +
>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>> +for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with GCC; see the file COPYING3.  If not see
>>> +<http://www.gnu.org/licenses/>.  */
>>> +
>>> +#ifndef GCC_LTO_DUMP_H_
>>> +#define GCC_LTO_DUMP_H_
>>> +
>>> +void dump();
>>> +void dump_list();
>>> +void dump_list2();
>>> +
>>> +#endif
>>> \ No newline at end of file
>>> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
>>> index d2ccaf6..15a56af 100644
>>> --- a/gcc/lto/lto.c
>>> +++ b/gcc/lto/lto.c
>>> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>>>   #include "fold-const.h"
>>>   #include "attribs.h"
>>>   #include "builtins.h"
>>> -
>>> +#include "lto-dump.h"
>>>
>>>   /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
>>>   static int lto_parallelism;
>>> @@ -3361,6 +3361,18 @@ lto_main (void)
>>>        command line.  */
>>>     read_cgraph_and_symbols (num_in_fnames, in_fnames);
>>>
>>> +  /*Dump everything*/
>>> +  if (flag_lto_dump)
>>> +    dump();
>>> +
>>> +  /*Dump variables and functions used in IL*/
>>> +  if (flag_lto_dump_list)
>>> +    dump_list();
>>> +
>>> +  /*Dump specific variables and functions used in IL*/
>>> +  if (flag_lto_dump_list2)
>>> +    dump_list2();
>>> +
>>>     timevar_stop (TV_PHASE_STREAM_IN);
>>>
>>>     if (!seen_error ())
>>> diff --git a/gcc/varpool.c b/gcc/varpool.c
>>> index 418753c..77f0adb 100644
>>> --- a/gcc/varpool.c
>>> +++ b/gcc/varpool.c
>>> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>>>     fprintf (f, "\n");
>>>   }
>>>
>>> -
>>>   /* Dump given varpool node to stderr.  */
>>>   void varpool_node::debug (void)
>>>   {
>>>
>>

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

* Re: [GSOC] LTO dump tool project
  2018-06-04 19:08           ` Martin Liška
@ 2018-06-08 13:41             ` Hrishikesh Kulkarni
  2018-06-08 13:45               ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-08 13:41 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

Linking is not taking place as the debug_function() being used is in
tree-cfg.c. How should I go about on adding in make-file considering
the dependencies?

Please find the diff file attached herewith.

Regards,
Hrishikesh

On Tue, Jun 5, 2018 at 12:38 AM, Martin Liška <mliska@suse.cz> wrote:
> On 06/04/2018 08:13 PM, Hrishikesh Kulkarni wrote:
>>
>> Hi,
>>
>> -fdump-lto-list will dump all the symbol list
>
>
> I see extra new lines in the output:
>
> $ lto1 -fdump-lto-list main.o
> [..snip..]
> Symbol Table
>                 Name            Type            Visibility
>
>            fwrite/15            function             default
>
>               foo/14            function             default
>
>          mystring/12            variable             default
>
>              pole/11            variable             default
>
>              main/13            function             default
>
>> -fdump-lto-list -demangle will dump all the list with symbol names
>> demangled
>
>
> Good for now. Note that non-demagle version prints function names with order
> (/$number).
> I would not print that.
>
>> -fdump-lto-symbol=foo will dump details of foo
>
>
> I would really prefer to use symtab_node::debug for now. It presents all
> details about
> symbol instead of current implementation which does: '-fdump-lto-list | grep
> foo'
>
>>
>> The output(demangled) will be in tabular form like nm:
>> Symbol Table
>>          Name         Type         Visibility
>>                printf            function             default
>>                     k            variable             default
>>                  main            function             default
>>                   bar            function             default
>>                   foo            function             default
>>
>> I have tried to format the changes according to gnu coding style and
>> added required methods in symtab_node.
>
>
> That's nice that you came up with new symbol_node methods. It's much better.
> About the GNU coding style, I still see trailing whitespace:
>
> === ERROR type #3: there should be no space before a left square bracket (1
> error(s)) ===
> gcc/symtab.c:818:26:  return visibility_types [DECL_VISIBILITY (decl)];
>
> === ERROR type #4: trailing whitespace (6 error(s)) ===
> gcc/lto/lto-dump.c:40:4:void█
> gcc/lto/lto-dump.c:45:0:█
> gcc/lto/lto-dump.c:56:52:               fprintf (stderr,
> "\n%20s",(flag_lto_dump_demangle)█
> gcc/lto/lto-dump.c:73:53:                       fprintf (stderr,
> "\n%20s",(flag_lto_dump_demangle)█
> gcc/lto/lto-dump.c:78:2:        }█
> gcc/lto/lto-dump.c:79:1:}█
>
> Martin
>
>
>>
>> Please find the diff file attached.
>>
>> Regards,
>> Hrishikesh
>>
>> On Mon, Jun 4, 2018 at 2:06 PM, Martin Liška <mliska@suse.cz> wrote:
>>>
>>> On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
>>>>
>>>> Hi,
>>>> I have pushed the changes to github
>>>> (https://github.com/hrisearch/gcc). Added a command line option for
>>>> specific dumps of variables and functions used in IL e.g.
>>>> -fdump-lto-list=foo will dump:
>>>> Call Graph:
>>>>
>>>> foo/1 (foo)
>>>>    Type: function
>>>>   visibility: default
>>>
>>>
>>> Hi.
>>>
>>> Thanks for the next step. I've got some comments about it:
>>>
>>> - -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
>>>    or something similar.
>>>
>>> - for -fdump-lto-list I would really prefer to use a format similar to
>>> nm:
>>>    print a header with column description and then one line for a symbol
>>>
>>> - think about mangling/demangling of C++ symbols, you can take a look at
>>> nm it also has --demangle, --no-demangle
>>>
>>> - please learn & try to use an autoformat for your editor in order to
>>>    fulfill GNU coding style. Following checker will help you:
>>>
>>> $ ./contrib/check_GNU_style.py /tmp/p
>>> === ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
>>> gcc/lto/lto-dump.c:38:17:/*Dump everything*/
>>> gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
>>> gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in
>>> IL*/
>>> gcc/lto/lto.c:3364:19:  /*Dump everything*/
>>> gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
>>> gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in
>>> IL*/
>>>
>>> === ERROR type #2: lines should not exceed 80 characters (11 error(s))
>>> ===
>>> gcc/lto/lto-dump.c:51:80:        static const char * const
>>> symtab_type_names[] = {"symbol", "function", "variable"};
>>> gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)",
>>> cnode->dump_asm_name (), cnode->name ());
>>> gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s",
>>> symtab_type_names[cnode->type]);
>>> gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)",
>>> vnode->dump_asm_name (), vnode->name ());
>>> gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s",
>>> symtab_type_names[vnode->type]);
>>> gcc/lto/lto-dump.c:80:80:        static const char * const
>>> symtab_type_names[] = {"symbol", "function", "variable"};
>>> gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s
>>> (%s)", cnode->dump_asm_name (), cnode->name ());
>>> gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n
>>> Type: %s", symtab_type_names[cnode->type]);
>>> gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s
>>> (%s)", vnode->dump_asm_name (), vnode->name ());
>>> gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n
>>> Type: %s", symtab_type_names[vnode->type]);
>>> gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o
>>> lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
>>> lto/lto-dump.o
>>>
>>> === ERROR type #3: there should be exactly one space between function
>>> name and parenthesis (15 error(s)) ===
>>> gcc/lto/lto-dump.c:39:9:void dump()
>>> gcc/lto/lto-dump.c:41:8:        fprintf(stderr, "\nHello World!\n");
>>> gcc/lto/lto-dump.c:45:14:void dump_list()
>>> gcc/lto/lto-dump.c:74:15:void dump_list2()
>>> gcc/lto/lto-dump.c:85:13:               if (!strcmp(flag_lto_dump_list2,
>>> cnode->name()))
>>> gcc/lto/lto-dump.c:97:16:       if (!strcmp(flag_lto_dump_list2,
>>> vnode->name()))
>>> gcc/lto/lto-dump.h:23:9:void dump();
>>> gcc/lto/lto-dump.h:24:14:void dump_list();
>>> gcc/lto/lto-dump.h:25:15:void dump_list2();
>>> gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
>>> gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
>>> gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined
>>> Var(flag_lto_dump_list2)
>>> gcc/lto/lto.c:3366:8:    dump();
>>> gcc/lto/lto.c:3370:13:    dump_list();
>>> gcc/lto/lto.c:3374:14:    dump_list2();
>>>
>>> === ERROR type #4: there should be no space before a left square bracket
>>> (4 error(s)) ===
>>> gcc/lto/lto-dump.c:59:19:               visibility_types [DECL_VISIBILITY
>>> (cnode->decl)]);
>>> gcc/lto/lto-dump.c:69:19:               visibility_types [DECL_VISIBILITY
>>> (vnode->decl)]);
>>> gcc/lto/lto-dump.c:90:20:                       visibility_types
>>> [DECL_VISIBILITY (cnode->decl)]);
>>> gcc/lto/lto-dump.c:102:20:                      visibility_types
>>> [DECL_VISIBILITY (vnode->decl)]);
>>>
>>> === ERROR type #5: trailing whitespace (5 error(s)) ===
>>> gcc/lto/lto-dump.c:50:0:█
>>> gcc/lto/lto-dump.c:79:0:█
>>> gcc/lto/lto-dump.c:92:2:        }█
>>> gcc/lto/lto-dump.c:98:3:                {█
>>> gcc/lto/lto-dump.c:105:1:}█
>>>
>>> And please try to avoid adding blank lines / remove blank lines in files
>>> which you don't modify.
>>> Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure,
>>> but will help you.
>>>
>>>>
>>>> Regards,
>>>> Hrishikesh
>>>>
>>>> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>
>>>>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>>>>>
>>>>>> $ nm main.o
>>>>>> 00000000 T main
>>>>>> 00000000 T mystring
>>>>>> 00000000 C pole
>>>>>
>>>>>
>>>>> Or we can be inspired by readelf:
>>>>>
>>>>> $ readelf -s a.out
>>>>> [snip]
>>>>> Symbol table '.symtab' contains 74 entries:
>>>>>     Num:    Value          Size Type    Bind   Vis      Ndx Name
>>>>>      66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>>>>      67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>>>>      68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>>>>      69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>>>>      70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>>>>> fwrite@@GLIBC_2.2.5
>>>>>
>>>>> Martin
>>>>
>>>>
>>>> specific-symbols-dump.diff
>>>>
>>>>
>>>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>>>> index 9a7d54d..b868695 100644
>>>> --- a/gcc/cgraph.c
>>>> +++ b/gcc/cgraph.c
>>>> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>>>>       fprintf (f, "  Is instrumented version.\n");
>>>>     else if (instrumented_version)
>>>>       fprintf (f, "  Has instrumented version.\n");
>>>> +
>>>>   }
>>>>
>>>>   /* Dump call graph node NODE to stderr.  */
>>>> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
>>>> index 4695077..465662e 100644
>>>> --- a/gcc/lto/Make-lang.in
>>>> +++ b/gcc/lto/Make-lang.in
>>>> @@ -22,7 +22,7 @@
>>>>   # The name of the LTO compiler.
>>>>   LTO_EXE = lto1$(exeext)
>>>>   # The LTO-specific object files inclued in $(LTO_EXE).
>>>> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o
>>>> lto/lto-partition.o lto/lto-symtab.o
>>>> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o
>>>> lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>>>   lto_OBJS = $(LTO_OBJS)
>>>>
>>>>   # this is only useful in a LTO bootstrap, but this does not work right
>>>> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
>>>> index 0a408d3..7600840 100644
>>>> --- a/gcc/lto/lang.opt
>>>> +++ b/gcc/lto/lang.opt
>>>> @@ -63,6 +63,18 @@ fwpa=
>>>>   LTO Driver RejectNegative Joined Var(flag_wpa)
>>>>   Whole program analysis (WPA) mode with number of parallel jobs
>>>> specified.
>>>>
>>>> +fdump
>>>> +LTO Var(flag_lto_dump)
>>>> +Call the dump function.
>>>> +
>>>> +fdump-lto-list
>>>> +LTO Var(flag_lto_dump_list)
>>>> +Call the dump function for variables and function in IL.
>>>> +
>>>> +fdump-lto-list=
>>>> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>>>> +
>>>> +
>>>>   fresolution=
>>>>   LTO Joined
>>>>   The resolution file.
>>>> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
>>>> new file mode 100644
>>>> index 0000000..90976cb
>>>> --- /dev/null
>>>> +++ b/gcc/lto/lto-dump.c
>>>> @@ -0,0 +1,105 @@
>>>> +/* LTO dump tool
>>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>>> +
>>>> +This file is part of GCC.
>>>> +
>>>> +GCC is free software; you can redistribute it and/or modify it under
>>>> +the terms of the GNU General Public License as published by the Free
>>>> +Software Foundation; either version 3, or (at your option) any later
>>>> +version.
>>>> +
>>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>>> +for more details.
>>>> +
>>>> +You should have received a copy of the GNU General Public License
>>>> +along with GCC; see the file COPYING3.  If not see
>>>> +<http://www.gnu.org/licenses/>.  */
>>>> +
>>>> +#include "config.h"
>>>> +#include "system.h"
>>>> +#include "coretypes.h"
>>>> +#include "target.h"
>>>> +#include "function.h"
>>>> +#include "basic-block.h"
>>>> +#include "tree.h"
>>>> +#include "gimple.h"
>>>> +#include "cgraph.h"
>>>> +#include "lto-streamer.h"
>>>> +#include "ipa-utils.h"
>>>> +#include "builtins.h"
>>>> +#include "alias.h"
>>>> +#include "lto-symtab.h"
>>>> +#include "stringpool.h"
>>>> +#include "attribs.h"
>>>> +#include "stdio.h"
>>>> +
>>>> +/*Dump everything*/
>>>> +void dump()
>>>> +{
>>>> +     fprintf(stderr, "\nHello World!\n");
>>>> +}
>>>> +
>>>> +/*Dump variables and functions used in IL*/
>>>> +void dump_list()
>>>> +{
>>>> +
>>>> +     fprintf (stderr, "Call Graph:\n");
>>>> +     cgraph_node *cnode;
>>>> +
>>>> +     static const char * const symtab_type_names[] = {"symbol",
>>>> "function", "variable"};
>>>> +     static const char * const visibility_types[] = {
>>>> +    "default", "protected", "hidden", "internal" };
>>>
>>>
>>> We have symbol_node class, this can be refactored into methods.
>>>
>>>> +     FOR_EACH_FUNCTION (cnode)
>>>> +     {
>>>> +             fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (),
>>>> cnode->name ());
>>>> +             fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[cnode->type]);
>>>> +             fprintf (stderr, "\n visibility: %s\n",
>>>> +             visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>>> +     }
>>>> +
>>>> +     fprintf (stderr, "\nVarpool:\n");
>>>> +     varpool_node *vnode;
>>>> +    FOR_EACH_VARIABLE (vnode)
>>>> +    {
>>>> +             fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (),
>>>> vnode->name ());
>>>> +             fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[vnode->type]);
>>>> +             fprintf (stderr, "\n visibility:%s\n",
>>>> +             visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>>
>>>
>>> Maybe content of the loop body can be a function that will print. Now
>>> it's copy&paste.
>>>
>>>> +     }
>>>> +}
>>>> +
>>>> +/*Dump specific variables and functions used in IL*/
>>>> +void dump_list2()
>>>> +{
>>>> +
>>>> +     fprintf (stderr, "Call Graph:\n");
>>>> +     cgraph_node *cnode;
>>>> +
>>>> +     static const char * const symtab_type_names[] = {"symbol",
>>>> "function", "variable"};
>>>> +     static const char * const visibility_types[] = {
>>>> +    "default", "protected", "hidden", "internal" };
>>>> +     FOR_EACH_FUNCTION (cnode)
>>>> +     {
>>>> +             if (!strcmp(flag_lto_dump_list2, cnode->name()))
>>>> +             {
>>>> +                     fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name
>>>> (), cnode->name ());
>>>> +                     fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[cnode->type]);
>>>> +                     fprintf (stderr, "\n visibility: %s\n",
>>>> +                     visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>>> +             }
>>>> +     }
>>>> +     fprintf (stderr, "\nVarpool:\n");
>>>> +     varpool_node *vnode;
>>>> +    FOR_EACH_VARIABLE (vnode)
>>>> +    {
>>>> +     if (!strcmp(flag_lto_dump_list2, vnode->name()))
>>>> +             {
>>>> +                     fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name
>>>> (), vnode->name ());
>>>> +                     fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[vnode->type]);
>>>> +                     fprintf (stderr, "\n visibility:%s\n",
>>>> +                     visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>>> +             }
>>>> +     }
>>>> +}
>>>
>>>
>>> The whole function is copy&paste. Please come up with new methods for
>>> symtab_node and use it.
>>>
>>> You wrote of the mailing list that you're planning to work on CMD
>>> options. But please finish
>>> first dumping of symbols. I would recomment to implement option that will
>>> print body
>>> of a function, which should accept similar dumpflags as we use for dump
>>> files:
>>>
>>> $ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout
>>> ~/Programming/testcases/tmp/main.c -c
>>>
>>> ;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0,
>>> symbol_order=2)
>>>
>>> main (int argc, char * * argv)
>>> {
>>>    int D.2621;
>>>    int _1;
>>>    int _8;
>>>    int _10;
>>>
>>> ;;   basic block 2, loop depth 0
>>> ;;    pred:       ENTRY
>>>    foo ();
>>>    fwrite (0B, 1, 0, 0B);
>>>    pole[11] = 123;
>>>    if (argc_7(D) == 1)
>>>      goto <bb 3>; [INV]
>>>    else
>>>      goto <bb 4>; [INV]
>>> ;;    succ:       3
>>> ;;                4
>>> ...
>>>
>>> $ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout
>>> ~/Programming/testcases/tmp/main.c -c
>>> int __GIMPLE ()
>>> main (int argc, char * * argv)
>>> {
>>>    int D_2621;
>>>    int _1;
>>>    int _8;
>>>    int _10;
>>>
>>>    bb_2:
>>>    foo ();
>>>    fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct
>>> FILE * restrict) 0);
>>>    pole[11] = 123;
>>>    if (argc_7(D) == 1)
>>>      goto bb_3;
>>>    else
>>>      goto bb_4;
>>> ...
>>>
>>> And I would also do a more verbose symbol dump option that will basically
>>> call symbol_node::debug.
>>>
>>> Thanks,
>>> Martin
>>>
>>>> \ No newline at end of file
>>>> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
>>>> new file mode 100644
>>>> index 0000000..0aef8d1
>>>> --- /dev/null
>>>> +++ b/gcc/lto/lto-dump.h
>>>> @@ -0,0 +1,27 @@
>>>> +/* LTO dump tool
>>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>>> +
>>>> +This file is part of GCC.
>>>> +
>>>> +GCC is free software; you can redistribute it and/or modify it under
>>>> +the terms of the GNU General Public License as published by the Free
>>>> +Software Foundation; either version 3, or (at your option) any later
>>>> +version.
>>>> +
>>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>>> +for more details.
>>>> +
>>>> +You should have received a copy of the GNU General Public License
>>>> +along with GCC; see the file COPYING3.  If not see
>>>> +<http://www.gnu.org/licenses/>.  */
>>>> +
>>>> +#ifndef GCC_LTO_DUMP_H_
>>>> +#define GCC_LTO_DUMP_H_
>>>> +
>>>> +void dump();
>>>> +void dump_list();
>>>> +void dump_list2();
>>>> +
>>>> +#endif
>>>> \ No newline at end of file
>>>> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
>>>> index d2ccaf6..15a56af 100644
>>>> --- a/gcc/lto/lto.c
>>>> +++ b/gcc/lto/lto.c
>>>> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>>>>   #include "fold-const.h"
>>>>   #include "attribs.h"
>>>>   #include "builtins.h"
>>>> -
>>>> +#include "lto-dump.h"
>>>>
>>>>   /* Number of parallel tasks to run, -1 if we want to use GNU Make
>>>> jobserver.  */
>>>>   static int lto_parallelism;
>>>> @@ -3361,6 +3361,18 @@ lto_main (void)
>>>>        command line.  */
>>>>     read_cgraph_and_symbols (num_in_fnames, in_fnames);
>>>>
>>>> +  /*Dump everything*/
>>>> +  if (flag_lto_dump)
>>>> +    dump();
>>>> +
>>>> +  /*Dump variables and functions used in IL*/
>>>> +  if (flag_lto_dump_list)
>>>> +    dump_list();
>>>> +
>>>> +  /*Dump specific variables and functions used in IL*/
>>>> +  if (flag_lto_dump_list2)
>>>> +    dump_list2();
>>>> +
>>>>     timevar_stop (TV_PHASE_STREAM_IN);
>>>>
>>>>     if (!seen_error ())
>>>> diff --git a/gcc/varpool.c b/gcc/varpool.c
>>>> index 418753c..77f0adb 100644
>>>> --- a/gcc/varpool.c
>>>> +++ b/gcc/varpool.c
>>>> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>>>>     fprintf (f, "\n");
>>>>   }
>>>>
>>>> -
>>>>   /* Dump given varpool node to stderr.  */
>>>>   void varpool_node::debug (void)
>>>>   {
>>>>
>>>
>

[-- Attachment #2: gimple-dump.diff --]
[-- Type: text/x-patch, Size: 4121 bytes --]

diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index 8529c82..8d20917 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -1320,7 +1320,6 @@ lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symta
       /* Restore decl state */
       file_data->current_decl_state = file_data->global_decl_state;
     }
-
   lto_data_in_delete (data_in);
 }
 
diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 465662e..9570ff3 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -22,7 +22,7 @@
 # The name of the LTO compiler.
 LTO_EXE = lto1$(exeext)
 # The LTO-specific object files inclued in $(LTO_EXE).
-LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
+LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o tree-cfg.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
 lto_OBJS = $(LTO_OBJS)
 
 # this is only useful in a LTO bootstrap, but this does not work right
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index a098797..c10c662 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -77,6 +77,9 @@ LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 demangle
 LTO Var(flag_lto_dump_demangle)
 
+fdump-lto-body=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index e0becd1..7371b4b 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "basic-block.h"
 #include "tree.h"
+#include "tree-cfg.h"
 #include "gimple.h"
 #include "cgraph.h"
 #include "lto-streamer.h"
@@ -36,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stdio.h"
 #include "lto.h"
 
+
 /* Dump everything.  */
 void
 dump ()
@@ -56,7 +58,7 @@ dump_list ()
 		fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)
 			? node->name (): node->dump_asm_name ());
 		fprintf (stderr, "%20s", node->dump_type_name ());
-		fprintf (stderr, "%20s\n", node->dump_visibility ());
+		fprintf (stderr, "%20s", node->dump_visibility ());
 	}
 }
 
@@ -70,10 +72,24 @@ dump_symbol ()
 	{
 		if (!strcmp(flag_lto_dump_symbol, node->name()))
 		{
-			fprintf (stderr, "\n%20s",(flag_lto_dump_demangle) 
-				? node->name (): node->dump_asm_name ());
-		fprintf (stderr, "%20s", node->dump_type_name ());
-		fprintf (stderr, "%20s\n", node->dump_visibility ());
+		// 	fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)
+		// 		? node->name (): node->dump_asm_name ());
+		// fprintf (stderr, "%20s", node->dump_type_name ());
+		// fprintf (stderr, "%20s", node->dump_visibility ());
+			node->debug();
+		}
 	}
+}
+
+/* Dump gimple body of specific function.  */
+void
+dump_body ()
+{
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp(cnode->name(), flag_lto_dump_body))
+		{
+			cnode->get_untransformed_body();
+			//debug_function (cnode->decl, 0);
 		}
 }	
\ No newline at end of file
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 352160c..3b6c9bc 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -29,4 +29,7 @@ void dump_list ();
 /*Dump specific variable or function used in IL.  */
 void dump_symbol ();
 
+/*Dump gimple body of specific function.  */
+void dump_body ();
+
 #endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index ab1eed3..88d1480 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -3373,6 +3373,10 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
+  /* Dump gimple body of specific function.  */
+  if (flag_lto_dump_body)
+    dump_body ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 1d2374f..0e08519 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -815,7 +815,7 @@ symtab_node::dump_visibility () const
     "default", "protected", "hidden", "internal"
   };
 
-  return visibility_types [DECL_VISIBILITY (decl)];
+  return visibility_types[DECL_VISIBILITY (decl)];
 }
 
 const char *

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

* Re: [GSOC] LTO dump tool project
  2018-06-08 13:41             ` Hrishikesh Kulkarni
@ 2018-06-08 13:45               ` Martin Liška
  2018-06-08 14:41                 ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-08 13:45 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/08/2018 03:27 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> Linking is not taking place as the debug_function() being used is in
> tree-cfg.c. How should I go about on adding in make-file considering
> the dependencies?

Hi.

There's wrong declaration of the function in header file. I'll fix it soon
on trunk. Please carry on with following patch:

diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 17634797c6e..363b59febd6 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "attribs.h"
 #include "builtins.h"
+#include "tree-cfg.h"
 
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
@@ -3338,6 +3339,8 @@ offload_handle_link_vars (void)
 void
 lto_main (void)
 {
+  // only test if it builds
+  debug_function (cfun->decl, TDF_NONE);
   /* LTO is called as a front end, even though it is not a front end.
      Because it is called as a front end, TV_PHASE_PARSING and
      TV_PARSE_GLOBAL are active, and we need to turn them off while
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 73237a604be..9491bb45feb 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -81,7 +81,7 @@ extern void fold_loop_internal_call (gimple *, tree);
 extern basic_block move_sese_region_to_fn (struct function *, basic_block,
 				           basic_block, tree);
 extern void dump_function_to_file (tree, FILE *, dump_flags_t);
-extern void debug_function (tree, int) ;
+extern void debug_function (tree, dump_flags_t);
 extern void print_loops_bb (FILE *, basic_block, int, int);
 extern void print_loops (FILE *, int);
 extern void debug (struct loop &ref);

Martin

> 
> Please find the diff file attached herewith.
> 
> Regards,
> Hrishikesh
> 
> On Tue, Jun 5, 2018 at 12:38 AM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/04/2018 08:13 PM, Hrishikesh Kulkarni wrote:
>>>
>>> Hi,
>>>
>>> -fdump-lto-list will dump all the symbol list
>>
>>
>> I see extra new lines in the output:
>>
>> $ lto1 -fdump-lto-list main.o
>> [..snip..]
>> Symbol Table
>>                 Name            Type            Visibility
>>
>>            fwrite/15            function             default
>>
>>               foo/14            function             default
>>
>>          mystring/12            variable             default
>>
>>              pole/11            variable             default
>>
>>              main/13            function             default
>>
>>> -fdump-lto-list -demangle will dump all the list with symbol names
>>> demangled
>>
>>
>> Good for now. Note that non-demagle version prints function names with order
>> (/$number).
>> I would not print that.
>>
>>> -fdump-lto-symbol=foo will dump details of foo
>>
>>
>> I would really prefer to use symtab_node::debug for now. It presents all
>> details about
>> symbol instead of current implementation which does: '-fdump-lto-list | grep
>> foo'
>>
>>>
>>> The output(demangled) will be in tabular form like nm:
>>> Symbol Table
>>>          Name         Type         Visibility
>>>                printf            function             default
>>>                     k            variable             default
>>>                  main            function             default
>>>                   bar            function             default
>>>                   foo            function             default
>>>
>>> I have tried to format the changes according to gnu coding style and
>>> added required methods in symtab_node.
>>
>>
>> That's nice that you came up with new symbol_node methods. It's much better.
>> About the GNU coding style, I still see trailing whitespace:
>>
>> === ERROR type #3: there should be no space before a left square bracket (1
>> error(s)) ===
>> gcc/symtab.c:818:26:  return visibility_types [DECL_VISIBILITY (decl)];
>>
>> === ERROR type #4: trailing whitespace (6 error(s)) ===
>> gcc/lto/lto-dump.c:40:4:voidâ–ˆ
>> gcc/lto/lto-dump.c:45:0:â–ˆ
>> gcc/lto/lto-dump.c:56:52:               fprintf (stderr,
>> "\n%20s",(flag_lto_dump_demangle)â–ˆ
>> gcc/lto/lto-dump.c:73:53:                       fprintf (stderr,
>> "\n%20s",(flag_lto_dump_demangle)â–ˆ
>> gcc/lto/lto-dump.c:78:2:        }â–ˆ
>> gcc/lto/lto-dump.c:79:1:}â–ˆ
>>
>> Martin
>>
>>
>>>
>>> Please find the diff file attached.
>>>
>>> Regards,
>>> Hrishikesh
>>>
>>> On Mon, Jun 4, 2018 at 2:06 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>
>>>> On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
>>>>>
>>>>> Hi,
>>>>> I have pushed the changes to github
>>>>> (https://github.com/hrisearch/gcc). Added a command line option for
>>>>> specific dumps of variables and functions used in IL e.g.
>>>>> -fdump-lto-list=foo will dump:
>>>>> Call Graph:
>>>>>
>>>>> foo/1 (foo)
>>>>>    Type: function
>>>>>   visibility: default
>>>>
>>>>
>>>> Hi.
>>>>
>>>> Thanks for the next step. I've got some comments about it:
>>>>
>>>> - -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
>>>>    or something similar.
>>>>
>>>> - for -fdump-lto-list I would really prefer to use a format similar to
>>>> nm:
>>>>    print a header with column description and then one line for a symbol
>>>>
>>>> - think about mangling/demangling of C++ symbols, you can take a look at
>>>> nm it also has --demangle, --no-demangle
>>>>
>>>> - please learn & try to use an autoformat for your editor in order to
>>>>    fulfill GNU coding style. Following checker will help you:
>>>>
>>>> $ ./contrib/check_GNU_style.py /tmp/p
>>>> === ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
>>>> gcc/lto/lto-dump.c:38:17:/*Dump everything*/
>>>> gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
>>>> gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in
>>>> IL*/
>>>> gcc/lto/lto.c:3364:19:  /*Dump everything*/
>>>> gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
>>>> gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in
>>>> IL*/
>>>>
>>>> === ERROR type #2: lines should not exceed 80 characters (11 error(s))
>>>> ===
>>>> gcc/lto/lto-dump.c:51:80:        static const char * const
>>>> symtab_type_names[] = {"symbol", "function", "variable"};
>>>> gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)",
>>>> cnode->dump_asm_name (), cnode->name ());
>>>> gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[cnode->type]);
>>>> gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)",
>>>> vnode->dump_asm_name (), vnode->name ());
>>>> gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s",
>>>> symtab_type_names[vnode->type]);
>>>> gcc/lto/lto-dump.c:80:80:        static const char * const
>>>> symtab_type_names[] = {"symbol", "function", "variable"};
>>>> gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s
>>>> (%s)", cnode->dump_asm_name (), cnode->name ());
>>>> gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n
>>>> Type: %s", symtab_type_names[cnode->type]);
>>>> gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s
>>>> (%s)", vnode->dump_asm_name (), vnode->name ());
>>>> gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n
>>>> Type: %s", symtab_type_names[vnode->type]);
>>>> gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o
>>>> lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
>>>> lto/lto-dump.o
>>>>
>>>> === ERROR type #3: there should be exactly one space between function
>>>> name and parenthesis (15 error(s)) ===
>>>> gcc/lto/lto-dump.c:39:9:void dump()
>>>> gcc/lto/lto-dump.c:41:8:        fprintf(stderr, "\nHello World!\n");
>>>> gcc/lto/lto-dump.c:45:14:void dump_list()
>>>> gcc/lto/lto-dump.c:74:15:void dump_list2()
>>>> gcc/lto/lto-dump.c:85:13:               if (!strcmp(flag_lto_dump_list2,
>>>> cnode->name()))
>>>> gcc/lto/lto-dump.c:97:16:       if (!strcmp(flag_lto_dump_list2,
>>>> vnode->name()))
>>>> gcc/lto/lto-dump.h:23:9:void dump();
>>>> gcc/lto/lto-dump.h:24:14:void dump_list();
>>>> gcc/lto/lto-dump.h:25:15:void dump_list2();
>>>> gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
>>>> gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
>>>> gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined
>>>> Var(flag_lto_dump_list2)
>>>> gcc/lto/lto.c:3366:8:    dump();
>>>> gcc/lto/lto.c:3370:13:    dump_list();
>>>> gcc/lto/lto.c:3374:14:    dump_list2();
>>>>
>>>> === ERROR type #4: there should be no space before a left square bracket
>>>> (4 error(s)) ===
>>>> gcc/lto/lto-dump.c:59:19:               visibility_types [DECL_VISIBILITY
>>>> (cnode->decl)]);
>>>> gcc/lto/lto-dump.c:69:19:               visibility_types [DECL_VISIBILITY
>>>> (vnode->decl)]);
>>>> gcc/lto/lto-dump.c:90:20:                       visibility_types
>>>> [DECL_VISIBILITY (cnode->decl)]);
>>>> gcc/lto/lto-dump.c:102:20:                      visibility_types
>>>> [DECL_VISIBILITY (vnode->decl)]);
>>>>
>>>> === ERROR type #5: trailing whitespace (5 error(s)) ===
>>>> gcc/lto/lto-dump.c:50:0:â–ˆ
>>>> gcc/lto/lto-dump.c:79:0:â–ˆ
>>>> gcc/lto/lto-dump.c:92:2:        }â–ˆ
>>>> gcc/lto/lto-dump.c:98:3:                {â–ˆ
>>>> gcc/lto/lto-dump.c:105:1:}â–ˆ
>>>>
>>>> And please try to avoid adding blank lines / remove blank lines in files
>>>> which you don't modify.
>>>> Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure,
>>>> but will help you.
>>>>
>>>>>
>>>>> Regards,
>>>>> Hrishikesh
>>>>>
>>>>> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>
>>>>>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>>>>>>
>>>>>>> $ nm main.o
>>>>>>> 00000000 T main
>>>>>>> 00000000 T mystring
>>>>>>> 00000000 C pole
>>>>>>
>>>>>>
>>>>>> Or we can be inspired by readelf:
>>>>>>
>>>>>> $ readelf -s a.out
>>>>>> [snip]
>>>>>> Symbol table '.symtab' contains 74 entries:
>>>>>>     Num:    Value          Size Type    Bind   Vis      Ndx Name
>>>>>>      66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>>>>>      67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>>>>>      68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>>>>>      69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>>>>>      70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>>>>>> fwrite@@GLIBC_2.2.5
>>>>>>
>>>>>> Martin
>>>>>
>>>>>
>>>>> specific-symbols-dump.diff
>>>>>
>>>>>
>>>>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>>>>> index 9a7d54d..b868695 100644
>>>>> --- a/gcc/cgraph.c
>>>>> +++ b/gcc/cgraph.c
>>>>> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>>>>>       fprintf (f, "  Is instrumented version.\n");
>>>>>     else if (instrumented_version)
>>>>>       fprintf (f, "  Has instrumented version.\n");
>>>>> +
>>>>>   }
>>>>>
>>>>>   /* Dump call graph node NODE to stderr.  */
>>>>> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
>>>>> index 4695077..465662e 100644
>>>>> --- a/gcc/lto/Make-lang.in
>>>>> +++ b/gcc/lto/Make-lang.in
>>>>> @@ -22,7 +22,7 @@
>>>>>   # The name of the LTO compiler.
>>>>>   LTO_EXE = lto1$(exeext)
>>>>>   # The LTO-specific object files inclued in $(LTO_EXE).
>>>>> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o
>>>>> lto/lto-partition.o lto/lto-symtab.o
>>>>> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o
>>>>> lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>>>>   lto_OBJS = $(LTO_OBJS)
>>>>>
>>>>>   # this is only useful in a LTO bootstrap, but this does not work right
>>>>> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
>>>>> index 0a408d3..7600840 100644
>>>>> --- a/gcc/lto/lang.opt
>>>>> +++ b/gcc/lto/lang.opt
>>>>> @@ -63,6 +63,18 @@ fwpa=
>>>>>   LTO Driver RejectNegative Joined Var(flag_wpa)
>>>>>   Whole program analysis (WPA) mode with number of parallel jobs
>>>>> specified.
>>>>>
>>>>> +fdump
>>>>> +LTO Var(flag_lto_dump)
>>>>> +Call the dump function.
>>>>> +
>>>>> +fdump-lto-list
>>>>> +LTO Var(flag_lto_dump_list)
>>>>> +Call the dump function for variables and function in IL.
>>>>> +
>>>>> +fdump-lto-list=
>>>>> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>>>>> +
>>>>> +
>>>>>   fresolution=
>>>>>   LTO Joined
>>>>>   The resolution file.
>>>>> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
>>>>> new file mode 100644
>>>>> index 0000000..90976cb
>>>>> --- /dev/null
>>>>> +++ b/gcc/lto/lto-dump.c
>>>>> @@ -0,0 +1,105 @@
>>>>> +/* LTO dump tool
>>>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>>>> +
>>>>> +This file is part of GCC.
>>>>> +
>>>>> +GCC is free software; you can redistribute it and/or modify it under
>>>>> +the terms of the GNU General Public License as published by the Free
>>>>> +Software Foundation; either version 3, or (at your option) any later
>>>>> +version.
>>>>> +
>>>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>>>> +for more details.
>>>>> +
>>>>> +You should have received a copy of the GNU General Public License
>>>>> +along with GCC; see the file COPYING3.  If not see
>>>>> +<http://www.gnu.org/licenses/>.  */
>>>>> +
>>>>> +#include "config.h"
>>>>> +#include "system.h"
>>>>> +#include "coretypes.h"
>>>>> +#include "target.h"
>>>>> +#include "function.h"
>>>>> +#include "basic-block.h"
>>>>> +#include "tree.h"
>>>>> +#include "gimple.h"
>>>>> +#include "cgraph.h"
>>>>> +#include "lto-streamer.h"
>>>>> +#include "ipa-utils.h"
>>>>> +#include "builtins.h"
>>>>> +#include "alias.h"
>>>>> +#include "lto-symtab.h"
>>>>> +#include "stringpool.h"
>>>>> +#include "attribs.h"
>>>>> +#include "stdio.h"
>>>>> +
>>>>> +/*Dump everything*/
>>>>> +void dump()
>>>>> +{
>>>>> +     fprintf(stderr, "\nHello World!\n");
>>>>> +}
>>>>> +
>>>>> +/*Dump variables and functions used in IL*/
>>>>> +void dump_list()
>>>>> +{
>>>>> +
>>>>> +     fprintf (stderr, "Call Graph:\n");
>>>>> +     cgraph_node *cnode;
>>>>> +
>>>>> +     static const char * const symtab_type_names[] = {"symbol",
>>>>> "function", "variable"};
>>>>> +     static const char * const visibility_types[] = {
>>>>> +    "default", "protected", "hidden", "internal" };
>>>>
>>>>
>>>> We have symbol_node class, this can be refactored into methods.
>>>>
>>>>> +     FOR_EACH_FUNCTION (cnode)
>>>>> +     {
>>>>> +             fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (),
>>>>> cnode->name ());
>>>>> +             fprintf (stderr, "\n  Type: %s",
>>>>> symtab_type_names[cnode->type]);
>>>>> +             fprintf (stderr, "\n visibility: %s\n",
>>>>> +             visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>>>> +     }
>>>>> +
>>>>> +     fprintf (stderr, "\nVarpool:\n");
>>>>> +     varpool_node *vnode;
>>>>> +    FOR_EACH_VARIABLE (vnode)
>>>>> +    {
>>>>> +             fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (),
>>>>> vnode->name ());
>>>>> +             fprintf (stderr, "\n  Type: %s",
>>>>> symtab_type_names[vnode->type]);
>>>>> +             fprintf (stderr, "\n visibility:%s\n",
>>>>> +             visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>>>
>>>>
>>>> Maybe content of the loop body can be a function that will print. Now
>>>> it's copy&paste.
>>>>
>>>>> +     }
>>>>> +}
>>>>> +
>>>>> +/*Dump specific variables and functions used in IL*/
>>>>> +void dump_list2()
>>>>> +{
>>>>> +
>>>>> +     fprintf (stderr, "Call Graph:\n");
>>>>> +     cgraph_node *cnode;
>>>>> +
>>>>> +     static const char * const symtab_type_names[] = {"symbol",
>>>>> "function", "variable"};
>>>>> +     static const char * const visibility_types[] = {
>>>>> +    "default", "protected", "hidden", "internal" };
>>>>> +     FOR_EACH_FUNCTION (cnode)
>>>>> +     {
>>>>> +             if (!strcmp(flag_lto_dump_list2, cnode->name()))
>>>>> +             {
>>>>> +                     fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name
>>>>> (), cnode->name ());
>>>>> +                     fprintf (stderr, "\n  Type: %s",
>>>>> symtab_type_names[cnode->type]);
>>>>> +                     fprintf (stderr, "\n visibility: %s\n",
>>>>> +                     visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>>>> +             }
>>>>> +     }
>>>>> +     fprintf (stderr, "\nVarpool:\n");
>>>>> +     varpool_node *vnode;
>>>>> +    FOR_EACH_VARIABLE (vnode)
>>>>> +    {
>>>>> +     if (!strcmp(flag_lto_dump_list2, vnode->name()))
>>>>> +             {
>>>>> +                     fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name
>>>>> (), vnode->name ());
>>>>> +                     fprintf (stderr, "\n  Type: %s",
>>>>> symtab_type_names[vnode->type]);
>>>>> +                     fprintf (stderr, "\n visibility:%s\n",
>>>>> +                     visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>>>> +             }
>>>>> +     }
>>>>> +}
>>>>
>>>>
>>>> The whole function is copy&paste. Please come up with new methods for
>>>> symtab_node and use it.
>>>>
>>>> You wrote of the mailing list that you're planning to work on CMD
>>>> options. But please finish
>>>> first dumping of symbols. I would recomment to implement option that will
>>>> print body
>>>> of a function, which should accept similar dumpflags as we use for dump
>>>> files:
>>>>
>>>> $ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout
>>>> ~/Programming/testcases/tmp/main.c -c
>>>>
>>>> ;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0,
>>>> symbol_order=2)
>>>>
>>>> main (int argc, char * * argv)
>>>> {
>>>>    int D.2621;
>>>>    int _1;
>>>>    int _8;
>>>>    int _10;
>>>>
>>>> ;;   basic block 2, loop depth 0
>>>> ;;    pred:       ENTRY
>>>>    foo ();
>>>>    fwrite (0B, 1, 0, 0B);
>>>>    pole[11] = 123;
>>>>    if (argc_7(D) == 1)
>>>>      goto <bb 3>; [INV]
>>>>    else
>>>>      goto <bb 4>; [INV]
>>>> ;;    succ:       3
>>>> ;;                4
>>>> ...
>>>>
>>>> $ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout
>>>> ~/Programming/testcases/tmp/main.c -c
>>>> int __GIMPLE ()
>>>> main (int argc, char * * argv)
>>>> {
>>>>    int D_2621;
>>>>    int _1;
>>>>    int _8;
>>>>    int _10;
>>>>
>>>>    bb_2:
>>>>    foo ();
>>>>    fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct
>>>> FILE * restrict) 0);
>>>>    pole[11] = 123;
>>>>    if (argc_7(D) == 1)
>>>>      goto bb_3;
>>>>    else
>>>>      goto bb_4;
>>>> ...
>>>>
>>>> And I would also do a more verbose symbol dump option that will basically
>>>> call symbol_node::debug.
>>>>
>>>> Thanks,
>>>> Martin
>>>>
>>>>> \ No newline at end of file
>>>>> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
>>>>> new file mode 100644
>>>>> index 0000000..0aef8d1
>>>>> --- /dev/null
>>>>> +++ b/gcc/lto/lto-dump.h
>>>>> @@ -0,0 +1,27 @@
>>>>> +/* LTO dump tool
>>>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>>>> +
>>>>> +This file is part of GCC.
>>>>> +
>>>>> +GCC is free software; you can redistribute it and/or modify it under
>>>>> +the terms of the GNU General Public License as published by the Free
>>>>> +Software Foundation; either version 3, or (at your option) any later
>>>>> +version.
>>>>> +
>>>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>>>> +for more details.
>>>>> +
>>>>> +You should have received a copy of the GNU General Public License
>>>>> +along with GCC; see the file COPYING3.  If not see
>>>>> +<http://www.gnu.org/licenses/>.  */
>>>>> +
>>>>> +#ifndef GCC_LTO_DUMP_H_
>>>>> +#define GCC_LTO_DUMP_H_
>>>>> +
>>>>> +void dump();
>>>>> +void dump_list();
>>>>> +void dump_list2();
>>>>> +
>>>>> +#endif
>>>>> \ No newline at end of file
>>>>> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
>>>>> index d2ccaf6..15a56af 100644
>>>>> --- a/gcc/lto/lto.c
>>>>> +++ b/gcc/lto/lto.c
>>>>> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>>>>>   #include "fold-const.h"
>>>>>   #include "attribs.h"
>>>>>   #include "builtins.h"
>>>>> -
>>>>> +#include "lto-dump.h"
>>>>>
>>>>>   /* Number of parallel tasks to run, -1 if we want to use GNU Make
>>>>> jobserver.  */
>>>>>   static int lto_parallelism;
>>>>> @@ -3361,6 +3361,18 @@ lto_main (void)
>>>>>        command line.  */
>>>>>     read_cgraph_and_symbols (num_in_fnames, in_fnames);
>>>>>
>>>>> +  /*Dump everything*/
>>>>> +  if (flag_lto_dump)
>>>>> +    dump();
>>>>> +
>>>>> +  /*Dump variables and functions used in IL*/
>>>>> +  if (flag_lto_dump_list)
>>>>> +    dump_list();
>>>>> +
>>>>> +  /*Dump specific variables and functions used in IL*/
>>>>> +  if (flag_lto_dump_list2)
>>>>> +    dump_list2();
>>>>> +
>>>>>     timevar_stop (TV_PHASE_STREAM_IN);
>>>>>
>>>>>     if (!seen_error ())
>>>>> diff --git a/gcc/varpool.c b/gcc/varpool.c
>>>>> index 418753c..77f0adb 100644
>>>>> --- a/gcc/varpool.c
>>>>> +++ b/gcc/varpool.c
>>>>> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>>>>>     fprintf (f, "\n");
>>>>>   }
>>>>>
>>>>> -
>>>>>   /* Dump given varpool node to stderr.  */
>>>>>   void varpool_node::debug (void)
>>>>>   {
>>>>>
>>>>
>>

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

* Re: [GSOC] LTO dump tool project
  2018-06-08 13:45               ` Martin Liška
@ 2018-06-08 14:41                 ` Martin Liška
  2018-06-08 18:29                   ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-08 14:41 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/08/2018 03:40 PM, Martin Liška wrote:
> There's wrong declaration of the function in header file. I'll fix it soon
> on trunk. Please carry on with following patch:

Fixed in r261327.

Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-08 14:41                 ` Martin Liška
@ 2018-06-08 18:29                   ` Hrishikesh Kulkarni
  2018-06-08 21:01                     ` Prathamesh Kulkarni
  2018-06-11 10:05                     ` Martin Liška
  0 siblings, 2 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-08 18:29 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

-fdump-lto-body=foo
will dump gimple body of the function foo

foo (int a, int b)
{
  <bb 2> [local count: 1073741825]:
  _3 = a_1(D) + b_2(D);
  return _3;

}

Please find the diff file attached herewith.

Regards,
Hrishikesh

On Fri, Jun 8, 2018 at 7:15 PM, Martin Liška <mliska@suse.cz> wrote:
> On 06/08/2018 03:40 PM, Martin Liška wrote:
>> There's wrong declaration of the function in header file. I'll fix it soon
>> on trunk. Please carry on with following patch:
>
> Fixed in r261327.
>
> Martin

[-- Attachment #2: body-dump.diff --]
[-- Type: text/x-patch, Size: 4859 bytes --]

diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index 8529c82..8d20917 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -1320,7 +1320,6 @@ lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symta
       /* Restore decl state */
       file_data->current_decl_state = file_data->global_decl_state;
     }
-
   lto_data_in_delete (data_in);
 }
 
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index a098797..c10c662 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -77,6 +77,9 @@ LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 demangle
 LTO Var(flag_lto_dump_demangle)
 
+fdump-lto-body=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index e0becd1..687c9c9 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "basic-block.h"
 #include "tree.h"
+#include "tree-cfg.h"
 #include "gimple.h"
 #include "cgraph.h"
 #include "lto-streamer.h"
@@ -36,13 +37,14 @@ along with GCC; see the file COPYING3.  If not see
 #include "stdio.h"
 #include "lto.h"
 
+
 /* Dump everything.  */
-void 
+void
 dump ()
 {
 	fprintf(stderr, "\nHello World!\n");
 }
-	
+
 /* Dump variables and functions used in IL.  */
 void
 dump_list ()
@@ -53,10 +55,14 @@ dump_list ()
     fprintf (stderr, "\t\tName \t\tType \t\tVisibility\n");
 	FOR_EACH_SYMBOL (node)
 	{
-		fprintf (stderr, "\n%20s",(flag_lto_dump_demangle) 
-			? node->name (): node->dump_asm_name ());
+    	const char *x = strchr (node->asm_name (), '/');
+    	if (flag_lto_dump_demangle)
+			fprintf (stderr, "\n%20s", node->name ());
+		else
+			fprintf (stderr, "\n%20s", node->asm_name (), 
+				node->asm_name ()-x);
 		fprintf (stderr, "%20s", node->dump_type_name ());
-		fprintf (stderr, "%20s\n", node->dump_visibility ());
+		fprintf (stderr, "%20s", node->dump_visibility ());
 	}
 }
 
@@ -67,13 +73,19 @@ dump_symbol ()
 	symtab_node *node;
     fprintf (stderr, "\t\tName \t\tType \t\tVisibility\n");
 	FOR_EACH_SYMBOL (node)
-	{
-		if (!strcmp(flag_lto_dump_symbol, node->name()))
+		if (!strcmp (flag_lto_dump_symbol, node->name ()))
+			node->debug ();
+}
+
+/* Dump gimple body of specific function.  */
+void
+dump_body ()
+{
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_lto_dump_body))
 		{
-			fprintf (stderr, "\n%20s",(flag_lto_dump_demangle) 
-				? node->name (): node->dump_asm_name ());
-		fprintf (stderr, "%20s", node->dump_type_name ());
-		fprintf (stderr, "%20s\n", node->dump_visibility ());
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, 0);
 		}
-	}	
 }	
\ No newline at end of file
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 352160c..3b6c9bc 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -29,4 +29,7 @@ void dump_list ();
 /*Dump specific variable or function used in IL.  */
 void dump_symbol ();
 
+/*Dump gimple body of specific function.  */
+void dump_body ();
+
 #endif
\ No newline at end of file
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index ab1eed3..88d1480 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -2170,7 +2170,7 @@ lto_file_read (lto_file *file, FILE *resolution_file, int *count)
   /* Finalize each lto file for each submodule in the merged object */
   for (file_data = file_list.first; file_data != NULL; file_data = file_data->next)
     lto_create_files_from_ids (file, file_data, count);
- 
+
   splay_tree_delete (file_ids);
   htab_delete (section_hash_table);
 
@@ -3373,6 +3373,10 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
+  /* Dump gimple body of specific function.  */
+  if (flag_lto_dump_body)
+    dump_body ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 1d2374f..0e08519 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -815,7 +815,7 @@ symtab_node::dump_visibility () const
     "default", "protected", "hidden", "internal"
   };
 
-  return visibility_types [DECL_VISIBILITY (decl)];
+  return visibility_types[DECL_VISIBILITY (decl)];
 }
 
 const char *
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 73237a6..3e10d15 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -81,7 +81,7 @@ extern void fold_loop_internal_call (gimple *, tree);
 extern basic_block move_sese_region_to_fn (struct function *, basic_block,
 				           basic_block, tree);
 extern void dump_function_to_file (tree, FILE *, dump_flags_t);
-extern void debug_function (tree, int) ;
+extern void debug_function (tree, dump_flags_t) ;
 extern void print_loops_bb (FILE *, basic_block, int, int);
 extern void print_loops (FILE *, int);
 extern void debug (struct loop &ref);

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

* Re: [GSOC] LTO dump tool project
  2018-06-08 18:29                   ` Hrishikesh Kulkarni
@ 2018-06-08 21:01                     ` Prathamesh Kulkarni
  2018-06-11 10:05                     ` Martin Liška
  1 sibling, 0 replies; 50+ messages in thread
From: Prathamesh Kulkarni @ 2018-06-08 21:01 UTC (permalink / raw)
  To: Hrishikesh Kulkarni
  Cc: GCC Development, Martin Liška, Jan Hubicka, Richard Biener,
	Martin Jambor

On 8 June 2018 at 22:46, Hrishikesh Kulkarni <hrishikeshparag@gmail.com> wrote:
> Hi,
>
> -fdump-lto-body=foo
> will dump gimple body of the function foo
>
> foo (int a, int b)
> {
>   <bb 2> [local count: 1073741825]:
>   _3 = a_1(D) + b_2(D);
>   return _3;
>
> }
>
> Please find the diff file attached herewith.
@@ -53,10 +55,14 @@ dump_list ()
     fprintf (stderr, "\t\tName \t\tType \t\tVisibility\n");
  FOR_EACH_SYMBOL (node)
  {
- fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)
- ? node->name (): node->dump_asm_name ());
+    const char *x = strchr (node->asm_name (), '/');
+    if (flag_lto_dump_demangle)
+ fprintf (stderr, "\n%20s", node->name ());
+ else
+ fprintf (stderr, "\n%20s", node->asm_name (),
+ node->asm_name ()-x);
Shouldn't this be:
fprintf (stderr, "\n%20.*s", (int) (x - node->asm_name ()), node->asm_name ()) ?
Also better to put strchr within else block since that's the only
place you seem to be using it.

Thanks,
Prathamesh
>
> Regards,
> Hrishikesh
>
> On Fri, Jun 8, 2018 at 7:15 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/08/2018 03:40 PM, Martin Liška wrote:
>>> There's wrong declaration of the function in header file. I'll fix it soon
>>> on trunk. Please carry on with following patch:
>>
>> Fixed in r261327.
>>
>> Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-08 18:29                   ` Hrishikesh Kulkarni
  2018-06-08 21:01                     ` Prathamesh Kulkarni
@ 2018-06-11 10:05                     ` Martin Liška
  2018-06-12 18:14                       ` Hrishikesh Kulkarni
  1 sibling, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-11 10:05 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/08/2018 07:16 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> -fdump-lto-body=foo
> will dump gimple body of the function foo
> 
> foo (int a, int b)
> {
>   <bb 2> [local count: 1073741825]:
>   _3 = a_1(D) + b_2(D);
>   return _3;
> 
> }
> 
> Please find the diff file attached herewith.
> 
> Regards,
> Hrishikesh
> 
> On Fri, Jun 8, 2018 at 7:15 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/08/2018 03:40 PM, Martin Liška wrote:
>>> There's wrong declaration of the function in header file. I'll fix it soon
>>> on trunk. Please carry on with following patch:
>>
>> Fixed in r261327.
>>
>> Martin

Hi.

Thanks for another new option. I have some comments:

1) remove these files from git branch:
diff --git a/gcc/cscope.out b/gcc/cscope.out
diff --git a/gcc/err b/gcc/err

2) You have repeated pattern:

FOR_EACH_SYMBOL (node)
  if (!strcmp (flag_lto_dump_symbol, node->name ()))
     some_action();

Let's come up with function symtab->find_symbol_by_name.

Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-11 10:05                     ` Martin Liška
@ 2018-06-12 18:14                       ` Hrishikesh Kulkarni
  2018-06-12 21:26                         ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-12 18:14 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

I tried tweaking the make file. I am probably missing something. Please advise.

Regards,

Hrishikesh

On Mon, Jun 11, 2018 at 1:36 PM, Martin Liška <mliska@suse.cz> wrote:
> On 06/08/2018 07:16 PM, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> -fdump-lto-body=foo
>> will dump gimple body of the function foo
>>
>> foo (int a, int b)
>> {
>>   <bb 2> [local count: 1073741825]:
>>   _3 = a_1(D) + b_2(D);
>>   return _3;
>>
>> }
>>
>> Please find the diff file attached herewith.
>>
>> Regards,
>> Hrishikesh
>>
>> On Fri, Jun 8, 2018 at 7:15 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 06/08/2018 03:40 PM, Martin Liška wrote:
>>>> There's wrong declaration of the function in header file. I'll fix it soon
>>>> on trunk. Please carry on with following patch:
>>>
>>> Fixed in r261327.
>>>
>>> Martin
>
> Hi.
>
> Thanks for another new option. I have some comments:
>
> 1) remove these files from git branch:
> diff --git a/gcc/cscope.out b/gcc/cscope.out
> diff --git a/gcc/err b/gcc/err
>
> 2) You have repeated pattern:
>
> FOR_EACH_SYMBOL (node)
>   if (!strcmp (flag_lto_dump_symbol, node->name ()))
>      some_action();
>
> Let's come up with function symtab->find_symbol_by_name.
>
> Martin

[-- Attachment #2: Make-lang.in --]
[-- Type: application/octet-stream, Size: 2833 bytes --]

# Top level -*- makefile -*- fragment for LTO
#   Copyright (C) 2009-2018 Free Software Foundation, Inc.

#This file is part of GCC.

#GCC is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 3, or (at your option)
#any later version.

#GCC is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# Variables

# The name of the LTO compiler.
LTO_EXE = lto1$(exeext)
LTO_DUMP_EXE = lto_dump1$(exeext)
# The LTO-specific object files inclued in $(LTO_EXE).
LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o 
lto_OBJS = $(LTO_OBJS)

LTO_DUMP_OBJS = lto/lto-lang.o lto/lto-dump.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o 
lto_dump_OBJS = $(LTO_DUMP_OBJS)

# this is only useful in a LTO bootstrap, but this does not work right
# now. Should reenable after this is fixed, but only when LTO bootstrap
# is enabled.

#ifeq ($(if $(wildcard ../stage_current),$(shell cat \
#  ../stage_current)),stageautofeedback)
#$(LTO_OBJS): CFLAGS += -fauto-profile=lto1.fda
#$(LTO_OBJS): lto1.fda
#endif


#ifeq ($(if $(wildcard ../stage_current),$(shell cat \
#  ../stage_current)),stageautofeedback)
#$(LTO_DUMP_OBJS): CFLAGS += -fauto-profile=lto_dump1.fda
#$(LTO_DUMP_OBJS): lto_dump1.fda
#endif

# Rules

# These hooks are used by the main GCC Makefile.  Consult that
# Makefile for documentation.
lto.all.cross: $(LTO_EXE)
lto.start.encap: $(LTO_EXE)
lto.rest.encap:
lto.tags:
lto.install-common:
lto.install-man:
lto.install-info:
lto.dvi:
lto.pdf:
lto.install-pdf:
lto.html:
lto.install-html:
lto.uninstall:
lto.info:
lto.man:
lto.srcextra:
lto.srcman:
lto.srcinfo:
lto.install-plugin:

lto.mostlyclean:
	rm -f $(LTO_DUMP_OBJS) $(LTO_DUMP_EXE) lto_dump1.fda $(LTO_OBJS) $(LTO_EXE) lto1.fda

lto.clean:
lto.distclean:
lto.maintainer-clean:
lto.stage1:
lto.stage2:
lto.stage3:
lto.stage4:
lto.stageprofile:
lto.stagefeedback:

# LTO rules.

# Use strict warnings for this front end.
lto-warn = $(STRICT_WARN)

$(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIBDEPS)
	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
		$(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS)
 LTO_DUMP_EXE = lto_dump

lto1.fda: ../prev-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
	$(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov lto1.fda -profile ../prev-gcc/$(PERF_DATA) -gcov_version 1

# LTO testing is done as part of C/C++/Fortran etc. testing.
check-lto:

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

* Re: [GSOC] LTO dump tool project
  2018-06-12 18:14                       ` Hrishikesh Kulkarni
@ 2018-06-12 21:26                         ` Martin Liška
  2018-06-13 10:08                           ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-12 21:26 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

On 06/12/2018 06:22 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> I tried tweaking the make file. I am probably missing something. Please advise.

Hi.

Next time please send diff. It's easier to read it. You'll need something like:

diff --git a/gcc/lto/config-lang.in b/gcc/lto/config-lang.in
index 7cb7a7752a1..52e452af5f3 100644
--- a/gcc/lto/config-lang.in
+++ b/gcc/lto/config-lang.in
@@ -18,8 +18,8 @@
  # <http://www.gnu.org/licenses/>.
  
  language="lto"
-compilers="lto1\$(exeext)"
-stagestuff="lto1\$(exeext)"
+compilers="lto1\$(exeext) lto-dump\$(exeext)"
+stagestuff="lto1\$(exeext) lto-dump\$(exeext)"
  
  gtfiles="\$(srcdir)/lto/lto-tree.h \$(srcdir)/lto/lto-lang.c \$(srcdir)/lto/lto.c \$(srcdir)/lto/lto.h"
  
And please rename it to lto-dump.

Martin

> 
> Regards,
> 
> Hrishikesh
> 
> On Mon, Jun 11, 2018 at 1:36 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/08/2018 07:16 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> -fdump-lto-body=foo
>>> will dump gimple body of the function foo
>>>
>>> foo (int a, int b)
>>> {
>>>    <bb 2> [local count: 1073741825]:
>>>    _3 = a_1(D) + b_2(D);
>>>    return _3;
>>>
>>> }
>>>
>>> Please find the diff file attached herewith.
>>>
>>> Regards,
>>> Hrishikesh
>>>
>>> On Fri, Jun 8, 2018 at 7:15 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 06/08/2018 03:40 PM, Martin Liška wrote:
>>>>> There's wrong declaration of the function in header file. I'll fix it soon
>>>>> on trunk. Please carry on with following patch:
>>>>
>>>> Fixed in r261327.
>>>>
>>>> Martin
>>
>> Hi.
>>
>> Thanks for another new option. I have some comments:
>>
>> 1) remove these files from git branch:
>> diff --git a/gcc/cscope.out b/gcc/cscope.out
>> diff --git a/gcc/err b/gcc/err
>>
>> 2) You have repeated pattern:
>>
>> FOR_EACH_SYMBOL (node)
>>    if (!strcmp (flag_lto_dump_symbol, node->name ()))
>>       some_action();
>>
>> Let's come up with function symtab->find_symbol_by_name.
>>
>> Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-12 21:26                         ` Martin Liška
@ 2018-06-13 10:08                           ` Martin Liška
  2018-06-17 22:42                             ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-13 10:08 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

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

Hi.

There's working patch that really generates lto-dump binary.

Martin

[-- Attachment #2: lto-dump.patch --]
[-- Type: text/x-patch, Size: 1825 bytes --]

diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 46950776dd2..502afe94851 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -21,10 +21,14 @@
 
 # The name of the LTO compiler.
 LTO_EXE = lto1$(exeext)
+LTO_DUMP_EXE = lto-dump$(exeext)
 # The LTO-specific object files inclued in $(LTO_EXE).
 LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
 lto_OBJS = $(LTO_OBJS)
 
+LTO_DUMP_OBJS = lto/lto-lang.o lto/lto-dump.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
+lto_dump_OBJS = $(LTO_DUMP_OBJS)
+
 # this is only useful in a LTO bootstrap, but this does not work right
 # now. Should reenable after this is fixed, but only when LTO bootstrap
 # is enabled.
@@ -39,8 +43,8 @@ lto_OBJS = $(LTO_OBJS)
 
 # These hooks are used by the main GCC Makefile.  Consult that
 # Makefile for documentation.
-lto.all.cross: $(LTO_EXE)
-lto.start.encap: $(LTO_EXE)
+lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
+lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.rest.encap:
 lto.tags:
 lto.install-common:
@@ -60,7 +64,7 @@ lto.srcinfo:
 lto.install-plugin:
 
 lto.mostlyclean:
-	rm -f $(LTO_OBJS) $(LTO_EXE) lto1.fda
+	rm -f $(LTO_DUMP_OBJS) $(LTO_DUMP_EXE) lto-dump.fda $(LTO_OBJS) $(LTO_EXE) lto1.fda
 
 lto.clean:
 lto.distclean:
@@ -81,6 +85,10 @@ $(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIBDEPS)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 		$(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS)
 
+$(LTO_DUMP_EXE): $(LTO_DUMP_OBJS) $(BACKEND) $(LIBDEPS)
+	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+		$(LTO_DUMP_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS)
+
 lto1.fda: ../prev-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
 	$(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov lto1.fda -profile ../prev-gcc/$(PERF_DATA) -gcov_version 1
 

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

* Re: [GSOC] LTO dump tool project
  2018-06-13 10:08                           ` Martin Liška
@ 2018-06-17 22:42                             ` Hrishikesh Kulkarni
  2018-06-18  9:34                               ` Martin Jambor
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-17 22:42 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

Hi,

I am trying to isolate the dump tool into real lto-dump tool. I have
started with the copy&paste of lto.c into lto-dump.c and done the
changes to Make-lang.in and config-lang.in suggested by Martin (patch
attached). However when I try to build, I get the following error:

In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:

../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such

file or directory

compilation terminated.


I am unable to find the missing dependencies and would be grateful for
suggestions on how to resolve the issue.

Please advise,

Regards,
Hrishikesh


On Wed, Jun 13, 2018 at 2:21 PM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> There's working patch that really generates lto-dump binary.
>
> Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-17 22:42                             ` Hrishikesh Kulkarni
@ 2018-06-18  9:34                               ` Martin Jambor
  2018-06-20 18:18                                 ` Hrishikesh Kulkarni
  2018-06-22 11:03                                 ` Martin Liška
  0 siblings, 2 replies; 50+ messages in thread
From: Martin Jambor @ 2018-06-18  9:34 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener

Hi,

On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
> Hi,
>
> I am trying to isolate the dump tool into real lto-dump tool. I have
> started with the copy&paste of lto.c into lto-dump.c and done the
> changes to Make-lang.in and config-lang.in suggested by Martin (patch
> attached). However when I try to build, I get the following error:
>
> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>
> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>
> file or directory
>
> compilation terminated.
>
>
> I am unable to find the missing dependencies and would be grateful for
> suggestions on how to resolve the issue.

insn-modes.h is one of header files which are generated at build time,
you will find it in the gcc subdirectory of your build directory (as
opposed to the source directory).

Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-18  9:34                               ` Martin Jambor
@ 2018-06-20 18:18                                 ` Hrishikesh Kulkarni
  2018-06-21 14:21                                   ` Martin Liška
  2018-06-21 14:28                                   ` Martin Liška
  2018-06-22 11:03                                 ` Martin Liška
  1 sibling, 2 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-20 18:18 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

Please find the diff file for dumping tree type stats attached here with.

example:

$ ../stage1-build/gcc/lto1 test_hello.o -fdump-lto-tree-type-stats
Reading object files: test_hello.o
    integer_type    3
    pointer_type    3
    array_type    1
    function_type    4

I have pushed the changes on Github repo.

Regards,

Hrishikesh

On Mon, Jun 18, 2018 at 2:15 PM, Martin Jambor <mjambor@suse.cz> wrote:
> Hi,
>
> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> I am trying to isolate the dump tool into real lto-dump tool. I have
>> started with the copy&paste of lto.c into lto-dump.c and done the
>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>> attached). However when I try to build, I get the following error:
>>
>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>
>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>
>> file or directory
>>
>> compilation terminated.
>>
>>
>> I am unable to find the missing dependencies and would be grateful for
>> suggestions on how to resolve the issue.
>
> insn-modes.h is one of header files which are generated at build time,
> you will find it in the gcc subdirectory of your build directory (as
> opposed to the source directory).
>
> Martin

[-- Attachment #2: tree_stats.diff --]
[-- Type: text/x-patch, Size: 2006 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index c10c662..dd506c0 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -77,6 +77,9 @@ LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 demangle
 LTO Var(flag_lto_dump_demangle)
 
+fdump-lto-tree-type-stats
+LTO Var(flag_lto_dump_tree_type_stats)
+
 fdump-lto-body=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
 
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index afdb76a..760a796 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -1799,9 +1799,6 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	  data_in->location_cache.accept_location_cache ();
 
 	  bool seen_type = false;
-
-
-
 	  for (unsigned i = 0; i < len; ++i)
 	    {
 	      tree t = streamer_tree_cache_get_tree (data_in->reader_cache,
@@ -1810,14 +1807,14 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 		 chains.  */
 	      if (TYPE_P (t))
 		{ 
-      itr = stats.find(TREE_CODE(t));
-      if (itr == stats.end())
+      if (flag_lto_dump_tree_type_stats)
       {
-        stats.insert(std :: pair <tree_code, int> (TREE_CODE(t), 1));
-      }
-      else
-        itr->second++;
-
+        itr = stats.find(TREE_CODE(t));
+        if (itr == stats.end())
+          stats.insert(std :: pair <tree_code, int> (TREE_CODE(t), 1));
+        else
+          itr->second++;
+      }  
 		  seen_type = true;
 		  num_prevailing_types++;
 		  lto_fixup_prevailing_type (t);
@@ -1865,10 +1862,9 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	}
     }
     fprintf(stderr, "\n");
-    for (itr = stats.begin(); itr != stats.end(); ++itr)
-    {
-      fprintf(stderr, "\t%s\t%d\n", get_tree_code_name(itr->first), itr->second );
-    }
+    if (flag_lto_dump_tree_type_stats)
+      for (itr = stats.begin(); itr != stats.end(); ++itr)
+        fprintf(stderr, "\t%s\t%d\n", get_tree_code_name(itr->first), itr->second );
 
   data_in->location_cache.apply_location_cache ();
 

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

* Re: [GSOC] LTO dump tool project
  2018-06-20 18:18                                 ` Hrishikesh Kulkarni
@ 2018-06-21 14:21                                   ` Martin Liška
  2018-06-21 14:28                                   ` Martin Liška
  1 sibling, 0 replies; 50+ messages in thread
From: Martin Liška @ 2018-06-21 14:21 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 06/20/2018 07:23 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> Please find the diff file for dumping tree type stats attached here with.
> 
> example:
> 
> $ ../stage1-build/gcc/lto1 test_hello.o -fdump-lto-tree-type-stats
> Reading object files: test_hello.o
>     integer_type    3
>     pointer_type    3
>     array_type    1
>     function_type    4
> 
> I have pushed the changes on Github repo.

Hi.

Good progress here. I would also dump statistics for GIMPLE statements.
If you configure gcc with  --enable-gather-detailed-mem-stats, you should
see:

./xgcc -B. /tmp/main.c -fmem-report -O2
...
GIMPLE statements
Kind                   Stmts      Bytes
---------------------------------------
assignments                6        480
phi nodes                  0          0
conditionals               8        640
everything else           21       1368
---------------------------------------
Total                     35       2488
...

Take a look at dump_gimple_statistics,   gimple_alloc_counts,
gimple_alloc_sizes.

We do the same for trees:

static uint64_t tree_code_counts[MAX_TREE_CODES];
uint64_t tree_node_counts[(int) all_kinds];
uint64_t tree_node_sizes[(int) all_kinds];

I believe the infrastructure should be shared.

Martin


> 
> Regards,
> 
> Hrishikesh
> 
> On Mon, Jun 18, 2018 at 2:15 PM, Martin Jambor <mjambor@suse.cz> wrote:
>> Hi,
>>
>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>> attached). However when I try to build, I get the following error:
>>>
>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>
>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>
>>> file or directory
>>>
>>> compilation terminated.
>>>
>>>
>>> I am unable to find the missing dependencies and would be grateful for
>>> suggestions on how to resolve the issue.
>>
>> insn-modes.h is one of header files which are generated at build time,
>> you will find it in the gcc subdirectory of your build directory (as
>> opposed to the source directory).
>>
>> Martin

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

* Re: [GSOC] LTO dump tool project
  2018-06-20 18:18                                 ` Hrishikesh Kulkarni
  2018-06-21 14:21                                   ` Martin Liška
@ 2018-06-21 14:28                                   ` Martin Liška
  1 sibling, 0 replies; 50+ messages in thread
From: Martin Liška @ 2018-06-21 14:28 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

Hi.

There were some questions from Hrishikesh about requested goals
of the project. Thus I would like to specify what I'm aware of:

1) symbol table
   - list all symbols
   - print details info about a symbol (symtab_node::debug)
   - print GIMPLE body of a function
     - I would like to see supporting levels what we have e.g.:

-fdump-tree-optimized-blocks
-fdump-tree-optimized-stats

It's defined in dumpfile.h:
enum dump_flag

   - I would like to see constructor of a global variable:
    DECL_INITIAL (...), probably print_generic_expr will work

we can consider adding similar options seen in nm:

       --no-demangle
           Do not demangle low-level symbol names.  This is the default.

       -p
       --no-sort
           Do not bother to sort the symbols in any order; print them in the order encountered.
       -S
       --print-size
           Print both value and size of defined symbols for the "bsd" output style.  This option has no effect for object formats that do not record symbol sizes, unless --size-sort is also used in which case a calculated size is displayed.
       -r
       --reverse-sort
           Reverse the order of the sort (whether numeric or alphabetic); let the last come first.

       --defined-only
           Display only defined symbols for each object file.

       --size-sort
           Sort symbols by size.  For ELF objects symbol sizes are read from the ELF, for other object types the symbol sizes are computed as the difference between the value of the symbol and the value of the symbol with the next higher value.  If the "bsd" output
           format is used the size of the symbol is printed, rather than the value, and -S must be used in order both size and value to be printed.

It's just for inspiration, see man nm

2) statistics
   - GIMPLE and TREE statistics, similar to what we do for -fmem-report

3) LTO objects
   - we should list read files, archives, ... and print some stats about it

4) tree types
   - list types
   - print one (debug_tree) with different verbosity level, again 'enum dump_flag'

5) visualization
   - should be done, via -fdump-ipa-icf-graph, generates .dot file. Should be easy to use.

6) separation to lto-dump binary
   - here I can help, I'll cook a patch for it

I believe it's a series of small patches that can implement that. I hope you'll
invent even more options as you play with LTO.

Martin



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

* Re: [GSOC] LTO dump tool project
  2018-06-18  9:34                               ` Martin Jambor
  2018-06-20 18:18                                 ` Hrishikesh Kulkarni
@ 2018-06-22 11:03                                 ` Martin Liška
       [not found]                                   ` <CAL+0whSq9fmpou57iJqkvFte-cOz4wsEcZ3WM_j_hzXj96dNYQ@mail.gmail.com>
  1 sibling, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-22 11:03 UTC (permalink / raw)
  To: Martin Jambor, Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener

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

On 06/18/2018 10:45 AM, Martin Jambor wrote:
> Hi,
> 
> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> I am trying to isolate the dump tool into real lto-dump tool. I have
>> started with the copy&paste of lto.c into lto-dump.c and done the
>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>> attached). However when I try to build, I get the following error:
>>
>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>
>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>
>> file or directory
>>
>> compilation terminated.
>>
>>
>> I am unable to find the missing dependencies and would be grateful for
>> suggestions on how to resolve the issue.
> 
> insn-modes.h is one of header files which are generated at build time,
> you will find it in the gcc subdirectory of your build directory (as
> opposed to the source directory).
> 
> Martin
> 

Hi.

There's patch that works for me.
Needed dependency is here:

+lto/lto-dump.o: $(LTO_EXE)

It's bit artificial, but for now it works. Please start working
on separation of dump infrastructure to lto-dump.c. You'll need
to factor out common code shared in between lto.c and lto-dump.c.

Martin

[-- Attachment #2: lto-dump.patch --]
[-- Type: text/x-patch, Size: 2260 bytes --]

diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 46950776dd2..7c1acdf6419 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -21,9 +21,12 @@
 
 # The name of the LTO compiler.
 LTO_EXE = lto1$(exeext)
+LTO_DUMP_EXE = lto-dump$(exeext)
 # The LTO-specific object files inclued in $(LTO_EXE).
 LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
 lto_OBJS = $(LTO_OBJS)
+LTO_DUMP_OBJS = lto/lto-lang.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
+lto_dump_OBJS = $(LTO_DUMP_OBJS)
 
 # this is only useful in a LTO bootstrap, but this does not work right
 # now. Should reenable after this is fixed, but only when LTO bootstrap
@@ -39,8 +42,8 @@ lto_OBJS = $(LTO_OBJS)
 
 # These hooks are used by the main GCC Makefile.  Consult that
 # Makefile for documentation.
-lto.all.cross: $(LTO_EXE)
-lto.start.encap: $(LTO_EXE)
+lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
+lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.rest.encap:
 lto.tags:
 lto.install-common:
@@ -60,7 +63,7 @@ lto.srcinfo:
 lto.install-plugin:
 
 lto.mostlyclean:
-	rm -f $(LTO_OBJS) $(LTO_EXE) lto1.fda
+	rm -f $(LTO_OBJS) $(LTO_EXE) lto1.fda $(LTO_DUMP_OBJS) $(LTO_DUMP_EXE) lto-dump.fda
 
 lto.clean:
 lto.distclean:
@@ -81,6 +84,12 @@ $(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIBDEPS)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 		$(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS)
 
+$(LTO_DUMP_EXE): $(LTO_EXE) $(LTO_DUMP_OBJS) $(BACKEND) $(LIBDEPS)
+	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+		$(LTO_DUMP_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS)
+
+lto/lto-dump.o: $(LTO_EXE)
+
 lto1.fda: ../prev-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
 	$(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov lto1.fda -profile ../prev-gcc/$(PERF_DATA) -gcov_version 1
 
diff --git a/gcc/lto/config-lang.in b/gcc/lto/config-lang.in
index 0b5a846e1ca..ada21681c6a 100644
--- a/gcc/lto/config-lang.in
+++ b/gcc/lto/config-lang.in
@@ -18,7 +18,7 @@
 # <http://www.gnu.org/licenses/>.
 
 language="lto"
-compilers="lto1\$(exeext)"
+compilers="lto1\$(exeext) lto-dump\$(exeext)"
 
 gtfiles="\$(srcdir)/lto/lto-tree.h \$(srcdir)/lto/lto-lang.c \$(srcdir)/lto/lto.c \$(srcdir)/lto/lto.h"
 

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

* Re: [GSOC] LTO dump tool project
       [not found]                                   ` <CAL+0whSq9fmpou57iJqkvFte-cOz4wsEcZ3WM_j_hzXj96dNYQ@mail.gmail.com>
@ 2018-06-26 20:02                                     ` Hrishikesh Kulkarni
  2018-06-27 22:43                                       ` Hrishikesh Kulkarni
  2018-06-29  7:25                                       ` Martin Liška
  0 siblings, 2 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-26 20:02 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have created another branch lto-dump-tool-improved as suggested.
I have applied the patch for separation to lto-dump binary, made a few
necessary changes in other files and it is running successfully.
I will keep on adding previous work to this branch incrementally.

Please find the diff file attached for dumping of TREE statistics and
GIMPLE statistics.

for example:
(after configuring with --enable-gather-detailed-mem-stats)
-fdump-lto-gimple-stats will dump
GIMPLE statements
Kind                   Stmts      Bytes
---------------------------------------
assignments                0          0
phi nodes                  0          0
conditionals               0          0
everything else            0          0
---------------------------------------
Total                      0          0
---------------------------------------

-fdump-lto-tree-stats will dump

Tree Statistics

Kind                   Nodes      Bytes
----------------------------------------
decls                   4327     932672
types                   1531     257208
blocks                     0          0
stmts                      0          0
refs                       0          0
exprs                      4        128
constants                 82       2060
identifiers             4430     177200
vecs                      16      28544
binfos                     0          0
ssa names                  0          0
constructors               0          0
random kinds            7301     291952
lang_decl kinds            0          0
lang_type kinds            0          0
omp clauses                0          0
----------------------------------------
Total                  17691    1689764



Please advise,

Hrishikesh

On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have created another branch lto-dump-tool-improved as suggested.
> I have applied the patch for separation to lto-dump binary, made a few
> necessary changes in other files and it is running successfully.
> I will keep on adding previous work to this branch incrementally.
>
> Please find the diff file attached for dumping of TREE statistics and GIMPLE
> statistics.
>
> for example:
> (after configuring with --enable-gather-detailed-mem-stats)
> -fdump-lto-gimple-stats will dump
> GIMPLE statements
> Kind                   Stmts      Bytes
> ---------------------------------------
> assignments                0          0
> phi nodes                  0          0
> conditionals               0          0
> everything else            0          0
> ---------------------------------------
> Total                      0          0
> ---------------------------------------
>
> -fdump-lto-tree-stats will dump
>
> Tree Statistics
>
> Kind                   Nodes      Bytes
> ----------------------------------------
> decls                   4327     932672
> types                   1531     257208
> blocks                     0          0
> stmts                      0          0
> refs                       0          0
> exprs                      4        128
> constants                 82       2060
> identifiers             4430     177200
> vecs                      16      28544
> binfos                     0          0
> ssa names                  0          0
> constructors               0          0
> random kinds            7301     291952
> lang_decl kinds            0          0
> lang_type kinds            0          0
> omp clauses                0          0
> ----------------------------------------
> Total                  17691    1689764
>
>
>
> Please advise,
>
> Hrishikesh
>
>
> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>
>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>> > Hi,
>> >
>> > On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>> >> Hi,
>> >>
>> >> I am trying to isolate the dump tool into real lto-dump tool. I have
>> >> started with the copy&paste of lto.c into lto-dump.c and done the
>> >> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>> >> attached). However when I try to build, I get the following error:
>> >>
>> >> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>> >>
>> >> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>> >>
>> >> file or directory
>> >>
>> >> compilation terminated.
>> >>
>> >>
>> >> I am unable to find the missing dependencies and would be grateful for
>> >> suggestions on how to resolve the issue.
>> >
>> > insn-modes.h is one of header files which are generated at build time,
>> > you will find it in the gcc subdirectory of your build directory (as
>> > opposed to the source directory).
>> >
>> > Martin
>> >
>>
>> Hi.
>>
>> There's patch that works for me.
>> Needed dependency is here:
>>
>> +lto/lto-dump.o: $(LTO_EXE)
>>
>> It's bit artificial, but for now it works. Please start working
>> on separation of dump infrastructure to lto-dump.c. You'll need
>> to factor out common code shared in between lto.c and lto-dump.c.
>>
>> Martin
>
>

[-- Attachment #2: stats.diff --]
[-- Type: text/x-patch, Size: 2078 bytes --]

diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 3a18b30..afdb76a 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -1757,7 +1757,8 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 
   /* We do not uniquify the pre-loaded cache entries, those are middle-end
      internal types that should not be merged.  */
-
+  std :: map <tree_code, int> stats; 
+  std :: map <tree_code, int> :: iterator itr;
   /* Read the global declarations and types.  */
   while (ib_main.p < ib_main.len)
     {
@@ -1799,8 +1800,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 
 	  bool seen_type = false;
 
-    std :: map <tree, int> stats; 
-    std :: map <tree, int> :: iterator itr;
+
 
 	  for (unsigned i = 0; i < len; ++i)
 	    {
@@ -1810,9 +1810,11 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 		 chains.  */
 	      if (TYPE_P (t))
 		{ 
-      itr = stats.find(t);
+      itr = stats.find(TREE_CODE(t));
       if (itr == stats.end())
-        stats.insert(std :: pair <tree, int> (t, 1));
+      {
+        stats.insert(std :: pair <tree_code, int> (TREE_CODE(t), 1));
+      }
       else
         itr->second++;
 
@@ -1844,12 +1846,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 		}
 	    }
 
-       for (itr = stats.begin(); itr != stats.end(); ++itr)
-      {
-        fprintf(stderr, "\t%s\t%d\n", get_tree_code_name(TREE_CODE(itr->first)), itr->second );
-      }
-    fprintf(stderr, "\n" );
-
+ 
 	  /* Register DECLs with the debuginfo machinery.  */
 	  while (!dref_queue.is_empty ())
 	    {
@@ -1867,6 +1864,12 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	  gcc_assert (t && data_in->reader_cache->nodes.length () == from);
 	}
     }
+    fprintf(stderr, "\n");
+    for (itr = stats.begin(); itr != stats.end(); ++itr)
+    {
+      fprintf(stderr, "\t%s\t%d\n", get_tree_code_name(itr->first), itr->second );
+    }
+
   data_in->location_cache.apply_location_cache ();
 
   /* Read in lto_in_decl_state objects.  */

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

* Re: [GSOC] LTO dump tool project
  2018-06-26 20:02                                     ` Hrishikesh Kulkarni
@ 2018-06-27 22:43                                       ` Hrishikesh Kulkarni
  2018-06-29  9:20                                         ` Martin Liška
  2018-06-29  7:25                                       ` Martin Liška
  1 sibling, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-06-27 22:43 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added new command line options:
-no-demangle -> for the default non demangled output
-no-sort -> for the list of symbols in order of their occurrence
-alpha-sort -> for the list of symbols in their alphabetical order
-reverse-sort -> for the list of symbols in reversed order
-defined-only -> for only the defined symbols

for example:

../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
-demangle -defined-only -reverse-sort

will dump

Symbol Table
        Name         Type         Visibility         Size
        main        function        default
        k        variable        default
        foo        function        default
        bar        function        default

It is a reversed alphabetical order of demangled symbol names which
have been defined(hence printf excluded).
Along with this I have also added all previous progress with reference
to symbol table to the new branch.

For further options to add like -size-sort and -print-size I tried to
access size of the symbol with symtab node using
TREE_INT_CST_LOW(DECL_SIZE(node->decl));
but I am unable to do so.
So how should I proceed with it?

Please find the diff file attached herewith. I have also pushed the
changes to the new branch.

Please advise,

Hrishikesh

On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have created another branch lto-dump-tool-improved as suggested.
> I have applied the patch for separation to lto-dump binary, made a few
> necessary changes in other files and it is running successfully.
> I will keep on adding previous work to this branch incrementally.
>
> Please find the diff file attached for dumping of TREE statistics and
> GIMPLE statistics.
>
> for example:
> (after configuring with --enable-gather-detailed-mem-stats)
> -fdump-lto-gimple-stats will dump
> GIMPLE statements
> Kind                   Stmts      Bytes
> ---------------------------------------
> assignments                0          0
> phi nodes                  0          0
> conditionals               0          0
> everything else            0          0
> ---------------------------------------
> Total                      0          0
> ---------------------------------------
>
> -fdump-lto-tree-stats will dump
>
> Tree Statistics
>
> Kind                   Nodes      Bytes
> ----------------------------------------
> decls                   4327     932672
> types                   1531     257208
> blocks                     0          0
> stmts                      0          0
> refs                       0          0
> exprs                      4        128
> constants                 82       2060
> identifiers             4430     177200
> vecs                      16      28544
> binfos                     0          0
> ssa names                  0          0
> constructors               0          0
> random kinds            7301     291952
> lang_decl kinds            0          0
> lang_type kinds            0          0
> omp clauses                0          0
> ----------------------------------------
> Total                  17691    1689764
>
>
>
> Please advise,
>
> Hrishikesh
>
> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have created another branch lto-dump-tool-improved as suggested.
>> I have applied the patch for separation to lto-dump binary, made a few
>> necessary changes in other files and it is running successfully.
>> I will keep on adding previous work to this branch incrementally.
>>
>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>> statistics.
>>
>> for example:
>> (after configuring with --enable-gather-detailed-mem-stats)
>> -fdump-lto-gimple-stats will dump
>> GIMPLE statements
>> Kind                   Stmts      Bytes
>> ---------------------------------------
>> assignments                0          0
>> phi nodes                  0          0
>> conditionals               0          0
>> everything else            0          0
>> ---------------------------------------
>> Total                      0          0
>> ---------------------------------------
>>
>> -fdump-lto-tree-stats will dump
>>
>> Tree Statistics
>>
>> Kind                   Nodes      Bytes
>> ----------------------------------------
>> decls                   4327     932672
>> types                   1531     257208
>> blocks                     0          0
>> stmts                      0          0
>> refs                       0          0
>> exprs                      4        128
>> constants                 82       2060
>> identifiers             4430     177200
>> vecs                      16      28544
>> binfos                     0          0
>> ssa names                  0          0
>> constructors               0          0
>> random kinds            7301     291952
>> lang_decl kinds            0          0
>> lang_type kinds            0          0
>> omp clauses                0          0
>> ----------------------------------------
>> Total                  17691    1689764
>>
>>
>>
>> Please advise,
>>
>> Hrishikesh
>>
>>
>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>
>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>> > Hi,
>>> >
>>> > On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>> >> Hi,
>>> >>
>>> >> I am trying to isolate the dump tool into real lto-dump tool. I have
>>> >> started with the copy&paste of lto.c into lto-dump.c and done the
>>> >> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>> >> attached). However when I try to build, I get the following error:
>>> >>
>>> >> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>> >>
>>> >> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>> >>
>>> >> file or directory
>>> >>
>>> >> compilation terminated.
>>> >>
>>> >>
>>> >> I am unable to find the missing dependencies and would be grateful for
>>> >> suggestions on how to resolve the issue.
>>> >
>>> > insn-modes.h is one of header files which are generated at build time,
>>> > you will find it in the gcc subdirectory of your build directory (as
>>> > opposed to the source directory).
>>> >
>>> > Martin
>>> >
>>>
>>> Hi.
>>>
>>> There's patch that works for me.
>>> Needed dependency is here:
>>>
>>> +lto/lto-dump.o: $(LTO_EXE)
>>>
>>> It's bit artificial, but for now it works. Please start working
>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>
>>> Martin
>>
>>

[-- Attachment #2: symbol_table_final.diff --]
[-- Type: text/x-patch, Size: 7344 bytes --]

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index ee7ebb4..ebef347 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -109,6 +109,12 @@ public:
   /* Return dump name with assembler name.  */
   const char *dump_asm_name () const;
 
+  /* Return visibility name.  */
+  const char *dump_visibility () const;
+
+  /* Return type_name name.  */
+  const char *dump_type_name () const;
+
   /* Add node into symbol table.  This function is not used directly, but via
      cgraph/varpool node creation routines.  */
   void register_symbol (void);
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index a38850a..73342ee 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -67,6 +67,44 @@ fdump
 LTO Var(flag_lto_dump)
 Call the dump function
 
+fdump-lto-list
+LTO Var(flag_lto_dump_list)
+Call the dump function for variables and function in IL.
+
+fdump-lto-symbol=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
+
+demangle
+LTO Var(flag_lto_dump_demangle)
+Dump the demangled output.
+
+no-demangle
+LTO Var(flag_lto_dump_no_demangle)
+Dump the non-demangled output.
+
+defined-only
+LTO Var(flag_lto_dump_defined)
+Dump only the defined symbols.
+
+alpha-sort
+LTO Var(flag_lto_alpha_sort)
+Sort the symbols alphabetically.
+
+size-sort
+LTO Var(flag_lto_size_sort)
+Sort the symbols according to size.
+
+reverse-sort
+LTO Var(flag_lto_reverse_sort)
+Display the symbols in reverse order.
+
+no-sort
+LTO Var(flag_lto_no_sort)
+Display the symbols in order of occurence.
+
+fdump-lto-body=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
+
 fdump-lto-tree-stats
 LTO Var(flag_lto_tree_stats)
 Dump the statistics of trees
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 8f7fdd9..36a7c04 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -56,12 +56,121 @@ along with GCC; see the file COPYING3.  If not see
 #include "attribs.h"
 #include "builtins.h"
 #include "print-tree.h"
+#include "stdio.h"
+#include "tree-cfg.h"
+#include "string.h"
+#include "iostream"
+#include "vector"
 
+class entry
+{
+public:
+	char name[20], type_name[20], visibility[20];
+	int size;
+};
+
+int compare(const void * a, const void * b)
+{
+	entry* ep1 = (entry*)a;
+	entry* ep2 = (entry*)b;
+	if (flag_lto_alpha_sort)
+		return strcmp(ep1->name,ep2->name);
+	else if (flag_lto_size_sort)
+		return ep1->size - ep2->size;
+	else
+		return strcmp(ep1->name,ep2->name);
+}
+
+/* Dump everything.  */
 static void dump()
 {
 	fprintf(stderr, "\nHello World!\n");
 }
 
+/* Dump variables and functions used in IL.  */
+void
+dump_list ()
+{
+	entry e;
+	std::vector <entry> vec;
+	std::vector <entry> :: iterator i;
+	std::vector <entry> :: reverse_iterator ir;
+	fprintf (stderr, "Symbol Table\n");
+    symtab_node *node;
+    fprintf (stderr, "\t\tName \t\tType \t\tVisibility \t\tSize\n");
+	if (!flag_lto_dump_defined)
+	{
+		FOR_EACH_SYMBOL (node)
+		{
+	    if (flag_lto_dump_demangle)
+				strcpy(e.name,node->name());
+		  else if (flag_lto_dump_no_demangle)
+				strcpy(e.name,node->asm_name());
+			else			
+				strcpy(e.name,node->asm_name());
+			strcpy(e.type_name, node->dump_type_name ());
+		  strcpy(e.visibility, node->dump_visibility ());
+			//e.size = TREE_INT_CST_LOW(DECL_SIZE(node->decl));
+			e.size = 0;
+			vec.push_back(e);
+		}
+	}
+	if (flag_lto_dump_defined)
+	{
+		FOR_EACH_DEFINED_SYMBOL (node)
+		{
+	    if (flag_lto_dump_demangle)
+				strcpy(e.name,node->name());
+		  else if (flag_lto_dump_no_demangle)
+				strcpy(e.name,node->asm_name());
+			else			
+				strcpy(e.name,node->asm_name());
+			strcpy(e.type_name, node->dump_type_name ());
+		  strcpy(e.visibility, node->dump_visibility ());
+			//e.size = TREE_INT_CST_LOW(DECL_SIZE(node->decl));
+			e.size = 0;
+			vec.push_back(e);
+		}
+	}
+	if (!flag_lto_no_sort)	
+	qsort(&vec.front(), vec.size(), sizeof(entry), compare);
+	if (!flag_lto_reverse_sort)
+		for (i = vec.begin(); i != vec.end(); ++i)
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\t\t\n",i->name, i->type_name, i->visibility );
+  else
+  	for (ir = vec.rbegin(); ir != vec.rend(); ++ir)
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\t\t\n",ir->name, ir->type_name, ir->visibility );	  
+}
+
+/* Dump specific variables and functions used in IL.  */
+void
+dump_symbol ()
+{
+	symtab_node *node;
+    fprintf (stderr, "Symbol:\t%s\n", flag_lto_dump_symbol);
+	FOR_EACH_SYMBOL (node)
+		if (!strcmp (flag_lto_dump_symbol, node->name ()))
+			node->debug ();
+   // node = symtab->find_symbol_by_name(flag_lto_dump_symbol);
+   //  if (node)
+	  //  node->debug ();
+	  fprintf(stderr, "\n" );
+}
+
+/* Dump gimple body of specific function.  */
+void
+dump_body ()
+{
+	fprintf(stderr, "Gimple body of function: %s\n", flag_lto_dump_body);
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_lto_dump_body))
+		{
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, 0);
+		}
+}
+
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
 
@@ -3368,15 +3477,29 @@ lto_main (void)
 
   if (flag_lto_gimple_stats)
 	  dump_gimple_statistics();
+
   if (flag_lto_tree_stats)
   {
   	fprintf(stderr, "Tree Statistics\n" );
 	dump_tree_statistics();
   }
+
+  /* Dump everything.  */
   if (flag_lto_dump)
-  {
     dump();
-  }
+
+    /* Dump variables and functions used in IL.  */
+  if (flag_lto_dump_list)
+    dump_list ();
+
+  /* Dump specific variables and functions used in IL.  */
+  if (flag_lto_dump_symbol)
+    dump_symbol ();
+
+  /* Dump gimple body of specific function.  */
+  if (flag_lto_dump_body)
+    dump_body ();
+
 
   timevar_stop (TV_PHASE_STREAM_IN);
 
diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
index 9bc3842..b2199d2 100644
--- a/gcc/lto/lto-dump.h
+++ b/gcc/lto/lto-dump.h
@@ -20,9 +20,8 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_LTO_DUMP_H_
 #define GCC_LTO_DUMP_H_
 
-void dump();
-
 /* A file.  */
+
 struct lto_file
 {
   /* The name of the file.  */
diff --git a/gcc/symtab.c b/gcc/symtab.c
index c153308..4b8d8e5 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -808,6 +808,24 @@ symtab_node::dump_referring (FILE *file)
 
 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
 
+/* Dump the visibility of the symbol.  */
+const char *
+symtab_node::dump_visibility () const
+{
+  static const char * const visibility_types[] = {
+    "default", "protected", "hidden", "internal"
+  };
+
+  return visibility_types[DECL_VISIBILITY (decl)];
+}
+
+/* Dump the type_name of the symbol.  */
+const char *
+symtab_node::dump_type_name () const
+{
+  return symtab_type_names[type];
+}
+
 /* Dump base fields of symtab nodes to F.  Not to be used directly.  */
 
 void
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 73237a6..3e10d15 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -81,7 +81,7 @@ extern void fold_loop_internal_call (gimple *, tree);
 extern basic_block move_sese_region_to_fn (struct function *, basic_block,
 				           basic_block, tree);
 extern void dump_function_to_file (tree, FILE *, dump_flags_t);
-extern void debug_function (tree, int) ;
+extern void debug_function (tree, dump_flags_t) ;
 extern void print_loops_bb (FILE *, basic_block, int, int);
 extern void print_loops (FILE *, int);
 extern void debug (struct loop &ref);

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

* Re: [GSOC] LTO dump tool project
  2018-06-26 20:02                                     ` Hrishikesh Kulkarni
  2018-06-27 22:43                                       ` Hrishikesh Kulkarni
@ 2018-06-29  7:25                                       ` Martin Liška
  1 sibling, 0 replies; 50+ messages in thread
From: Martin Liška @ 2018-06-29  7:25 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 06/26/2018 09:45 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> I have created another branch lto-dump-tool-improved as suggested.
> I have applied the patch for separation to lto-dump binary, made a few
> necessary changes in other files and it is running successfully.
> I will keep on adding previous work to this branch incrementally.
> 
> Please find the diff file attached for dumping of TREE statistics and
> GIMPLE statistics.
> 
> for example:
> (after configuring with --enable-gather-detailed-mem-stats)
> -fdump-lto-gimple-stats will dump
> GIMPLE statements
> Kind                   Stmts      Bytes
> ---------------------------------------
> assignments                0          0
> phi nodes                  0          0
> conditionals               0          0
> everything else            0          0
> ---------------------------------------
> Total                      0          0
> ---------------------------------------
> 
> -fdump-lto-tree-stats will dump
> 
> Tree Statistics
> 
> Kind                   Nodes      Bytes
> ----------------------------------------
> decls                   4327     932672
> types                   1531     257208
> blocks                     0          0
> stmts                      0          0
> refs                       0          0
> exprs                      4        128
> constants                 82       2060
> identifiers             4430     177200
> vecs                      16      28544
> binfos                     0          0
> ssa names                  0          0
> constructors               0          0
> random kinds            7301     291952
> lang_decl kinds            0          0
> lang_type kinds            0          0
> omp clauses                0          0
> ----------------------------------------
> Total                  17691    1689764
> 
> 
> 
> Please advise,
> 
> Hrishikesh
> 
> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have created another branch lto-dump-tool-improved as suggested.

Hi.

Great, it's now much more readable!

>> I have applied the patch for separation to lto-dump binary, made a few
>> necessary changes in other files and it is running successfully.
>> I will keep on adding previous work to this branch incrementally.

Good.

>>
>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>> statistics.
>>
>> for example:
>> (after configuring with --enable-gather-detailed-mem-stats)
>> -fdump-lto-gimple-stats will dump
>> GIMPLE statements
>> Kind                   Stmts      Bytes
>> ---------------------------------------
>> assignments                0          0
>> phi nodes                  0          0
>> conditionals               0          0
>> everything else            0          0
>> ---------------------------------------
>> Total                      0          0
>> ---------------------------------------

I guess problem is that all numbers are zeros. Easiest what you can
do is to run normal GCC with -fmem-report and add '-wrapper gdb,--args'.
That will open GCC in debugger, that you can place a breapoint and you'll
see a backtrace.

>>
>> -fdump-lto-tree-stats will dump
>>
>> Tree Statistics
>>
>> Kind                   Nodes      Bytes
>> ----------------------------------------
>> decls                   4327     932672
>> types                   1531     257208
>> blocks                     0          0
>> stmts                      0          0
>> refs                       0          0
>> exprs                      4        128
>> constants                 82       2060
>> identifiers             4430     177200
>> vecs                      16      28544
>> binfos                     0          0
>> ssa names                  0          0
>> constructors               0          0
>> random kinds            7301     291952
>> lang_decl kinds            0          0
>> lang_type kinds            0          0
>> omp clauses                0          0
>> ----------------------------------------
>> Total                  17691    1689764
>>

The output looks good for trees.

>>
>>
>> Please advise,

Next time, please specify where is problem for which you need advise ;)

Martin

>>
>> Hrishikesh
>>
>>
>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>
>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>> Hi,
>>>>
>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>> Hi,
>>>>>
>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>> attached). However when I try to build, I get the following error:
>>>>>
>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>
>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>
>>>>> file or directory
>>>>>
>>>>> compilation terminated.
>>>>>
>>>>>
>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>> suggestions on how to resolve the issue.
>>>>
>>>> insn-modes.h is one of header files which are generated at build time,
>>>> you will find it in the gcc subdirectory of your build directory (as
>>>> opposed to the source directory).
>>>>
>>>> Martin
>>>>
>>>
>>> Hi.
>>>
>>> There's patch that works for me.
>>> Needed dependency is here:
>>>
>>> +lto/lto-dump.o: $(LTO_EXE)
>>>
>>> It's bit artificial, but for now it works. Please start working
>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>
>>> Martin
>>
>>

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

* Re: [GSOC] LTO dump tool project
  2018-06-27 22:43                                       ` Hrishikesh Kulkarni
@ 2018-06-29  9:20                                         ` Martin Liška
  2018-07-03 13:09                                           ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-06-29  9:20 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> I have added new command line options:
> -no-demangle -> for the default non demangled output
> -no-sort -> for the list of symbols in order of their occurrence
> -alpha-sort -> for the list of symbols in their alphabetical order
> -reverse-sort -> for the list of symbols in reversed order
> -defined-only -> for only the defined symbols

Hi.

Good progress.

> 
> for example:
> 
> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
> -demangle -defined-only -reverse-sort

Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
from the older options.

> 
> will dump
> 
> Symbol Table
>         Name         Type         Visibility         Size
>         main        function        default
>         k        variable        default
>         foo        function        default
>         bar        function        default
> 
> It is a reversed alphabetical order of demangled symbol names which
> have been defined(hence printf excluded).
> Along with this I have also added all previous progress with reference
> to symbol table to the new branch.
> 
> For further options to add like -size-sort and -print-size I tried to
> access size of the symbol with symtab node using
> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
> but I am unable to do so.
> So how should I proceed with it?

Sent advises via instant messaging.

Martin

> 
> Please find the diff file attached herewith. I have also pushed the
> changes to the new branch.
> 
> Please advise,
> 
> Hrishikesh> 
> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have created another branch lto-dump-tool-improved as suggested.
>> I have applied the patch for separation to lto-dump binary, made a few
>> necessary changes in other files and it is running successfully.
>> I will keep on adding previous work to this branch incrementally.
>>
>> Please find the diff file attached for dumping of TREE statistics and
>> GIMPLE statistics.
>>
>> for example:
>> (after configuring with --enable-gather-detailed-mem-stats)
>> -fdump-lto-gimple-stats will dump
>> GIMPLE statements
>> Kind                   Stmts      Bytes
>> ---------------------------------------
>> assignments                0          0
>> phi nodes                  0          0
>> conditionals               0          0
>> everything else            0          0
>> ---------------------------------------
>> Total                      0          0
>> ---------------------------------------
>>
>> -fdump-lto-tree-stats will dump
>>
>> Tree Statistics
>>
>> Kind                   Nodes      Bytes
>> ----------------------------------------
>> decls                   4327     932672
>> types                   1531     257208
>> blocks                     0          0
>> stmts                      0          0
>> refs                       0          0
>> exprs                      4        128
>> constants                 82       2060
>> identifiers             4430     177200
>> vecs                      16      28544
>> binfos                     0          0
>> ssa names                  0          0
>> constructors               0          0
>> random kinds            7301     291952
>> lang_decl kinds            0          0
>> lang_type kinds            0          0
>> omp clauses                0          0
>> ----------------------------------------
>> Total                  17691    1689764
>>
>>
>>
>> Please advise,
>>
>> Hrishikesh
>>
>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> I have created another branch lto-dump-tool-improved as suggested.
>>> I have applied the patch for separation to lto-dump binary, made a few
>>> necessary changes in other files and it is running successfully.
>>> I will keep on adding previous work to this branch incrementally.
>>>
>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>> statistics.
>>>
>>> for example:
>>> (after configuring with --enable-gather-detailed-mem-stats)
>>> -fdump-lto-gimple-stats will dump
>>> GIMPLE statements
>>> Kind                   Stmts      Bytes
>>> ---------------------------------------
>>> assignments                0          0
>>> phi nodes                  0          0
>>> conditionals               0          0
>>> everything else            0          0
>>> ---------------------------------------
>>> Total                      0          0
>>> ---------------------------------------
>>>
>>> -fdump-lto-tree-stats will dump
>>>
>>> Tree Statistics
>>>
>>> Kind                   Nodes      Bytes
>>> ----------------------------------------
>>> decls                   4327     932672
>>> types                   1531     257208
>>> blocks                     0          0
>>> stmts                      0          0
>>> refs                       0          0
>>> exprs                      4        128
>>> constants                 82       2060
>>> identifiers             4430     177200
>>> vecs                      16      28544
>>> binfos                     0          0
>>> ssa names                  0          0
>>> constructors               0          0
>>> random kinds            7301     291952
>>> lang_decl kinds            0          0
>>> lang_type kinds            0          0
>>> omp clauses                0          0
>>> ----------------------------------------
>>> Total                  17691    1689764
>>>
>>>
>>>
>>> Please advise,
>>>
>>> Hrishikesh
>>>
>>>
>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>
>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>> Hi,
>>>>>
>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>> attached). However when I try to build, I get the following error:
>>>>>>
>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>
>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>
>>>>>> file or directory
>>>>>>
>>>>>> compilation terminated.
>>>>>>
>>>>>>
>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>> suggestions on how to resolve the issue.
>>>>>
>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>> opposed to the source directory).
>>>>>
>>>>> Martin
>>>>>
>>>>
>>>> Hi.
>>>>
>>>> There's patch that works for me.
>>>> Needed dependency is here:
>>>>
>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>
>>>> It's bit artificial, but for now it works. Please start working
>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>
>>>> Martin
>>>
>>>

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

* Re: [GSOC] LTO dump tool project
  2018-06-29  9:20                                         ` Martin Liška
@ 2018-07-03 13:09                                           ` Hrishikesh Kulkarni
  2018-07-04 18:54                                             ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-03 13:09 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

Thanks for suggestions. I have started incorporating them. As a first:

I have added command line options:
-print-size  to print the size of functions and variables
size of variables is in bits and size of functions is represented as
number of basic blocks.

-print-value  to print the value of initialization of global variables.

-size-sort  to sort the symbol names according to the size.

for example command line options:

 ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
-print-value -size-sort

the dump is:

Symbol Table
        Name         Type         Visibility        Size     Value

        printf         function        default           0
        main         function        default           3
        foo            function        default           3
        bar            function        default           6

        z               variable        default           8        97
        k               variable        default          32        5
        p               variable        default          32
4.400000095367431640625e+0

I have also tried to make memory allocation dynamic to the best of my knowledge.
I have pushed the changes to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh


On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> I have added new command line options:
>> -no-demangle -> for the default non demangled output
>> -no-sort -> for the list of symbols in order of their occurrence
>> -alpha-sort -> for the list of symbols in their alphabetical order
>> -reverse-sort -> for the list of symbols in reversed order
>> -defined-only -> for only the defined symbols
>
> Hi.
>
> Good progress.
>
>>
>> for example:
>>
>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>> -demangle -defined-only -reverse-sort
>
> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
> from the older options.
>
>>
>> will dump
>>
>> Symbol Table
>>         Name         Type         Visibility         Size
>>         main        function        default
>>         k        variable        default
>>         foo        function        default
>>         bar        function        default
>>
>> It is a reversed alphabetical order of demangled symbol names which
>> have been defined(hence printf excluded).
>> Along with this I have also added all previous progress with reference
>> to symbol table to the new branch.
>>
>> For further options to add like -size-sort and -print-size I tried to
>> access size of the symbol with symtab node using
>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>> but I am unable to do so.
>> So how should I proceed with it?
>
> Sent advises via instant messaging.
>
> Martin
>
>>
>> Please find the diff file attached herewith. I have also pushed the
>> changes to the new branch.
>>
>> Please advise,
>>
>> Hrishikesh>
>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> I have created another branch lto-dump-tool-improved as suggested.
>>> I have applied the patch for separation to lto-dump binary, made a few
>>> necessary changes in other files and it is running successfully.
>>> I will keep on adding previous work to this branch incrementally.
>>>
>>> Please find the diff file attached for dumping of TREE statistics and
>>> GIMPLE statistics.
>>>
>>> for example:
>>> (after configuring with --enable-gather-detailed-mem-stats)
>>> -fdump-lto-gimple-stats will dump
>>> GIMPLE statements
>>> Kind                   Stmts      Bytes
>>> ---------------------------------------
>>> assignments                0          0
>>> phi nodes                  0          0
>>> conditionals               0          0
>>> everything else            0          0
>>> ---------------------------------------
>>> Total                      0          0
>>> ---------------------------------------
>>>
>>> -fdump-lto-tree-stats will dump
>>>
>>> Tree Statistics
>>>
>>> Kind                   Nodes      Bytes
>>> ----------------------------------------
>>> decls                   4327     932672
>>> types                   1531     257208
>>> blocks                     0          0
>>> stmts                      0          0
>>> refs                       0          0
>>> exprs                      4        128
>>> constants                 82       2060
>>> identifiers             4430     177200
>>> vecs                      16      28544
>>> binfos                     0          0
>>> ssa names                  0          0
>>> constructors               0          0
>>> random kinds            7301     291952
>>> lang_decl kinds            0          0
>>> lang_type kinds            0          0
>>> omp clauses                0          0
>>> ----------------------------------------
>>> Total                  17691    1689764
>>>
>>>
>>>
>>> Please advise,
>>>
>>> Hrishikesh
>>>
>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>> necessary changes in other files and it is running successfully.
>>>> I will keep on adding previous work to this branch incrementally.
>>>>
>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>> statistics.
>>>>
>>>> for example:
>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>> -fdump-lto-gimple-stats will dump
>>>> GIMPLE statements
>>>> Kind                   Stmts      Bytes
>>>> ---------------------------------------
>>>> assignments                0          0
>>>> phi nodes                  0          0
>>>> conditionals               0          0
>>>> everything else            0          0
>>>> ---------------------------------------
>>>> Total                      0          0
>>>> ---------------------------------------
>>>>
>>>> -fdump-lto-tree-stats will dump
>>>>
>>>> Tree Statistics
>>>>
>>>> Kind                   Nodes      Bytes
>>>> ----------------------------------------
>>>> decls                   4327     932672
>>>> types                   1531     257208
>>>> blocks                     0          0
>>>> stmts                      0          0
>>>> refs                       0          0
>>>> exprs                      4        128
>>>> constants                 82       2060
>>>> identifiers             4430     177200
>>>> vecs                      16      28544
>>>> binfos                     0          0
>>>> ssa names                  0          0
>>>> constructors               0          0
>>>> random kinds            7301     291952
>>>> lang_decl kinds            0          0
>>>> lang_type kinds            0          0
>>>> omp clauses                0          0
>>>> ----------------------------------------
>>>> Total                  17691    1689764
>>>>
>>>>
>>>>
>>>> Please advise,
>>>>
>>>> Hrishikesh
>>>>
>>>>
>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>
>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>> Hi,
>>>>>>
>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>
>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>
>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>
>>>>>>> file or directory
>>>>>>>
>>>>>>> compilation terminated.
>>>>>>>
>>>>>>>
>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>> suggestions on how to resolve the issue.
>>>>>>
>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>> opposed to the source directory).
>>>>>>
>>>>>> Martin
>>>>>>
>>>>>
>>>>> Hi.
>>>>>
>>>>> There's patch that works for me.
>>>>> Needed dependency is here:
>>>>>
>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>
>>>>> It's bit artificial, but for now it works. Please start working
>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>
>>>>> Martin
>>>>
>>>>
>

[-- Attachment #2: symtab_list.diff --]
[-- Type: text/x-patch, Size: 7723 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 73342ee..23f37a0 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -86,6 +86,14 @@ defined-only
 LTO Var(flag_lto_dump_defined)
 Dump only the defined symbols.
 
+print-size
+LTO Var(flag_lto_print_size)
+Print the size of the symbols.
+
+print-value
+LTO Var(flag_lto_print_value)
+Print the initial values of the variables.
+
 alpha-sort
 LTO Var(flag_lto_alpha_sort)
 Sort the symbols alphabetically.
@@ -107,11 +115,11 @@ LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
 
 fdump-lto-tree-stats
 LTO Var(flag_lto_tree_stats)
-Dump the statistics of trees
+Dump the statistics of trees.
 
 fdump-lto-gimple-stats
 LTO Var(flag_lto_gimple_stats)
-Dump the statistics of gimple statements
+Dump the statistics of gimple statements.
 
 fresolution=
 LTO Joined
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 36a7c04..d4c2928 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -27,7 +27,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "basic-block.h"
 #include "tree.h"
 #include "gimple.h"
+#include "cfg.h"
 #include "cfghooks.h"
+#include "tree-cfg.h"
 #include "alloc-pool.h"
 #include "tree-pass.h"
 #include "tree-streamer.h"
@@ -56,17 +58,17 @@ along with GCC; see the file COPYING3.  If not see
 #include "attribs.h"
 #include "builtins.h"
 #include "print-tree.h"
-#include "stdio.h"
-#include "tree-cfg.h"
-#include "string.h"
-#include "iostream"
-#include "vector"
+#include "tree-pretty-print.h"
+#include <map>
+#include <iterator>
+#include <vector>
 
 class entry
 {
 public:
-	char name[20], type_name[20], visibility[20];
+	char *name, *type_name, *visibility;
 	int size;
+	tree value_tree;
 };
 
 int compare(const void * a, const void * b)
@@ -91,44 +93,81 @@ static void dump()
 void
 dump_list ()
 {
-	entry e;
 	std::vector <entry> vec;
 	std::vector <entry> :: iterator i;
 	std::vector <entry> :: reverse_iterator ir;
+	
 	fprintf (stderr, "Symbol Table\n");
-    symtab_node *node;
-    fprintf (stderr, "\t\tName \t\tType \t\tVisibility \t\tSize\n");
-	if (!flag_lto_dump_defined)
+  cgraph_node *cnode;
+  varpool_node *vnode;
+  
+  fprintf (stderr, "\t\tName \t\tType \t\tVisibility ");
+  if (flag_lto_print_size)
+	  fprintf(stderr, "\t\tSize ");
+  if (flag_lto_print_value)
+  	fprintf(stderr, "\t\tValue");
+  fprintf(stderr, "\n\n");
+	FOR_EACH_FUNCTION (cnode)
 	{
-		FOR_EACH_SYMBOL (node)
+		entry e;
+		if(!flag_lto_dump_defined || cnode->definition)
 		{
 	    if (flag_lto_dump_demangle)
-				strcpy(e.name,node->name());
+				e.name = xstrdup(cnode->name());
 		  else if (flag_lto_dump_no_demangle)
-				strcpy(e.name,node->asm_name());
+				e.name = xstrdup(cnode->asm_name());
 			else			
-				strcpy(e.name,node->asm_name());
-			strcpy(e.type_name, node->dump_type_name ());
-		  strcpy(e.visibility, node->dump_visibility ());
-			//e.size = TREE_INT_CST_LOW(DECL_SIZE(node->decl));
+				e.name = xstrdup(cnode->asm_name());
+			e.type_name = xstrdup(cnode->dump_type_name ());
+		  e.visibility = xstrdup(cnode->dump_visibility ());
 			e.size = 0;
+		  if (cnode->definition)
+	    {
+	    	cnode->get_untransformed_body ();
+	    	e.size = n_basic_blocks_for_fn(DECL_STRUCT_FUNCTION(cnode->decl));
+	    }
 			vec.push_back(e);
 		}
 	}
-	if (flag_lto_dump_defined)
+	if (!flag_lto_no_sort)	
+	qsort(&vec.front(), vec.size(), sizeof(entry), compare);
+	if (!flag_lto_reverse_sort)
+		for (i = vec.begin(); i != vec.end(); ++i)
+		{
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name, i->visibility );
+			if (flag_lto_print_size)
+				fprintf(stderr, "\t\t%d", i->size);
+			fprintf(stderr, "\n");
+		}
+  else
+  	for (ir = vec.rbegin(); ir != vec.rend(); ++ir)
+  	{
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\n",ir->name, ir->type_name, ir->visibility );	  
+			if (flag_lto_print_size)
+				fprintf(stderr, "\t\t%d\n", ir->size);
+			fprintf(stderr, "\n");
+		}
+  vec.clear();  
+  fprintf(stderr, "\n");
+
+	FOR_EACH_VARIABLE (vnode)
 	{
-		FOR_EACH_DEFINED_SYMBOL (node)
+		entry e;
+  	if(!flag_lto_dump_defined || vnode->definition)
 		{
-	    if (flag_lto_dump_demangle)
-				strcpy(e.name,node->name());
+		  if (flag_lto_dump_demangle)
+				e.name = xstrdup (vnode->name());
 		  else if (flag_lto_dump_no_demangle)
-				strcpy(e.name,node->asm_name());
-			else			
-				strcpy(e.name,node->asm_name());
-			strcpy(e.type_name, node->dump_type_name ());
-		  strcpy(e.visibility, node->dump_visibility ());
-			//e.size = TREE_INT_CST_LOW(DECL_SIZE(node->decl));
+				e.name = xstrdup (vnode->asm_name());
+			else
+				e.name = xstrdup (vnode->asm_name());
+			e.type_name = xstrdup (vnode->dump_type_name ());
+		  e.visibility = xstrdup (vnode->dump_visibility ());
 			e.size = 0;
+   		if (DECL_SIZE (vnode->decl) && tree_fits_shwi_p (DECL_SIZE (vnode->decl)))
+				e.size = tree_to_shwi (DECL_SIZE (vnode->decl));
+			vnode->get_constructor ();
+			e.value_tree = DECL_INITIAL (vnode->decl);
 			vec.push_back(e);
 		}
 	}
@@ -136,10 +175,26 @@ dump_list ()
 	qsort(&vec.front(), vec.size(), sizeof(entry), compare);
 	if (!flag_lto_reverse_sort)
 		for (i = vec.begin(); i != vec.end(); ++i)
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\t\t\n",i->name, i->type_name, i->visibility );
+		{
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name, i->visibility );
+      if (flag_lto_print_size)
+				fprintf(stderr, "\t\t%d\t\t", i->size);
+			if (flag_lto_print_value && i->value_tree)
+      	debug_generic_expr (i->value_tree);
+			else
+				fprintf(stderr, "\n");
+		}
   else
   	for (ir = vec.rbegin(); ir != vec.rend(); ++ir)
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\t\t\n",ir->name, ir->type_name, ir->visibility );	  
+  	{
+    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",ir->name, ir->type_name, ir->visibility );	  
+      if (flag_lto_print_size)
+				fprintf(stderr, "\t\t%d\t\t", ir->size);
+			if (flag_lto_print_value && ir->value_tree)
+      	debug_generic_expr (i->value_tree);
+			else
+				fprintf(stderr, "\n");
+		}
 }
 
 /* Dump specific variables and functions used in IL.  */
@@ -151,26 +206,9 @@ dump_symbol ()
 	FOR_EACH_SYMBOL (node)
 		if (!strcmp (flag_lto_dump_symbol, node->name ()))
 			node->debug ();
-   // node = symtab->find_symbol_by_name(flag_lto_dump_symbol);
-   //  if (node)
-	  //  node->debug ();
 	  fprintf(stderr, "\n" );
 }
 
-/* Dump gimple body of specific function.  */
-void
-dump_body ()
-{
-	fprintf(stderr, "Gimple body of function: %s\n", flag_lto_dump_body);
-	cgraph_node *cnode;
-	FOR_EACH_FUNCTION (cnode)
-		if (!strcmp (cnode->name (), flag_lto_dump_body))
-		{
-			cnode->get_untransformed_body ();
-			debug_function (cnode->decl, 0);
-		}
-}
-
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
 
@@ -1963,6 +2001,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	  gcc_assert (t && data_in->reader_cache->nodes.length () == from);
 	}
     }
+
   data_in->location_cache.apply_location_cache ();
 
   /* Read in lto_in_decl_state objects.  */
@@ -3475,13 +3514,12 @@ lto_main (void)
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
-  if (flag_lto_gimple_stats)
-	  dump_gimple_statistics();
+  dump_gimple_statistics();
 
   if (flag_lto_tree_stats)
   {
   	fprintf(stderr, "Tree Statistics\n" );
-	dump_tree_statistics();
+		dump_tree_statistics();
   }
 
   /* Dump everything.  */
@@ -3496,11 +3534,6 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
-  /* Dump gimple body of specific function.  */
-  if (flag_lto_dump_body)
-    dump_body ();
-
-
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())

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

* Re: [GSOC] LTO dump tool project
  2018-07-03 13:09                                           ` Hrishikesh Kulkarni
@ 2018-07-04 18:54                                             ` Hrishikesh Kulkarni
  2018-07-05 17:11                                               ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-04 18:54 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have:
tried to do all the formatting and style corrections according to
output given by check_GNU_style.py
removed '-fdump-lto' prefix from the command line options
added few necessary comments in the code
added command line option -type-stats from previous branch (added a
new percentage column to it)
for e.g.
    integer_type    3    25.00%
    pointer_type    3    25.00%
    array_type    1    8.33%
    function_type    5    41.67%
I have pushed the changes  to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh

On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> Thanks for suggestions. I have started incorporating them. As a first:
>
> I have added command line options:
> -print-size  to print the size of functions and variables
> size of variables is in bits and size of functions is represented as
> number of basic blocks.
>
> -print-value  to print the value of initialization of global variables.
>
> -size-sort  to sort the symbol names according to the size.
>
> for example command line options:
>
>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
> -print-value -size-sort
>
> the dump is:
>
> Symbol Table
>         Name         Type         Visibility        Size     Value
>
>         printf         function        default           0
>         main         function        default           3
>         foo            function        default           3
>         bar            function        default           6
>
>         z               variable        default           8        97
>         k               variable        default          32        5
>         p               variable        default          32
> 4.400000095367431640625e+0
>
> I have also tried to make memory allocation dynamic to the best of my knowledge.
> I have pushed the changes to the repo. Please find the diff file
> attached herewith.
>
> Regards,
>
> Hrishikesh
>
>
> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> I have added new command line options:
>>> -no-demangle -> for the default non demangled output
>>> -no-sort -> for the list of symbols in order of their occurrence
>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>> -reverse-sort -> for the list of symbols in reversed order
>>> -defined-only -> for only the defined symbols
>>
>> Hi.
>>
>> Good progress.
>>
>>>
>>> for example:
>>>
>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>> -demangle -defined-only -reverse-sort
>>
>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>> from the older options.
>>
>>>
>>> will dump
>>>
>>> Symbol Table
>>>         Name         Type         Visibility         Size
>>>         main        function        default
>>>         k        variable        default
>>>         foo        function        default
>>>         bar        function        default
>>>
>>> It is a reversed alphabetical order of demangled symbol names which
>>> have been defined(hence printf excluded).
>>> Along with this I have also added all previous progress with reference
>>> to symbol table to the new branch.
>>>
>>> For further options to add like -size-sort and -print-size I tried to
>>> access size of the symbol with symtab node using
>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>> but I am unable to do so.
>>> So how should I proceed with it?
>>
>> Sent advises via instant messaging.
>>
>> Martin
>>
>>>
>>> Please find the diff file attached herewith. I have also pushed the
>>> changes to the new branch.
>>>
>>> Please advise,
>>>
>>> Hrishikesh>
>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>> necessary changes in other files and it is running successfully.
>>>> I will keep on adding previous work to this branch incrementally.
>>>>
>>>> Please find the diff file attached for dumping of TREE statistics and
>>>> GIMPLE statistics.
>>>>
>>>> for example:
>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>> -fdump-lto-gimple-stats will dump
>>>> GIMPLE statements
>>>> Kind                   Stmts      Bytes
>>>> ---------------------------------------
>>>> assignments                0          0
>>>> phi nodes                  0          0
>>>> conditionals               0          0
>>>> everything else            0          0
>>>> ---------------------------------------
>>>> Total                      0          0
>>>> ---------------------------------------
>>>>
>>>> -fdump-lto-tree-stats will dump
>>>>
>>>> Tree Statistics
>>>>
>>>> Kind                   Nodes      Bytes
>>>> ----------------------------------------
>>>> decls                   4327     932672
>>>> types                   1531     257208
>>>> blocks                     0          0
>>>> stmts                      0          0
>>>> refs                       0          0
>>>> exprs                      4        128
>>>> constants                 82       2060
>>>> identifiers             4430     177200
>>>> vecs                      16      28544
>>>> binfos                     0          0
>>>> ssa names                  0          0
>>>> constructors               0          0
>>>> random kinds            7301     291952
>>>> lang_decl kinds            0          0
>>>> lang_type kinds            0          0
>>>> omp clauses                0          0
>>>> ----------------------------------------
>>>> Total                  17691    1689764
>>>>
>>>>
>>>>
>>>> Please advise,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>> necessary changes in other files and it is running successfully.
>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>
>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>> statistics.
>>>>>
>>>>> for example:
>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>> -fdump-lto-gimple-stats will dump
>>>>> GIMPLE statements
>>>>> Kind                   Stmts      Bytes
>>>>> ---------------------------------------
>>>>> assignments                0          0
>>>>> phi nodes                  0          0
>>>>> conditionals               0          0
>>>>> everything else            0          0
>>>>> ---------------------------------------
>>>>> Total                      0          0
>>>>> ---------------------------------------
>>>>>
>>>>> -fdump-lto-tree-stats will dump
>>>>>
>>>>> Tree Statistics
>>>>>
>>>>> Kind                   Nodes      Bytes
>>>>> ----------------------------------------
>>>>> decls                   4327     932672
>>>>> types                   1531     257208
>>>>> blocks                     0          0
>>>>> stmts                      0          0
>>>>> refs                       0          0
>>>>> exprs                      4        128
>>>>> constants                 82       2060
>>>>> identifiers             4430     177200
>>>>> vecs                      16      28544
>>>>> binfos                     0          0
>>>>> ssa names                  0          0
>>>>> constructors               0          0
>>>>> random kinds            7301     291952
>>>>> lang_decl kinds            0          0
>>>>> lang_type kinds            0          0
>>>>> omp clauses                0          0
>>>>> ----------------------------------------
>>>>> Total                  17691    1689764
>>>>>
>>>>>
>>>>>
>>>>> Please advise,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>>
>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>
>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>
>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>
>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>
>>>>>>>> file or directory
>>>>>>>>
>>>>>>>> compilation terminated.
>>>>>>>>
>>>>>>>>
>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>
>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>> opposed to the source directory).
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> There's patch that works for me.
>>>>>> Needed dependency is here:
>>>>>>
>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>
>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>
>>>>>> Martin
>>>>>
>>>>>
>>

[-- Attachment #2: style.diff --]
[-- Type: text/x-patch, Size: 8768 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 23f37a0..8abc051 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -67,11 +67,11 @@ fdump
 LTO Var(flag_lto_dump)
 Call the dump function
 
-fdump-lto-list
+list
 LTO Var(flag_lto_dump_list)
 Call the dump function for variables and function in IL.
 
-fdump-lto-symbol=
+symbol=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 
 demangle
@@ -110,14 +110,18 @@ no-sort
 LTO Var(flag_lto_no_sort)
 Display the symbols in order of occurence.
 
-fdump-lto-body=
+body=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
 
-fdump-lto-tree-stats
+type-stats
+LTO Var(flag_lto_dump_type_stats)
+Dump the statistics of tree types.
+
+tree-stats
 LTO Var(flag_lto_tree_stats)
 Dump the statistics of trees.
 
-fdump-lto-gimple-stats
+gimple-stats
 LTO Var(flag_lto_gimple_stats)
 Dump the statistics of gimple statements.
 
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 8cec86d..0fb9b86 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -71,22 +71,23 @@ public:
 	tree value_tree;
 };
 
-int compare(const void * a, const void * b)
+/* Compare function for qsort.  */
+int compare (const void * a, const void * b)
 {
 	entry* ep1 = (entry*)a;
 	entry* ep2 = (entry*)b;
 	if (flag_lto_alpha_sort)
-		return strcmp(ep1->name,ep2->name);
+		return strcmp (ep1->name,ep2->name);
 	else if (flag_lto_size_sort)
 		return ep1->size - ep2->size;
 	else
-		return strcmp(ep1->name,ep2->name);
+		return strcmp (ep1->name,ep2->name);
 }
 
 /* Dump everything.  */
-static void dump()
+static void dump ()
 {
-	fprintf(stderr, "\nHello World!\n");
+	fprintf (stderr, "\nHello World!\n");
 }
 
 /* Dump variables and functions used in IL.  */
@@ -100,7 +101,7 @@ dump_list ()
 	fprintf (stderr, "Symbol Table\n");
   cgraph_node *cnode;
   varpool_node *vnode;
-  
+
   fprintf (stderr, "\t\tName \t\tType \t\tVisibility ");
   if (flag_lto_print_size)
 	  fprintf(stderr, "\t\tSize ");
@@ -110,45 +111,48 @@ dump_list ()
 	FOR_EACH_FUNCTION (cnode)
 	{
 		entry e;
-		if(!flag_lto_dump_defined || cnode->definition)
+		if (!flag_lto_dump_defined || cnode->definition)
 		{
 	    if (flag_lto_dump_demangle)
-				e.name = xstrdup(cnode->name());
+				e.name = xstrdup (cnode->name ());
 		  else if (flag_lto_dump_no_demangle)
-				e.name = xstrdup(cnode->asm_name());
-			else			
-				e.name = xstrdup(cnode->asm_name());
-			e.type_name = xstrdup(cnode->dump_type_name ());
-		  e.visibility = xstrdup(cnode->dump_visibility ());
+				e.name = xstrdup (cnode->asm_name ());
+			else
+				e.name = xstrdup (cnode->asm_name ());
+			e.type_name = xstrdup (cnode->dump_type_name ());
+		  e.visibility = xstrdup (cnode->dump_visibility ());
 			e.size = 0;
 		  if (cnode->definition)
 	    {
 	    	cnode->get_untransformed_body ();
-	    	e.size = n_basic_blocks_for_fn(DECL_STRUCT_FUNCTION(cnode->decl));
+	    	e.size = n_basic_blocks_for_fn
+	    	(DECL_STRUCT_FUNCTION (cnode->decl));
 	    }
-			vec.push_back(e);
+			vec.push_back (e);
 		}
 	}
 	if (!flag_lto_no_sort)	
-	qsort(&vec.front(), vec.size(), sizeof(entry), compare);
+	qsort (&vec.front (), vec.size (), sizeof (entry), compare);
 	if (!flag_lto_reverse_sort)
-		for (i = vec.begin(); i != vec.end(); ++i)
+		for (i = vec.begin (); i != vec.end (); ++i)
 		{
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name, i->visibility );
+    	fprintf (stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name,
+    		i->visibility);
 			if (flag_lto_print_size)
-				fprintf(stderr, "\t\t%d", i->size);
-			fprintf(stderr, "\n");
+				fprintf (stderr, "\t\t%d", i->size);
+			fprintf (stderr, "\n");
 		}
   else
-  	for (ir = vec.rbegin(); ir != vec.rend(); ++ir)
+  	for (ir = vec.rbegin (); ir != vec.rend (); ++ir)
   	{
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s\n",ir->name, ir->type_name, ir->visibility );	  
+    	fprintf (stderr, "\t\t%s\t\t%s\t\t%s\n",ir->name, ir->type_name,
+    		ir->visibility);
 			if (flag_lto_print_size)
-				fprintf(stderr, "\t\t%d\n", ir->size);
-			fprintf(stderr, "\n");
+				fprintf (stderr, "\t\t%d\n", ir->size);
+			fprintf (stderr, "\n");
 		}
-  vec.clear();  
-  fprintf(stderr, "\n");
+  vec.clear ();
+  fprintf (stderr, "\n");
 
 	FOR_EACH_VARIABLE (vnode)
 	{
@@ -156,11 +160,11 @@ dump_list ()
   	if(!flag_lto_dump_defined || vnode->definition)
 		{
 		  if (flag_lto_dump_demangle)
-				e.name = xstrdup (vnode->name());
+				e.name = xstrdup (vnode->name ());
 		  else if (flag_lto_dump_no_demangle)
-				e.name = xstrdup (vnode->asm_name());
+				e.name = xstrdup (vnode->asm_name ());
 			else
-				e.name = xstrdup (vnode->asm_name());
+				e.name = xstrdup (vnode->asm_name ());
 			e.type_name = xstrdup (vnode->dump_type_name ());
 		  e.visibility = xstrdup (vnode->dump_visibility ());
 			e.size = 0;
@@ -168,32 +172,34 @@ dump_list ()
 				e.size = tree_to_shwi (DECL_SIZE (vnode->decl));
 			vnode->get_constructor ();
 			e.value_tree = DECL_INITIAL (vnode->decl);
-			vec.push_back(e);
+			vec.push_back (e);
 		}
 	}
-	if (!flag_lto_no_sort)	
-	qsort(&vec.front(), vec.size(), sizeof(entry), compare);
+	if (!flag_lto_no_sort)
+	qsort (&vec.front (), vec.size (), sizeof (entry), compare);
 	if (!flag_lto_reverse_sort)
-		for (i = vec.begin(); i != vec.end(); ++i)
+		for (i = vec.begin (); i != vec.end (); ++i)
 		{
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name, i->visibility );
+    	fprintf (stderr, "\t\t%s\t\t%s\t\t%s",i->name, i->type_name,
+    		i->visibility);
       if (flag_lto_print_size)
-				fprintf(stderr, "\t\t%d\t\t", i->size);
+				fprintf (stderr, "\t\t%d\t\t", i->size);
 			if (flag_lto_print_value && i->value_tree)
       	debug_generic_expr (i->value_tree);
 			else
-				fprintf(stderr, "\n");
+				fprintf (stderr, "\n");
 		}
   else
   	for (ir = vec.rbegin(); ir != vec.rend(); ++ir)
   	{
-    	fprintf(stderr, "\t\t%s\t\t%s\t\t%s",ir->name, ir->type_name, ir->visibility );	  
+    	fprintf (stderr, "\t\t%s\t\t%s\t\t%s",ir->name, ir->type_name,
+    		ir->visibility);
       if (flag_lto_print_size)
-				fprintf(stderr, "\t\t%d\t\t", ir->size);
+				fprintf (stderr, "\t\t%d\t\t", ir->size);
 			if (flag_lto_print_value && ir->value_tree)
       	debug_generic_expr (i->value_tree);
 			else
-				fprintf(stderr, "\n");
+				fprintf (stderr, "\n");
 		}
 }
 
@@ -206,7 +212,7 @@ dump_symbol ()
 	FOR_EACH_SYMBOL (node)
 		if (!strcmp (flag_lto_dump_symbol, node->name ()))
 			node->debug ();
-	  fprintf(stderr, "\n" );
+	  fprintf (stderr, "\n");
 }
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
@@ -1907,7 +1913,9 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 
   /* We do not uniquify the pre-loaded cache entries, those are middle-end
      internal types that should not be merged.  */
-
+	std :: map <tree_code, int> stats;
+  std :: map <tree_code, int> :: iterator itr;
+  int total = 0;
   /* Read the global declarations and types.  */
   while (ib_main.p < ib_main.len)
     {
@@ -1956,6 +1964,18 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 		 chains.  */
 	      if (TYPE_P (t))
 		{
+			/* Map the tree types to their frequencies.  */
+			print_node_brief (stderr, "", t, 0);
+			if (flag_lto_dump_type_stats)
+			{
+			  itr = stats.find (TREE_CODE (t));
+			  if (itr == stats.end ())
+			    stats.insert (std :: pair <tree_code, int>
+			    	(TREE_CODE (t), 1));
+			  else
+			    itr->second++;
+			  total++;
+			}
 		  seen_type = true;
 		  num_prevailing_types++;
 		  lto_fixup_prevailing_type (t);
@@ -2001,6 +2021,13 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	  gcc_assert (t && data_in->reader_cache->nodes.length () == from);
 	}
     }
+		fprintf (stderr, "\n");
+		/* Dump the tree type stats.  */
+		if (flag_lto_dump_type_stats)
+		  for (itr = stats.begin (); itr != stats.end (); ++itr)
+		    fprintf (stderr, "\t%s\t%d\t%0.2f%\n",
+		     get_tree_code_name (itr->first)
+		    	, itr->second, float (itr->second)/total*100);
 
   data_in->location_cache.apply_location_cache ();
 
@@ -3514,20 +3541,22 @@ lto_main (void)
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
+	/* Dump gimple statement statistics.  */
 	if (flag_lto_gimple_stats)
 	{
-		dump_gimple_statistics();
+		dump_gimple_statistics ();
 	}
 
+	/* Dump tree statistics.  */
   if (flag_lto_tree_stats)
   {
-  	fprintf(stderr, "Tree Statistics\n" );
-		dump_tree_statistics();
+  	fprintf (stderr, "Tree Statistics\n");
+		dump_tree_statistics ();
   }
 
   /* Dump everything.  */
   if (flag_lto_dump)
-    dump();
+    dump ();
 
     /* Dump variables and functions used in IL.  */
   if (flag_lto_dump_list)

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

* Re: [GSOC] LTO dump tool project
  2018-07-04 18:54                                             ` Hrishikesh Kulkarni
@ 2018-07-05 17:11                                               ` Hrishikesh Kulkarni
  2018-07-09  7:51                                                 ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-05 17:11 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added new command line option:
-objects
which will dump size, offset and name of each section for all lto objects

for example:
$ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects

gives output:
            LTO object name: test_hello.o

NO.        OFFSET        SIZE        SECTION NAME

1        64        15        .gnu.lto_.profile.a7add72ac123628
2        79        55        .gnu.lto_.icf.a7add72ac123628
3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
4        268        116        .gnu.lto_.inline.a7add72ac123628
5        384        24        .gnu.lto_.pureconst.a7add72ac123628
6        408        306        .gnu.lto_foo.a7add72ac123628
7        714        469        .gnu.lto_bar.a7add72ac123628
8        1183        345        .gnu.lto_main.a7add72ac123628
9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
10        1616        15        .gnu.lto_.refs.a7add72ac123628
11        1631        1205        .gnu.lto_.decls.a7add72ac123628
12        2836        109        .gnu.lto_.symtab.a7add72ac123628
13        2945        76        .gnu.lto_.opts

            LTO object name: test.o

NO.        OFFSET        SIZE        SECTION NAME

1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
12        1999        76        .gnu.lto_.opts


I have pushed the changes to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh

On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have:
> tried to do all the formatting and style corrections according to
> output given by check_GNU_style.py
> removed '-fdump-lto' prefix from the command line options
> added few necessary comments in the code
> added command line option -type-stats from previous branch (added a
> new percentage column to it)
> for e.g.
>     integer_type    3    25.00%
>     pointer_type    3    25.00%
>     array_type    1    8.33%
>     function_type    5    41.67%
> I have pushed the changes  to the repo. Please find the diff file
> attached herewith.
>
> Regards,
>
> Hrishikesh
>
> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> Thanks for suggestions. I have started incorporating them. As a first:
>>
>> I have added command line options:
>> -print-size  to print the size of functions and variables
>> size of variables is in bits and size of functions is represented as
>> number of basic blocks.
>>
>> -print-value  to print the value of initialization of global variables.
>>
>> -size-sort  to sort the symbol names according to the size.
>>
>> for example command line options:
>>
>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>> -print-value -size-sort
>>
>> the dump is:
>>
>> Symbol Table
>>         Name         Type         Visibility        Size     Value
>>
>>         printf         function        default           0
>>         main         function        default           3
>>         foo            function        default           3
>>         bar            function        default           6
>>
>>         z               variable        default           8        97
>>         k               variable        default          32        5
>>         p               variable        default          32
>> 4.400000095367431640625e+0
>>
>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>> I have pushed the changes to the repo. Please find the diff file
>> attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>>
>>
>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>> Hi,
>>>>
>>>> I have added new command line options:
>>>> -no-demangle -> for the default non demangled output
>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>> -reverse-sort -> for the list of symbols in reversed order
>>>> -defined-only -> for only the defined symbols
>>>
>>> Hi.
>>>
>>> Good progress.
>>>
>>>>
>>>> for example:
>>>>
>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>> -demangle -defined-only -reverse-sort
>>>
>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>> from the older options.
>>>
>>>>
>>>> will dump
>>>>
>>>> Symbol Table
>>>>         Name         Type         Visibility         Size
>>>>         main        function        default
>>>>         k        variable        default
>>>>         foo        function        default
>>>>         bar        function        default
>>>>
>>>> It is a reversed alphabetical order of demangled symbol names which
>>>> have been defined(hence printf excluded).
>>>> Along with this I have also added all previous progress with reference
>>>> to symbol table to the new branch.
>>>>
>>>> For further options to add like -size-sort and -print-size I tried to
>>>> access size of the symbol with symtab node using
>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>> but I am unable to do so.
>>>> So how should I proceed with it?
>>>
>>> Sent advises via instant messaging.
>>>
>>> Martin
>>>
>>>>
>>>> Please find the diff file attached herewith. I have also pushed the
>>>> changes to the new branch.
>>>>
>>>> Please advise,
>>>>
>>>> Hrishikesh>
>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>> necessary changes in other files and it is running successfully.
>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>
>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>> GIMPLE statistics.
>>>>>
>>>>> for example:
>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>> -fdump-lto-gimple-stats will dump
>>>>> GIMPLE statements
>>>>> Kind                   Stmts      Bytes
>>>>> ---------------------------------------
>>>>> assignments                0          0
>>>>> phi nodes                  0          0
>>>>> conditionals               0          0
>>>>> everything else            0          0
>>>>> ---------------------------------------
>>>>> Total                      0          0
>>>>> ---------------------------------------
>>>>>
>>>>> -fdump-lto-tree-stats will dump
>>>>>
>>>>> Tree Statistics
>>>>>
>>>>> Kind                   Nodes      Bytes
>>>>> ----------------------------------------
>>>>> decls                   4327     932672
>>>>> types                   1531     257208
>>>>> blocks                     0          0
>>>>> stmts                      0          0
>>>>> refs                       0          0
>>>>> exprs                      4        128
>>>>> constants                 82       2060
>>>>> identifiers             4430     177200
>>>>> vecs                      16      28544
>>>>> binfos                     0          0
>>>>> ssa names                  0          0
>>>>> constructors               0          0
>>>>> random kinds            7301     291952
>>>>> lang_decl kinds            0          0
>>>>> lang_type kinds            0          0
>>>>> omp clauses                0          0
>>>>> ----------------------------------------
>>>>> Total                  17691    1689764
>>>>>
>>>>>
>>>>>
>>>>> Please advise,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>> necessary changes in other files and it is running successfully.
>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>
>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>> statistics.
>>>>>>
>>>>>> for example:
>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>> -fdump-lto-gimple-stats will dump
>>>>>> GIMPLE statements
>>>>>> Kind                   Stmts      Bytes
>>>>>> ---------------------------------------
>>>>>> assignments                0          0
>>>>>> phi nodes                  0          0
>>>>>> conditionals               0          0
>>>>>> everything else            0          0
>>>>>> ---------------------------------------
>>>>>> Total                      0          0
>>>>>> ---------------------------------------
>>>>>>
>>>>>> -fdump-lto-tree-stats will dump
>>>>>>
>>>>>> Tree Statistics
>>>>>>
>>>>>> Kind                   Nodes      Bytes
>>>>>> ----------------------------------------
>>>>>> decls                   4327     932672
>>>>>> types                   1531     257208
>>>>>> blocks                     0          0
>>>>>> stmts                      0          0
>>>>>> refs                       0          0
>>>>>> exprs                      4        128
>>>>>> constants                 82       2060
>>>>>> identifiers             4430     177200
>>>>>> vecs                      16      28544
>>>>>> binfos                     0          0
>>>>>> ssa names                  0          0
>>>>>> constructors               0          0
>>>>>> random kinds            7301     291952
>>>>>> lang_decl kinds            0          0
>>>>>> lang_type kinds            0          0
>>>>>> omp clauses                0          0
>>>>>> ----------------------------------------
>>>>>> Total                  17691    1689764
>>>>>>
>>>>>>
>>>>>>
>>>>>> Please advise,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>>
>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>
>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>
>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>
>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>
>>>>>>>>> file or directory
>>>>>>>>>
>>>>>>>>> compilation terminated.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>
>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>> opposed to the source directory).
>>>>>>>>
>>>>>>>> Martin
>>>>>>>>
>>>>>>>
>>>>>>> Hi.
>>>>>>>
>>>>>>> There's patch that works for me.
>>>>>>> Needed dependency is here:
>>>>>>>
>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>
>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>
>>>>>>> Martin
>>>>>>
>>>>>>
>>>

[-- Attachment #2: objects.diff --]
[-- Type: text/x-patch, Size: 1306 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 8abc051..9e7d1fc 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -110,6 +110,10 @@ no-sort
 LTO Var(flag_lto_no_sort)
 Display the symbols in order of occurence.
 
+objects
+LTO Var(flag_lto_dump_objects)
+Dump the details of LTO objects.
+
 body=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
 
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 0fb9b86..8c29d1b 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -2337,6 +2337,17 @@ lto_file_read (lto_file *file, FILE *resolution_file, int *count)
   memset (&section_list, 0, sizeof (struct lto_section_list)); 
   section_hash_table = lto_obj_build_section_table (file, &section_list);
 
+  /* Dump the details of LTO objects.  */
+  if (flag_lto_dump_objects)
+  {
+	  int i=0;
+	  fprintf (stderr, "\n\t\t\tLTO object name: %s\n", file->filename);
+	  fprintf (stderr, "\nNO.\t\tOFFSET\t\tSIZE\t\tSECTION NAME\n\n");
+	  for (section = section_list.first; section != NULL; section = section->next)
+	  	fprintf (stderr, "%d\t\t%d\t\t%d\t\t%s\n",++i
+	  		, section->start, section->len, section->name);
+	}
+
   /* Find all sub modules in the object and put their sections into new hash
      tables in a splay tree. */
   file_ids = lto_splay_tree_new ();

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

* Re: [GSOC] LTO dump tool project
  2018-07-05 17:11                                               ` Hrishikesh Kulkarni
@ 2018-07-09  7:51                                                 ` Hrishikesh Kulkarni
  2018-07-09  8:34                                                   ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-09  7:51 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

The command line option -gimple-stats will dump the statistics of
gimple statements.

For example:

$ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats

will dump:

GIMPLE statements
Kind                   Stmts      Bytes
---------------------------------------
assignments                3        264
phi nodes                  1        248
conditionals               1         80
everything else           12        704
---------------------------------------
Total                     17       1296
---------------------------------------

I have pushed the changes to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh

On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have added new command line option:
> -objects
> which will dump size, offset and name of each section for all lto objects
>
> for example:
> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>
> gives output:
>             LTO object name: test_hello.o
>
> NO.        OFFSET        SIZE        SECTION NAME
>
> 1        64        15        .gnu.lto_.profile.a7add72ac123628
> 2        79        55        .gnu.lto_.icf.a7add72ac123628
> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
> 4        268        116        .gnu.lto_.inline.a7add72ac123628
> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
> 6        408        306        .gnu.lto_foo.a7add72ac123628
> 7        714        469        .gnu.lto_bar.a7add72ac123628
> 8        1183        345        .gnu.lto_main.a7add72ac123628
> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
> 13        2945        76        .gnu.lto_.opts
>
>             LTO object name: test.o
>
> NO.        OFFSET        SIZE        SECTION NAME
>
> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
> 12        1999        76        .gnu.lto_.opts
>
>
> I have pushed the changes to the repo. Please find the diff file
> attached herewith.
>
> Regards,
>
> Hrishikesh
>
> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have:
>> tried to do all the formatting and style corrections according to
>> output given by check_GNU_style.py
>> removed '-fdump-lto' prefix from the command line options
>> added few necessary comments in the code
>> added command line option -type-stats from previous branch (added a
>> new percentage column to it)
>> for e.g.
>>     integer_type    3    25.00%
>>     pointer_type    3    25.00%
>>     array_type    1    8.33%
>>     function_type    5    41.67%
>> I have pushed the changes  to the repo. Please find the diff file
>> attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>
>>> I have added command line options:
>>> -print-size  to print the size of functions and variables
>>> size of variables is in bits and size of functions is represented as
>>> number of basic blocks.
>>>
>>> -print-value  to print the value of initialization of global variables.
>>>
>>> -size-sort  to sort the symbol names according to the size.
>>>
>>> for example command line options:
>>>
>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>> -print-value -size-sort
>>>
>>> the dump is:
>>>
>>> Symbol Table
>>>         Name         Type         Visibility        Size     Value
>>>
>>>         printf         function        default           0
>>>         main         function        default           3
>>>         foo            function        default           3
>>>         bar            function        default           6
>>>
>>>         z               variable        default           8        97
>>>         k               variable        default          32        5
>>>         p               variable        default          32
>>> 4.400000095367431640625e+0
>>>
>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>> I have pushed the changes to the repo. Please find the diff file
>>> attached herewith.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>>
>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>> Hi,
>>>>>
>>>>> I have added new command line options:
>>>>> -no-demangle -> for the default non demangled output
>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>> -defined-only -> for only the defined symbols
>>>>
>>>> Hi.
>>>>
>>>> Good progress.
>>>>
>>>>>
>>>>> for example:
>>>>>
>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>> -demangle -defined-only -reverse-sort
>>>>
>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>> from the older options.
>>>>
>>>>>
>>>>> will dump
>>>>>
>>>>> Symbol Table
>>>>>         Name         Type         Visibility         Size
>>>>>         main        function        default
>>>>>         k        variable        default
>>>>>         foo        function        default
>>>>>         bar        function        default
>>>>>
>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>> have been defined(hence printf excluded).
>>>>> Along with this I have also added all previous progress with reference
>>>>> to symbol table to the new branch.
>>>>>
>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>> access size of the symbol with symtab node using
>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>> but I am unable to do so.
>>>>> So how should I proceed with it?
>>>>
>>>> Sent advises via instant messaging.
>>>>
>>>> Martin
>>>>
>>>>>
>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>> changes to the new branch.
>>>>>
>>>>> Please advise,
>>>>>
>>>>> Hrishikesh>
>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>> necessary changes in other files and it is running successfully.
>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>
>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>> GIMPLE statistics.
>>>>>>
>>>>>> for example:
>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>> -fdump-lto-gimple-stats will dump
>>>>>> GIMPLE statements
>>>>>> Kind                   Stmts      Bytes
>>>>>> ---------------------------------------
>>>>>> assignments                0          0
>>>>>> phi nodes                  0          0
>>>>>> conditionals               0          0
>>>>>> everything else            0          0
>>>>>> ---------------------------------------
>>>>>> Total                      0          0
>>>>>> ---------------------------------------
>>>>>>
>>>>>> -fdump-lto-tree-stats will dump
>>>>>>
>>>>>> Tree Statistics
>>>>>>
>>>>>> Kind                   Nodes      Bytes
>>>>>> ----------------------------------------
>>>>>> decls                   4327     932672
>>>>>> types                   1531     257208
>>>>>> blocks                     0          0
>>>>>> stmts                      0          0
>>>>>> refs                       0          0
>>>>>> exprs                      4        128
>>>>>> constants                 82       2060
>>>>>> identifiers             4430     177200
>>>>>> vecs                      16      28544
>>>>>> binfos                     0          0
>>>>>> ssa names                  0          0
>>>>>> constructors               0          0
>>>>>> random kinds            7301     291952
>>>>>> lang_decl kinds            0          0
>>>>>> lang_type kinds            0          0
>>>>>> omp clauses                0          0
>>>>>> ----------------------------------------
>>>>>> Total                  17691    1689764
>>>>>>
>>>>>>
>>>>>>
>>>>>> Please advise,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>
>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>> statistics.
>>>>>>>
>>>>>>> for example:
>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>> GIMPLE statements
>>>>>>> Kind                   Stmts      Bytes
>>>>>>> ---------------------------------------
>>>>>>> assignments                0          0
>>>>>>> phi nodes                  0          0
>>>>>>> conditionals               0          0
>>>>>>> everything else            0          0
>>>>>>> ---------------------------------------
>>>>>>> Total                      0          0
>>>>>>> ---------------------------------------
>>>>>>>
>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>
>>>>>>> Tree Statistics
>>>>>>>
>>>>>>> Kind                   Nodes      Bytes
>>>>>>> ----------------------------------------
>>>>>>> decls                   4327     932672
>>>>>>> types                   1531     257208
>>>>>>> blocks                     0          0
>>>>>>> stmts                      0          0
>>>>>>> refs                       0          0
>>>>>>> exprs                      4        128
>>>>>>> constants                 82       2060
>>>>>>> identifiers             4430     177200
>>>>>>> vecs                      16      28544
>>>>>>> binfos                     0          0
>>>>>>> ssa names                  0          0
>>>>>>> constructors               0          0
>>>>>>> random kinds            7301     291952
>>>>>>> lang_decl kinds            0          0
>>>>>>> lang_type kinds            0          0
>>>>>>> omp clauses                0          0
>>>>>>> ----------------------------------------
>>>>>>> Total                  17691    1689764
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Please advise,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>
>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>
>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>
>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>
>>>>>>>>>> file or directory
>>>>>>>>>>
>>>>>>>>>> compilation terminated.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>
>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>> opposed to the source directory).
>>>>>>>>>
>>>>>>>>> Martin
>>>>>>>>>
>>>>>>>>
>>>>>>>> Hi.
>>>>>>>>
>>>>>>>> There's patch that works for me.
>>>>>>>> Needed dependency is here:
>>>>>>>>
>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>
>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>
>>>>>>>> Martin
>>>>>>>
>>>>>>>
>>>>

[-- Attachment #2: gimple-stats.diff --]
[-- Type: text/x-patch, Size: 536 bytes --]

diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 8c29d1b..40fdbbe 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -3553,10 +3553,13 @@ lto_main (void)
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
 	/* Dump gimple statement statistics.  */
-	if (flag_lto_gimple_stats)
-	{
+  if (flag_lto_gimple_stats)
+  {
+		cgraph_node *node;
+		FOR_EACH_DEFINED_FUNCTION (node)
+		 node->get_untransformed_body ();
 		dump_gimple_statistics ();
-	}
+  }
 
 	/* Dump tree statistics.  */
   if (flag_lto_tree_stats)

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

* Re: [GSOC] LTO dump tool project
  2018-07-09  7:51                                                 ` Hrishikesh Kulkarni
@ 2018-07-09  8:34                                                   ` Martin Liška
  2018-07-10 18:40                                                     ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-07-09  8:34 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> The command line option -gimple-stats will dump the statistics of
> gimple statements.
> 
> For example:
> 
> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
> 
> will dump:
> 
> GIMPLE statements
> Kind                   Stmts      Bytes
> ---------------------------------------
> assignments                3        264
> phi nodes                  1        248
> conditionals               1         80
> everything else           12        704
> ---------------------------------------
> Total                     17       1296
> ---------------------------------------
> 
> I have pushed the changes to the repo. Please find the diff file
> attached herewith.
> 
> Regards,
> 
> Hrishikesh

Hi.

Thanks for the work. I briefly took a look at the code and I would
focus now directly on refactoring:

- please make a new branch, first copy lto-dump.c file and all the
Makefile needed stuff and commit that.
- next please rebase (squash) all your patches which you have on top
of it; you did some formatting corrections and it's very hard to read
- please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
the most problematic is usage of horizontal white spaces. We use 2 spaces
for indentation level, and 8 spaces are replaced with a tabular; without that reading your
code is very hard for me
- then please start refactoring functionality that is copied from lto.c and put shared
stuff into a header file that will be used by lto.c and lto-dump.c.

Other observations:
- you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
- come up with more specific name for 'entry' and 'compare'
- 'entry' should have functions that will print names, ... according to options
(flag_lto_dump_demangle, ...); you can have overrides for functions and variables
- I would first put all symbols into the vector and then I would print it on a single place
- consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
- exit after functions like dump_list, dump_symbol,...
- remove dummy 'dump' function

Martin

> 
> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have added new command line option:
>> -objects
>> which will dump size, offset and name of each section for all lto objects
>>
>> for example:
>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>
>> gives output:
>>             LTO object name: test_hello.o
>>
>> NO.        OFFSET        SIZE        SECTION NAME
>>
>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>> 13        2945        76        .gnu.lto_.opts
>>
>>             LTO object name: test.o
>>
>> NO.        OFFSET        SIZE        SECTION NAME
>>
>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>> 12        1999        76        .gnu.lto_.opts
>>
>>
>> I have pushed the changes to the repo. Please find the diff file
>> attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> I have:
>>> tried to do all the formatting and style corrections according to
>>> output given by check_GNU_style.py
>>> removed '-fdump-lto' prefix from the command line options
>>> added few necessary comments in the code
>>> added command line option -type-stats from previous branch (added a
>>> new percentage column to it)
>>> for e.g.
>>>     integer_type    3    25.00%
>>>     pointer_type    3    25.00%
>>>     array_type    1    8.33%
>>>     function_type    5    41.67%
>>> I have pushed the changes  to the repo. Please find the diff file
>>> attached herewith.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>
>>>> I have added command line options:
>>>> -print-size  to print the size of functions and variables
>>>> size of variables is in bits and size of functions is represented as
>>>> number of basic blocks.
>>>>
>>>> -print-value  to print the value of initialization of global variables.
>>>>
>>>> -size-sort  to sort the symbol names according to the size.
>>>>
>>>> for example command line options:
>>>>
>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>> -print-value -size-sort
>>>>
>>>> the dump is:
>>>>
>>>> Symbol Table
>>>>         Name         Type         Visibility        Size     Value
>>>>
>>>>         printf         function        default           0
>>>>         main         function        default           3
>>>>         foo            function        default           3
>>>>         bar            function        default           6
>>>>
>>>>         z               variable        default           8        97
>>>>         k               variable        default          32        5
>>>>         p               variable        default          32
>>>> 4.400000095367431640625e+0
>>>>
>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>> I have pushed the changes to the repo. Please find the diff file
>>>> attached herewith.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>>
>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have added new command line options:
>>>>>> -no-demangle -> for the default non demangled output
>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>> -defined-only -> for only the defined symbols
>>>>>
>>>>> Hi.
>>>>>
>>>>> Good progress.
>>>>>
>>>>>>
>>>>>> for example:
>>>>>>
>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>> -demangle -defined-only -reverse-sort
>>>>>
>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>> from the older options.
>>>>>
>>>>>>
>>>>>> will dump
>>>>>>
>>>>>> Symbol Table
>>>>>>         Name         Type         Visibility         Size
>>>>>>         main        function        default
>>>>>>         k        variable        default
>>>>>>         foo        function        default
>>>>>>         bar        function        default
>>>>>>
>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>> have been defined(hence printf excluded).
>>>>>> Along with this I have also added all previous progress with reference
>>>>>> to symbol table to the new branch.
>>>>>>
>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>> access size of the symbol with symtab node using
>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>> but I am unable to do so.
>>>>>> So how should I proceed with it?
>>>>>
>>>>> Sent advises via instant messaging.
>>>>>
>>>>> Martin
>>>>>
>>>>>>
>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>> changes to the new branch.
>>>>>>
>>>>>> Please advise,
>>>>>>
>>>>>> Hrishikesh>
>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>
>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>> GIMPLE statistics.
>>>>>>>
>>>>>>> for example:
>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>> GIMPLE statements
>>>>>>> Kind                   Stmts      Bytes
>>>>>>> ---------------------------------------
>>>>>>> assignments                0          0
>>>>>>> phi nodes                  0          0
>>>>>>> conditionals               0          0
>>>>>>> everything else            0          0
>>>>>>> ---------------------------------------
>>>>>>> Total                      0          0
>>>>>>> ---------------------------------------
>>>>>>>
>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>
>>>>>>> Tree Statistics
>>>>>>>
>>>>>>> Kind                   Nodes      Bytes
>>>>>>> ----------------------------------------
>>>>>>> decls                   4327     932672
>>>>>>> types                   1531     257208
>>>>>>> blocks                     0          0
>>>>>>> stmts                      0          0
>>>>>>> refs                       0          0
>>>>>>> exprs                      4        128
>>>>>>> constants                 82       2060
>>>>>>> identifiers             4430     177200
>>>>>>> vecs                      16      28544
>>>>>>> binfos                     0          0
>>>>>>> ssa names                  0          0
>>>>>>> constructors               0          0
>>>>>>> random kinds            7301     291952
>>>>>>> lang_decl kinds            0          0
>>>>>>> lang_type kinds            0          0
>>>>>>> omp clauses                0          0
>>>>>>> ----------------------------------------
>>>>>>> Total                  17691    1689764
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Please advise,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>
>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>> statistics.
>>>>>>>>
>>>>>>>> for example:
>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>> GIMPLE statements
>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>> ---------------------------------------
>>>>>>>> assignments                0          0
>>>>>>>> phi nodes                  0          0
>>>>>>>> conditionals               0          0
>>>>>>>> everything else            0          0
>>>>>>>> ---------------------------------------
>>>>>>>> Total                      0          0
>>>>>>>> ---------------------------------------
>>>>>>>>
>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>
>>>>>>>> Tree Statistics
>>>>>>>>
>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>> ----------------------------------------
>>>>>>>> decls                   4327     932672
>>>>>>>> types                   1531     257208
>>>>>>>> blocks                     0          0
>>>>>>>> stmts                      0          0
>>>>>>>> refs                       0          0
>>>>>>>> exprs                      4        128
>>>>>>>> constants                 82       2060
>>>>>>>> identifiers             4430     177200
>>>>>>>> vecs                      16      28544
>>>>>>>> binfos                     0          0
>>>>>>>> ssa names                  0          0
>>>>>>>> constructors               0          0
>>>>>>>> random kinds            7301     291952
>>>>>>>> lang_decl kinds            0          0
>>>>>>>> lang_type kinds            0          0
>>>>>>>> omp clauses                0          0
>>>>>>>> ----------------------------------------
>>>>>>>> Total                  17691    1689764
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Please advise,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>>
>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>
>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>
>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>
>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>
>>>>>>>>>>> file or directory
>>>>>>>>>>>
>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>
>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>
>>>>>>>>>> Martin
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi.
>>>>>>>>>
>>>>>>>>> There's patch that works for me.
>>>>>>>>> Needed dependency is here:
>>>>>>>>>
>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>
>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>
>>>>>>>>> Martin
>>>>>>>>
>>>>>>>>
>>>>>

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

* Re: [GSOC] LTO dump tool project
  2018-07-09  8:34                                                   ` Martin Liška
@ 2018-07-10 18:40                                                     ` Hrishikesh Kulkarni
  2018-07-12 18:06                                                       ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-10 18:40 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

Hi,

Thanks for suggestions. I would start working on these points and will
try to complete as early as possible.

Regards,

Hrishikesh

On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> The command line option -gimple-stats will dump the statistics of
>> gimple statements.
>>
>> For example:
>>
>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>
>> will dump:
>>
>> GIMPLE statements
>> Kind                   Stmts      Bytes
>> ---------------------------------------
>> assignments                3        264
>> phi nodes                  1        248
>> conditionals               1         80
>> everything else           12        704
>> ---------------------------------------
>> Total                     17       1296
>> ---------------------------------------
>>
>> I have pushed the changes to the repo. Please find the diff file
>> attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>
> Hi.
>
> Thanks for the work. I briefly took a look at the code and I would
> focus now directly on refactoring:
>
> - please make a new branch, first copy lto-dump.c file and all the
> Makefile needed stuff and commit that.
> - next please rebase (squash) all your patches which you have on top
> of it; you did some formatting corrections and it's very hard to read
> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
> the most problematic is usage of horizontal white spaces. We use 2 spaces
> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
> code is very hard for me
> - then please start refactoring functionality that is copied from lto.c and put shared
> stuff into a header file that will be used by lto.c and lto-dump.c.
>
> Other observations:
> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
> - come up with more specific name for 'entry' and 'compare'
> - 'entry' should have functions that will print names, ... according to options
> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
> - I would first put all symbols into the vector and then I would print it on a single place
> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
> - exit after functions like dump_list, dump_symbol,...
> - remove dummy 'dump' function
>
> Martin
>
>>
>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> I have added new command line option:
>>> -objects
>>> which will dump size, offset and name of each section for all lto objects
>>>
>>> for example:
>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>
>>> gives output:
>>>             LTO object name: test_hello.o
>>>
>>> NO.        OFFSET        SIZE        SECTION NAME
>>>
>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>> 13        2945        76        .gnu.lto_.opts
>>>
>>>             LTO object name: test.o
>>>
>>> NO.        OFFSET        SIZE        SECTION NAME
>>>
>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>> 12        1999        76        .gnu.lto_.opts
>>>
>>>
>>> I have pushed the changes to the repo. Please find the diff file
>>> attached herewith.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have:
>>>> tried to do all the formatting and style corrections according to
>>>> output given by check_GNU_style.py
>>>> removed '-fdump-lto' prefix from the command line options
>>>> added few necessary comments in the code
>>>> added command line option -type-stats from previous branch (added a
>>>> new percentage column to it)
>>>> for e.g.
>>>>     integer_type    3    25.00%
>>>>     pointer_type    3    25.00%
>>>>     array_type    1    8.33%
>>>>     function_type    5    41.67%
>>>> I have pushed the changes  to the repo. Please find the diff file
>>>> attached herewith.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>
>>>>> I have added command line options:
>>>>> -print-size  to print the size of functions and variables
>>>>> size of variables is in bits and size of functions is represented as
>>>>> number of basic blocks.
>>>>>
>>>>> -print-value  to print the value of initialization of global variables.
>>>>>
>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>
>>>>> for example command line options:
>>>>>
>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>> -print-value -size-sort
>>>>>
>>>>> the dump is:
>>>>>
>>>>> Symbol Table
>>>>>         Name         Type         Visibility        Size     Value
>>>>>
>>>>>         printf         function        default           0
>>>>>         main         function        default           3
>>>>>         foo            function        default           3
>>>>>         bar            function        default           6
>>>>>
>>>>>         z               variable        default           8        97
>>>>>         k               variable        default          32        5
>>>>>         p               variable        default          32
>>>>> 4.400000095367431640625e+0
>>>>>
>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>> attached herewith.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>>
>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have added new command line options:
>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>> -defined-only -> for only the defined symbols
>>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> Good progress.
>>>>>>
>>>>>>>
>>>>>>> for example:
>>>>>>>
>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>
>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>> from the older options.
>>>>>>
>>>>>>>
>>>>>>> will dump
>>>>>>>
>>>>>>> Symbol Table
>>>>>>>         Name         Type         Visibility         Size
>>>>>>>         main        function        default
>>>>>>>         k        variable        default
>>>>>>>         foo        function        default
>>>>>>>         bar        function        default
>>>>>>>
>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>> have been defined(hence printf excluded).
>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>> to symbol table to the new branch.
>>>>>>>
>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>> access size of the symbol with symtab node using
>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>> but I am unable to do so.
>>>>>>> So how should I proceed with it?
>>>>>>
>>>>>> Sent advises via instant messaging.
>>>>>>
>>>>>> Martin
>>>>>>
>>>>>>>
>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>> changes to the new branch.
>>>>>>>
>>>>>>> Please advise,
>>>>>>>
>>>>>>> Hrishikesh>
>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>
>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>> GIMPLE statistics.
>>>>>>>>
>>>>>>>> for example:
>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>> GIMPLE statements
>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>> ---------------------------------------
>>>>>>>> assignments                0          0
>>>>>>>> phi nodes                  0          0
>>>>>>>> conditionals               0          0
>>>>>>>> everything else            0          0
>>>>>>>> ---------------------------------------
>>>>>>>> Total                      0          0
>>>>>>>> ---------------------------------------
>>>>>>>>
>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>
>>>>>>>> Tree Statistics
>>>>>>>>
>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>> ----------------------------------------
>>>>>>>> decls                   4327     932672
>>>>>>>> types                   1531     257208
>>>>>>>> blocks                     0          0
>>>>>>>> stmts                      0          0
>>>>>>>> refs                       0          0
>>>>>>>> exprs                      4        128
>>>>>>>> constants                 82       2060
>>>>>>>> identifiers             4430     177200
>>>>>>>> vecs                      16      28544
>>>>>>>> binfos                     0          0
>>>>>>>> ssa names                  0          0
>>>>>>>> constructors               0          0
>>>>>>>> random kinds            7301     291952
>>>>>>>> lang_decl kinds            0          0
>>>>>>>> lang_type kinds            0          0
>>>>>>>> omp clauses                0          0
>>>>>>>> ----------------------------------------
>>>>>>>> Total                  17691    1689764
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Please advise,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>
>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>> statistics.
>>>>>>>>>
>>>>>>>>> for example:
>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>> GIMPLE statements
>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>> ---------------------------------------
>>>>>>>>> assignments                0          0
>>>>>>>>> phi nodes                  0          0
>>>>>>>>> conditionals               0          0
>>>>>>>>> everything else            0          0
>>>>>>>>> ---------------------------------------
>>>>>>>>> Total                      0          0
>>>>>>>>> ---------------------------------------
>>>>>>>>>
>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>
>>>>>>>>> Tree Statistics
>>>>>>>>>
>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>> ----------------------------------------
>>>>>>>>> decls                   4327     932672
>>>>>>>>> types                   1531     257208
>>>>>>>>> blocks                     0          0
>>>>>>>>> stmts                      0          0
>>>>>>>>> refs                       0          0
>>>>>>>>> exprs                      4        128
>>>>>>>>> constants                 82       2060
>>>>>>>>> identifiers             4430     177200
>>>>>>>>> vecs                      16      28544
>>>>>>>>> binfos                     0          0
>>>>>>>>> ssa names                  0          0
>>>>>>>>> constructors               0          0
>>>>>>>>> random kinds            7301     291952
>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>> lang_type kinds            0          0
>>>>>>>>> omp clauses                0          0
>>>>>>>>> ----------------------------------------
>>>>>>>>> Total                  17691    1689764
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Please advise,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>
>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>
>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>
>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>
>>>>>>>>>>>> file or directory
>>>>>>>>>>>>
>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>
>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>
>>>>>>>>>>> Martin
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hi.
>>>>>>>>>>
>>>>>>>>>> There's patch that works for me.
>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>
>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>
>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>
>>>>>>>>>> Martin
>>>>>>>>>
>>>>>>>>>
>>>>>>
>

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

* Re: [GSOC] LTO dump tool project
  2018-07-10 18:40                                                     ` Hrishikesh Kulkarni
@ 2018-07-12 18:06                                                       ` Hrishikesh Kulkarni
  2018-07-13  9:17                                                         ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-12 18:06 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added command line options:

-body=
To dump gimple body (TDF_NONE) of specific function.

-optimized-blocks=
To dump gimple body (TDF_BLOCKS) of specific function.

-optimized-stats=
To dump gimple body (TDF_STATS) of specific function.

-optimized-vops=
To dump gimple body (TDF_VOPS) of specific function.

for example:

-body=foo  will dump

Gimple body of function: foo
foo (int a, int b)
{
  <bb 2> [local count: 1073741825]:
  _3 = a_1(D) + b_2(D);
  return _3;

}


-optimized-blocks=foo  will dump

Gimple body of function: foo
foo (int a, int b)
{
;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  _3 = a_1(D) + b_2(D);
  return _3;
;;    succ:       EXIT

}


-optimized-stats=foo  will dump

Gimple body of function: foo
foo (int a, int b)
{
  <bb 2> [local count: 1073741825]:
  _3 = a_1(D) + b_2(D);
  return _3;

}


-optimized-vops=foo  will dump

Gimple body of function: foo
foo (int a, int b)
{
  <bb 2> [local count: 1073741825]:
  _3 = a_1(D) + b_2(D);
  # VUSE <.MEM_4(D)>
  return _3;

}

I have pushed the changes to the current branch. Please find the diff
file attached herewith.

I have tried to follow the coding conventions as far as possible in
this patch. Please let me know if I am missing out something so that I
can improve the same while refactoring and clean up as suggested in
the previous mail.

Regards,

Hrishikesh

On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> Thanks for suggestions. I would start working on these points and will
> try to complete as early as possible.
>
> Regards,
>
> Hrishikesh
>
> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> The command line option -gimple-stats will dump the statistics of
>>> gimple statements.
>>>
>>> For example:
>>>
>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>
>>> will dump:
>>>
>>> GIMPLE statements
>>> Kind                   Stmts      Bytes
>>> ---------------------------------------
>>> assignments                3        264
>>> phi nodes                  1        248
>>> conditionals               1         80
>>> everything else           12        704
>>> ---------------------------------------
>>> Total                     17       1296
>>> ---------------------------------------
>>>
>>> I have pushed the changes to the repo. Please find the diff file
>>> attached herewith.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>
>> Hi.
>>
>> Thanks for the work. I briefly took a look at the code and I would
>> focus now directly on refactoring:
>>
>> - please make a new branch, first copy lto-dump.c file and all the
>> Makefile needed stuff and commit that.
>> - next please rebase (squash) all your patches which you have on top
>> of it; you did some formatting corrections and it's very hard to read
>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>> code is very hard for me
>> - then please start refactoring functionality that is copied from lto.c and put shared
>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>
>> Other observations:
>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>> - come up with more specific name for 'entry' and 'compare'
>> - 'entry' should have functions that will print names, ... according to options
>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>> - I would first put all symbols into the vector and then I would print it on a single place
>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>> - exit after functions like dump_list, dump_symbol,...
>> - remove dummy 'dump' function
>>
>> Martin
>>
>>>
>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have added new command line option:
>>>> -objects
>>>> which will dump size, offset and name of each section for all lto objects
>>>>
>>>> for example:
>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>
>>>> gives output:
>>>>             LTO object name: test_hello.o
>>>>
>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>
>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>> 13        2945        76        .gnu.lto_.opts
>>>>
>>>>             LTO object name: test.o
>>>>
>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>
>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>> 12        1999        76        .gnu.lto_.opts
>>>>
>>>>
>>>> I have pushed the changes to the repo. Please find the diff file
>>>> attached herewith.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I have:
>>>>> tried to do all the formatting and style corrections according to
>>>>> output given by check_GNU_style.py
>>>>> removed '-fdump-lto' prefix from the command line options
>>>>> added few necessary comments in the code
>>>>> added command line option -type-stats from previous branch (added a
>>>>> new percentage column to it)
>>>>> for e.g.
>>>>>     integer_type    3    25.00%
>>>>>     pointer_type    3    25.00%
>>>>>     array_type    1    8.33%
>>>>>     function_type    5    41.67%
>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>> attached herewith.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>
>>>>>> I have added command line options:
>>>>>> -print-size  to print the size of functions and variables
>>>>>> size of variables is in bits and size of functions is represented as
>>>>>> number of basic blocks.
>>>>>>
>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>
>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>
>>>>>> for example command line options:
>>>>>>
>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>> -print-value -size-sort
>>>>>>
>>>>>> the dump is:
>>>>>>
>>>>>> Symbol Table
>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>
>>>>>>         printf         function        default           0
>>>>>>         main         function        default           3
>>>>>>         foo            function        default           3
>>>>>>         bar            function        default           6
>>>>>>
>>>>>>         z               variable        default           8        97
>>>>>>         k               variable        default          32        5
>>>>>>         p               variable        default          32
>>>>>> 4.400000095367431640625e+0
>>>>>>
>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>> attached herewith.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>>
>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have added new command line options:
>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>
>>>>>>> Hi.
>>>>>>>
>>>>>>> Good progress.
>>>>>>>
>>>>>>>>
>>>>>>>> for example:
>>>>>>>>
>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>
>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>> from the older options.
>>>>>>>
>>>>>>>>
>>>>>>>> will dump
>>>>>>>>
>>>>>>>> Symbol Table
>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>         main        function        default
>>>>>>>>         k        variable        default
>>>>>>>>         foo        function        default
>>>>>>>>         bar        function        default
>>>>>>>>
>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>> have been defined(hence printf excluded).
>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>> to symbol table to the new branch.
>>>>>>>>
>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>> access size of the symbol with symtab node using
>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>> but I am unable to do so.
>>>>>>>> So how should I proceed with it?
>>>>>>>
>>>>>>> Sent advises via instant messaging.
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>>>
>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>> changes to the new branch.
>>>>>>>>
>>>>>>>> Please advise,
>>>>>>>>
>>>>>>>> Hrishikesh>
>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>
>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>> GIMPLE statistics.
>>>>>>>>>
>>>>>>>>> for example:
>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>> GIMPLE statements
>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>> ---------------------------------------
>>>>>>>>> assignments                0          0
>>>>>>>>> phi nodes                  0          0
>>>>>>>>> conditionals               0          0
>>>>>>>>> everything else            0          0
>>>>>>>>> ---------------------------------------
>>>>>>>>> Total                      0          0
>>>>>>>>> ---------------------------------------
>>>>>>>>>
>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>
>>>>>>>>> Tree Statistics
>>>>>>>>>
>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>> ----------------------------------------
>>>>>>>>> decls                   4327     932672
>>>>>>>>> types                   1531     257208
>>>>>>>>> blocks                     0          0
>>>>>>>>> stmts                      0          0
>>>>>>>>> refs                       0          0
>>>>>>>>> exprs                      4        128
>>>>>>>>> constants                 82       2060
>>>>>>>>> identifiers             4430     177200
>>>>>>>>> vecs                      16      28544
>>>>>>>>> binfos                     0          0
>>>>>>>>> ssa names                  0          0
>>>>>>>>> constructors               0          0
>>>>>>>>> random kinds            7301     291952
>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>> lang_type kinds            0          0
>>>>>>>>> omp clauses                0          0
>>>>>>>>> ----------------------------------------
>>>>>>>>> Total                  17691    1689764
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Please advise,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>
>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>> statistics.
>>>>>>>>>>
>>>>>>>>>> for example:
>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>> GIMPLE statements
>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> assignments                0          0
>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>> conditionals               0          0
>>>>>>>>>> everything else            0          0
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> Total                      0          0
>>>>>>>>>> ---------------------------------------
>>>>>>>>>>
>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>
>>>>>>>>>> Tree Statistics
>>>>>>>>>>
>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>> ----------------------------------------
>>>>>>>>>> decls                   4327     932672
>>>>>>>>>> types                   1531     257208
>>>>>>>>>> blocks                     0          0
>>>>>>>>>> stmts                      0          0
>>>>>>>>>> refs                       0          0
>>>>>>>>>> exprs                      4        128
>>>>>>>>>> constants                 82       2060
>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>> vecs                      16      28544
>>>>>>>>>> binfos                     0          0
>>>>>>>>>> ssa names                  0          0
>>>>>>>>>> constructors               0          0
>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>> omp clauses                0          0
>>>>>>>>>> ----------------------------------------
>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Please advise,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>
>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>
>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>
>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>
>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>
>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>
>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>
>>>>>>>>>>>> Martin
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Hi.
>>>>>>>>>>>
>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>
>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>
>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>
>>>>>>>>>>> Martin
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>
>>

[-- Attachment #2: gimple-body-variations.diff --]
[-- Type: text/x-patch, Size: 3035 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 9e7d1fc..7c671c0 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -117,6 +117,15 @@ Dump the details of LTO objects.
 body=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
 
+optimized-blocks=
+LTO Driver RejectNegative Joined Var(flag_tree_optimized_blocks)
+
+optimized-stats=
+LTO Driver RejectNegative Joined Var(flag_tree_optimized_stats)
+
+optimized-vops=
+LTO Driver RejectNegative Joined Var(flag_tree_optimized_vops)
+
 type-stats
 LTO Var(flag_lto_dump_type_stats)
 Dump the statistics of tree types.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 40fdbbe..623c825 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -215,6 +215,66 @@ dump_symbol ()
 	  fprintf (stderr, "\n");
 }
 
+/* Dump gimple body (TDF_NONE) of specific function.  */
+void
+dump_body_none ()
+{
+	fprintf (stderr, "Gimple body of function: %s\n",
+	    flag_lto_dump_body);
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_lto_dump_body))
+		{
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, 0);
+		}
+}
+
+/* Dump gimple body (TDF_BLOCKS) of specific function.  */
+void
+dump_body_blocks ()
+{
+	fprintf (stderr, "Gimple body of function: %s\n",
+	    flag_tree_optimized_blocks);
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_tree_optimized_blocks))
+		{
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, TDF_BLOCKS);
+		}
+}
+
+/* Dump gimple body (TDF_STATS) of specific function.  */
+void
+dump_body_stats ()
+{
+	fprintf (stderr, "Gimple body of function: %s\n",
+	    flag_tree_optimized_stats);
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_tree_optimized_stats))
+		{
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, TDF_STATS);
+		}
+}
+
+/* Dump gimple body (TDF_VOPS) of specific function.  */
+void
+dump_body_vops ()
+{
+	fprintf (stderr, "Gimple body of function: %s\n",
+		  flag_tree_optimized_vops);
+	cgraph_node *cnode;
+	FOR_EACH_FUNCTION (cnode)
+		if (!strcmp (cnode->name (), flag_tree_optimized_vops))
+		{
+			cnode->get_untransformed_body ();
+			debug_function (cnode->decl, TDF_VOPS);
+		}
+}
+
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
 
@@ -3580,6 +3640,22 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
+  /* Dump gimple body (TDF_NONE) of specific function.  */
+  if (flag_lto_dump_body)
+    dump_body_none ();
+
+  /* Dump gimple body (TDF_BLOCKS) of specific function.  */
+  if (flag_tree_optimized_blocks)
+    dump_body_blocks ();
+
+  /* Dump gimple body (TDF_STATS) of specific function.  */
+  if (flag_tree_optimized_stats)
+    dump_body_stats ();
+
+  /* Dump gimple body (TDF_VOPS) of specific function.  */
+  if (flag_tree_optimized_vops)
+    dump_body_vops ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())

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

* Re: [GSOC] LTO dump tool project
  2018-07-12 18:06                                                       ` Hrishikesh Kulkarni
@ 2018-07-13  9:17                                                         ` Martin Liška
  2018-07-16 15:44                                                           ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-07-13  9:17 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> I have added command line options:
> 
> -body=
> To dump gimple body (TDF_NONE) of specific function.
> 
> -optimized-blocks=
> To dump gimple body (TDF_BLOCKS) of specific function.
> 
> -optimized-stats=
> To dump gimple body (TDF_STATS) of specific function.
> 
> -optimized-vops=
> To dump gimple body (TDF_VOPS) of specific function.

Hi.

Thanks for it. However I would expect something more smart:
-optimized=[vops,stats,block]. Note that you should do similar
what's done in: gcc/dumpfile.c

int
gcc::dump_manager::
dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)

that will automatically parse   dump_flags_t flags;

Then the copy&parse will not be needed.

> 
> for example:
> 
> -body=foo  will dump
> 
> Gimple body of function: foo
> foo (int a, int b)
> {
>   <bb 2> [local count: 1073741825]:
>   _3 = a_1(D) + b_2(D);
>   return _3;
> 
> }
> 
> 
> -optimized-blocks=foo  will dump
> 
> Gimple body of function: foo
> foo (int a, int b)
> {
> ;;   basic block 2, loop depth 0
> ;;    pred:       ENTRY
>   _3 = a_1(D) + b_2(D);
>   return _3;
> ;;    succ:       EXIT
> 
> }
> 
> 
> -optimized-stats=foo  will dump
> 
> Gimple body of function: foo
> foo (int a, int b)
> {
>   <bb 2> [local count: 1073741825]:
>   _3 = a_1(D) + b_2(D);
>   return _3;
> 
> }
> 
> 
> -optimized-vops=foo  will dump
> 
> Gimple body of function: foo
> foo (int a, int b)
> {
>   <bb 2> [local count: 1073741825]:
>   _3 = a_1(D) + b_2(D);
>   # VUSE <.MEM_4(D)>
>   return _3;
> 
> }
> 
> I have pushed the changes to the current branch. Please find the diff
> file attached herewith.
> 
> I have tried to follow the coding conventions as far as possible in
> this patch. Please let me know if I am missing out something so that I
> can improve the same while refactoring and clean up as suggested in
> the previous mail.

As mentioned in the previous email, indentation level is 2. And every 8 spaces
are replaced with a tabular. In our patch, you use indentation level equal to
one tab, which results in indentation level 8.

Martin

> 
> Regards,
> 
> Hrishikesh
> 
> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> Thanks for suggestions. I would start working on these points and will
>> try to complete as early as possible.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>> Hi,
>>>>
>>>> The command line option -gimple-stats will dump the statistics of
>>>> gimple statements.
>>>>
>>>> For example:
>>>>
>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>
>>>> will dump:
>>>>
>>>> GIMPLE statements
>>>> Kind                   Stmts      Bytes
>>>> ---------------------------------------
>>>> assignments                3        264
>>>> phi nodes                  1        248
>>>> conditionals               1         80
>>>> everything else           12        704
>>>> ---------------------------------------
>>>> Total                     17       1296
>>>> ---------------------------------------
>>>>
>>>> I have pushed the changes to the repo. Please find the diff file
>>>> attached herewith.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>
>>> Hi.
>>>
>>> Thanks for the work. I briefly took a look at the code and I would
>>> focus now directly on refactoring:
>>>
>>> - please make a new branch, first copy lto-dump.c file and all the
>>> Makefile needed stuff and commit that.
>>> - next please rebase (squash) all your patches which you have on top
>>> of it; you did some formatting corrections and it's very hard to read
>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>> code is very hard for me
>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>
>>> Other observations:
>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>> - come up with more specific name for 'entry' and 'compare'
>>> - 'entry' should have functions that will print names, ... according to options
>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>> - I would first put all symbols into the vector and then I would print it on a single place
>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>> - exit after functions like dump_list, dump_symbol,...
>>> - remove dummy 'dump' function
>>>
>>> Martin
>>>
>>>>
>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I have added new command line option:
>>>>> -objects
>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>
>>>>> for example:
>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>
>>>>> gives output:
>>>>>             LTO object name: test_hello.o
>>>>>
>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>
>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>
>>>>>             LTO object name: test.o
>>>>>
>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>
>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>
>>>>>
>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>> attached herewith.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have:
>>>>>> tried to do all the formatting and style corrections according to
>>>>>> output given by check_GNU_style.py
>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>> added few necessary comments in the code
>>>>>> added command line option -type-stats from previous branch (added a
>>>>>> new percentage column to it)
>>>>>> for e.g.
>>>>>>     integer_type    3    25.00%
>>>>>>     pointer_type    3    25.00%
>>>>>>     array_type    1    8.33%
>>>>>>     function_type    5    41.67%
>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>> attached herewith.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>
>>>>>>> I have added command line options:
>>>>>>> -print-size  to print the size of functions and variables
>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>> number of basic blocks.
>>>>>>>
>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>
>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>
>>>>>>> for example command line options:
>>>>>>>
>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>> -print-value -size-sort
>>>>>>>
>>>>>>> the dump is:
>>>>>>>
>>>>>>> Symbol Table
>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>
>>>>>>>         printf         function        default           0
>>>>>>>         main         function        default           3
>>>>>>>         foo            function        default           3
>>>>>>>         bar            function        default           6
>>>>>>>
>>>>>>>         z               variable        default           8        97
>>>>>>>         k               variable        default          32        5
>>>>>>>         p               variable        default          32
>>>>>>> 4.400000095367431640625e+0
>>>>>>>
>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>> attached herewith.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have added new command line options:
>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>
>>>>>>>> Hi.
>>>>>>>>
>>>>>>>> Good progress.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> for example:
>>>>>>>>>
>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>
>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>> from the older options.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> will dump
>>>>>>>>>
>>>>>>>>> Symbol Table
>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>         main        function        default
>>>>>>>>>         k        variable        default
>>>>>>>>>         foo        function        default
>>>>>>>>>         bar        function        default
>>>>>>>>>
>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>
>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>> but I am unable to do so.
>>>>>>>>> So how should I proceed with it?
>>>>>>>>
>>>>>>>> Sent advises via instant messaging.
>>>>>>>>
>>>>>>>> Martin
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>> changes to the new branch.
>>>>>>>>>
>>>>>>>>> Please advise,
>>>>>>>>>
>>>>>>>>> Hrishikesh>
>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>
>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>
>>>>>>>>>> for example:
>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>> GIMPLE statements
>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> assignments                0          0
>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>> conditionals               0          0
>>>>>>>>>> everything else            0          0
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> Total                      0          0
>>>>>>>>>> ---------------------------------------
>>>>>>>>>>
>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>
>>>>>>>>>> Tree Statistics
>>>>>>>>>>
>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>> ----------------------------------------
>>>>>>>>>> decls                   4327     932672
>>>>>>>>>> types                   1531     257208
>>>>>>>>>> blocks                     0          0
>>>>>>>>>> stmts                      0          0
>>>>>>>>>> refs                       0          0
>>>>>>>>>> exprs                      4        128
>>>>>>>>>> constants                 82       2060
>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>> vecs                      16      28544
>>>>>>>>>> binfos                     0          0
>>>>>>>>>> ssa names                  0          0
>>>>>>>>>> constructors               0          0
>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>> omp clauses                0          0
>>>>>>>>>> ----------------------------------------
>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Please advise,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>
>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>> statistics.
>>>>>>>>>>>
>>>>>>>>>>> for example:
>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> assignments                0          0
>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>> everything else            0          0
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> Total                      0          0
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>
>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>
>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>
>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>> refs                       0          0
>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>> constructors               0          0
>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Please advise,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>
>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>
>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Hi.
>>>>>>>>>>>>
>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>
>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>
>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>
>>>>>>>>>>>> Martin
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>
>>>

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

* Re: [GSOC] LTO dump tool project
  2018-07-13  9:17                                                         ` Martin Liška
@ 2018-07-16 15:44                                                           ` Hrishikesh Kulkarni
  2018-07-17 13:00                                                             ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-16 15:44 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

As suggested I have created command line option -optimized=[none,
blocks, stats, vops] to dump the respective gimple bodies of all
functions.

for example:

-optimized=blocks will dump

Gimple body of function: main
main ()
{
;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  printf ("%d", 8);
  return 0;
;;    succ:       EXIT

}


Gimple body of function: bar
bar (int a, int b, int cond)
{
  int ret;

;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  if (cond_2(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]
;;    succ:       3
;;                4

;;   basic block 3, loop depth 0
;;    pred:       2
  ret_5 = a_3(D) + b_4(D);
  goto <bb 5>; [100.00%]
;;    succ:       5

;;   basic block 4, loop depth 0
;;    pred:       2
  ret_6 = a_3(D) - b_4(D);
;;    succ:       5

;;   basic block 5, loop depth 0
;;    pred:       3
;;                4
  # ret_1 = PHI <ret_5(3), ret_6(4)>
  return ret_1;
;;    succ:       EXIT

}


Gimple body of function: foo
foo (int a, int b)
{
;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  _3 = a_1(D) + b_2(D);
  return _3;
;;    succ:       EXIT

}

I have pushed the changes to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh

On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> I have added command line options:
>>
>> -body=
>> To dump gimple body (TDF_NONE) of specific function.
>>
>> -optimized-blocks=
>> To dump gimple body (TDF_BLOCKS) of specific function.
>>
>> -optimized-stats=
>> To dump gimple body (TDF_STATS) of specific function.
>>
>> -optimized-vops=
>> To dump gimple body (TDF_VOPS) of specific function.
>
> Hi.
>
> Thanks for it. However I would expect something more smart:
> -optimized=[vops,stats,block]. Note that you should do similar
> what's done in: gcc/dumpfile.c
>
> int
> gcc::dump_manager::
> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>
> that will automatically parse   dump_flags_t flags;
>
> Then the copy&parse will not be needed.
>
>>
>> for example:
>>
>> -body=foo  will dump
>>
>> Gimple body of function: foo
>> foo (int a, int b)
>> {
>>   <bb 2> [local count: 1073741825]:
>>   _3 = a_1(D) + b_2(D);
>>   return _3;
>>
>> }
>>
>>
>> -optimized-blocks=foo  will dump
>>
>> Gimple body of function: foo
>> foo (int a, int b)
>> {
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>   _3 = a_1(D) + b_2(D);
>>   return _3;
>> ;;    succ:       EXIT
>>
>> }
>>
>>
>> -optimized-stats=foo  will dump
>>
>> Gimple body of function: foo
>> foo (int a, int b)
>> {
>>   <bb 2> [local count: 1073741825]:
>>   _3 = a_1(D) + b_2(D);
>>   return _3;
>>
>> }
>>
>>
>> -optimized-vops=foo  will dump
>>
>> Gimple body of function: foo
>> foo (int a, int b)
>> {
>>   <bb 2> [local count: 1073741825]:
>>   _3 = a_1(D) + b_2(D);
>>   # VUSE <.MEM_4(D)>
>>   return _3;
>>
>> }
>>
>> I have pushed the changes to the current branch. Please find the diff
>> file attached herewith.
>>
>> I have tried to follow the coding conventions as far as possible in
>> this patch. Please let me know if I am missing out something so that I
>> can improve the same while refactoring and clean up as suggested in
>> the previous mail.
>
> As mentioned in the previous email, indentation level is 2. And every 8 spaces
> are replaced with a tabular. In our patch, you use indentation level equal to
> one tab, which results in indentation level 8.
>
> Martin
>
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> Thanks for suggestions. I would start working on these points and will
>>> try to complete as early as possible.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>> Hi,
>>>>>
>>>>> The command line option -gimple-stats will dump the statistics of
>>>>> gimple statements.
>>>>>
>>>>> For example:
>>>>>
>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>
>>>>> will dump:
>>>>>
>>>>> GIMPLE statements
>>>>> Kind                   Stmts      Bytes
>>>>> ---------------------------------------
>>>>> assignments                3        264
>>>>> phi nodes                  1        248
>>>>> conditionals               1         80
>>>>> everything else           12        704
>>>>> ---------------------------------------
>>>>> Total                     17       1296
>>>>> ---------------------------------------
>>>>>
>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>> attached herewith.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>
>>>> Hi.
>>>>
>>>> Thanks for the work. I briefly took a look at the code and I would
>>>> focus now directly on refactoring:
>>>>
>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>> Makefile needed stuff and commit that.
>>>> - next please rebase (squash) all your patches which you have on top
>>>> of it; you did some formatting corrections and it's very hard to read
>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>> code is very hard for me
>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>
>>>> Other observations:
>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>> - come up with more specific name for 'entry' and 'compare'
>>>> - 'entry' should have functions that will print names, ... according to options
>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>> - exit after functions like dump_list, dump_symbol,...
>>>> - remove dummy 'dump' function
>>>>
>>>> Martin
>>>>
>>>>>
>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have added new command line option:
>>>>>> -objects
>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>
>>>>>> for example:
>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>
>>>>>> gives output:
>>>>>>             LTO object name: test_hello.o
>>>>>>
>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>
>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>
>>>>>>             LTO object name: test.o
>>>>>>
>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>
>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>
>>>>>>
>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>> attached herewith.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have:
>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>> output given by check_GNU_style.py
>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>> added few necessary comments in the code
>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>> new percentage column to it)
>>>>>>> for e.g.
>>>>>>>     integer_type    3    25.00%
>>>>>>>     pointer_type    3    25.00%
>>>>>>>     array_type    1    8.33%
>>>>>>>     function_type    5    41.67%
>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>> attached herewith.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>
>>>>>>>> I have added command line options:
>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>> number of basic blocks.
>>>>>>>>
>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>
>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>
>>>>>>>> for example command line options:
>>>>>>>>
>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>> -print-value -size-sort
>>>>>>>>
>>>>>>>> the dump is:
>>>>>>>>
>>>>>>>> Symbol Table
>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>
>>>>>>>>         printf         function        default           0
>>>>>>>>         main         function        default           3
>>>>>>>>         foo            function        default           3
>>>>>>>>         bar            function        default           6
>>>>>>>>
>>>>>>>>         z               variable        default           8        97
>>>>>>>>         k               variable        default          32        5
>>>>>>>>         p               variable        default          32
>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>
>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>> attached herewith.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>>
>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have added new command line options:
>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>
>>>>>>>>> Hi.
>>>>>>>>>
>>>>>>>>> Good progress.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> for example:
>>>>>>>>>>
>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>
>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>> from the older options.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> will dump
>>>>>>>>>>
>>>>>>>>>> Symbol Table
>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>         main        function        default
>>>>>>>>>>         k        variable        default
>>>>>>>>>>         foo        function        default
>>>>>>>>>>         bar        function        default
>>>>>>>>>>
>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>
>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>> but I am unable to do so.
>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>
>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>
>>>>>>>>> Martin
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>> changes to the new branch.
>>>>>>>>>>
>>>>>>>>>> Please advise,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh>
>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>
>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>
>>>>>>>>>>> for example:
>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> assignments                0          0
>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>> everything else            0          0
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> Total                      0          0
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>
>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>
>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>
>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>> refs                       0          0
>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>> constructors               0          0
>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Please advise,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>
>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>> statistics.
>>>>>>>>>>>>
>>>>>>>>>>>> for example:
>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>
>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>
>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>
>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>
>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>
>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Martin
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>
>>>>
>

[-- Attachment #2: variations_of_gimple_body.diff --]
[-- Type: text/x-patch, Size: 3795 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 7c671c0..26770d5 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -114,17 +114,8 @@ objects
 LTO Var(flag_lto_dump_objects)
 Dump the details of LTO objects.
 
-body=
-LTO Driver RejectNegative Joined Var(flag_lto_dump_body)
-
-optimized-blocks=
-LTO Driver RejectNegative Joined Var(flag_tree_optimized_blocks)
-
-optimized-stats=
-LTO Driver RejectNegative Joined Var(flag_tree_optimized_stats)
-
-optimized-vops=
-LTO Driver RejectNegative Joined Var(flag_tree_optimized_vops)
+optimized=
+LTO Driver RejectNegative Joined Var(flag_optimized)
 
 type-stats
 LTO Var(flag_lto_dump_type_stats)
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 623c825..1c83ab5 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -215,64 +215,29 @@ dump_symbol ()
 	  fprintf (stderr, "\n");
 }
 
-/* Dump gimple body (TDF_NONE) of specific function.  */
+/* Dump specific gimple bodies of all functions.  */
 void
-dump_body_none ()
-{
-	fprintf (stderr, "Gimple body of function: %s\n",
-	    flag_lto_dump_body);
-	cgraph_node *cnode;
-	FOR_EACH_FUNCTION (cnode)
-		if (!strcmp (cnode->name (), flag_lto_dump_body))
-		{
-			cnode->get_untransformed_body ();
-			debug_function (cnode->decl, 0);
-		}
-}
-
-/* Dump gimple body (TDF_BLOCKS) of specific function.  */
-void
-dump_body_blocks ()
-{
-	fprintf (stderr, "Gimple body of function: %s\n",
-	    flag_tree_optimized_blocks);
-	cgraph_node *cnode;
-	FOR_EACH_FUNCTION (cnode)
-		if (!strcmp (cnode->name (), flag_tree_optimized_blocks))
-		{
-			cnode->get_untransformed_body ();
-			debug_function (cnode->decl, TDF_BLOCKS);
-		}
-}
-
-/* Dump gimple body (TDF_STATS) of specific function.  */
-void
-dump_body_stats ()
-{
-	fprintf (stderr, "Gimple body of function: %s\n",
-	    flag_tree_optimized_stats);
-	cgraph_node *cnode;
-	FOR_EACH_FUNCTION (cnode)
-		if (!strcmp (cnode->name (), flag_tree_optimized_stats))
-		{
-			cnode->get_untransformed_body ();
-			debug_function (cnode->decl, TDF_STATS);
-		}
-}
-
-/* Dump gimple body (TDF_VOPS) of specific function.  */
-void
-dump_body_vops ()
-{
-	fprintf (stderr, "Gimple body of function: %s\n",
-		  flag_tree_optimized_vops);
-	cgraph_node *cnode;
-	FOR_EACH_FUNCTION (cnode)
-		if (!strcmp (cnode->name (), flag_tree_optimized_vops))
-		{
-			cnode->get_untransformed_body ();
-			debug_function (cnode->decl, TDF_VOPS);
-		}
+dump_body ()
+{
+  dump_flags_t flags = TDF_NONE;
+  if (!strcmp (flag_optimized, "blocks"))
+    flags = TDF_BLOCKS;
+  else if (!strcmp (flag_optimized, "stats"))
+    flags = TDF_STATS;
+  else if (!strcmp (flag_optimized, "vops"))
+    flags = TDF_VOPS;
+  else if (!strcmp (flag_optimized, "none"))
+    flags = TDF_NONE;
+  cgraph_node *cnode;
+  FOR_EACH_FUNCTION (cnode)
+  {
+    if (cnode->definition)
+    {
+      fprintf (stderr, "Gimple body of function: %s\n", cnode->name ());
+      cnode->get_untransformed_body ();
+      debug_function (cnode->decl, flags);
+    }
+  }
 }
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
@@ -3640,21 +3605,9 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
-  /* Dump gimple body (TDF_NONE) of specific function.  */
-  if (flag_lto_dump_body)
-    dump_body_none ();
-
-  /* Dump gimple body (TDF_BLOCKS) of specific function.  */
-  if (flag_tree_optimized_blocks)
-    dump_body_blocks ();
-
-  /* Dump gimple body (TDF_STATS) of specific function.  */
-  if (flag_tree_optimized_stats)
-    dump_body_stats ();
-
-  /* Dump gimple body (TDF_VOPS) of specific function.  */
-  if (flag_tree_optimized_vops)
-    dump_body_vops ();
+  /* Dump specfic gimple body of all functions.  */
+  if (flag_optimized)
+    dump_body ();
 
   timevar_stop (TV_PHASE_STREAM_IN);
 

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

* Re: [GSOC] LTO dump tool project
  2018-07-16 15:44                                                           ` Hrishikesh Kulkarni
@ 2018-07-17 13:00                                                             ` Martin Liška
  2018-07-18 18:04                                                               ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-07-17 13:00 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Martin Jambor, Richard Biener

On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> As suggested I have created command line option -optimized=[none,
> blocks, stats, vops] to dump the respective gimple bodies of all
> functions.
> 
> for example:
> 
> -optimized=blocks will dump


Hi.

The name does not make much sense and you removed option that
limited function name. So instead I would create something like:

-fdump-body=foo
and
-fdump-level=optimized

I don't like how you do manual parsing in:
+  if (!strcmp (flag_optimized, "blocks"))
+    flags = TDF_BLOCKS;
+  else if (!strcmp (flag_optimized, "stats"))
+    flags = TDF_STATS;
+  else if (!strcmp (flag_optimized, "vops"))
+    flags = TDF_VOPS;
+  else if (!strcmp (flag_optimized, "none"))
+    flags = TDF_NONE;

As I wrote in previous email, take a look how it's done
in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
and reuse that functionality.

Martin

> 
> Gimple body of function: main
> main ()
> {
> ;;   basic block 2, loop depth 0
> ;;    pred:       ENTRY
>   printf ("%d", 8);
>   return 0;
> ;;    succ:       EXIT
> 
> }
> 
> 
> Gimple body of function: bar
> bar (int a, int b, int cond)
> {
>   int ret;
> 
> ;;   basic block 2, loop depth 0
> ;;    pred:       ENTRY
>   if (cond_2(D) != 0)
>     goto <bb 3>; [50.00%]
>   else
>     goto <bb 4>; [50.00%]
> ;;    succ:       3
> ;;                4
> 
> ;;   basic block 3, loop depth 0
> ;;    pred:       2
>   ret_5 = a_3(D) + b_4(D);
>   goto <bb 5>; [100.00%]
> ;;    succ:       5
> 
> ;;   basic block 4, loop depth 0
> ;;    pred:       2
>   ret_6 = a_3(D) - b_4(D);
> ;;    succ:       5
> 
> ;;   basic block 5, loop depth 0
> ;;    pred:       3
> ;;                4
>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>   return ret_1;
> ;;    succ:       EXIT
> 
> }
> 
> 
> Gimple body of function: foo
> foo (int a, int b)
> {
> ;;   basic block 2, loop depth 0
> ;;    pred:       ENTRY
>   _3 = a_1(D) + b_2(D);
>   return _3;
> ;;    succ:       EXIT
> 
> }
> 
> I have pushed the changes to the repo. Please find the diff file
> attached herewith.
> 
> Regards,
> 
> Hrishikesh
> 
> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> I have added command line options:
>>>
>>> -body=
>>> To dump gimple body (TDF_NONE) of specific function.
>>>
>>> -optimized-blocks=
>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>
>>> -optimized-stats=
>>> To dump gimple body (TDF_STATS) of specific function.
>>>
>>> -optimized-vops=
>>> To dump gimple body (TDF_VOPS) of specific function.
>>
>> Hi.
>>
>> Thanks for it. However I would expect something more smart:
>> -optimized=[vops,stats,block]. Note that you should do similar
>> what's done in: gcc/dumpfile.c
>>
>> int
>> gcc::dump_manager::
>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>
>> that will automatically parse   dump_flags_t flags;
>>
>> Then the copy&parse will not be needed.
>>
>>>
>>> for example:
>>>
>>> -body=foo  will dump
>>>
>>> Gimple body of function: foo
>>> foo (int a, int b)
>>> {
>>>   <bb 2> [local count: 1073741825]:
>>>   _3 = a_1(D) + b_2(D);
>>>   return _3;
>>>
>>> }
>>>
>>>
>>> -optimized-blocks=foo  will dump
>>>
>>> Gimple body of function: foo
>>> foo (int a, int b)
>>> {
>>> ;;   basic block 2, loop depth 0
>>> ;;    pred:       ENTRY
>>>   _3 = a_1(D) + b_2(D);
>>>   return _3;
>>> ;;    succ:       EXIT
>>>
>>> }
>>>
>>>
>>> -optimized-stats=foo  will dump
>>>
>>> Gimple body of function: foo
>>> foo (int a, int b)
>>> {
>>>   <bb 2> [local count: 1073741825]:
>>>   _3 = a_1(D) + b_2(D);
>>>   return _3;
>>>
>>> }
>>>
>>>
>>> -optimized-vops=foo  will dump
>>>
>>> Gimple body of function: foo
>>> foo (int a, int b)
>>> {
>>>   <bb 2> [local count: 1073741825]:
>>>   _3 = a_1(D) + b_2(D);
>>>   # VUSE <.MEM_4(D)>
>>>   return _3;
>>>
>>> }
>>>
>>> I have pushed the changes to the current branch. Please find the diff
>>> file attached herewith.
>>>
>>> I have tried to follow the coding conventions as far as possible in
>>> this patch. Please let me know if I am missing out something so that I
>>> can improve the same while refactoring and clean up as suggested in
>>> the previous mail.
>>
>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>> are replaced with a tabular. In our patch, you use indentation level equal to
>> one tab, which results in indentation level 8.
>>
>> Martin
>>
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Thanks for suggestions. I would start working on these points and will
>>>> try to complete as early as possible.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>> Hi,
>>>>>>
>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>> gimple statements.
>>>>>>
>>>>>> For example:
>>>>>>
>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>
>>>>>> will dump:
>>>>>>
>>>>>> GIMPLE statements
>>>>>> Kind                   Stmts      Bytes
>>>>>> ---------------------------------------
>>>>>> assignments                3        264
>>>>>> phi nodes                  1        248
>>>>>> conditionals               1         80
>>>>>> everything else           12        704
>>>>>> ---------------------------------------
>>>>>> Total                     17       1296
>>>>>> ---------------------------------------
>>>>>>
>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>> attached herewith.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>
>>>>> Hi.
>>>>>
>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>> focus now directly on refactoring:
>>>>>
>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>> Makefile needed stuff and commit that.
>>>>> - next please rebase (squash) all your patches which you have on top
>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>> code is very hard for me
>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>
>>>>> Other observations:
>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>> - remove dummy 'dump' function
>>>>>
>>>>> Martin
>>>>>
>>>>>>
>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have added new command line option:
>>>>>>> -objects
>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>
>>>>>>> for example:
>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>
>>>>>>> gives output:
>>>>>>>             LTO object name: test_hello.o
>>>>>>>
>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>
>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>
>>>>>>>             LTO object name: test.o
>>>>>>>
>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>
>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>
>>>>>>>
>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>> attached herewith.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have:
>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>> output given by check_GNU_style.py
>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>> added few necessary comments in the code
>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>> new percentage column to it)
>>>>>>>> for e.g.
>>>>>>>>     integer_type    3    25.00%
>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>     array_type    1    8.33%
>>>>>>>>     function_type    5    41.67%
>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>> attached herewith.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>
>>>>>>>>> I have added command line options:
>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>> number of basic blocks.
>>>>>>>>>
>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>
>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>
>>>>>>>>> for example command line options:
>>>>>>>>>
>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>> -print-value -size-sort
>>>>>>>>>
>>>>>>>>> the dump is:
>>>>>>>>>
>>>>>>>>> Symbol Table
>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>
>>>>>>>>>         printf         function        default           0
>>>>>>>>>         main         function        default           3
>>>>>>>>>         foo            function        default           3
>>>>>>>>>         bar            function        default           6
>>>>>>>>>
>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>         p               variable        default          32
>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>
>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>> attached herewith.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>
>>>>>>>>>> Hi.
>>>>>>>>>>
>>>>>>>>>> Good progress.
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> for example:
>>>>>>>>>>>
>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>
>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>> from the older options.
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> will dump
>>>>>>>>>>>
>>>>>>>>>>> Symbol Table
>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>         main        function        default
>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>
>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>
>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>
>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>
>>>>>>>>>> Martin
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>
>>>>>>>>>>> Please advise,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>
>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>
>>>>>>>>>>>> for example:
>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>
>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>
>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>
>>>>>>>>>>>>> for example:
>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>
>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>
>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>
>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>
>>>>>
>>

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

* Re: [GSOC] LTO dump tool project
  2018-07-17 13:00                                                             ` Martin Liška
@ 2018-07-18 18:04                                                               ` Hrishikesh Kulkarni
  2018-07-22  1:25                                                                 ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-18 18:04 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I tried doing as suggested

+  dfi.pflags = 0;
+  dump_switch_p_1 (arg, &dfi, false);

1.>  the value of dfi.pflags is not changing even if different command
line options are passed like -fdump-blocks or -fdump-vops

2.> what is the significance of bool doglob?

Please find the diff file attached herewith.

Please advise.

Hrishikesh

On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>> Hi,
>>
>> As suggested I have created command line option -optimized=[none,
>> blocks, stats, vops] to dump the respective gimple bodies of all
>> functions.
>>
>> for example:
>>
>> -optimized=blocks will dump
>
>
> Hi.
>
> The name does not make much sense and you removed option that
> limited function name. So instead I would create something like:
>
> -fdump-body=foo
> and
> -fdump-level=optimized
>
> I don't like how you do manual parsing in:
> +  if (!strcmp (flag_optimized, "blocks"))
> +    flags = TDF_BLOCKS;
> +  else if (!strcmp (flag_optimized, "stats"))
> +    flags = TDF_STATS;
> +  else if (!strcmp (flag_optimized, "vops"))
> +    flags = TDF_VOPS;
> +  else if (!strcmp (flag_optimized, "none"))
> +    flags = TDF_NONE;
>
> As I wrote in previous email, take a look how it's done
> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
> and reuse that functionality.
>
> Martin
>
>>
>> Gimple body of function: main
>> main ()
>> {
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>   printf ("%d", 8);
>>   return 0;
>> ;;    succ:       EXIT
>>
>> }
>>
>>
>> Gimple body of function: bar
>> bar (int a, int b, int cond)
>> {
>>   int ret;
>>
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>   if (cond_2(D) != 0)
>>     goto <bb 3>; [50.00%]
>>   else
>>     goto <bb 4>; [50.00%]
>> ;;    succ:       3
>> ;;                4
>>
>> ;;   basic block 3, loop depth 0
>> ;;    pred:       2
>>   ret_5 = a_3(D) + b_4(D);
>>   goto <bb 5>; [100.00%]
>> ;;    succ:       5
>>
>> ;;   basic block 4, loop depth 0
>> ;;    pred:       2
>>   ret_6 = a_3(D) - b_4(D);
>> ;;    succ:       5
>>
>> ;;   basic block 5, loop depth 0
>> ;;    pred:       3
>> ;;                4
>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>   return ret_1;
>> ;;    succ:       EXIT
>>
>> }
>>
>>
>> Gimple body of function: foo
>> foo (int a, int b)
>> {
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>   _3 = a_1(D) + b_2(D);
>>   return _3;
>> ;;    succ:       EXIT
>>
>> }
>>
>> I have pushed the changes to the repo. Please find the diff file
>> attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>> Hi,
>>>>
>>>> I have added command line options:
>>>>
>>>> -body=
>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>
>>>> -optimized-blocks=
>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>
>>>> -optimized-stats=
>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>
>>>> -optimized-vops=
>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>
>>> Hi.
>>>
>>> Thanks for it. However I would expect something more smart:
>>> -optimized=[vops,stats,block]. Note that you should do similar
>>> what's done in: gcc/dumpfile.c
>>>
>>> int
>>> gcc::dump_manager::
>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>
>>> that will automatically parse   dump_flags_t flags;
>>>
>>> Then the copy&parse will not be needed.
>>>
>>>>
>>>> for example:
>>>>
>>>> -body=foo  will dump
>>>>
>>>> Gimple body of function: foo
>>>> foo (int a, int b)
>>>> {
>>>>   <bb 2> [local count: 1073741825]:
>>>>   _3 = a_1(D) + b_2(D);
>>>>   return _3;
>>>>
>>>> }
>>>>
>>>>
>>>> -optimized-blocks=foo  will dump
>>>>
>>>> Gimple body of function: foo
>>>> foo (int a, int b)
>>>> {
>>>> ;;   basic block 2, loop depth 0
>>>> ;;    pred:       ENTRY
>>>>   _3 = a_1(D) + b_2(D);
>>>>   return _3;
>>>> ;;    succ:       EXIT
>>>>
>>>> }
>>>>
>>>>
>>>> -optimized-stats=foo  will dump
>>>>
>>>> Gimple body of function: foo
>>>> foo (int a, int b)
>>>> {
>>>>   <bb 2> [local count: 1073741825]:
>>>>   _3 = a_1(D) + b_2(D);
>>>>   return _3;
>>>>
>>>> }
>>>>
>>>>
>>>> -optimized-vops=foo  will dump
>>>>
>>>> Gimple body of function: foo
>>>> foo (int a, int b)
>>>> {
>>>>   <bb 2> [local count: 1073741825]:
>>>>   _3 = a_1(D) + b_2(D);
>>>>   # VUSE <.MEM_4(D)>
>>>>   return _3;
>>>>
>>>> }
>>>>
>>>> I have pushed the changes to the current branch. Please find the diff
>>>> file attached herewith.
>>>>
>>>> I have tried to follow the coding conventions as far as possible in
>>>> this patch. Please let me know if I am missing out something so that I
>>>> can improve the same while refactoring and clean up as suggested in
>>>> the previous mail.
>>>
>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>> one tab, which results in indentation level 8.
>>>
>>> Martin
>>>
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> Thanks for suggestions. I would start working on these points and will
>>>>> try to complete as early as possible.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>> gimple statements.
>>>>>>>
>>>>>>> For example:
>>>>>>>
>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>
>>>>>>> will dump:
>>>>>>>
>>>>>>> GIMPLE statements
>>>>>>> Kind                   Stmts      Bytes
>>>>>>> ---------------------------------------
>>>>>>> assignments                3        264
>>>>>>> phi nodes                  1        248
>>>>>>> conditionals               1         80
>>>>>>> everything else           12        704
>>>>>>> ---------------------------------------
>>>>>>> Total                     17       1296
>>>>>>> ---------------------------------------
>>>>>>>
>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>> attached herewith.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>> focus now directly on refactoring:
>>>>>>
>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>> Makefile needed stuff and commit that.
>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>> code is very hard for me
>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>
>>>>>> Other observations:
>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>> - remove dummy 'dump' function
>>>>>>
>>>>>> Martin
>>>>>>
>>>>>>>
>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have added new command line option:
>>>>>>>> -objects
>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>
>>>>>>>> for example:
>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>
>>>>>>>> gives output:
>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>
>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>
>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>
>>>>>>>>             LTO object name: test.o
>>>>>>>>
>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>
>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>
>>>>>>>>
>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>> attached herewith.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have:
>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>> added few necessary comments in the code
>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>> new percentage column to it)
>>>>>>>>> for e.g.
>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>     function_type    5    41.67%
>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>> attached herewith.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>
>>>>>>>>>> I have added command line options:
>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>> number of basic blocks.
>>>>>>>>>>
>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>
>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>
>>>>>>>>>> for example command line options:
>>>>>>>>>>
>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>
>>>>>>>>>> the dump is:
>>>>>>>>>>
>>>>>>>>>> Symbol Table
>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>
>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>         main         function        default           3
>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>
>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>         p               variable        default          32
>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>
>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>> attached herewith.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>
>>>>>>>>>>> Hi.
>>>>>>>>>>>
>>>>>>>>>>> Good progress.
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> for example:
>>>>>>>>>>>>
>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>
>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>> from the older options.
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> will dump
>>>>>>>>>>>>
>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>
>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>
>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>
>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>
>>>>>>>>>>> Martin
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>
>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>
>>>>>>>>>>>>> for example:
>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>
>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>
>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>
>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>
>

[-- Attachment #2: gimple_body_issue.diff --]
[-- Type: text/x-patch, Size: 3545 bytes --]

diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 0f16d4f..531f912 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -30,6 +30,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfg.h"
 #include "langhooks.h"
 
+#include "cgraph.h"
+
 /* If non-NULL, return one past-the-end of the matching SUBPART of
    the WHOLE string.  */
 #define skip_leading_substring(whole,  part) \
@@ -898,6 +900,26 @@ dump_switch_p (const char *arg)
   return any;
 }
 
+int
+gcc::dump_manager::
+dump_body_p (const char *arg)
+{
+  struct dump_file_info dfi;
+  dfi.pflags = 0;
+  dump_switch_p_1 (arg, &dfi, false);
+  cgraph_node *cnode;
+  fprintf(stderr, "%d\n", dfi.pflags);
+  FOR_EACH_FUNCTION (cnode)
+  {
+    if (cnode->definition && !strcmp (flag_body, cnode->name ()))
+    {
+      fprintf (stderr, "Gimple body of function: %s\n", cnode->name ());
+      cnode->get_untransformed_body ();
+      debug_function (cnode->decl, dfi.pflags);
+    }
+  }
+}
+
 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
    and filename.  Return non-zero if it is a recognized switch.  */
 
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h
index 21803a6..04a103d 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -239,6 +239,9 @@ public:
   int
   dump_switch_p (const char *arg);
 
+  int
+  dump_body_p (const char *arg); 
+
   /* Start a dump for PHASE. Store user-supplied dump flags in
      *FLAG_PTR.  Return the number of streams opened.  Set globals
      DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 26770d5..78a88a8 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -114,9 +114,12 @@ objects
 LTO Var(flag_lto_dump_objects)
 Dump the details of LTO objects.
 
-optimized=
+fdump-optimized=
 LTO Driver RejectNegative Joined Var(flag_optimized)
 
+fdump-body=
+LTO Driver RejectNegative Joined Var(flag_body)
+
 type-stats
 LTO Var(flag_lto_dump_type_stats)
 Dump the statistics of tree types.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 1c83ab5..2f6b6b1 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -219,25 +219,28 @@ dump_symbol ()
 void
 dump_body ()
 {
-  dump_flags_t flags = TDF_NONE;
-  if (!strcmp (flag_optimized, "blocks"))
-    flags = TDF_BLOCKS;
-  else if (!strcmp (flag_optimized, "stats"))
-    flags = TDF_STATS;
-  else if (!strcmp (flag_optimized, "vops"))
-    flags = TDF_VOPS;
-  else if (!strcmp (flag_optimized, "none"))
-    flags = TDF_NONE;
-  cgraph_node *cnode;
-  FOR_EACH_FUNCTION (cnode)
-  {
-    if (cnode->definition)
-    {
-      fprintf (stderr, "Gimple body of function: %s\n", cnode->name ());
-      cnode->get_untransformed_body ();
-      debug_function (cnode->decl, flags);
-    }
-  }
+	g->get_dumps ()->dump_body_p (flag_optimized);
+
+  
+  // dump_flags_t flags = TDF_NONE;
+  // if (!strcmp (flag_optimized, "blocks"))
+  //   flags = TDF_BLOCKS;
+  // else if (!strcmp (flag_optimized, "stats"))
+  //   flags = TDF_STATS;
+  // else if (!strcmp (flag_optimized, "vops"))
+  //   flags = TDF_VOPS;
+  // else if (!strcmp (flag_optimized, "none"))
+  //   flags = TDF_NONE;
+  // cgraph_node *cnode;
+  // FOR_EACH_FUNCTION (cnode)
+  // {
+  //   if (cnode->definition)
+  //   {
+  //     fprintf (stderr, "Gimple body of function: %s\n", cnode->name ());
+  //     cnode->get_untransformed_body ();
+  //     debug_function (cnode->decl, flags);
+  //   }
+  // }
 }
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */

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

* Re: [GSOC] LTO dump tool project
  2018-07-18 18:04                                                               ` Hrishikesh Kulkarni
@ 2018-07-22  1:25                                                                 ` Hrishikesh Kulkarni
  2018-07-24  3:54                                                                   ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-22  1:25 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

Please find the patch for dumping list of symbols(incorporating your
suggestions) attached herewith.
I have created a new branch lto-dump-tool-v4 and pushed the changes to it.

Command line options used are:
-list
-demangle
-no-demangle
-defined-only
-print-value
-alpha-sort
-size-sort
-reverse-sort
-no-sort

Mean while I am working on doing the parsing using dump_switch_p_1
infrastructure.

Regards,

Hrishikesh

On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I tried doing as suggested
>
> +  dfi.pflags = 0;
> +  dump_switch_p_1 (arg, &dfi, false);
>
> 1.>  the value of dfi.pflags is not changing even if different command
> line options are passed like -fdump-blocks or -fdump-vops
>
> 2.> what is the significance of bool doglob?
>
> Please find the diff file attached herewith.
>
> Please advise.
>
> Hrishikesh
>
> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>>
>>> As suggested I have created command line option -optimized=[none,
>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>> functions.
>>>
>>> for example:
>>>
>>> -optimized=blocks will dump
>>
>>
>> Hi.
>>
>> The name does not make much sense and you removed option that
>> limited function name. So instead I would create something like:
>>
>> -fdump-body=foo
>> and
>> -fdump-level=optimized
>>
>> I don't like how you do manual parsing in:
>> +  if (!strcmp (flag_optimized, "blocks"))
>> +    flags = TDF_BLOCKS;
>> +  else if (!strcmp (flag_optimized, "stats"))
>> +    flags = TDF_STATS;
>> +  else if (!strcmp (flag_optimized, "vops"))
>> +    flags = TDF_VOPS;
>> +  else if (!strcmp (flag_optimized, "none"))
>> +    flags = TDF_NONE;
>>
>> As I wrote in previous email, take a look how it's done
>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>> and reuse that functionality.
>>
>> Martin
>>
>>>
>>> Gimple body of function: main
>>> main ()
>>> {
>>> ;;   basic block 2, loop depth 0
>>> ;;    pred:       ENTRY
>>>   printf ("%d", 8);
>>>   return 0;
>>> ;;    succ:       EXIT
>>>
>>> }
>>>
>>>
>>> Gimple body of function: bar
>>> bar (int a, int b, int cond)
>>> {
>>>   int ret;
>>>
>>> ;;   basic block 2, loop depth 0
>>> ;;    pred:       ENTRY
>>>   if (cond_2(D) != 0)
>>>     goto <bb 3>; [50.00%]
>>>   else
>>>     goto <bb 4>; [50.00%]
>>> ;;    succ:       3
>>> ;;                4
>>>
>>> ;;   basic block 3, loop depth 0
>>> ;;    pred:       2
>>>   ret_5 = a_3(D) + b_4(D);
>>>   goto <bb 5>; [100.00%]
>>> ;;    succ:       5
>>>
>>> ;;   basic block 4, loop depth 0
>>> ;;    pred:       2
>>>   ret_6 = a_3(D) - b_4(D);
>>> ;;    succ:       5
>>>
>>> ;;   basic block 5, loop depth 0
>>> ;;    pred:       3
>>> ;;                4
>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>   return ret_1;
>>> ;;    succ:       EXIT
>>>
>>> }
>>>
>>>
>>> Gimple body of function: foo
>>> foo (int a, int b)
>>> {
>>> ;;   basic block 2, loop depth 0
>>> ;;    pred:       ENTRY
>>>   _3 = a_1(D) + b_2(D);
>>>   return _3;
>>> ;;    succ:       EXIT
>>>
>>> }
>>>
>>> I have pushed the changes to the repo. Please find the diff file
>>> attached herewith.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>> Hi,
>>>>>
>>>>> I have added command line options:
>>>>>
>>>>> -body=
>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>
>>>>> -optimized-blocks=
>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>
>>>>> -optimized-stats=
>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>
>>>>> -optimized-vops=
>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>
>>>> Hi.
>>>>
>>>> Thanks for it. However I would expect something more smart:
>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>> what's done in: gcc/dumpfile.c
>>>>
>>>> int
>>>> gcc::dump_manager::
>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>
>>>> that will automatically parse   dump_flags_t flags;
>>>>
>>>> Then the copy&parse will not be needed.
>>>>
>>>>>
>>>>> for example:
>>>>>
>>>>> -body=foo  will dump
>>>>>
>>>>> Gimple body of function: foo
>>>>> foo (int a, int b)
>>>>> {
>>>>>   <bb 2> [local count: 1073741825]:
>>>>>   _3 = a_1(D) + b_2(D);
>>>>>   return _3;
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> -optimized-blocks=foo  will dump
>>>>>
>>>>> Gimple body of function: foo
>>>>> foo (int a, int b)
>>>>> {
>>>>> ;;   basic block 2, loop depth 0
>>>>> ;;    pred:       ENTRY
>>>>>   _3 = a_1(D) + b_2(D);
>>>>>   return _3;
>>>>> ;;    succ:       EXIT
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> -optimized-stats=foo  will dump
>>>>>
>>>>> Gimple body of function: foo
>>>>> foo (int a, int b)
>>>>> {
>>>>>   <bb 2> [local count: 1073741825]:
>>>>>   _3 = a_1(D) + b_2(D);
>>>>>   return _3;
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> -optimized-vops=foo  will dump
>>>>>
>>>>> Gimple body of function: foo
>>>>> foo (int a, int b)
>>>>> {
>>>>>   <bb 2> [local count: 1073741825]:
>>>>>   _3 = a_1(D) + b_2(D);
>>>>>   # VUSE <.MEM_4(D)>
>>>>>   return _3;
>>>>>
>>>>> }
>>>>>
>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>> file attached herewith.
>>>>>
>>>>> I have tried to follow the coding conventions as far as possible in
>>>>> this patch. Please let me know if I am missing out something so that I
>>>>> can improve the same while refactoring and clean up as suggested in
>>>>> the previous mail.
>>>>
>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>> one tab, which results in indentation level 8.
>>>>
>>>> Martin
>>>>
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>> try to complete as early as possible.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>> gimple statements.
>>>>>>>>
>>>>>>>> For example:
>>>>>>>>
>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>
>>>>>>>> will dump:
>>>>>>>>
>>>>>>>> GIMPLE statements
>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>> ---------------------------------------
>>>>>>>> assignments                3        264
>>>>>>>> phi nodes                  1        248
>>>>>>>> conditionals               1         80
>>>>>>>> everything else           12        704
>>>>>>>> ---------------------------------------
>>>>>>>> Total                     17       1296
>>>>>>>> ---------------------------------------
>>>>>>>>
>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>> attached herewith.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> Hi.
>>>>>>>
>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>> focus now directly on refactoring:
>>>>>>>
>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>> Makefile needed stuff and commit that.
>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>> code is very hard for me
>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>
>>>>>>> Other observations:
>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>> - remove dummy 'dump' function
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have added new command line option:
>>>>>>>>> -objects
>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>
>>>>>>>>> for example:
>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>
>>>>>>>>> gives output:
>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>
>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>
>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>
>>>>>>>>>             LTO object name: test.o
>>>>>>>>>
>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>
>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>> attached herewith.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have:
>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>> new percentage column to it)
>>>>>>>>>> for e.g.
>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>> attached herewith.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>
>>>>>>>>>>> I have added command line options:
>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>
>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>
>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>
>>>>>>>>>>> for example command line options:
>>>>>>>>>>>
>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>
>>>>>>>>>>> the dump is:
>>>>>>>>>>>
>>>>>>>>>>> Symbol Table
>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>
>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>
>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>
>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>> attached herewith.
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>
>>>>>>>>>>>> Hi.
>>>>>>>>>>>>
>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>
>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>
>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>
>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>
>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>
>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>
>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>
>>>>>>>>>>>> Martin
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>
>>

[-- Attachment #2: symbol_list.diff --]
[-- Type: text/x-patch, Size: 7050 bytes --]

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index a8b1b4c..dbb6d4d 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -111,6 +111,12 @@ public:
   /* Return dump name with assembler name.  */
   const char *dump_asm_name () const;
 
+  /* Return visibility name.  */
+  const char *dump_visibility () const;
+
+  /* Return type_name name.  */
+  const char *dump_type_name () const;
+
   /* Add node into symbol table.  This function is not used directly, but via
      cgraph/varpool node creation routines.  */
   void register_symbol (void);
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 1d280a8..0d28d89 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -66,6 +66,42 @@ fwpa=
 LTO Driver RejectNegative Joined Var(flag_wpa)
 Whole program analysis (WPA) mode with number of parallel jobs specified.
 
+list
+LTO Var(flag_lto_dump_list)
+Call the dump function for variables and function in IL.
+
+demangle
+LTO Var(flag_lto_dump_demangle)
+Dump the demangled output.
+
+no-demangle
+LTO Var(flag_lto_dump_no_demangle)
+Dump the non-demangled output.
+
+defined-only
+LTO Var(flag_lto_dump_defined)
+Dump only the defined symbols.
+
+print-value
+LTO Var(flag_lto_print_value)
+Print the initial values of the variables.
+
+alpha-sort
+LTO Var(flag_lto_alpha_sort)
+Sort the symbols alphabetically.
+
+size-sort
+LTO Var(flag_lto_size_sort)
+Sort the symbols according to size.
+
+reverse-sort
+LTO Var(flag_lto_reverse_sort)
+Display the symbols in reverse order.
+
+no-sort
+LTO Var(flag_lto_no_sort)
+Display the symbols in order of occurence.
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 8db280e..fcc180d 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "basic-block.h"
 #include "tree.h"
 #include "gimple.h"
+#include "cfg.h"
 #include "cfghooks.h"
 #include "alloc-pool.h"
 #include "tree-pass.h"
@@ -55,7 +56,171 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "attribs.h"
 #include "builtins.h"
+#include "tree-pretty-print.h"
 
+struct symbol_entry
+{
+  symtab_node *node;
+  symbol_entry (symtab_node *node_): node (node_)
+  {}
+  char* get_name ()
+  {
+    if (flag_lto_dump_demangle)
+      return xstrdup (node->name ());
+    else if (flag_lto_dump_no_demangle)
+      return xstrdup (node->asm_name ());
+    else
+      return xstrdup (node->asm_name ());
+
+  }
+
+  virtual size_t get_size () = 0;
+  virtual void dump () = 0;
+};
+
+struct variable_entry: public symbol_entry
+{
+  variable_entry (varpool_node *node_): symbol_entry (node_)
+  {}
+  virtual size_t get_size ()
+  {
+    varpool_node *vnode = (varpool_node*)node;
+    if (DECL_SIZE (vnode->decl) && tree_fits_shwi_p (DECL_SIZE (vnode->decl)))
+      return tree_to_shwi (DECL_SIZE (vnode->decl));
+    return 0;
+  }
+  virtual void dump ()
+  {
+    const char *name = get_name ();
+    const char *type_name = node->dump_type_name ();
+    const char *visibility = node->dump_visibility ();
+    size_t sz = get_size ();
+    varpool_node *vnode = (varpool_node*)node;
+    vnode->get_constructor ();
+    tree value_tree = DECL_INITIAL (vnode->decl);
+    fprintf (stderr,"%10s %10s %10s %10zu\t", name, type_name, visibility, sz);
+    if (flag_lto_print_value && value_tree)
+      debug_generic_expr (value_tree);
+    else
+      fprintf (stderr, "\n");
+  }
+};
+
+
+struct function_entry: public symbol_entry
+{
+  function_entry (cgraph_node *node_): symbol_entry (node_)
+  {}
+
+  virtual size_t get_size ()
+  {
+    cgraph_node *cnode = dyn_cast<cgraph_node *> (node);
+    gcc_assert (cnode);
+
+    return (cnode->definition)
+	   ? n_basic_blocks_for_fn (DECL_STRUCT_FUNCTION (cnode->decl))
+	   : 0;
+  }
+  void dump ()
+  {
+    const char *name = get_name ();
+    const char *type_name = node->dump_type_name ();
+    const char *visibility = node->dump_visibility ();
+    size_t sz = get_size ();
+    fprintf (stderr,"%10s %10s %10s %10zu\n", name, type_name, visibility, sz);
+  }
+};
+
+
+int size_compare (const void *a, const void *b)
+{
+  symbol_entry *e1 = *(symbol_entry **) a;
+  symbol_entry *e2 = *(symbol_entry **) b;
+
+  return e1->get_size () - e2->get_size ();
+}
+
+int alpha_compare (const void *a, const void *b)
+{
+  symbol_entry *e1 = *(symbol_entry **) a;
+  symbol_entry *e2 = *(symbol_entry **) b;
+
+  return strcmp (e1->get_name (), e2->get_name ());
+}
+
+
+void dump_list_functions (void)
+{
+  auto_vec<symbol_entry *> v;
+
+  cgraph_node *cnode;
+  FOR_EACH_FUNCTION (cnode)
+  {
+    if (cnode->definition)
+      cnode->get_untransformed_body ();
+    symbol_entry *e = new function_entry (cnode);
+    if (!flag_lto_dump_defined || cnode->definition)
+      v.safe_push (e);
+  }
+
+  if (!flag_lto_no_sort)
+  {
+    if (flag_lto_size_sort)
+      v.qsort (size_compare);
+    else if (flag_lto_alpha_sort)
+      v.qsort (alpha_compare);
+  }
+  if (flag_lto_reverse_sort)
+    v.reverse ();
+
+  fprintf (stderr, "\n\tName\tType\tVisibility\tSize");
+  if (flag_lto_print_value)
+    fprintf (stderr, "\tValue");
+  fprintf (stderr, "\n\n");
+
+  int i=0;
+  symbol_entry* e;
+  FOR_EACH_VEC_ELT (v, i, e)
+    e->dump ();
+}
+
+
+void dump_list_variables (void)
+{
+  auto_vec<symbol_entry *> v;
+
+  varpool_node *vnode;
+  FOR_EACH_VARIABLE (vnode)
+  {
+    symbol_entry *e = new variable_entry (vnode);
+    if (!flag_lto_dump_defined || vnode->definition)
+      v.safe_push (e);
+  }
+
+  if (!flag_lto_no_sort)
+  {
+    if (flag_lto_size_sort)
+      v.qsort (size_compare);
+    else if (flag_lto_alpha_sort)
+      v.qsort (alpha_compare);
+  }
+
+
+  if (flag_lto_reverse_sort)
+    v.reverse ();
+
+  fprintf (stderr, "\n");
+  int i=0;
+  symbol_entry* e;
+  FOR_EACH_VEC_ELT (v, i, e)
+    e->dump ();
+}
+
+void dump_list (void)
+{
+  dump_list_functions ();
+  dump_list_variables ();
+}
 
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
@@ -3399,6 +3564,9 @@ lto_main (void)
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);
 
+  if (flag_lto_dump_list)
+    dump_list ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())
diff --git a/gcc/symtab.c b/gcc/symtab.c
index c5464cb..e9b9419 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -808,6 +808,24 @@ symtab_node::dump_referring (FILE *file)
 
 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
 
+/* Dump the visibility of the symbol.  */
+const char *
+symtab_node::dump_visibility () const
+{
+  static const char * const visibility_types[] = {
+      "default", "protected", "hidden", "internal"
+  };
+
+  return visibility_types[DECL_VISIBILITY (decl)];
+}
+
+/* Dump the type_name of the symbol.  */
+const char *
+symtab_node::dump_type_name () const
+{
+  return symtab_type_names[type];
+}
+
 /* Dump base fields of symtab nodes to F.  Not to be used directly.  */
 
 void

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

* Re: [GSOC] LTO dump tool project
  2018-07-22  1:25                                                                 ` Hrishikesh Kulkarni
@ 2018-07-24  3:54                                                                   ` Hrishikesh Kulkarni
  2018-07-25  9:34                                                                     ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-24  3:54 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

Please find the patch for dumping detail information of a specified
symbol attached herewith.
I have also pushed the changes to the new branch (lto-dump-tool-v4).

Regards,

Hrishikesh

On Sun, Jul 22, 2018 at 2:39 AM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> Please find the patch for dumping list of symbols(incorporating your
> suggestions) attached herewith.
> I have created a new branch lto-dump-tool-v4 and pushed the changes to it.
>
> Command line options used are:
> -list
> -demangle
> -no-demangle
> -defined-only
> -print-value
> -alpha-sort
> -size-sort
> -reverse-sort
> -no-sort
>
> Mean while I am working on doing the parsing using dump_switch_p_1
> infrastructure.
>
> Regards,
>
> Hrishikesh
>
> On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I tried doing as suggested
>>
>> +  dfi.pflags = 0;
>> +  dump_switch_p_1 (arg, &dfi, false);
>>
>> 1.>  the value of dfi.pflags is not changing even if different command
>> line options are passed like -fdump-blocks or -fdump-vops
>>
>> 2.> what is the significance of bool doglob?
>>
>> Please find the diff file attached herewith.
>>
>> Please advise.
>>
>> Hrishikesh
>>
>> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>>> Hi,
>>>>
>>>> As suggested I have created command line option -optimized=[none,
>>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>>> functions.
>>>>
>>>> for example:
>>>>
>>>> -optimized=blocks will dump
>>>
>>>
>>> Hi.
>>>
>>> The name does not make much sense and you removed option that
>>> limited function name. So instead I would create something like:
>>>
>>> -fdump-body=foo
>>> and
>>> -fdump-level=optimized
>>>
>>> I don't like how you do manual parsing in:
>>> +  if (!strcmp (flag_optimized, "blocks"))
>>> +    flags = TDF_BLOCKS;
>>> +  else if (!strcmp (flag_optimized, "stats"))
>>> +    flags = TDF_STATS;
>>> +  else if (!strcmp (flag_optimized, "vops"))
>>> +    flags = TDF_VOPS;
>>> +  else if (!strcmp (flag_optimized, "none"))
>>> +    flags = TDF_NONE;
>>>
>>> As I wrote in previous email, take a look how it's done
>>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>> and reuse that functionality.
>>>
>>> Martin
>>>
>>>>
>>>> Gimple body of function: main
>>>> main ()
>>>> {
>>>> ;;   basic block 2, loop depth 0
>>>> ;;    pred:       ENTRY
>>>>   printf ("%d", 8);
>>>>   return 0;
>>>> ;;    succ:       EXIT
>>>>
>>>> }
>>>>
>>>>
>>>> Gimple body of function: bar
>>>> bar (int a, int b, int cond)
>>>> {
>>>>   int ret;
>>>>
>>>> ;;   basic block 2, loop depth 0
>>>> ;;    pred:       ENTRY
>>>>   if (cond_2(D) != 0)
>>>>     goto <bb 3>; [50.00%]
>>>>   else
>>>>     goto <bb 4>; [50.00%]
>>>> ;;    succ:       3
>>>> ;;                4
>>>>
>>>> ;;   basic block 3, loop depth 0
>>>> ;;    pred:       2
>>>>   ret_5 = a_3(D) + b_4(D);
>>>>   goto <bb 5>; [100.00%]
>>>> ;;    succ:       5
>>>>
>>>> ;;   basic block 4, loop depth 0
>>>> ;;    pred:       2
>>>>   ret_6 = a_3(D) - b_4(D);
>>>> ;;    succ:       5
>>>>
>>>> ;;   basic block 5, loop depth 0
>>>> ;;    pred:       3
>>>> ;;                4
>>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>>   return ret_1;
>>>> ;;    succ:       EXIT
>>>>
>>>> }
>>>>
>>>>
>>>> Gimple body of function: foo
>>>> foo (int a, int b)
>>>> {
>>>> ;;   basic block 2, loop depth 0
>>>> ;;    pred:       ENTRY
>>>>   _3 = a_1(D) + b_2(D);
>>>>   return _3;
>>>> ;;    succ:       EXIT
>>>>
>>>> }
>>>>
>>>> I have pushed the changes to the repo. Please find the diff file
>>>> attached herewith.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have added command line options:
>>>>>>
>>>>>> -body=
>>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>>
>>>>>> -optimized-blocks=
>>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>>
>>>>>> -optimized-stats=
>>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>>
>>>>>> -optimized-vops=
>>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>>
>>>>> Hi.
>>>>>
>>>>> Thanks for it. However I would expect something more smart:
>>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>>> what's done in: gcc/dumpfile.c
>>>>>
>>>>> int
>>>>> gcc::dump_manager::
>>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>
>>>>> that will automatically parse   dump_flags_t flags;
>>>>>
>>>>> Then the copy&parse will not be needed.
>>>>>
>>>>>>
>>>>>> for example:
>>>>>>
>>>>>> -body=foo  will dump
>>>>>>
>>>>>> Gimple body of function: foo
>>>>>> foo (int a, int b)
>>>>>> {
>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>   return _3;
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> -optimized-blocks=foo  will dump
>>>>>>
>>>>>> Gimple body of function: foo
>>>>>> foo (int a, int b)
>>>>>> {
>>>>>> ;;   basic block 2, loop depth 0
>>>>>> ;;    pred:       ENTRY
>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>   return _3;
>>>>>> ;;    succ:       EXIT
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> -optimized-stats=foo  will dump
>>>>>>
>>>>>> Gimple body of function: foo
>>>>>> foo (int a, int b)
>>>>>> {
>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>   return _3;
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> -optimized-vops=foo  will dump
>>>>>>
>>>>>> Gimple body of function: foo
>>>>>> foo (int a, int b)
>>>>>> {
>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>   # VUSE <.MEM_4(D)>
>>>>>>   return _3;
>>>>>>
>>>>>> }
>>>>>>
>>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>>> file attached herewith.
>>>>>>
>>>>>> I have tried to follow the coding conventions as far as possible in
>>>>>> this patch. Please let me know if I am missing out something so that I
>>>>>> can improve the same while refactoring and clean up as suggested in
>>>>>> the previous mail.
>>>>>
>>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>>> one tab, which results in indentation level 8.
>>>>>
>>>>> Martin
>>>>>
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>>> try to complete as early as possible.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>>> gimple statements.
>>>>>>>>>
>>>>>>>>> For example:
>>>>>>>>>
>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>>
>>>>>>>>> will dump:
>>>>>>>>>
>>>>>>>>> GIMPLE statements
>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>> ---------------------------------------
>>>>>>>>> assignments                3        264
>>>>>>>>> phi nodes                  1        248
>>>>>>>>> conditionals               1         80
>>>>>>>>> everything else           12        704
>>>>>>>>> ---------------------------------------
>>>>>>>>> Total                     17       1296
>>>>>>>>> ---------------------------------------
>>>>>>>>>
>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>> attached herewith.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> Hi.
>>>>>>>>
>>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>>> focus now directly on refactoring:
>>>>>>>>
>>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>>> Makefile needed stuff and commit that.
>>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>>> code is very hard for me
>>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>>
>>>>>>>> Other observations:
>>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>>> - remove dummy 'dump' function
>>>>>>>>
>>>>>>>> Martin
>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have added new command line option:
>>>>>>>>>> -objects
>>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>>
>>>>>>>>>> for example:
>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>>
>>>>>>>>>> gives output:
>>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>>
>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>
>>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>>
>>>>>>>>>>             LTO object name: test.o
>>>>>>>>>>
>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>
>>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>> attached herewith.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I have:
>>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>>> new percentage column to it)
>>>>>>>>>>> for e.g.
>>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>>> attached herewith.
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>>
>>>>>>>>>>>> I have added command line options:
>>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>>
>>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>>
>>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>>
>>>>>>>>>>>> for example command line options:
>>>>>>>>>>>>
>>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>>
>>>>>>>>>>>> the dump is:
>>>>>>>>>>>>
>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>>
>>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>>
>>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>>
>>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>
>>>>>>>>>>>> Regards,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>>
>>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>
>>>>>
>>>

[-- Attachment #2: symbol.diff --]
[-- Type: text/x-patch, Size: 1230 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 0d28d89..6c014ae 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -102,6 +102,9 @@ no-sort
 LTO Var(flag_lto_no_sort)
 Display the symbols in order of occurence.
 
+symbol=
+LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index fcc180d..b0f10e6 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -222,6 +222,18 @@ void dump_list (void)
   dump_list_variables ();
 }
 
+/* Dump specific variables and functions used in IL.  */
+void
+dump_symbol ()
+{
+  symtab_node *node;
+  fprintf (stderr, "Symbol:\t%s\n", flag_lto_dump_symbol);
+  FOR_EACH_SYMBOL (node)
+    if (!strcmp (flag_lto_dump_symbol, node->name ()))
+      node->debug ();
+  fprintf (stderr, "\n");
+}
+
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
 
@@ -3567,6 +3579,10 @@ lto_main (void)
   if (flag_lto_dump_list)
     dump_list ();
 
+  /* Dump specific variables and functions used in IL.  */
+  if (flag_lto_dump_symbol)
+    dump_symbol ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())

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

* Re: [GSOC] LTO dump tool project
  2018-07-24  3:54                                                                   ` Hrishikesh Kulkarni
@ 2018-07-25  9:34                                                                     ` Hrishikesh Kulkarni
  2018-07-27 22:41                                                                       ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-25  9:34 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

Please find the patch for dumping details of LTO objects attached herewith.
I have also added the changes to the new branch (lto-dump-tool-v4).

Regards,

Hrishikesh

On Mon, Jul 23, 2018 at 10:28 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> Please find the patch for dumping detail information of a specified
> symbol attached herewith.
> I have also pushed the changes to the new branch (lto-dump-tool-v4).
>
> Regards,
>
> Hrishikesh
>
> On Sun, Jul 22, 2018 at 2:39 AM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> Please find the patch for dumping list of symbols(incorporating your
>> suggestions) attached herewith.
>> I have created a new branch lto-dump-tool-v4 and pushed the changes to it.
>>
>> Command line options used are:
>> -list
>> -demangle
>> -no-demangle
>> -defined-only
>> -print-value
>> -alpha-sort
>> -size-sort
>> -reverse-sort
>> -no-sort
>>
>> Mean while I am working on doing the parsing using dump_switch_p_1
>> infrastructure.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> I tried doing as suggested
>>>
>>> +  dfi.pflags = 0;
>>> +  dump_switch_p_1 (arg, &dfi, false);
>>>
>>> 1.>  the value of dfi.pflags is not changing even if different command
>>> line options are passed like -fdump-blocks or -fdump-vops
>>>
>>> 2.> what is the significance of bool doglob?
>>>
>>> Please find the diff file attached herewith.
>>>
>>> Please advise.
>>>
>>> Hrishikesh
>>>
>>> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>>>> Hi,
>>>>>
>>>>> As suggested I have created command line option -optimized=[none,
>>>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>>>> functions.
>>>>>
>>>>> for example:
>>>>>
>>>>> -optimized=blocks will dump
>>>>
>>>>
>>>> Hi.
>>>>
>>>> The name does not make much sense and you removed option that
>>>> limited function name. So instead I would create something like:
>>>>
>>>> -fdump-body=foo
>>>> and
>>>> -fdump-level=optimized
>>>>
>>>> I don't like how you do manual parsing in:
>>>> +  if (!strcmp (flag_optimized, "blocks"))
>>>> +    flags = TDF_BLOCKS;
>>>> +  else if (!strcmp (flag_optimized, "stats"))
>>>> +    flags = TDF_STATS;
>>>> +  else if (!strcmp (flag_optimized, "vops"))
>>>> +    flags = TDF_VOPS;
>>>> +  else if (!strcmp (flag_optimized, "none"))
>>>> +    flags = TDF_NONE;
>>>>
>>>> As I wrote in previous email, take a look how it's done
>>>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>> and reuse that functionality.
>>>>
>>>> Martin
>>>>
>>>>>
>>>>> Gimple body of function: main
>>>>> main ()
>>>>> {
>>>>> ;;   basic block 2, loop depth 0
>>>>> ;;    pred:       ENTRY
>>>>>   printf ("%d", 8);
>>>>>   return 0;
>>>>> ;;    succ:       EXIT
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> Gimple body of function: bar
>>>>> bar (int a, int b, int cond)
>>>>> {
>>>>>   int ret;
>>>>>
>>>>> ;;   basic block 2, loop depth 0
>>>>> ;;    pred:       ENTRY
>>>>>   if (cond_2(D) != 0)
>>>>>     goto <bb 3>; [50.00%]
>>>>>   else
>>>>>     goto <bb 4>; [50.00%]
>>>>> ;;    succ:       3
>>>>> ;;                4
>>>>>
>>>>> ;;   basic block 3, loop depth 0
>>>>> ;;    pred:       2
>>>>>   ret_5 = a_3(D) + b_4(D);
>>>>>   goto <bb 5>; [100.00%]
>>>>> ;;    succ:       5
>>>>>
>>>>> ;;   basic block 4, loop depth 0
>>>>> ;;    pred:       2
>>>>>   ret_6 = a_3(D) - b_4(D);
>>>>> ;;    succ:       5
>>>>>
>>>>> ;;   basic block 5, loop depth 0
>>>>> ;;    pred:       3
>>>>> ;;                4
>>>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>>>   return ret_1;
>>>>> ;;    succ:       EXIT
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> Gimple body of function: foo
>>>>> foo (int a, int b)
>>>>> {
>>>>> ;;   basic block 2, loop depth 0
>>>>> ;;    pred:       ENTRY
>>>>>   _3 = a_1(D) + b_2(D);
>>>>>   return _3;
>>>>> ;;    succ:       EXIT
>>>>>
>>>>> }
>>>>>
>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>> attached herewith.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have added command line options:
>>>>>>>
>>>>>>> -body=
>>>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>>>
>>>>>>> -optimized-blocks=
>>>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>>>
>>>>>>> -optimized-stats=
>>>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>>>
>>>>>>> -optimized-vops=
>>>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> Thanks for it. However I would expect something more smart:
>>>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>>>> what's done in: gcc/dumpfile.c
>>>>>>
>>>>>> int
>>>>>> gcc::dump_manager::
>>>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>>
>>>>>> that will automatically parse   dump_flags_t flags;
>>>>>>
>>>>>> Then the copy&parse will not be needed.
>>>>>>
>>>>>>>
>>>>>>> for example:
>>>>>>>
>>>>>>> -body=foo  will dump
>>>>>>>
>>>>>>> Gimple body of function: foo
>>>>>>> foo (int a, int b)
>>>>>>> {
>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>   return _3;
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> -optimized-blocks=foo  will dump
>>>>>>>
>>>>>>> Gimple body of function: foo
>>>>>>> foo (int a, int b)
>>>>>>> {
>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>> ;;    pred:       ENTRY
>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>   return _3;
>>>>>>> ;;    succ:       EXIT
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> -optimized-stats=foo  will dump
>>>>>>>
>>>>>>> Gimple body of function: foo
>>>>>>> foo (int a, int b)
>>>>>>> {
>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>   return _3;
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> -optimized-vops=foo  will dump
>>>>>>>
>>>>>>> Gimple body of function: foo
>>>>>>> foo (int a, int b)
>>>>>>> {
>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>   # VUSE <.MEM_4(D)>
>>>>>>>   return _3;
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>>>> file attached herewith.
>>>>>>>
>>>>>>> I have tried to follow the coding conventions as far as possible in
>>>>>>> this patch. Please let me know if I am missing out something so that I
>>>>>>> can improve the same while refactoring and clean up as suggested in
>>>>>>> the previous mail.
>>>>>>
>>>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>>>> one tab, which results in indentation level 8.
>>>>>>
>>>>>> Martin
>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>>>> try to complete as early as possible.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>>>> gimple statements.
>>>>>>>>>>
>>>>>>>>>> For example:
>>>>>>>>>>
>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>>>
>>>>>>>>>> will dump:
>>>>>>>>>>
>>>>>>>>>> GIMPLE statements
>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> assignments                3        264
>>>>>>>>>> phi nodes                  1        248
>>>>>>>>>> conditionals               1         80
>>>>>>>>>> everything else           12        704
>>>>>>>>>> ---------------------------------------
>>>>>>>>>> Total                     17       1296
>>>>>>>>>> ---------------------------------------
>>>>>>>>>>
>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>> attached herewith.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> Hi.
>>>>>>>>>
>>>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>>>> focus now directly on refactoring:
>>>>>>>>>
>>>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>>>> Makefile needed stuff and commit that.
>>>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>>>> code is very hard for me
>>>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>>>
>>>>>>>>> Other observations:
>>>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>>>> - remove dummy 'dump' function
>>>>>>>>>
>>>>>>>>> Martin
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I have added new command line option:
>>>>>>>>>>> -objects
>>>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>>>
>>>>>>>>>>> for example:
>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>>>
>>>>>>>>>>> gives output:
>>>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>>>
>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>
>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>>>
>>>>>>>>>>>             LTO object name: test.o
>>>>>>>>>>>
>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>
>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>> attached herewith.
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have:
>>>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>>>> new percentage column to it)
>>>>>>>>>>>> for e.g.
>>>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>
>>>>>>>>>>>> Regards,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have added command line options:
>>>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>>>
>>>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>>>
>>>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>>>
>>>>>>>>>>>>> for example command line options:
>>>>>>>>>>>>>
>>>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>>>
>>>>>>>>>>>>> the dump is:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>>>
>>>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>>>
>>>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>
>>>>>>
>>>>

[-- Attachment #2: object.diff --]
[-- Type: text/x-patch, Size: 1329 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 6c014ae..99f0fea 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -105,6 +105,10 @@ Display the symbols in order of occurence.
 symbol=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 
+objects
+LTO Var(flag_lto_dump_objects)
+Dump the details of LTO objects.
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index b0f10e6..8e9c7f6 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -2347,6 +2347,17 @@ lto_file_read (lto_file *file, FILE *resolution_file, int *count)
   memset (&section_list, 0, sizeof (struct lto_section_list)); 
   section_hash_table = lto_obj_build_section_table (file, &section_list);
 
+  /* Dump the details of LTO objects.  */
+  if (flag_lto_dump_objects)
+  {
+    int i=0;
+    fprintf (stderr, "\n\t\t\tLTO object name: %s\n", file->filename);
+    fprintf (stderr, "\nNO.\t\tOFFSET\t\tSIZE\t\tSECTION NAME\n\n");
+    for (section = section_list.first; section != NULL; section = section->next)
+      fprintf (stderr, "%d\t\t%d\t\t%d\t\t%s\n",
+	      ++i, section->start, section->len, section->name);
+  }
+
   /* Find all sub modules in the object and put their sections into new hash
      tables in a splay tree. */
   file_ids = lto_splay_tree_new ();

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

* Re: [GSOC] LTO dump tool project
  2018-07-25  9:34                                                                     ` Hrishikesh Kulkarni
@ 2018-07-27 22:41                                                                       ` Hrishikesh Kulkarni
  2018-07-28 16:54                                                                         ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-27 22:41 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added command line option -type-stats to the new branch which
dumps the statistics of tree types.
As suggested hash_map is used from hash-map.h.

Please find the patch attached herewith.

Regards,

Hrishikesh

On Tue, Jul 24, 2018 at 10:42 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> Please find the patch for dumping details of LTO objects attached herewith.
> I have also added the changes to the new branch (lto-dump-tool-v4).
>
> Regards,
>
> Hrishikesh
>
> On Mon, Jul 23, 2018 at 10:28 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> Please find the patch for dumping detail information of a specified
>> symbol attached herewith.
>> I have also pushed the changes to the new branch (lto-dump-tool-v4).
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Sun, Jul 22, 2018 at 2:39 AM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> Please find the patch for dumping list of symbols(incorporating your
>>> suggestions) attached herewith.
>>> I have created a new branch lto-dump-tool-v4 and pushed the changes to it.
>>>
>>> Command line options used are:
>>> -list
>>> -demangle
>>> -no-demangle
>>> -defined-only
>>> -print-value
>>> -alpha-sort
>>> -size-sort
>>> -reverse-sort
>>> -no-sort
>>>
>>> Mean while I am working on doing the parsing using dump_switch_p_1
>>> infrastructure.
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I tried doing as suggested
>>>>
>>>> +  dfi.pflags = 0;
>>>> +  dump_switch_p_1 (arg, &dfi, false);
>>>>
>>>> 1.>  the value of dfi.pflags is not changing even if different command
>>>> line options are passed like -fdump-blocks or -fdump-vops
>>>>
>>>> 2.> what is the significance of bool doglob?
>>>>
>>>> Please find the diff file attached herewith.
>>>>
>>>> Please advise.
>>>>
>>>> Hrishikesh
>>>>
>>>> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>>>>> Hi,
>>>>>>
>>>>>> As suggested I have created command line option -optimized=[none,
>>>>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>>>>> functions.
>>>>>>
>>>>>> for example:
>>>>>>
>>>>>> -optimized=blocks will dump
>>>>>
>>>>>
>>>>> Hi.
>>>>>
>>>>> The name does not make much sense and you removed option that
>>>>> limited function name. So instead I would create something like:
>>>>>
>>>>> -fdump-body=foo
>>>>> and
>>>>> -fdump-level=optimized
>>>>>
>>>>> I don't like how you do manual parsing in:
>>>>> +  if (!strcmp (flag_optimized, "blocks"))
>>>>> +    flags = TDF_BLOCKS;
>>>>> +  else if (!strcmp (flag_optimized, "stats"))
>>>>> +    flags = TDF_STATS;
>>>>> +  else if (!strcmp (flag_optimized, "vops"))
>>>>> +    flags = TDF_VOPS;
>>>>> +  else if (!strcmp (flag_optimized, "none"))
>>>>> +    flags = TDF_NONE;
>>>>>
>>>>> As I wrote in previous email, take a look how it's done
>>>>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>> and reuse that functionality.
>>>>>
>>>>> Martin
>>>>>
>>>>>>
>>>>>> Gimple body of function: main
>>>>>> main ()
>>>>>> {
>>>>>> ;;   basic block 2, loop depth 0
>>>>>> ;;    pred:       ENTRY
>>>>>>   printf ("%d", 8);
>>>>>>   return 0;
>>>>>> ;;    succ:       EXIT
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Gimple body of function: bar
>>>>>> bar (int a, int b, int cond)
>>>>>> {
>>>>>>   int ret;
>>>>>>
>>>>>> ;;   basic block 2, loop depth 0
>>>>>> ;;    pred:       ENTRY
>>>>>>   if (cond_2(D) != 0)
>>>>>>     goto <bb 3>; [50.00%]
>>>>>>   else
>>>>>>     goto <bb 4>; [50.00%]
>>>>>> ;;    succ:       3
>>>>>> ;;                4
>>>>>>
>>>>>> ;;   basic block 3, loop depth 0
>>>>>> ;;    pred:       2
>>>>>>   ret_5 = a_3(D) + b_4(D);
>>>>>>   goto <bb 5>; [100.00%]
>>>>>> ;;    succ:       5
>>>>>>
>>>>>> ;;   basic block 4, loop depth 0
>>>>>> ;;    pred:       2
>>>>>>   ret_6 = a_3(D) - b_4(D);
>>>>>> ;;    succ:       5
>>>>>>
>>>>>> ;;   basic block 5, loop depth 0
>>>>>> ;;    pred:       3
>>>>>> ;;                4
>>>>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>>>>   return ret_1;
>>>>>> ;;    succ:       EXIT
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Gimple body of function: foo
>>>>>> foo (int a, int b)
>>>>>> {
>>>>>> ;;   basic block 2, loop depth 0
>>>>>> ;;    pred:       ENTRY
>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>   return _3;
>>>>>> ;;    succ:       EXIT
>>>>>>
>>>>>> }
>>>>>>
>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>> attached herewith.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have added command line options:
>>>>>>>>
>>>>>>>> -body=
>>>>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>>>>
>>>>>>>> -optimized-blocks=
>>>>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>>>>
>>>>>>>> -optimized-stats=
>>>>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>>>>
>>>>>>>> -optimized-vops=
>>>>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>>>>
>>>>>>> Hi.
>>>>>>>
>>>>>>> Thanks for it. However I would expect something more smart:
>>>>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>>>>> what's done in: gcc/dumpfile.c
>>>>>>>
>>>>>>> int
>>>>>>> gcc::dump_manager::
>>>>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>>>
>>>>>>> that will automatically parse   dump_flags_t flags;
>>>>>>>
>>>>>>> Then the copy&parse will not be needed.
>>>>>>>
>>>>>>>>
>>>>>>>> for example:
>>>>>>>>
>>>>>>>> -body=foo  will dump
>>>>>>>>
>>>>>>>> Gimple body of function: foo
>>>>>>>> foo (int a, int b)
>>>>>>>> {
>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>   return _3;
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> -optimized-blocks=foo  will dump
>>>>>>>>
>>>>>>>> Gimple body of function: foo
>>>>>>>> foo (int a, int b)
>>>>>>>> {
>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>   return _3;
>>>>>>>> ;;    succ:       EXIT
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> -optimized-stats=foo  will dump
>>>>>>>>
>>>>>>>> Gimple body of function: foo
>>>>>>>> foo (int a, int b)
>>>>>>>> {
>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>   return _3;
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> -optimized-vops=foo  will dump
>>>>>>>>
>>>>>>>> Gimple body of function: foo
>>>>>>>> foo (int a, int b)
>>>>>>>> {
>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>   # VUSE <.MEM_4(D)>
>>>>>>>>   return _3;
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>>>>> file attached herewith.
>>>>>>>>
>>>>>>>> I have tried to follow the coding conventions as far as possible in
>>>>>>>> this patch. Please let me know if I am missing out something so that I
>>>>>>>> can improve the same while refactoring and clean up as suggested in
>>>>>>>> the previous mail.
>>>>>>>
>>>>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>>>>> one tab, which results in indentation level 8.
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>>>>> try to complete as early as possible.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>>>>> gimple statements.
>>>>>>>>>>>
>>>>>>>>>>> For example:
>>>>>>>>>>>
>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>>>>
>>>>>>>>>>> will dump:
>>>>>>>>>>>
>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> assignments                3        264
>>>>>>>>>>> phi nodes                  1        248
>>>>>>>>>>> conditionals               1         80
>>>>>>>>>>> everything else           12        704
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>> Total                     17       1296
>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>
>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>> attached herewith.
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> Hi.
>>>>>>>>>>
>>>>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>>>>> focus now directly on refactoring:
>>>>>>>>>>
>>>>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>>>>> Makefile needed stuff and commit that.
>>>>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>>>>> code is very hard for me
>>>>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>>>>
>>>>>>>>>> Other observations:
>>>>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>>>>> - remove dummy 'dump' function
>>>>>>>>>>
>>>>>>>>>> Martin
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have added new command line option:
>>>>>>>>>>>> -objects
>>>>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>>>>
>>>>>>>>>>>> for example:
>>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>>>>
>>>>>>>>>>>> gives output:
>>>>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>>>>
>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>
>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>>>>
>>>>>>>>>>>>             LTO object name: test.o
>>>>>>>>>>>>
>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>
>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>
>>>>>>>>>>>> Regards,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have:
>>>>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>>>>> new percentage column to it)
>>>>>>>>>>>>> for e.g.
>>>>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have added command line options:
>>>>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for example command line options:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the dump is:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>
>>>>>

[-- Attachment #2: type_stats.diff --]
[-- Type: text/x-patch, Size: 2133 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 99f0fea..75e9545 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -109,6 +109,10 @@ objects
 LTO Var(flag_lto_dump_objects)
 Dump the details of LTO objects.
 
+type-stats
+LTO Var(flag_lto_dump_type_stats)
+Dump the statistics of tree types.
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 8e9c7f6..102a869 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -1946,6 +1946,10 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
   /* We do not uniquify the pre-loaded cache entries, those are middle-end
      internal types that should not be merged.  */
 
+  typedef int_hash<unsigned, 0, UINT_MAX> code_id_hash;
+  hash_map <code_id_hash, unsigned> hm;
+  unsigned total = 0;
+
   /* Read the global declarations and types.  */
   while (ib_main.p < ib_main.len)
     {
@@ -1994,6 +1998,15 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 		 chains.  */
 	      if (TYPE_P (t))
 		{
+		  /* Map the tree types to their frequencies.  */
+		  if (flag_lto_dump_type_stats)
+		  {
+		    unsigned key = (unsigned) TREE_CODE (t);
+		    unsigned *countp = hm.get (key);
+		    hm.put (key, countp ? (*countp) + 1 : 1);
+		    total++;
+		  }
+
 		  seen_type = true;
 		  num_prevailing_types++;
 		  lto_fixup_prevailing_type (t);
@@ -2039,6 +2052,21 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 	  gcc_assert (t && data_in->reader_cache->nodes.length () == from);
 	}
     }
+
+    if (flag_lto_dump_type_stats)
+    {
+      fprintf (stderr, "%s\n\nType\tFrequency\tPercentage\n");
+      for (hash_map<code_id_hash, unsigned>::iterator itr = hm.begin ();
+	   itr != hm.end ();
+	   ++itr)
+      {
+	std::pair<unsigned, unsigned> p = *itr;
+	enum tree_code code = (enum tree_code) p.first;
+	fprintf (stderr, "%s\t%d\t%0.2f%\n", get_tree_code_name (code),
+		 p.second, float (p.second)/total*100);
+      }
+    }
+
   data_in->location_cache.apply_location_cache ();
 
   /* Read in lto_in_decl_state objects.  */

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

* Re: [GSOC] LTO dump tool project
  2018-07-27 22:41                                                                       ` Hrishikesh Kulkarni
@ 2018-07-28 16:54                                                                         ` Hrishikesh Kulkarni
  2018-07-31  6:25                                                                           ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-28 16:54 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added command line options
-gimple-stats to dump GIMPLE statistics
-tree-stats to dump TREE statistics

I have pushed the changes to the new branch. Please find the diff file
attached herewith.

Regards,

Hrishikesh

On Fri, Jul 27, 2018 at 11:15 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have added command line option -type-stats to the new branch which
> dumps the statistics of tree types.
> As suggested hash_map is used from hash-map.h.
>
> Please find the patch attached herewith.
>
> Regards,
>
> Hrishikesh
>
> On Tue, Jul 24, 2018 at 10:42 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> Please find the patch for dumping details of LTO objects attached herewith.
>> I have also added the changes to the new branch (lto-dump-tool-v4).
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Mon, Jul 23, 2018 at 10:28 PM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> Please find the patch for dumping detail information of a specified
>>> symbol attached herewith.
>>> I have also pushed the changes to the new branch (lto-dump-tool-v4).
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Sun, Jul 22, 2018 at 2:39 AM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Please find the patch for dumping list of symbols(incorporating your
>>>> suggestions) attached herewith.
>>>> I have created a new branch lto-dump-tool-v4 and pushed the changes to it.
>>>>
>>>> Command line options used are:
>>>> -list
>>>> -demangle
>>>> -no-demangle
>>>> -defined-only
>>>> -print-value
>>>> -alpha-sort
>>>> -size-sort
>>>> -reverse-sort
>>>> -no-sort
>>>>
>>>> Mean while I am working on doing the parsing using dump_switch_p_1
>>>> infrastructure.
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I tried doing as suggested
>>>>>
>>>>> +  dfi.pflags = 0;
>>>>> +  dump_switch_p_1 (arg, &dfi, false);
>>>>>
>>>>> 1.>  the value of dfi.pflags is not changing even if different command
>>>>> line options are passed like -fdump-blocks or -fdump-vops
>>>>>
>>>>> 2.> what is the significance of bool doglob?
>>>>>
>>>>> Please find the diff file attached herewith.
>>>>>
>>>>> Please advise.
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> As suggested I have created command line option -optimized=[none,
>>>>>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>>>>>> functions.
>>>>>>>
>>>>>>> for example:
>>>>>>>
>>>>>>> -optimized=blocks will dump
>>>>>>
>>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> The name does not make much sense and you removed option that
>>>>>> limited function name. So instead I would create something like:
>>>>>>
>>>>>> -fdump-body=foo
>>>>>> and
>>>>>> -fdump-level=optimized
>>>>>>
>>>>>> I don't like how you do manual parsing in:
>>>>>> +  if (!strcmp (flag_optimized, "blocks"))
>>>>>> +    flags = TDF_BLOCKS;
>>>>>> +  else if (!strcmp (flag_optimized, "stats"))
>>>>>> +    flags = TDF_STATS;
>>>>>> +  else if (!strcmp (flag_optimized, "vops"))
>>>>>> +    flags = TDF_VOPS;
>>>>>> +  else if (!strcmp (flag_optimized, "none"))
>>>>>> +    flags = TDF_NONE;
>>>>>>
>>>>>> As I wrote in previous email, take a look how it's done
>>>>>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>> and reuse that functionality.
>>>>>>
>>>>>> Martin
>>>>>>
>>>>>>>
>>>>>>> Gimple body of function: main
>>>>>>> main ()
>>>>>>> {
>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>> ;;    pred:       ENTRY
>>>>>>>   printf ("%d", 8);
>>>>>>>   return 0;
>>>>>>> ;;    succ:       EXIT
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Gimple body of function: bar
>>>>>>> bar (int a, int b, int cond)
>>>>>>> {
>>>>>>>   int ret;
>>>>>>>
>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>> ;;    pred:       ENTRY
>>>>>>>   if (cond_2(D) != 0)
>>>>>>>     goto <bb 3>; [50.00%]
>>>>>>>   else
>>>>>>>     goto <bb 4>; [50.00%]
>>>>>>> ;;    succ:       3
>>>>>>> ;;                4
>>>>>>>
>>>>>>> ;;   basic block 3, loop depth 0
>>>>>>> ;;    pred:       2
>>>>>>>   ret_5 = a_3(D) + b_4(D);
>>>>>>>   goto <bb 5>; [100.00%]
>>>>>>> ;;    succ:       5
>>>>>>>
>>>>>>> ;;   basic block 4, loop depth 0
>>>>>>> ;;    pred:       2
>>>>>>>   ret_6 = a_3(D) - b_4(D);
>>>>>>> ;;    succ:       5
>>>>>>>
>>>>>>> ;;   basic block 5, loop depth 0
>>>>>>> ;;    pred:       3
>>>>>>> ;;                4
>>>>>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>>>>>   return ret_1;
>>>>>>> ;;    succ:       EXIT
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Gimple body of function: foo
>>>>>>> foo (int a, int b)
>>>>>>> {
>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>> ;;    pred:       ENTRY
>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>   return _3;
>>>>>>> ;;    succ:       EXIT
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>> attached herewith.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Hrishikesh
>>>>>>>
>>>>>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I have added command line options:
>>>>>>>>>
>>>>>>>>> -body=
>>>>>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>>>>>
>>>>>>>>> -optimized-blocks=
>>>>>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>>>>>
>>>>>>>>> -optimized-stats=
>>>>>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>>>>>
>>>>>>>>> -optimized-vops=
>>>>>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>>>>>
>>>>>>>> Hi.
>>>>>>>>
>>>>>>>> Thanks for it. However I would expect something more smart:
>>>>>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>>>>>> what's done in: gcc/dumpfile.c
>>>>>>>>
>>>>>>>> int
>>>>>>>> gcc::dump_manager::
>>>>>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>>>>
>>>>>>>> that will automatically parse   dump_flags_t flags;
>>>>>>>>
>>>>>>>> Then the copy&parse will not be needed.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> for example:
>>>>>>>>>
>>>>>>>>> -body=foo  will dump
>>>>>>>>>
>>>>>>>>> Gimple body of function: foo
>>>>>>>>> foo (int a, int b)
>>>>>>>>> {
>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>   return _3;
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -optimized-blocks=foo  will dump
>>>>>>>>>
>>>>>>>>> Gimple body of function: foo
>>>>>>>>> foo (int a, int b)
>>>>>>>>> {
>>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>   return _3;
>>>>>>>>> ;;    succ:       EXIT
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -optimized-stats=foo  will dump
>>>>>>>>>
>>>>>>>>> Gimple body of function: foo
>>>>>>>>> foo (int a, int b)
>>>>>>>>> {
>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>   return _3;
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -optimized-vops=foo  will dump
>>>>>>>>>
>>>>>>>>> Gimple body of function: foo
>>>>>>>>> foo (int a, int b)
>>>>>>>>> {
>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>   # VUSE <.MEM_4(D)>
>>>>>>>>>   return _3;
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>>>>>> file attached herewith.
>>>>>>>>>
>>>>>>>>> I have tried to follow the coding conventions as far as possible in
>>>>>>>>> this patch. Please let me know if I am missing out something so that I
>>>>>>>>> can improve the same while refactoring and clean up as suggested in
>>>>>>>>> the previous mail.
>>>>>>>>
>>>>>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>>>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>>>>>> one tab, which results in indentation level 8.
>>>>>>>>
>>>>>>>> Martin
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Hrishikesh
>>>>>>>>>
>>>>>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>>>>>> try to complete as early as possible.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>>>>>> gimple statements.
>>>>>>>>>>>>
>>>>>>>>>>>> For example:
>>>>>>>>>>>>
>>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>>>>>
>>>>>>>>>>>> will dump:
>>>>>>>>>>>>
>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> assignments                3        264
>>>>>>>>>>>> phi nodes                  1        248
>>>>>>>>>>>> conditionals               1         80
>>>>>>>>>>>> everything else           12        704
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>> Total                     17       1296
>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>
>>>>>>>>>>>> Regards,
>>>>>>>>>>>>
>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>> Hi.
>>>>>>>>>>>
>>>>>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>>>>>> focus now directly on refactoring:
>>>>>>>>>>>
>>>>>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>>>>>> Makefile needed stuff and commit that.
>>>>>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>>>>>> code is very hard for me
>>>>>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>>>>>
>>>>>>>>>>> Other observations:
>>>>>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>>>>>> - remove dummy 'dump' function
>>>>>>>>>>>
>>>>>>>>>>> Martin
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have added new command line option:
>>>>>>>>>>>>> -objects
>>>>>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>>>>>
>>>>>>>>>>>>> for example:
>>>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>>>>>
>>>>>>>>>>>>> gives output:
>>>>>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>>>>>
>>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>>
>>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>>>>>
>>>>>>>>>>>>>             LTO object name: test.o
>>>>>>>>>>>>>
>>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>>
>>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have:
>>>>>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>>>>>> new percentage column to it)
>>>>>>>>>>>>>> for e.g.
>>>>>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have added command line options:
>>>>>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for example command line options:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the dump is:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>
>>>>>>

[-- Attachment #2: gimple_and_tree_stats.diff --]
[-- Type: text/x-patch, Size: 2619 bytes --]

diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 75e9545..29a58e3 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -113,6 +113,14 @@ type-stats
 LTO Var(flag_lto_dump_type_stats)
 Dump the statistics of tree types.
 
+tree-stats
+LTO Var(flag_lto_tree_stats)
+Dump the statistics of trees.
+
+gimple-stats
+LTO Var(flag_lto_gimple_stats)
+Dump the statistics of gimple statements.
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 102a869..a90549f 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -3622,6 +3622,22 @@ lto_main (void)
   if (flag_lto_dump_symbol)
     dump_symbol ();
 
+  /* Dump gimple statement statistics.  */
+  if (flag_lto_gimple_stats)
+  {
+    cgraph_node *node;
+    FOR_EACH_DEFINED_FUNCTION (node)
+    node->get_untransformed_body ();
+    dump_gimple_statistics ();
+  }
+
+  /* Dump tree statistics.  */
+  if (flag_lto_tree_stats)
+  {
+    fprintf (stderr, "Tree Statistics\n");
+    dump_tree_statistics ();
+  }
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())
diff --git a/gcc/tree.c b/gcc/tree.c
index bace9c8..0d86262 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -9113,18 +9113,22 @@ dump_tree_statistics (void)
       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
       fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", "Total",
 	       total_nodes, total_bytes);
-      mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
-      fprintf (stderr, "Code                   Nodes\n");
-      mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
-      for (i = 0; i < (int) MAX_TREE_CODES; i++)
-	fprintf (stderr, "%-32s %7" PRIu64 "\n",
-		 get_tree_code_name ((enum tree_code) i), tree_code_counts[i]);
-      mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
-      fprintf (stderr, "\n");
-      ssanames_print_statistics ();
-      fprintf (stderr, "\n");
-      phinodes_print_statistics ();
-      fprintf (stderr, "\n");
+      if (!flag_lto_tree_stats)
+      {
+	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
+	fprintf (stderr, "Code                   Nodes\n");
+	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
+	for (i = 0; i < (int) MAX_TREE_CODES; i++)
+	  fprintf (stderr, "%-32s %7" PRIu64 "\n",
+		   get_tree_code_name ((enum tree_code) i),
+		   tree_code_counts[i]);
+	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
+	fprintf (stderr, "\n");
+	ssanames_print_statistics ();
+	fprintf (stderr, "\n");
+	phinodes_print_statistics ();
+	fprintf (stderr, "\n");
+      }
     }
   else
     fprintf (stderr, "(No per-node statistics)\n");

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

* Re: [GSOC] LTO dump tool project
  2018-07-28 16:54                                                                         ` Hrishikesh Kulkarni
@ 2018-07-31  6:25                                                                           ` Hrishikesh Kulkarni
  0 siblings, 0 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-07-31  6:25 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Martin Jambor, Richard Biener

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

Hi,

I have added command line options
-fdump-level=
-fdump-body=
to dump specific optimized body of specified function.

I have made the necessary changes as suggested to avoid manual parsing.

I have pushed the changes to the branch lto-dump-tool-v4. Please find
the diff file attached herewith.

Regards,

Hrishikesh

On Sat, Jul 28, 2018 at 8:47 PM, Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
> Hi,
>
> I have added command line options
> -gimple-stats to dump GIMPLE statistics
> -tree-stats to dump TREE statistics
>
> I have pushed the changes to the new branch. Please find the diff file
> attached herewith.
>
> Regards,
>
> Hrishikesh
>
> On Fri, Jul 27, 2018 at 11:15 PM, Hrishikesh Kulkarni
> <hrishikeshparag@gmail.com> wrote:
>> Hi,
>>
>> I have added command line option -type-stats to the new branch which
>> dumps the statistics of tree types.
>> As suggested hash_map is used from hash-map.h.
>>
>> Please find the patch attached herewith.
>>
>> Regards,
>>
>> Hrishikesh
>>
>> On Tue, Jul 24, 2018 at 10:42 PM, Hrishikesh Kulkarni
>> <hrishikeshparag@gmail.com> wrote:
>>> Hi,
>>>
>>> Please find the patch for dumping details of LTO objects attached herewith.
>>> I have also added the changes to the new branch (lto-dump-tool-v4).
>>>
>>> Regards,
>>>
>>> Hrishikesh
>>>
>>> On Mon, Jul 23, 2018 at 10:28 PM, Hrishikesh Kulkarni
>>> <hrishikeshparag@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Please find the patch for dumping detail information of a specified
>>>> symbol attached herewith.
>>>> I have also pushed the changes to the new branch (lto-dump-tool-v4).
>>>>
>>>> Regards,
>>>>
>>>> Hrishikesh
>>>>
>>>> On Sun, Jul 22, 2018 at 2:39 AM, Hrishikesh Kulkarni
>>>> <hrishikeshparag@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> Please find the patch for dumping list of symbols(incorporating your
>>>>> suggestions) attached herewith.
>>>>> I have created a new branch lto-dump-tool-v4 and pushed the changes to it.
>>>>>
>>>>> Command line options used are:
>>>>> -list
>>>>> -demangle
>>>>> -no-demangle
>>>>> -defined-only
>>>>> -print-value
>>>>> -alpha-sort
>>>>> -size-sort
>>>>> -reverse-sort
>>>>> -no-sort
>>>>>
>>>>> Mean while I am working on doing the parsing using dump_switch_p_1
>>>>> infrastructure.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Hrishikesh
>>>>>
>>>>> On Wed, Jul 18, 2018 at 11:14 PM, Hrishikesh Kulkarni
>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I tried doing as suggested
>>>>>>
>>>>>> +  dfi.pflags = 0;
>>>>>> +  dump_switch_p_1 (arg, &dfi, false);
>>>>>>
>>>>>> 1.>  the value of dfi.pflags is not changing even if different command
>>>>>> line options are passed like -fdump-blocks or -fdump-vops
>>>>>>
>>>>>> 2.> what is the significance of bool doglob?
>>>>>>
>>>>>> Please find the diff file attached herewith.
>>>>>>
>>>>>> Please advise.
>>>>>>
>>>>>> Hrishikesh
>>>>>>
>>>>>> On Tue, Jul 17, 2018 at 6:30 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>> On 07/16/2018 05:44 PM, Hrishikesh Kulkarni wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> As suggested I have created command line option -optimized=[none,
>>>>>>>> blocks, stats, vops] to dump the respective gimple bodies of all
>>>>>>>> functions.
>>>>>>>>
>>>>>>>> for example:
>>>>>>>>
>>>>>>>> -optimized=blocks will dump
>>>>>>>
>>>>>>>
>>>>>>> Hi.
>>>>>>>
>>>>>>> The name does not make much sense and you removed option that
>>>>>>> limited function name. So instead I would create something like:
>>>>>>>
>>>>>>> -fdump-body=foo
>>>>>>> and
>>>>>>> -fdump-level=optimized
>>>>>>>
>>>>>>> I don't like how you do manual parsing in:
>>>>>>> +  if (!strcmp (flag_optimized, "blocks"))
>>>>>>> +    flags = TDF_BLOCKS;
>>>>>>> +  else if (!strcmp (flag_optimized, "stats"))
>>>>>>> +    flags = TDF_STATS;
>>>>>>> +  else if (!strcmp (flag_optimized, "vops"))
>>>>>>> +    flags = TDF_VOPS;
>>>>>>> +  else if (!strcmp (flag_optimized, "none"))
>>>>>>> +    flags = TDF_NONE;
>>>>>>>
>>>>>>> As I wrote in previous email, take a look how it's done
>>>>>>> in dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>>> and reuse that functionality.
>>>>>>>
>>>>>>> Martin
>>>>>>>
>>>>>>>>
>>>>>>>> Gimple body of function: main
>>>>>>>> main ()
>>>>>>>> {
>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>   printf ("%d", 8);
>>>>>>>>   return 0;
>>>>>>>> ;;    succ:       EXIT
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> Gimple body of function: bar
>>>>>>>> bar (int a, int b, int cond)
>>>>>>>> {
>>>>>>>>   int ret;
>>>>>>>>
>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>   if (cond_2(D) != 0)
>>>>>>>>     goto <bb 3>; [50.00%]
>>>>>>>>   else
>>>>>>>>     goto <bb 4>; [50.00%]
>>>>>>>> ;;    succ:       3
>>>>>>>> ;;                4
>>>>>>>>
>>>>>>>> ;;   basic block 3, loop depth 0
>>>>>>>> ;;    pred:       2
>>>>>>>>   ret_5 = a_3(D) + b_4(D);
>>>>>>>>   goto <bb 5>; [100.00%]
>>>>>>>> ;;    succ:       5
>>>>>>>>
>>>>>>>> ;;   basic block 4, loop depth 0
>>>>>>>> ;;    pred:       2
>>>>>>>>   ret_6 = a_3(D) - b_4(D);
>>>>>>>> ;;    succ:       5
>>>>>>>>
>>>>>>>> ;;   basic block 5, loop depth 0
>>>>>>>> ;;    pred:       3
>>>>>>>> ;;                4
>>>>>>>>   # ret_1 = PHI <ret_5(3), ret_6(4)>
>>>>>>>>   return ret_1;
>>>>>>>> ;;    succ:       EXIT
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> Gimple body of function: foo
>>>>>>>> foo (int a, int b)
>>>>>>>> {
>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>   return _3;
>>>>>>>> ;;    succ:       EXIT
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>> attached herewith.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> Hrishikesh
>>>>>>>>
>>>>>>>> On Fri, Jul 13, 2018 at 2:47 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>> On 07/12/2018 08:05 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have added command line options:
>>>>>>>>>>
>>>>>>>>>> -body=
>>>>>>>>>> To dump gimple body (TDF_NONE) of specific function.
>>>>>>>>>>
>>>>>>>>>> -optimized-blocks=
>>>>>>>>>> To dump gimple body (TDF_BLOCKS) of specific function.
>>>>>>>>>>
>>>>>>>>>> -optimized-stats=
>>>>>>>>>> To dump gimple body (TDF_STATS) of specific function.
>>>>>>>>>>
>>>>>>>>>> -optimized-vops=
>>>>>>>>>> To dump gimple body (TDF_VOPS) of specific function.
>>>>>>>>>
>>>>>>>>> Hi.
>>>>>>>>>
>>>>>>>>> Thanks for it. However I would expect something more smart:
>>>>>>>>> -optimized=[vops,stats,block]. Note that you should do similar
>>>>>>>>> what's done in: gcc/dumpfile.c
>>>>>>>>>
>>>>>>>>> int
>>>>>>>>> gcc::dump_manager::
>>>>>>>>> dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
>>>>>>>>>
>>>>>>>>> that will automatically parse   dump_flags_t flags;
>>>>>>>>>
>>>>>>>>> Then the copy&parse will not be needed.
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> for example:
>>>>>>>>>>
>>>>>>>>>> -body=foo  will dump
>>>>>>>>>>
>>>>>>>>>> Gimple body of function: foo
>>>>>>>>>> foo (int a, int b)
>>>>>>>>>> {
>>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>>   return _3;
>>>>>>>>>>
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> -optimized-blocks=foo  will dump
>>>>>>>>>>
>>>>>>>>>> Gimple body of function: foo
>>>>>>>>>> foo (int a, int b)
>>>>>>>>>> {
>>>>>>>>>> ;;   basic block 2, loop depth 0
>>>>>>>>>> ;;    pred:       ENTRY
>>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>>   return _3;
>>>>>>>>>> ;;    succ:       EXIT
>>>>>>>>>>
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> -optimized-stats=foo  will dump
>>>>>>>>>>
>>>>>>>>>> Gimple body of function: foo
>>>>>>>>>> foo (int a, int b)
>>>>>>>>>> {
>>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>>   return _3;
>>>>>>>>>>
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> -optimized-vops=foo  will dump
>>>>>>>>>>
>>>>>>>>>> Gimple body of function: foo
>>>>>>>>>> foo (int a, int b)
>>>>>>>>>> {
>>>>>>>>>>   <bb 2> [local count: 1073741825]:
>>>>>>>>>>   _3 = a_1(D) + b_2(D);
>>>>>>>>>>   # VUSE <.MEM_4(D)>
>>>>>>>>>>   return _3;
>>>>>>>>>>
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> I have pushed the changes to the current branch. Please find the diff
>>>>>>>>>> file attached herewith.
>>>>>>>>>>
>>>>>>>>>> I have tried to follow the coding conventions as far as possible in
>>>>>>>>>> this patch. Please let me know if I am missing out something so that I
>>>>>>>>>> can improve the same while refactoring and clean up as suggested in
>>>>>>>>>> the previous mail.
>>>>>>>>>
>>>>>>>>> As mentioned in the previous email, indentation level is 2. And every 8 spaces
>>>>>>>>> are replaced with a tabular. In our patch, you use indentation level equal to
>>>>>>>>> one tab, which results in indentation level 8.
>>>>>>>>>
>>>>>>>>> Martin
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Hrishikesh
>>>>>>>>>>
>>>>>>>>>> On Wed, Jul 11, 2018 at 12:10 AM, Hrishikesh Kulkarni
>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> Thanks for suggestions. I would start working on these points and will
>>>>>>>>>>> try to complete as early as possible.
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Jul 9, 2018 at 2:04 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>> On 07/09/2018 09:50 AM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> The command line option -gimple-stats will dump the statistics of
>>>>>>>>>>>>> gimple statements.
>>>>>>>>>>>>>
>>>>>>>>>>>>> For example:
>>>>>>>>>>>>>
>>>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o -gimple-stats
>>>>>>>>>>>>>
>>>>>>>>>>>>> will dump:
>>>>>>>>>>>>>
>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> assignments                3        264
>>>>>>>>>>>>> phi nodes                  1        248
>>>>>>>>>>>>> conditionals               1         80
>>>>>>>>>>>>> everything else           12        704
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>> Total                     17       1296
>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>
>>>>>>>>>>>> Hi.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks for the work. I briefly took a look at the code and I would
>>>>>>>>>>>> focus now directly on refactoring:
>>>>>>>>>>>>
>>>>>>>>>>>> - please make a new branch, first copy lto-dump.c file and all the
>>>>>>>>>>>> Makefile needed stuff and commit that.
>>>>>>>>>>>> - next please rebase (squash) all your patches which you have on top
>>>>>>>>>>>> of it; you did some formatting corrections and it's very hard to read
>>>>>>>>>>>> - please fix coding style, it's mentioned here: https://gcc.gnu.org/codingconventions.html
>>>>>>>>>>>> the most problematic is usage of horizontal white spaces. We use 2 spaces
>>>>>>>>>>>> for indentation level, and 8 spaces are replaced with a tabular; without that reading your
>>>>>>>>>>>> code is very hard for me
>>>>>>>>>>>> - then please start refactoring functionality that is copied from lto.c and put shared
>>>>>>>>>>>> stuff into a header file that will be used by lto.c and lto-dump.c.
>>>>>>>>>>>>
>>>>>>>>>>>> Other observations:
>>>>>>>>>>>> - you use "\t\t%s\t\t%s\t\t%s" formats for prints; I think it would be better to
>>>>>>>>>>>> use fixed strings with spaces, try %20s. It's probably also used by tools like nm or objdump
>>>>>>>>>>>> - come up with more specific name for 'entry' and 'compare'
>>>>>>>>>>>> - 'entry' should have functions that will print names, ... according to options
>>>>>>>>>>>> (flag_lto_dump_demangle, ...); you can have overrides for functions and variables
>>>>>>>>>>>> - I would first put all symbols into the vector and then I would print it on a single place
>>>>>>>>>>>> - consider using vec from vec.h, hash_map from hash-map.h instead of std:: variants
>>>>>>>>>>>> - exit after functions like dump_list, dump_symbol,...
>>>>>>>>>>>> - remove dummy 'dump' function
>>>>>>>>>>>>
>>>>>>>>>>>> Martin
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Thu, Jul 5, 2018 at 10:41 PM, Hrishikesh Kulkarni
>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have added new command line option:
>>>>>>>>>>>>>> -objects
>>>>>>>>>>>>>> which will dump size, offset and name of each section for all lto objects
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>> $ ../stage1-build/gcc/lto-dump test_hello.o test.o -objects
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> gives output:
>>>>>>>>>>>>>>             LTO object name: test_hello.o
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.a7add72ac123628
>>>>>>>>>>>>>> 2        79        55        .gnu.lto_.icf.a7add72ac123628
>>>>>>>>>>>>>> 3        134        134        .gnu.lto_.jmpfuncs.a7add72ac123628
>>>>>>>>>>>>>> 4        268        116        .gnu.lto_.inline.a7add72ac123628
>>>>>>>>>>>>>> 5        384        24        .gnu.lto_.pureconst.a7add72ac123628
>>>>>>>>>>>>>> 6        408        306        .gnu.lto_foo.a7add72ac123628
>>>>>>>>>>>>>> 7        714        469        .gnu.lto_bar.a7add72ac123628
>>>>>>>>>>>>>> 8        1183        345        .gnu.lto_main.a7add72ac123628
>>>>>>>>>>>>>> 9        1528        88        .gnu.lto_.symbol_nodes.a7add72ac123628
>>>>>>>>>>>>>> 10        1616        15        .gnu.lto_.refs.a7add72ac123628
>>>>>>>>>>>>>> 11        1631        1205        .gnu.lto_.decls.a7add72ac123628
>>>>>>>>>>>>>> 12        2836        109        .gnu.lto_.symtab.a7add72ac123628
>>>>>>>>>>>>>> 13        2945        76        .gnu.lto_.opts
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>             LTO object name: test.o
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> NO.        OFFSET        SIZE        SECTION NAME
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 1        64        15        .gnu.lto_.profile.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 2        79        30        .gnu.lto_.icf.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 3        109        108        .gnu.lto_.jmpfuncs.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 4        217        62        .gnu.lto_.inline.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 5        279        21        .gnu.lto_.pureconst.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 6        300        194        .gnu.lto_koo.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 7        494        389        .gnu.lto_gain.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 8        883        77        .gnu.lto_.symbol_nodes.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 9        960        15        .gnu.lto_.refs.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 10        975        966        .gnu.lto_.decls.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 11        1941        58        .gnu.lto_.symtab.ffab9cb8eb84fc03
>>>>>>>>>>>>>> 12        1999        76        .gnu.lto_.opts
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Thu, Jul 5, 2018 at 12:24 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have:
>>>>>>>>>>>>>>> tried to do all the formatting and style corrections according to
>>>>>>>>>>>>>>> output given by check_GNU_style.py
>>>>>>>>>>>>>>> removed '-fdump-lto' prefix from the command line options
>>>>>>>>>>>>>>> added few necessary comments in the code
>>>>>>>>>>>>>>> added command line option -type-stats from previous branch (added a
>>>>>>>>>>>>>>> new percentage column to it)
>>>>>>>>>>>>>>> for e.g.
>>>>>>>>>>>>>>>     integer_type    3    25.00%
>>>>>>>>>>>>>>>     pointer_type    3    25.00%
>>>>>>>>>>>>>>>     array_type    1    8.33%
>>>>>>>>>>>>>>>     function_type    5    41.67%
>>>>>>>>>>>>>>> I have pushed the changes  to the repo. Please find the diff file
>>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Tue, Jul 3, 2018 at 6:39 PM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks for suggestions. I have started incorporating them. As a first:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have added command line options:
>>>>>>>>>>>>>>>> -print-size  to print the size of functions and variables
>>>>>>>>>>>>>>>> size of variables is in bits and size of functions is represented as
>>>>>>>>>>>>>>>> number of basic blocks.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> -print-value  to print the value of initialization of global variables.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> -size-sort  to sort the symbol names according to the size.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for example command line options:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>  ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -print-size
>>>>>>>>>>>>>>>> -print-value -size-sort
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the dump is:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>>         Name         Type         Visibility        Size     Value
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>         printf         function        default           0
>>>>>>>>>>>>>>>>         main         function        default           3
>>>>>>>>>>>>>>>>         foo            function        default           3
>>>>>>>>>>>>>>>>         bar            function        default           6
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>         z               variable        default           8        97
>>>>>>>>>>>>>>>>         k               variable        default          32        5
>>>>>>>>>>>>>>>>         p               variable        default          32
>>>>>>>>>>>>>>>> 4.400000095367431640625e+0
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have also tried to make memory allocation dynamic to the best of my knowledge.
>>>>>>>>>>>>>>>> I have pushed the changes to the repo. Please find the diff file
>>>>>>>>>>>>>>>> attached herewith.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Regards,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Fri, Jun 29, 2018 at 12:55 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>> On 06/27/2018 10:06 PM, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I have added new command line options:
>>>>>>>>>>>>>>>>>> -no-demangle -> for the default non demangled output
>>>>>>>>>>>>>>>>>> -no-sort -> for the list of symbols in order of their occurrence
>>>>>>>>>>>>>>>>>> -alpha-sort -> for the list of symbols in their alphabetical order
>>>>>>>>>>>>>>>>>> -reverse-sort -> for the list of symbols in reversed order
>>>>>>>>>>>>>>>>>> -defined-only -> for only the defined symbols
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Good progress.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> ../stage1-build/gcc/lto-dump test_hello.o -fdump-lto-list -alpha-sort
>>>>>>>>>>>>>>>>>> -demangle -defined-only -reverse-sort
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Now as you have a separate tool (lto-dump), you can strip 'fdump-lto' prefix
>>>>>>>>>>>>>>>>> from the older options.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> will dump
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Symbol Table
>>>>>>>>>>>>>>>>>>         Name         Type         Visibility         Size
>>>>>>>>>>>>>>>>>>         main        function        default
>>>>>>>>>>>>>>>>>>         k        variable        default
>>>>>>>>>>>>>>>>>>         foo        function        default
>>>>>>>>>>>>>>>>>>         bar        function        default
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> It is a reversed alphabetical order of demangled symbol names which
>>>>>>>>>>>>>>>>>> have been defined(hence printf excluded).
>>>>>>>>>>>>>>>>>> Along with this I have also added all previous progress with reference
>>>>>>>>>>>>>>>>>> to symbol table to the new branch.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> For further options to add like -size-sort and -print-size I tried to
>>>>>>>>>>>>>>>>>> access size of the symbol with symtab node using
>>>>>>>>>>>>>>>>>> TREE_INT_CST_LOW(DECL_SIZE(node->decl));
>>>>>>>>>>>>>>>>>> but I am unable to do so.
>>>>>>>>>>>>>>>>>> So how should I proceed with it?
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Sent advises via instant messaging.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please find the diff file attached herewith. I have also pushed the
>>>>>>>>>>>>>>>>>> changes to the new branch.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hrishikesh>
>>>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:15 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and
>>>>>>>>>>>>>>>>>>> GIMPLE statistics.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On Wed, Jun 27, 2018 at 1:00 AM, Hrishikesh Kulkarni
>>>>>>>>>>>>>>>>>>> <hrishikeshparag@gmail.com> wrote:
>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I have created another branch lto-dump-tool-improved as suggested.
>>>>>>>>>>>>>>>>>>>> I have applied the patch for separation to lto-dump binary, made a few
>>>>>>>>>>>>>>>>>>>> necessary changes in other files and it is running successfully.
>>>>>>>>>>>>>>>>>>>> I will keep on adding previous work to this branch incrementally.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Please find the diff file attached for dumping of TREE statistics and GIMPLE
>>>>>>>>>>>>>>>>>>>> statistics.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> for example:
>>>>>>>>>>>>>>>>>>>> (after configuring with --enable-gather-detailed-mem-stats)
>>>>>>>>>>>>>>>>>>>> -fdump-lto-gimple-stats will dump
>>>>>>>>>>>>>>>>>>>> GIMPLE statements
>>>>>>>>>>>>>>>>>>>> Kind                   Stmts      Bytes
>>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>>> assignments                0          0
>>>>>>>>>>>>>>>>>>>> phi nodes                  0          0
>>>>>>>>>>>>>>>>>>>> conditionals               0          0
>>>>>>>>>>>>>>>>>>>> everything else            0          0
>>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>>> Total                      0          0
>>>>>>>>>>>>>>>>>>>> ---------------------------------------
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> -fdump-lto-tree-stats will dump
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Tree Statistics
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Kind                   Nodes      Bytes
>>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>>> decls                   4327     932672
>>>>>>>>>>>>>>>>>>>> types                   1531     257208
>>>>>>>>>>>>>>>>>>>> blocks                     0          0
>>>>>>>>>>>>>>>>>>>> stmts                      0          0
>>>>>>>>>>>>>>>>>>>> refs                       0          0
>>>>>>>>>>>>>>>>>>>> exprs                      4        128
>>>>>>>>>>>>>>>>>>>> constants                 82       2060
>>>>>>>>>>>>>>>>>>>> identifiers             4430     177200
>>>>>>>>>>>>>>>>>>>> vecs                      16      28544
>>>>>>>>>>>>>>>>>>>> binfos                     0          0
>>>>>>>>>>>>>>>>>>>> ssa names                  0          0
>>>>>>>>>>>>>>>>>>>> constructors               0          0
>>>>>>>>>>>>>>>>>>>> random kinds            7301     291952
>>>>>>>>>>>>>>>>>>>> lang_decl kinds            0          0
>>>>>>>>>>>>>>>>>>>> lang_type kinds            0          0
>>>>>>>>>>>>>>>>>>>> omp clauses                0          0
>>>>>>>>>>>>>>>>>>>> ----------------------------------------
>>>>>>>>>>>>>>>>>>>> Total                  17691    1689764
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Please advise,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Hrishikesh
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On Fri, Jun 22, 2018 at 2:29 PM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> On 06/18/2018 10:45 AM, Martin Jambor wrote:
>>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> On Sun, Jun 17 2018, Hrishikesh Kulkarni wrote:
>>>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> I am trying to isolate the dump tool into real lto-dump tool. I have
>>>>>>>>>>>>>>>>>>>>>>> started with the copy&paste of lto.c into lto-dump.c and done the
>>>>>>>>>>>>>>>>>>>>>>> changes to Make-lang.in and config-lang.in suggested by Martin (patch
>>>>>>>>>>>>>>>>>>>>>>> attached). However when I try to build, I get the following error:
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> In file included from ../../gcc/gcc/lto/lto-dump.c:24:0:
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> ../../gcc/gcc/coretypes.h:397:24: fatal error: insn-modes.h: No such
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> file or directory
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> compilation terminated.
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> I am unable to find the missing dependencies and would be grateful for
>>>>>>>>>>>>>>>>>>>>>>> suggestions on how to resolve the issue.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> insn-modes.h is one of header files which are generated at build time,
>>>>>>>>>>>>>>>>>>>>>> you will find it in the gcc subdirectory of your build directory (as
>>>>>>>>>>>>>>>>>>>>>> opposed to the source directory).
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Hi.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> There's patch that works for me.
>>>>>>>>>>>>>>>>>>>>> Needed dependency is here:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> +lto/lto-dump.o: $(LTO_EXE)
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> It's bit artificial, but for now it works. Please start working
>>>>>>>>>>>>>>>>>>>>> on separation of dump infrastructure to lto-dump.c. You'll need
>>>>>>>>>>>>>>>>>>>>> to factor out common code shared in between lto.c and lto-dump.c.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Martin
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>
>>>>>>>

[-- Attachment #2: optimized_body.diff --]
[-- Type: text/x-patch, Size: 3420 bytes --]

diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 6c9920c..6ebb665 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -123,6 +123,7 @@ static struct dump_file_info dump_files[TDI_end] =
    in dumpfile.h and opt_info_options below. */
 static const kv_pair<dump_flags_t> dump_options[] =
 {
+  {"none", TDF_NONE},
   {"address", TDF_ADDRESS},
   {"asmname", TDF_ASMNAME},
   {"slim", TDF_SLIM},
@@ -1298,6 +1299,33 @@ opt_info_enable_passes (optgroup_flags_t optgroup_flags, dump_flags_t flags,
   return n;
 }
 
+dump_flags_t
+parse_dump_option (const char *option_value)
+{
+  dump_flags_t flags = TDF_NONE;
+  const char *ptr = option_value;
+
+  const struct kv_pair<dump_flags_t> *option_ptr;
+  const char *eq_ptr;
+  unsigned length;
+
+  eq_ptr = strchr (ptr, '=');
+
+  length = strlen (eq_ptr) -1;
+  ptr = eq_ptr;
+  ptr++;
+
+  for (option_ptr = dump_options; option_ptr->name; option_ptr++)
+    if (strlen (option_ptr->name) == length
+	&& !memcmp (option_ptr->name, ptr, length))
+    {
+      flags |= option_ptr->value;
+      break;
+    }
+
+  return flags;
+}
+
 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
    relevant details in the dump_files array.  */
 
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h
index ad14acd..7b560fc 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -421,6 +421,8 @@ extern void dump_end (int, FILE *);
 extern int opt_info_switch_p (const char *);
 extern const char *dump_flag_name (int);
 extern const kv_pair<optgroup_flags_t> optgroup_options[];
+extern dump_flags_t
+parse_dump_option (const char *);
 
 /* Global variables used to communicate with passes.  */
 extern FILE *dump_file;
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 29a58e3..88a8598 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -121,6 +121,12 @@ gimple-stats
 LTO Var(flag_lto_gimple_stats)
 Dump the statistics of gimple statements.
 
+fdump-level=
+LTO Driver RejectNegative Joined Var(flag_dump_level)
+
+fdump-body=
+LTO Driver RejectNegative Joined Var(flag_dump_body)
+
 fresolution=
 LTO Joined
 The resolution file.
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index a90549f..7ba1a6a 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "cfg.h"
 #include "cfghooks.h"
+#include "tree-cfg.h"
 #include "alloc-pool.h"
 #include "tree-pass.h"
 #include "tree-streamer.h"
@@ -234,6 +235,28 @@ dump_symbol ()
   fprintf (stderr, "\n");
 }
 
+/* Dump specific gimple body of specified function.  */
+void
+dump_body ()
+{
+  dump_flags_t flags;
+
+  char buf[100];
+  sprintf (buf, "-level=%s", flag_dump_level);
+  flags = parse_dump_option (buf);
+
+  cgraph_node *cnode;
+  FOR_EACH_FUNCTION (cnode)
+  {
+    if (cnode->definition && !strcmp (cnode->name (), flag_dump_body))
+    {
+      fprintf (stderr, "Gimple body of function: %s\n", cnode->name ());
+      cnode->get_untransformed_body ();
+      debug_function (cnode->decl, flags);
+    }
+  }
+}
+
 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
 static int lto_parallelism;
 
@@ -3638,6 +3661,10 @@ lto_main (void)
     dump_tree_statistics ();
   }
 
+  /* Dump specific gimple body of specified function.  */
+  if (flag_dump_level && flag_dump_body)
+    dump_body ();
+
   timevar_stop (TV_PHASE_STREAM_IN);
 
   if (!seen_error ())

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

* [GSOC] LTO dump tool project - feedback
  2018-05-29 17:03 [GSOC] LTO dump tool project Hrishikesh Kulkarni
  2018-05-29 17:17 ` Prathamesh Kulkarni
  2018-05-29 17:38 ` Martin Liška
@ 2018-08-01 13:29 ` Martin Liška
  2018-08-03 13:47   ` Hrishikesh Kulkarni
  2 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-08-01 13:29 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

Hi.

I decided to come up with a new sub-thread that will be linked
to a root of email discussion. First, thank you for working on
the project and there's a feedback that I can provide now:

1) options of lto-dump:
   a) no-demangle - does not make sense because it's default
   b) you should exit after one command, you probably don't want to support:
       -list bzlib.o -tree-stats
   c) following should be maybe handled:
      $ lto-dump -list bzlib.o bzlib.o

bzlib.c:468:5: note: previously defined here
bzlib.c:407:5: error: ‘BZ2_bzCompress’ has already been defined
 int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
     ^
bzlib.c:407:5: note: previously defined here
bzlib.c:148:5: error: ‘BZ2_bzCompressInit’ has already been defined
 int BZ_API(BZ2_bzCompressInit)

   d) you should add --help option, take a look at gcov-dump --help, or gcov --help,
      or gcov-tool --help.
   e) alpha-sort - maybe name-sort, or alphabetic-sort?

2) output formatting
   a) you mix usage of tabulars and fixed columns (%10d), please use the later
      at all places
   b) I see a lot of extra output when using the tool:
...
Reading object files: bzlib.o {GC start 2164k} 
Reading the callgraph
Merging declarations
Reading summaries
Reading function bodies:
Performing interprocedural optimizations
 <whole-program> <profile_estimate> <icf> in:BZ2_bzCompressEnd in:BZ2_bzDecompressEnd <devirt> <cp> <cdtor> <fnsummary> <inline> <pure-const> <free-fnsummary> <static-var> <single-use> <comdats>Assembling functions:
 <materialize-all-clones> <simdclone> add_pair_to_block in:add_pair_to_block default_bzfree in:default_bzfree default_bzalloc in:default_bzalloc handle_compress.isra.2 in:handle_compress.isra.2 in:copy_output_until_stop in:copy_input_until_stop BZ2_bz__AssertH__fail in:BZ2_bz__AssertH__fail BZ2_bzCompressInit in:BZ2_bzCompressInit BZ2_bzCompress in:BZ2_bzCompress BZ2_bzCompressEnd BZ2_bzDecompressInit in:BZ2_bzDecompressInit BZ2_indexIntoF in:BZ2_indexIntoF BZ2_bzDecompress in:BZ2_bzDecompress in:unRLE_obuf_to_output_SMALL in:unRLE_obuf_to_output_FAST {GC 5331k -> 2747k} BZ2_bzDecompressEnd BZ2_bzWriteOpen in:BZ2_bzWriteOpen in:BZ2_bzWriteOpen.part.3 BZ2_bzWrite in:BZ2_bzWrite in:BZ2_bzWrite.part.4 BZ2_bzWriteClose64 in:BZ2_bzWriteClose64 in:BZ2_bzWriteClose64.part.5 BZ2_bzWriteClose in:BZ2_bzWriteClose BZ2_bzReadOpen in:BZ2_bzReadOpen in:BZ2_bzReadOpen.part.6 {GC 5332k -> 2307k} bzopen_or_bzdopen in:bzopen_or_bzdopen BZ2_bzReadClose in:BZ2_bzReadClose in:BZ2_bzReadClose.part.7 BZ2_bzRead in:BZ2_bzRead in:BZ2_bzRead.part.8 in:myfeof BZ2_bzReadGetUnused in:BZ2_bzReadGetUnused in:BZ2_bzReadGetUnused.part.9 BZ2_bzBuffToBuffCompress in:BZ2_bzBuffToBuffCompress BZ2_bzBuffToBuffDecompress in:BZ2_bzBuffToBuffDecompress BZ2_bzlibVersion in:BZ2_bzlibVersion BZ2_bzopen in:BZ2_bzopen BZ2_bzdopen in:BZ2_bzdopen BZ2_bzread in:BZ2_bzread in:BZ2_bzread.part.10 BZ2_bzwrite in:BZ2_bzwrite BZ2_bzflush in:BZ2_bzflush BZ2_bzclose in:BZ2_bzclose BZ2_bzerror in:BZ2_bzerror in:bzerrorstrings
...

please remove it
   c) you mix all upper letters in header of lists, please unify that (Visibility, SECTION NAME)
   d) -gimple-stats does not work for me, no output and -tree-stats definitely not print all trees used
   e) you should not require -fdump-level for -fdump-body, select a default value for the level please
   f) why -fdump-level and -fdump-body start with '-f'

3) written source code
   a) I need following patch to build it:
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 9a1ff61852c..48fc7d9a181 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -370,4 +370,4 @@ lto_main (void)
   timevar_push (TV_PARSE_GLOBAL);
 }
 
-#include "gt-lto-lto.h"
+//#include "gt-lto-lto.h"
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index bc61d25f61d..301ed4b2e25 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -143,4 +143,4 @@ lto_main (void)
   timevar_push (TV_PARSE_GLOBAL);
 }
 
-#include "gt-lto-lto.h"
+//#include "gt-lto-lto.h"

can you please check it?

   b) you added parse_dump_option, but it's used only in dump-lto.c, why not in dumpfile.c?
   c) lto-dump.c still contains a lot of code in lto_main that's not needed (and is responsible
      for extra output)
   e) you moved all to lto-common.c, but functionality exclusively used only in lto.c should remain there
   f) you should probably dump to stdout, rather that stderr
   g) there are still quite some functions in lto-dump.c that are missing comment, lto_main comment should
      be rewritten
4) misc
   a) lto-dump should be installed with 'make install', similarly as lto1 is
   b) lto-dump command option should be documentation, again take a look for gcov-dump, gcov, gcov-tool (*.texi file)
   c) would be nice to have some test-cases for that, but it's probably out of scope of the project
   d) I bet there will be quite some extra includes of header file in lto-dump.c, please adjust file comment and
      year of creation

Martin

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

* Re: [GSOC] LTO dump tool project - feedback
  2018-08-01 13:29 ` [GSOC] LTO dump tool project - feedback Martin Liška
@ 2018-08-03 13:47   ` Hrishikesh Kulkarni
  2018-08-15 12:01     ` Martin Liška
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-08-03 13:47 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

Thanks for inputs and feedback. As per feedback, I have made all the
corrections/changes to the best of my understanding. Please find
details of the same given below.:
1) options of lto-dump:
a) removed the no-demangle command line option as it is default.
b) exit added after every dump. (to make it execute separately)
c) Made necessary change to consider single occurrence of object file
even if there are multiple occurrences.
d) -help option added.
e) alpha-sort renamed as name-sort,
flag_lto_alpha_sort renamed as flag_lto_name_sort,
alpha_compare() renamed as name_compare().

2) output formatting:
a) All '\t' replaced with (%10d) format.
b) Made necessary changes to remove extra output.
c) All list headers unified in a way that first letter is capital.
d) Made changes so that all used trees are printed. For gimple stats I
tried configuring with --enable-gather-detailed-mem-stats which worked
for me.
e) TDF_NONE made default level, -dump-body= can be invoked without -dump-level=
f)Renamed the command line options as -dump-body=, -dump-level=

3) written source code:
a) Deleted the header "gt-lto-lto.h" from lto.c and lto-dump.c and
added to lto-common.c
b) Modified parse_dump_option() and used in dumpfile.c.
c) Unnecessary code from lto_main() in lto-dump.c deleted.
e) Shifted all the functionalities used exclusively in lto.c from
lto-common.c to lto.c.
f) Used stdout instead of stderr.
g) Added/rewritten comments for all functions and structs and also for
lto_main().

4) misc:
a) Tried to modify make file for 'make install' of lto-dump. (diff
file attached)
b) Documented the lto-dump-tool command line options in
lto-dump-tool.texi could not link it in makefile. (diff file attached)
d) Removed all extra headers from lto-dump.c, added year of creation
and file comments.

I have pushed all the changes to the branch lto-dump-tool-v4.

I am facing some issue while modifying the Makefile for the points 4.a
and 4.b. Please find the diff file for the same attached herewith.

Thanks and Regards,

Hrishikesh

On Wed, Aug 1, 2018 at 6:59 PM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> I decided to come up with a new sub-thread that will be linked
> to a root of email discussion. First, thank you for working on
> the project and there's a feedback that I can provide now:
>
> 1) options of lto-dump:
>    a) no-demangle - does not make sense because it's default
>    b) you should exit after one command, you probably don't want to support:
>        -list bzlib.o -tree-stats
>    c) following should be maybe handled:
>       $ lto-dump -list bzlib.o bzlib.o
>
> bzlib.c:468:5: note: previously defined here
> bzlib.c:407:5: error: ‘BZ2_bzCompress’ has already been defined
>  int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
>      ^
> bzlib.c:407:5: note: previously defined here
> bzlib.c:148:5: error: ‘BZ2_bzCompressInit’ has already been defined
>  int BZ_API(BZ2_bzCompressInit)
>
>    d) you should add --help option, take a look at gcov-dump --help, or gcov --help,
>       or gcov-tool --help.
>    e) alpha-sort - maybe name-sort, or alphabetic-sort?
>
> 2) output formatting
>    a) you mix usage of tabulars and fixed columns (%10d), please use the later
>       at all places
>    b) I see a lot of extra output when using the tool:
> ...
> Reading object files: bzlib.o {GC start 2164k}
> Reading the callgraph
> Merging declarations
> Reading summaries
> Reading function bodies:
> Performing interprocedural optimizations
>  <whole-program> <profile_estimate> <icf> in:BZ2_bzCompressEnd in:BZ2_bzDecompressEnd <devirt> <cp> <cdtor> <fnsummary> <inline> <pure-const> <free-fnsummary> <static-var> <single-use> <comdats>Assembling functions:
>  <materialize-all-clones> <simdclone> add_pair_to_block in:add_pair_to_block default_bzfree in:default_bzfree default_bzalloc in:default_bzalloc handle_compress.isra.2 in:handle_compress.isra.2 in:copy_output_until_stop in:copy_input_until_stop BZ2_bz__AssertH__fail in:BZ2_bz__AssertH__fail BZ2_bzCompressInit in:BZ2_bzCompressInit BZ2_bzCompress in:BZ2_bzCompress BZ2_bzCompressEnd BZ2_bzDecompressInit in:BZ2_bzDecompressInit BZ2_indexIntoF in:BZ2_indexIntoF BZ2_bzDecompress in:BZ2_bzDecompress in:unRLE_obuf_to_output_SMALL in:unRLE_obuf_to_output_FAST {GC 5331k -> 2747k} BZ2_bzDecompressEnd BZ2_bzWriteOpen in:BZ2_bzWriteOpen in:BZ2_bzWriteOpen.part.3 BZ2_bzWrite in:BZ2_bzWrite in:BZ2_bzWrite.part.4 BZ2_bzWriteClose64 in:BZ2_bzWriteClose64 in:BZ2_bzWriteClose64.part.5 BZ2_bzWriteClose in:BZ2_bzWriteClose BZ2_bzReadOpen in:BZ2_bzReadOpen in:BZ2_bzReadOpen.part.6 {GC 5332k -> 2307k} bzopen_or_bzdopen in:bzopen_or_bzdopen BZ2_bzReadClose in:BZ2_bzReadClose in:BZ2_bzReadClose.part.7 BZ2_bzRead in:BZ2_bzRead in:BZ2_bzRead.part.8 in:myfeof BZ2_bzReadGetUnused in:BZ2_bzReadGetUnused in:BZ2_bzReadGetUnused.part.9 BZ2_bzBuffToBuffCompress in:BZ2_bzBuffToBuffCompress BZ2_bzBuffToBuffDecompress in:BZ2_bzBuffToBuffDecompress BZ2_bzlibVersion in:BZ2_bzlibVersion BZ2_bzopen in:BZ2_bzopen BZ2_bzdopen in:BZ2_bzdopen BZ2_bzread in:BZ2_bzread in:BZ2_bzread.part.10 BZ2_bzwrite in:BZ2_bzwrite BZ2_bzflush in:BZ2_bzflush BZ2_bzclose in:BZ2_bzclose BZ2_bzerror in:BZ2_bzerror in:bzerrorstrings
> ...
>
> please remove it
>    c) you mix all upper letters in header of lists, please unify that (Visibility, SECTION NAME)
>    d) -gimple-stats does not work for me, no output and -tree-stats definitely not print all trees used
>    e) you should not require -fdump-level for -fdump-body, select a default value for the level please
>    f) why -fdump-level and -fdump-body start with '-f'
>
> 3) written source code
>    a) I need following patch to build it:
> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
> index 9a1ff61852c..48fc7d9a181 100644
> --- a/gcc/lto/lto-dump.c
> +++ b/gcc/lto/lto-dump.c
> @@ -370,4 +370,4 @@ lto_main (void)
>    timevar_push (TV_PARSE_GLOBAL);
>  }
>
> -#include "gt-lto-lto.h"
> +//#include "gt-lto-lto.h"
> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
> index bc61d25f61d..301ed4b2e25 100644
> --- a/gcc/lto/lto.c
> +++ b/gcc/lto/lto.c
> @@ -143,4 +143,4 @@ lto_main (void)
>    timevar_push (TV_PARSE_GLOBAL);
>  }
>
> -#include "gt-lto-lto.h"
> +//#include "gt-lto-lto.h"
>
> can you please check it?
>
>    b) you added parse_dump_option, but it's used only in dump-lto.c, why not in dumpfile.c?
>    c) lto-dump.c still contains a lot of code in lto_main that's not needed (and is responsible
>       for extra output)
>    e) you moved all to lto-common.c, but functionality exclusively used only in lto.c should remain there
>    f) you should probably dump to stdout, rather that stderr
>    g) there are still quite some functions in lto-dump.c that are missing comment, lto_main comment should
>       be rewritten
> 4) misc
>    a) lto-dump should be installed with 'make install', similarly as lto1 is
>    b) lto-dump command option should be documentation, again take a look for gcov-dump, gcov, gcov-tool (*.texi file)
>    c) would be nice to have some test-cases for that, but it's probably out of scope of the project
>    d) I bet there will be quite some extra includes of header file in lto-dump.c, please adjust file comment and
>       year of creation
>
> Martin

[-- Attachment #2: make_file.diff --]
[-- Type: text/x-patch, Size: 1402 bytes --]

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b871640..4f38261 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3161,7 +3161,7 @@ TEXI_GCC_FILES = gcc.texi gcc-common.texi gcc-vers.texi frontends.texi	\
 	 gcov.texi trouble.texi bugreport.texi service.texi		\
 	 contribute.texi compat.texi funding.texi gnu.texi gpl_v3.texi	\
 	 fdl.texi contrib.texi cppenv.texi cppopts.texi avr-mmcu.texi	\
-	 implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi
+	 implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi lto-dump-tool.texi
 
 # we explicitly use $(srcdir)/doc/tm.texi here to avoid confusion with
 # the generated tm.texi; the latter might have a more recent timestamp,
@@ -3600,6 +3600,15 @@ install-common: native lang.install-common installdirs
 	    gcov-tool$(exeext) $(DESTDIR)$(bindir)/$(GCOV_TOOL_INSTALL_NAME)$(exeext); \
 	  fi; \
 	fi
+# Install lto-dump-tool if it was compiled.
+    -if test "$(enable_as_accelerator)" != "yes" ; then \
+      if [ -f lto-dump-tool$(exeext) ]; \
+      then \
+        rm -f $(DESTDIR)$(bindir)/$(LTO_DUMP_TOOL_INSTALL_NAME)$(exeext); \
+        $(INSTALL_PROGRAM) \
+        lto-dump-tool$(exeext) $(DESTDIR)$(bindir)/$(LTO_DUMP_TOOL_INSTALL_NAME)$(exeext); \
+      fi; \
+    fi
 # Install gcov-dump if it was compiled.
 	-if test "$(enable_as_accelerator)" != "yes" ; then \
 	  if [ -f gcov-dump$(exeext) ]; \

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

* Re: [GSOC] LTO dump tool project - feedback
  2018-08-03 13:47   ` Hrishikesh Kulkarni
@ 2018-08-15 12:01     ` Martin Liška
  2018-08-16 14:20       ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Martin Liška @ 2018-08-15 12:01 UTC (permalink / raw)
  To: Hrishikesh Kulkarni, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

Hi.

After last update of the branch, there's a feedback that will be needed
before we can adept to have it merged into trunk:

1) there's patch for lto-dump proper install:

diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index e474f85ebc6..e9d2659025c 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -46,7 +46,10 @@ lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.rest.encap:
 lto.tags:
-lto.install-common:
+lto.install-common: installdirs
+	$(INSTALL_PROGRAM) $(LTO_DUMP_EXE) \
+	  $(DESTDIR)/$(bindir)/$(LTO_DUMP_EXE)
+
 lto.install-man:
 lto.install-info:
 lto.dvi:

2) If I build bzip2 (just add -flto into Makefile) with your branch I see an ICE:

$ cd bzip2-1.0.6
$ make
[...]
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -flto=9   -o bzip2 bzip2.o -L. -lbz2
lto1: internal compiler error: unexpected offset
0x767bfc lto_resolution_read
	../../gcc/lto/lto-common.c:1951
0x767bfc lto_file_read
	../../gcc/lto/lto-common.c:2169
0x767bfc read_cgraph_and_symbols(unsigned int, char const**)
	../../gcc/lto/lto-common.c:2631
0x74f042 lto_main()
	../../gcc/lto/lto.c:580

3) I still see an extra info that is not needed:

Time variable                                   usr           sys          wall               GGC
 phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    2029 kB ( 52%)
 phase parsing                      :   0.01 (100%)   0.00 (  0%)   0.02 (100%)    1887 kB ( 48%)
 ipa cp                             :   0.00 (  0%)   0.00 (  0%)   0.01 ( 50%)     119 kB (  3%)
 ipa lto gimple in                  :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    1136 kB ( 29%)
 tree operand scan                  :   0.01 (100%)   0.00 (  0%)   0.01 ( 50%)     158 kB (  4%)
 TOTAL                              :   0.01          0.00          0.02           3917 kB
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

4) -list:
 a) please add header, it was useful
 b) -no-sort makes no sense to me, it's default isn't it?

5) -symbol=
 a) if symbol is not found, we should print an error
6) -objects= - why '=' ?
7) -type-stats - you have extra empty lines at the beginning
   - please align header with values
8) -tree-stats - probably also --enable-gather-.. is needed?
9) -dump-body - again, if does not exist, error should be printed
10) -dump-level - again error if wrong value, document possible values if possible
11) please fix formatting of lto-dump so that it explains which suboptions are possible:

$ gcov-tool --help
Usage: gcov-tool [OPTION]... SUB_COMMAND [OPTION]...

Offline tool to handle gcda counts

  -h, --help                            Print this help, then exit
  -v, --version                         Print version number, then exit
  merge [options] <dir1> <dir2>         Merge coverage file contents
    -o, --output <dir>                  Output directory
    -v, --verbose                       Verbose mode
    -w, --weight <w1,w2>                Set weights (float point values)
  rewrite [options] <dir>               Rewrite coverage file contents
    -n, --normalize <int64_t>           Normalize the profile
    -o, --output <dir>                  Output directory
    -s, --scale <float or simple-frac>  Scale the profile counters
    -v, --verbose                       Verbose mode
  overlap [options] <dir1> <dir2>       Compute the overlap of two profiles
    -f, --function                      Print function level info
    -F, --fullname                      Print full filename
    -h, --hotonly                       Only print info for hot objects/functions
    -o, --object                        Print object level info
    -t <float>, --hot_threshold <float> Set the threshold for hotness
    -v, --verbose                       Verbose mode

12) Do not name it in documentation 'lto-dump-tool', use simply 'lto-dump'.
13) make sure man page is generated for lto-dump
14) I noticed that you smashed some whitespaces for files where you didn't do any
changes: gcc/tree.c, lto.c(do_whole_program_analysis) and other places
15) test the tool on a bigger program built with LTO, ideally for both LGEN and also
LTRANS files
16) The last bigger challenge is the option handling, we currently participate in lto/lang.opt.
Ideally I would prefer using standard mechanism getopt_long, take a look at gcov-dump.c.
Can you please investigate that.

Anyway, thank you for working on that. I hope we can send a patch submission into GCC's trunk soon.
Martin

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

* Re: [GSOC] LTO dump tool project - feedback
  2018-08-15 12:01     ` Martin Liška
@ 2018-08-16 14:20       ` Hrishikesh Kulkarni
  2018-08-26 17:56         ` Hrishikesh Kulkarni
  0 siblings, 1 reply; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-08-16 14:20 UTC (permalink / raw)
  To: Martin Liška, GCC Development
  Cc: Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

Thanks for the feedback.
I have made the corrections for the feedback points:
1,  4,  5,  6,  7,  8,  9,  11,  12.
I am working on the remaining points.

I have pushed the changes to the repo (lto-dump-tool-v4 branch) and
attached the diff file herewith.

Regards,

Hrishikesh

On Wed, Aug 15, 2018 at 5:30 PM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> After last update of the branch, there's a feedback that will be needed
> before we can adept to have it merged into trunk:
>
> 1) there's patch for lto-dump proper install:
>
> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
> index e474f85ebc6..e9d2659025c 100644
> --- a/gcc/lto/Make-lang.in
> +++ b/gcc/lto/Make-lang.in
> @@ -46,7 +46,10 @@ lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
>  lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
>  lto.rest.encap:
>  lto.tags:
> -lto.install-common:
> +lto.install-common: installdirs
> +       $(INSTALL_PROGRAM) $(LTO_DUMP_EXE) \
> +         $(DESTDIR)/$(bindir)/$(LTO_DUMP_EXE)
> +
>  lto.install-man:
>  lto.install-info:
>  lto.dvi:
>
> 2) If I build bzip2 (just add -flto into Makefile) with your branch I see an ICE:
>
> $ cd bzip2-1.0.6
> $ make
> [...]
> gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -flto=9   -o bzip2 bzip2.o -L. -lbz2
> lto1: internal compiler error: unexpected offset
> 0x767bfc lto_resolution_read
>         ../../gcc/lto/lto-common.c:1951
> 0x767bfc lto_file_read
>         ../../gcc/lto/lto-common.c:2169
> 0x767bfc read_cgraph_and_symbols(unsigned int, char const**)
>         ../../gcc/lto/lto-common.c:2631
> 0x74f042 lto_main()
>         ../../gcc/lto/lto.c:580
>
> 3) I still see an extra info that is not needed:
>
> Time variable                                   usr           sys          wall               GGC
>  phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    2029 kB ( 52%)
>  phase parsing                      :   0.01 (100%)   0.00 (  0%)   0.02 (100%)    1887 kB ( 48%)
>  ipa cp                             :   0.00 (  0%)   0.00 (  0%)   0.01 ( 50%)     119 kB (  3%)
>  ipa lto gimple in                  :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    1136 kB ( 29%)
>  tree operand scan                  :   0.01 (100%)   0.00 (  0%)   0.01 ( 50%)     158 kB (  4%)
>  TOTAL                              :   0.01          0.00          0.02           3917 kB
> Extra diagnostic checks enabled; compiler may run slowly.
> Configure with --enable-checking=release to disable checks.
>
> 4) -list:
>  a) please add header, it was useful
>  b) -no-sort makes no sense to me, it's default isn't it?
>
> 5) -symbol=
>  a) if symbol is not found, we should print an error
> 6) -objects= - why '=' ?
> 7) -type-stats - you have extra empty lines at the beginning
>    - please align header with values
> 8) -tree-stats - probably also --enable-gather-.. is needed?
> 9) -dump-body - again, if does not exist, error should be printed
> 10) -dump-level - again error if wrong value, document possible values if possible
> 11) please fix formatting of lto-dump so that it explains which suboptions are possible:
>
> $ gcov-tool --help
> Usage: gcov-tool [OPTION]... SUB_COMMAND [OPTION]...
>
> Offline tool to handle gcda counts
>
>   -h, --help                            Print this help, then exit
>   -v, --version                         Print version number, then exit
>   merge [options] <dir1> <dir2>         Merge coverage file contents
>     -o, --output <dir>                  Output directory
>     -v, --verbose                       Verbose mode
>     -w, --weight <w1,w2>                Set weights (float point values)
>   rewrite [options] <dir>               Rewrite coverage file contents
>     -n, --normalize <int64_t>           Normalize the profile
>     -o, --output <dir>                  Output directory
>     -s, --scale <float or simple-frac>  Scale the profile counters
>     -v, --verbose                       Verbose mode
>   overlap [options] <dir1> <dir2>       Compute the overlap of two profiles
>     -f, --function                      Print function level info
>     -F, --fullname                      Print full filename
>     -h, --hotonly                       Only print info for hot objects/functions
>     -o, --object                        Print object level info
>     -t <float>, --hot_threshold <float> Set the threshold for hotness
>     -v, --verbose                       Verbose mode
>
> 12) Do not name it in documentation 'lto-dump-tool', use simply 'lto-dump'.
> 13) make sure man page is generated for lto-dump
> 14) I noticed that you smashed some whitespaces for files where you didn't do any
> changes: gcc/tree.c, lto.c(do_whole_program_analysis) and other places
> 15) test the tool on a bigger program built with LTO, ideally for both LGEN and also
> LTRANS files
> 16) The last bigger challenge is the option handling, we currently participate in lto/lang.opt.
> Ideally I would prefer using standard mechanism getopt_long, take a look at gcov-dump.c.
> Can you please investigate that.
>
> Anyway, thank you for working on that. I hope we can send a patch submission into GCC's trunk soon.
> Martin

[-- Attachment #2: 15_feedback_5.diff --]
[-- Type: text/x-patch, Size: 10847 bytes --]

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b871640..f6de933 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3161,7 +3161,7 @@ TEXI_GCC_FILES = gcc.texi gcc-common.texi gcc-vers.texi frontends.texi	\
 	 gcov.texi trouble.texi bugreport.texi service.texi		\
 	 contribute.texi compat.texi funding.texi gnu.texi gpl_v3.texi	\
 	 fdl.texi contrib.texi cppenv.texi cppopts.texi avr-mmcu.texi	\
-	 implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi
+	 implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi lto-dump.texi
 
 # we explicitly use $(srcdir)/doc/tm.texi here to avoid confusion with
 # the generated tm.texi; the latter might have a more recent timestamp,
diff --git a/gcc/doc/gcc.texi b/gcc/doc/gcc.texi
index da1c1ab..d03e4b3 100644
--- a/gcc/doc/gcc.texi
+++ b/gcc/doc/gcc.texi
@@ -68,7 +68,7 @@ Texts being (a) (see below), and with the Back-Cover Texts being (b)
 * gcov: (gcc) Gcov.            @command{gcov}---a test coverage program.
 * gcov-tool: (gcc) Gcov-tool.  @command{gcov-tool}---an offline gcda profile processing program.
 * gcov-dump: (gcc) Gcov-dump.  @command{gcov-dump}---an offline gcda and gcno profile dump tool.
-* lto-dump-tool: (gcc) lto-dump-tool. @command{lto-dump-tool}---Tool for
+* lto-dump: (gcc) lto-dump. @command{lto-dump}---Tool for
 dumping LTO object files.
 @end direntry
 This file documents the use of the GNU compilers.
@@ -144,7 +144,7 @@ Introduction, gccint, GNU Compiler Collection (GCC) Internals}.
 * Gcov::            @command{gcov}---a test coverage program.
 * Gcov-tool::       @command{gcov-tool}---an offline gcda profile processing program.
 * Gcov-dump::       @command{gcov-dump}---an offline gcda and gcno profile dump tool.
-* lto-dump-tool::   @command{lto-dump-tool}---Tool for dumping LTO
+* lto-dump::   @command{lto-dump}---Tool for dumping LTO
 object files.
 * Trouble::         If you have trouble using GCC.
 * Bugs::            How, why and where to report bugs.
diff --git a/gcc/doc/lto-dump.texi b/gcc/doc/lto-dump.texi
index b66019d..062b795 100644
--- a/gcc/doc/lto-dump.texi
+++ b/gcc/doc/lto-dump.texi
@@ -25,39 +25,39 @@ included in the gfdl(7) man page.
      funds for GNU development.
 @c man end
 @c Set file name and title for the man page.
-@setfilename lto-dump-tool
+@setfilename lto-dump
 @settitle Tool for dumping LTO object files. 
 @end ignore
 
-@node lto-dump-tool
-@chapter @command{lto-dump-tool}---Tool for dumping LTO object files.
+@node lto-dump
+@chapter @command{lto-dump}---Tool for dumping LTO object files.
 
 @menu
-* lto-dump-tool Intro::             Introduction to lto-dump-tool.
-* Invoking lto-dump-tool::          How to use lto-dump-tool.
+* lto-dump Intro::             Introduction to lto-dump.
+* Invoking lto-dump::          How to use lto-dump.
 @end menu
 
-@node lto-dump-tool Intro
-@section Introduction to @command{lto-dump-tool}
+@node lto-dump Intro
+@section Introduction to @command{lto-dump}
 @c man begin DESCRIPTION
 
-@command{lto-dump-tool} is a tool you can use in conjunction with GCC to
+@command{lto-dump} is a tool you can use in conjunction with GCC to
 dump link time optimization object files.
 
 @c man end
 
-@node Invoking lto-dump-tool
-@section Invoking @command{lto-dump-tool}
+@node Invoking lto-dump
+@section Invoking @command{lto-dump}
 
 @smallexample
-Usage: lto-dump-tool @r{[}@var{OPTION}@r{]} ... @var{objfiles}
+Usage: lto-dump @r{[}@var{OPTION}@r{]} ... @var{objfiles}
 @end smallexample
 
-@command{lto-dump-tool} accepts the following options:
+@command{lto-dump} accepts the following options:
 
 @ignore
 @c man begin SYNOPSIS
-lto-dump-tool [@option{-list}]
+lto-dump [@option{-list}]
      [@option{-demangle}]
      [@option{-defined-only}]
      [@option{-print-value}]
@@ -66,13 +66,13 @@ lto-dump-tool [@option{-list}]
      [@option{-reverse-sort}]
      [@option{-no-sort}]
      [@option{-symbol=}]
-     [@option{-objects=}]
+     [@option{-objects}]
      [@option{-type-stats}]
      [@option{-tree-stats}]
      [@option{-gimple-stats}]
      [@option{-dump-level=}]
      [@option{-dump-body=}]
-     [@option{-help}] @var{lto-dump-tool}
+     [@option{-help}] @var{lto-dump}
 @c man end
 @end ignore
 
@@ -105,7 +105,7 @@ Dump the symbols in order of occurence.
 @item -symbol=
 Dump the details of specific symbol.
 
-@item -objects=
+@item -objects
 Dump the details of LTO objects.
 
 @item -type-stats
diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index e474f85..b8049ba 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -46,7 +46,10 @@ lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
 lto.rest.encap:
 lto.tags:
-lto.install-common:
+lto.install-common: installdirs
+	$(INSTALL_PROGRAM) $(LTO_DUMP_EXE) \
+	$(DESTDIR)/$(bindir)/$(LTO_DUMP_EXE)
+
 lto.install-man:
 lto.install-info:
 lto.dvi:
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index 931f6b5..9103810 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -94,10 +94,6 @@ reverse-sort
 LTO Var(flag_lto_reverse_sort)
 Display the symbols in reverse order.
 
-no-sort
-LTO Var(flag_lto_no_sort)
-Display the symbols in order of occurence.
-
 symbol=
 LTO Driver RejectNegative Joined Var(flag_lto_dump_symbol)
 
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index f664faa..10356e4 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -1827,14 +1827,14 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 
     if (flag_lto_dump_type_stats)
     {
-      fprintf (stdout, "\n\n     Type     Frequency   Percentage\n\n");
+      fprintf (stdout, "       Type     Frequency   Percentage\n\n");
       for (hash_map<code_id_hash, unsigned>::iterator itr = hm.begin ();
 	   itr != hm.end ();
 	   ++itr)
       {
 	std::pair<unsigned, unsigned> p = *itr;
 	enum tree_code code = (enum tree_code) p.first;
-	fprintf (stdout, "%14s %6d %10.2f%\n", get_tree_code_name (code),
+	fprintf (stdout, "%14s %6d %12.2f%\n", get_tree_code_name (code),
 		 p.second, float (p.second)/total*100);
       }
     }
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 5930b14..7b2717c 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -152,16 +152,17 @@ void dump_list_functions (void)
       v.safe_push (e);
   }
 
-  if (!flag_lto_no_sort)
-  {
-    if (flag_lto_size_sort)
-      v.qsort (size_compare);
-    else if (flag_lto_name_sort)
-      v.qsort (name_compare);
-  }
+  if (flag_lto_size_sort)
+    v.qsort (size_compare);
+  else if (flag_lto_name_sort)
+    v.qsort (name_compare);
   if (flag_lto_reverse_sort)
     v.reverse ();
 
+  printf ("Type   Visibility  Size  Name");
+  if (flag_lto_print_value)
+    printf("  Value");
+  printf("\n");
   int i=0;
   symbol_entry* e;
   FOR_EACH_VEC_ELT (v, i, e)
@@ -182,15 +183,10 @@ void dump_list_variables (void)
       v.safe_push (e);
   }
 
-  if (!flag_lto_no_sort)
-  {
-    if (flag_lto_size_sort)
-      v.qsort (size_compare);
-    else if (flag_lto_name_sort)
-      v.qsort (name_compare);
-  }
-
-
+  if (flag_lto_size_sort)
+    v.qsort (size_compare);
+  else if (flag_lto_name_sort)
+    v.qsort (name_compare);
   if (flag_lto_reverse_sort)
     v.reverse ();
 
@@ -213,49 +209,57 @@ void dump_list (void)
 /* Dump specific variables and functions used in IL.  */
 void dump_symbol ()
 {
+  int flag = 0;
   symtab_node *node;
   printf ("Symbol: %s\n", flag_lto_dump_symbol);
   FOR_EACH_SYMBOL (node)
     if (!strcmp (flag_lto_dump_symbol, node->name ()))
+    {
       node->debug ();
-  printf ("\n");
+      printf ("\n");
+      flag = 1;
+    }
+    if (!flag)
+      error_at (input_location, "Symbol not found.");
   return;
 }
 
 /* Dump specific gimple body of specified function.  */
 void dump_body ()
 {
+  int flag = 0;
   dump_flags_t flags;
   flags = (flag_dump_level)
 	 ? parse_dump_option (flag_dump_level, 0, 0)
 	 : TDF_NONE;
   cgraph_node *cnode;
   FOR_EACH_FUNCTION (cnode)
+  if (cnode->definition && !strcmp (cnode->name (), flag_dump_body))
   {
-    if (cnode->definition && !strcmp (cnode->name (), flag_dump_body))
-    {
-      printf ("Gimple Body of Function: %s\n", cnode->name ());
-      cnode->get_untransformed_body ();
-      debug_function (cnode->decl, flags);
-    }
+    printf ("Gimple Body of Function: %s\n", cnode->name ());
+    cnode->get_untransformed_body ();
+    debug_function (cnode->decl, flags);
+    flag = 1;
   }
-    return;
+  if (!flag)
+    error_at (input_location, "Function not found.");
+  return;
 }
 
 /* List of command line options for dumping.  */
 void dump_tool_help ()
 {
   printf ("\nLTO dump tool command line options.\n\n");
-  printf ("-list : Dump the symbol list.\n");
-  printf ("    -demangle : Dump the demangled output.\n");
-  printf ("    -defined-only : Dump only the defined symbols.\n");
-  printf ("    -print-value : Dump initial values of the variables.\n");
-  printf ("    -name-sort : Sort the symbols alphabetically.\n");
-  printf ("    -size-sort : Sort the symbols according to size.\n");
-  printf ("    -reverse-sort : Dump the symbols in reverse order.\n");
-  printf ("    -no-sort : Dump the symbols in order of occurence.\n");
+  printf("Usage: lto-dump [OPTION]... SUB_COMMAND [OPTION]...\n\n");
+  printf ("-list [options] : Dump the symbol list.\n");
+  printf ("  -demangle : Dump the demangled output.\n");
+  printf ("  -defined-only : Dump only the defined symbols.\n");
+  printf ("  -print-value : Dump initial values of the variables.\n");
+  printf ("  -name-sort : Sort the symbols alphabetically.\n");
+  printf ("  -size-sort : Sort the symbols according to size.\n");
+  printf ("  -reverse-sort : Dump the symbols in reverse order.\n");
   printf ("-symbol= : Dump the details of specific symbol.\n");
-  printf ("-objects= : Dump the details of LTO objects.\n");
+  printf ("-objects : Dump the details of LTO objects.\n");
   printf ("-type-stats : Dump statistics of tree types.\n");
   printf ("-tree-stats : Dump statistics of trees.\n");
   printf ("-gimple-stats : Dump statistics of gimple statements.\n");
@@ -308,7 +312,7 @@ lto_main (void)
   {
     cgraph_node *node;
     FOR_EACH_DEFINED_FUNCTION (node)
-    node->get_untransformed_body ();
+      node->get_untransformed_body ();
     if (!GATHER_STATISTICS)
       warning_at (input_location, 0, "Not configured with --enable-gather-detailed-mem-stats.");
     else
@@ -319,8 +323,13 @@ lto_main (void)
   /* Dump tree statistics.  */
   if (flag_lto_tree_stats)
   {
-    printf ("Tree Statistics\n");
-    dump_tree_statistics ();
+    if (!GATHER_STATISTICS)
+      warning_at (input_location, 0, "Not configured with --enable-gather-detailed-mem-stats.");
+    else
+    {
+      printf ("Tree Statistics\n");
+      dump_tree_statistics ();
+    }
     return;
   }
 

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

* Re: [GSOC] LTO dump tool project - feedback
  2018-08-16 14:20       ` Hrishikesh Kulkarni
@ 2018-08-26 17:56         ` Hrishikesh Kulkarni
  0 siblings, 0 replies; 50+ messages in thread
From: Hrishikesh Kulkarni @ 2018-08-26 17:56 UTC (permalink / raw)
  To: GCC Development
  Cc: Martin Liška, Jan Hubicka, Richard Biener, Martin Jambor

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

Hi,

I have made changes for feedback points 3 and 10.

With this I have completed/ made changes for points
1,  3,  4,  5,  6,  7,  8,  9,  10,  11,  12.

I have pushed the changes to the repo. Please find the diff file
attached herewith.

Regards,

Hrishikesh
On Thu, Aug 16, 2018 at 7:50 PM Hrishikesh Kulkarni
<hrishikeshparag@gmail.com> wrote:
>
> Hi,
>
> Thanks for the feedback.
> I have made the corrections for the feedback points:
> 1,  4,  5,  6,  7,  8,  9,  11,  12.
> I am working on the remaining points.
>
> I have pushed the changes to the repo (lto-dump-tool-v4 branch) and
> attached the diff file herewith.
>
> Regards,
>
> Hrishikesh
>
> On Wed, Aug 15, 2018 at 5:30 PM, Martin Liška <mliska@suse.cz> wrote:
> > Hi.
> >
> > After last update of the branch, there's a feedback that will be needed
> > before we can adept to have it merged into trunk:
> >
> > 1) there's patch for lto-dump proper install:
> >
> > diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
> > index e474f85ebc6..e9d2659025c 100644
> > --- a/gcc/lto/Make-lang.in
> > +++ b/gcc/lto/Make-lang.in
> > @@ -46,7 +46,10 @@ lto.all.cross: $(LTO_EXE) $(LTO_DUMP_EXE)
> >  lto.start.encap: $(LTO_EXE) $(LTO_DUMP_EXE)
> >  lto.rest.encap:
> >  lto.tags:
> > -lto.install-common:
> > +lto.install-common: installdirs
> > +       $(INSTALL_PROGRAM) $(LTO_DUMP_EXE) \
> > +         $(DESTDIR)/$(bindir)/$(LTO_DUMP_EXE)
> > +
> >  lto.install-man:
> >  lto.install-info:
> >  lto.dvi:
> >
> > 2) If I build bzip2 (just add -flto into Makefile) with your branch I see an ICE:
> >
> > $ cd bzip2-1.0.6
> > $ make
> > [...]
> > gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -flto=9   -o bzip2 bzip2.o -L. -lbz2
> > lto1: internal compiler error: unexpected offset
> > 0x767bfc lto_resolution_read
> >         ../../gcc/lto/lto-common.c:1951
> > 0x767bfc lto_file_read
> >         ../../gcc/lto/lto-common.c:2169
> > 0x767bfc read_cgraph_and_symbols(unsigned int, char const**)
> >         ../../gcc/lto/lto-common.c:2631
> > 0x74f042 lto_main()
> >         ../../gcc/lto/lto.c:580
> >
> > 3) I still see an extra info that is not needed:
> >
> > Time variable                                   usr           sys          wall               GGC
> >  phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    2029 kB ( 52%)
> >  phase parsing                      :   0.01 (100%)   0.00 (  0%)   0.02 (100%)    1887 kB ( 48%)
> >  ipa cp                             :   0.00 (  0%)   0.00 (  0%)   0.01 ( 50%)     119 kB (  3%)
> >  ipa lto gimple in                  :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    1136 kB ( 29%)
> >  tree operand scan                  :   0.01 (100%)   0.00 (  0%)   0.01 ( 50%)     158 kB (  4%)
> >  TOTAL                              :   0.01          0.00          0.02           3917 kB
> > Extra diagnostic checks enabled; compiler may run slowly.
> > Configure with --enable-checking=release to disable checks.
> >
> > 4) -list:
> >  a) please add header, it was useful
> >  b) -no-sort makes no sense to me, it's default isn't it?
> >
> > 5) -symbol=
> >  a) if symbol is not found, we should print an error
> > 6) -objects= - why '=' ?
> > 7) -type-stats - you have extra empty lines at the beginning
> >    - please align header with values
> > 8) -tree-stats - probably also --enable-gather-.. is needed?
> > 9) -dump-body - again, if does not exist, error should be printed
> > 10) -dump-level - again error if wrong value, document possible values if possible
> > 11) please fix formatting of lto-dump so that it explains which suboptions are possible:
> >
> > $ gcov-tool --help
> > Usage: gcov-tool [OPTION]... SUB_COMMAND [OPTION]...
> >
> > Offline tool to handle gcda counts
> >
> >   -h, --help                            Print this help, then exit
> >   -v, --version                         Print version number, then exit
> >   merge [options] <dir1> <dir2>         Merge coverage file contents
> >     -o, --output <dir>                  Output directory
> >     -v, --verbose                       Verbose mode
> >     -w, --weight <w1,w2>                Set weights (float point values)
> >   rewrite [options] <dir>               Rewrite coverage file contents
> >     -n, --normalize <int64_t>           Normalize the profile
> >     -o, --output <dir>                  Output directory
> >     -s, --scale <float or simple-frac>  Scale the profile counters
> >     -v, --verbose                       Verbose mode
> >   overlap [options] <dir1> <dir2>       Compute the overlap of two profiles
> >     -f, --function                      Print function level info
> >     -F, --fullname                      Print full filename
> >     -h, --hotonly                       Only print info for hot objects/functions
> >     -o, --object                        Print object level info
> >     -t <float>, --hot_threshold <float> Set the threshold for hotness
> >     -v, --verbose                       Verbose mode
> >
> > 12) Do not name it in documentation 'lto-dump-tool', use simply 'lto-dump'.
> > 13) make sure man page is generated for lto-dump
> > 14) I noticed that you smashed some whitespaces for files where you didn't do any
> > changes: gcc/tree.c, lto.c(do_whole_program_analysis) and other places
> > 15) test the tool on a bigger program built with LTO, ideally for both LGEN and also
> > LTRANS files
> > 16) The last bigger challenge is the option handling, we currently participate in lto/lang.opt.
> > Ideally I would prefer using standard mechanism getopt_long, take a look at gcov-dump.c.
> > Can you please investigate that.
> >
> > Anyway, thank you for working on that. I hope we can send a patch submission into GCC's trunk soon.
> > Martin

[-- Attachment #2: 16_feedback_6.diff --]
[-- Type: text/x-patch, Size: 1630 bytes --]

diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 0c25e71..95dccda 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -1346,9 +1346,12 @@ parse_dump_option (const char *option_value, const char **pos_p,
 	    *pos_p = ptr + 1;
 	  break;
 	}
-      else if (swtch)
-	warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
-		 length, ptr, swtch);
+      else
+      {
+	warning (0, "ignoring unknown option %q.*s",
+		 length, ptr);
+	flags = TDF_ERROR;
+      }
     found:
       ptr = end_ptr;
   }
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h
index 9d7b049..03cec10 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -146,7 +146,9 @@ enum dump_flag
 	     | MSG_NOTE),
 
   /* Dumping for -fcompare-debug.  */
-  TDF_COMPARE_DEBUG = (1 << 25)
+  TDF_COMPARE_DEBUG = (1 << 25),
+
+  TDF_ERROR = (1<<26)
 };
 
 /* Dump flags type.  */
diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
index 7b2717c..b1854c2 100644
--- a/gcc/lto/lto-dump.c
+++ b/gcc/lto/lto-dump.c
@@ -232,6 +232,11 @@ void dump_body ()
   flags = (flag_dump_level)
 	 ? parse_dump_option (flag_dump_level, 0, 0)
 	 : TDF_NONE;
+  if (flags == TDF_ERROR)
+  {
+    error_at (input_location, "Level not found, use none, slim, blocks, vops.");
+    return;
+  }
   cgraph_node *cnode;
   FOR_EACH_FUNCTION (cnode)
   if (cnode->definition && !strcmp (cnode->name (), flag_dump_body))
@@ -288,7 +293,7 @@ lto_main (void)
 
   /* Initialize the LTO front end.  */
   lto_fe_init ();
-
+  g_timer = false;
   /* Read all the symbols and call graph from all the files in the
      command line.  */
   read_cgraph_and_symbols (num_in_fnames, in_fnames);

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

end of thread, other threads:[~2018-08-26 17:56 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29 17:03 [GSOC] LTO dump tool project Hrishikesh Kulkarni
2018-05-29 17:17 ` Prathamesh Kulkarni
2018-05-29 17:39   ` Martin Liška
2018-05-29 17:38 ` Martin Liška
2018-05-29 17:43   ` Martin Liška
2018-06-01 18:59     ` Hrishikesh Kulkarni
2018-06-04  8:36       ` Martin Liška
2018-06-04 18:13         ` Hrishikesh Kulkarni
2018-06-04 19:08           ` Martin Liška
2018-06-08 13:41             ` Hrishikesh Kulkarni
2018-06-08 13:45               ` Martin Liška
2018-06-08 14:41                 ` Martin Liška
2018-06-08 18:29                   ` Hrishikesh Kulkarni
2018-06-08 21:01                     ` Prathamesh Kulkarni
2018-06-11 10:05                     ` Martin Liška
2018-06-12 18:14                       ` Hrishikesh Kulkarni
2018-06-12 21:26                         ` Martin Liška
2018-06-13 10:08                           ` Martin Liška
2018-06-17 22:42                             ` Hrishikesh Kulkarni
2018-06-18  9:34                               ` Martin Jambor
2018-06-20 18:18                                 ` Hrishikesh Kulkarni
2018-06-21 14:21                                   ` Martin Liška
2018-06-21 14:28                                   ` Martin Liška
2018-06-22 11:03                                 ` Martin Liška
     [not found]                                   ` <CAL+0whSq9fmpou57iJqkvFte-cOz4wsEcZ3WM_j_hzXj96dNYQ@mail.gmail.com>
2018-06-26 20:02                                     ` Hrishikesh Kulkarni
2018-06-27 22:43                                       ` Hrishikesh Kulkarni
2018-06-29  9:20                                         ` Martin Liška
2018-07-03 13:09                                           ` Hrishikesh Kulkarni
2018-07-04 18:54                                             ` Hrishikesh Kulkarni
2018-07-05 17:11                                               ` Hrishikesh Kulkarni
2018-07-09  7:51                                                 ` Hrishikesh Kulkarni
2018-07-09  8:34                                                   ` Martin Liška
2018-07-10 18:40                                                     ` Hrishikesh Kulkarni
2018-07-12 18:06                                                       ` Hrishikesh Kulkarni
2018-07-13  9:17                                                         ` Martin Liška
2018-07-16 15:44                                                           ` Hrishikesh Kulkarni
2018-07-17 13:00                                                             ` Martin Liška
2018-07-18 18:04                                                               ` Hrishikesh Kulkarni
2018-07-22  1:25                                                                 ` Hrishikesh Kulkarni
2018-07-24  3:54                                                                   ` Hrishikesh Kulkarni
2018-07-25  9:34                                                                     ` Hrishikesh Kulkarni
2018-07-27 22:41                                                                       ` Hrishikesh Kulkarni
2018-07-28 16:54                                                                         ` Hrishikesh Kulkarni
2018-07-31  6:25                                                                           ` Hrishikesh Kulkarni
2018-06-29  7:25                                       ` Martin Liška
2018-08-01 13:29 ` [GSOC] LTO dump tool project - feedback Martin Liška
2018-08-03 13:47   ` Hrishikesh Kulkarni
2018-08-15 12:01     ` Martin Liška
2018-08-16 14:20       ` Hrishikesh Kulkarni
2018-08-26 17:56         ` Hrishikesh Kulkarni

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