This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Identifying global state within GCC


On Thu, 2013-05-02 at 07:20 -0600, Jeff Law wrote:
> On 05/01/2013 02:32 PM, David Malcolm wrote:
> > I had a go at writing a custom pass to try to locate places where GCC
> > makes use of global state.
> >
> > You can see the pass here (which I implemented using gcc-python-plugin):
> > https://gcc-python-plugin.readthedocs.org/en/latest/working-with-c.html#finding-global-variables
> >
> > A build log from recompiling gcc using this pass can be seen at:
> > http://fedorapeople.org/~dmalcolm/gcc/2013-05-01/make.log
> > (about 12MB in size; I killed it when I saw that stage 1 was done).
> >
> > I'm sure there are quite a few false positives in there.
> >
> > Hope this is helpful.  FWIW I had an earlier version of the pass which
> > merely gave *declaration* sites for global variables, rather than all
> > *uses* of such variables.
> I wonder how useful it would be to filter out the source line 
> information, then produce a histogram of which global state is hit the 
> most often across the build.  That'd give us an interesting hitlist as 
> we start trying to remove the global state.

A python script to do this (by parsing the logs) can be seen at:
http://fedorapeople.org/~dmalcolm/gcc/2013-05-02/make-histogram.py

The results of running it can be seen at:
http://fedorapeople.org/~dmalcolm/gcc/2013-05-02/histogram.txt
(141k)

The top 40 globals from the list are:
[('struct recog_data recog_data', 11802),
 ('struct gcc_options global_options', 11431),
 ('union tree_node *[133] global_trees', 5472),
 ('struct FILE * dump_file', 4832),
 ('struct function * cfun', 4602),
 ('struct rtx_def *[129] const_int_rtx', 3744),
 ('union tree_node *[138] built_in_attributes', 2186),
 ('union tree_node *[311] builtin_types', 2099),
 ('int which_alternative', 1758),
 ('unsigned char[87] mode_size', 1495),
 ('struct df_d * df', 1205),
 ('struct gcc_target targetm', 1069),
 ('struct _IO_FILE * stderr', 990),
 ('location_t input_location', 930),
 ('struct saved_scope * scope_chain', 930),
 ('int dump_flags', 927),
 ('struct rtl_data x_rtl', 885),
 ('union tree_node *[13] integer_types', 846),
 ('unsigned char[72] ix86_tune_features', 815),
 ('union tree_node * current_function_decl', 756),
 ('unsigned char[302][64] tree_contains_struct', 623),
 ('int reload_completed', 606),
 ('struct target_hard_regs default_target_hard_regs', 585),
 ('struct target_rtl default_target_rtl', 552),
 ('int flag_isoc99', 547),
 ('struct rtl_hooks rtl_hooks', 501),
 ('struct reload[180] rld', 498),
 ('union tree_node *[57] cp_global_trees', 489),
 ('LOC vect_location', 467),
 ('struct target_ira default_target_ira', 440),
 ('struct cxx_pretty_printer scratch_pretty_printer', 402),
 ('machine_mode word_mode', 377),
 ('struct line_maps * line_table', 376),
 ('struct FILE * asm_out_file', 358),
 ('union tree_node *[55] c_global_trees', 348),
 ('union tree_node *[4] sizetype_tab', 331),
 ('struct vec sched_luids', 326),
 ('struct _IO_FILE * stdout', 311),
 ('struct vec h_i_d', 300),
 ('struct lang_hooks lang_hooks', 287)]

Hope this is helpful
Dave
from collections import Counter, namedtuple
from pprint import pprint
import re

class Usage(namedtuple('Usage', ('filename', 'line', 'column', 'global_'))):
    PATTERN = '(.+):(.+):(.+): note: use of global state "(.+)" here'
    pattern = re.compile(PATTERN)

usage_count = Counter()

with open('build-with-fgs/make.log') as f:
    for line in f:
        m = Usage.pattern.match(line)
        if m:
            u = Usage(*m.groups())
            usage_count[u.global_] += 1

pprint(usage_count.most_common())

Attachment: histogram.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]