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 <[email protected]> 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
>> <[email protected]> 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
>>> <[email protected]> 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 <[email protected]> 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
>>>>
>>>>
>
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 ())