From: David Malcolm <dmalcolm@redhat.com>
To: Basile Starynkevitch <basile@starynkevitch.net>
Cc: gcc@gcc.gnu.org
Subject: Re: where to insert a new Simple IPA [measuring] pass from a plugin ?
Date: Mon, 30 Sep 2013 16:04:00 -0000 [thread overview]
Message-ID: <1380557061.4027.10.camel@surprise> (raw)
In-Reply-To: <20130930134915.GA7386@ours.starynkevitch.net>
[-- Attachment #1: Type: text/plain, Size: 3808 bytes --]
On Mon, 2013-09-30 at 15:49 +0200, Basile Starynkevitch wrote:
> Hello,
>
> I want to insert, thru a plugin, a new IPA pass which won't change any
> internal representation but will just count Gimples and functions at the IPA level.
>
> (for what it is worth, the plugin is MELT http://gcc-melt.org/
> and the IPA pass is coded in MELT; but we can safely pretend
> all this is C++ code - which in fact it is,
> since MELT generates C++ code).
>
>
> BTW, -fdump-passes show me notably:
>
>
> tree-cfg : ON
> *warn_function_return : ON
> tree-ompexp : OFF
> *build_cgraph_edges : ON
> *free_lang_data : ON
> ipa-visibility : ON
> ipa-early_local_cleanups : ON
>
> I have some issues finding the right place for such a pass. I was thinking of passing
> as the reference_pass_name of some struct register_pass_info either the "ipa-visibility" string or the "visibility" string, but somehow that does not work.
>
> It is a pity that, AFAIK, a plugin cannot insert its pass in front of
> the all_small_ipa_passes (the variable inside passes.c) - or of the
> all_regular_ipa_passes; it would be
> nice if we had some plugin API for such things. What do you think?
I had a go at implementing this using the python plugin, and I was
successful: it worked for me (with gcc 4.7.2 fwiw) as a
SIMPLE_IPA_PASS, registering before "*free_lang_data", or as an
IPA_PASS, registering before "whole-program".
I'm attaching the script I wrote, though obviously it will need
translating from Python to MELT. Hope this is helpful.
Here's the output: it's tallying the kinds of gimple statements since,
by function, within "demo.c":
$ LD_LIBRARY_PATH=gcc-c-api ./gcc-with-python show-stats.py demo.c -I/usr/include/python2.7 -c
make_a_list_of_random_ints_badly: [(<type 'gcc.GimpleAssign'>, 6), (<type 'gcc.GimpleCall'>, 5), (<type 'gcc.GimpleCond'>, 2), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
buggy_converter: [(<type 'gcc.GimpleAssign'>, 6), (<type 'gcc.GimpleCall'>, 1), (<type 'gcc.GimpleCond'>, 1), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
kwargs_example: [(<type 'gcc.GimpleAssign'>, 10), (<type 'gcc.GimpleCall'>, 1), (<type 'gcc.GimpleCond'>, 1), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
too_many_varargs: [(<type 'gcc.GimpleAssign'>, 7), (<type 'gcc.GimpleCall'>, 1), (<type 'gcc.GimpleCond'>, 1), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
not_enough_varargs: [(<type 'gcc.GimpleAssign'>, 5), (<type 'gcc.GimpleCall'>, 1), (<type 'gcc.GimpleCond'>, 1), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
socket_htons: [(<type 'gcc.GimpleAssign'>, 7), (<type 'gcc.GimpleCall'>, 3), (<type 'gcc.GimpleCond'>, 1), (<type 'gcc.GimpleReturn'>, 1), (<type 'gcc.GimpleLabel'>, 1)]
> BTW, I also have a suggestion. We have some (relatively new) code
> (perhaps from 4.8) which suggest names in error messages when an
> identifier is misspelled..
>
> Can't we use the same code (or at least same algorithm) to suggest
> a pass name when given a mispelled pass name from a plugin?
>
>
> In general, I find that we are a bit lacking documentation about where
> and how a plugin can insert its own passes.
Agreed. FWIW I find this map very helpful for this kind of thing:
https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
Perhaps it can somehow be integrated into GCC's own documentation.
> Regards.
>
> PS. See also http://gcc.gnu.org/ml/gcc/2010-11/msg00638.html
Hope this is constructive
Dave
[-- Attachment #2: show-stats.py --]
[-- Type: text/x-python, Size: 1006 bytes --]
from collections import Counter
import gcc
# We'll implement this as a custom pass, to be called directly before
# 'whole-program'
# See https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
# for a map showing how GCC's passes (actually for GCC 4.6)
class CountingPass(gcc.SimpleIpaPass):
def execute(self):
for node in gcc.get_callgraph_nodes():
# Tally gimple statements by type:
stmt_kinds = Counter()
fun = node.decl.function
if fun:
for bb in fun.cfg.basic_blocks:
if bb.gimple:
for stmt in bb.gimple:
stmt_kinds[type(stmt)] += 1
print('%s: %s' % (fun.decl.name, stmt_kinds.most_common(5)))
ps = CountingPass(name='counting-pass')
ps.register_before('*free_lang_data')
# This also works registering before "whole-program", but one has to change the
# base class to a gcc.IpaPass, rather than a gcc.SimpleIpaPass
prev parent reply other threads:[~2013-09-30 16:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-30 13:49 Basile Starynkevitch
2013-09-30 16:04 ` David Malcolm [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380557061.4027.10.camel@surprise \
--to=dmalcolm@redhat.com \
--cc=basile@starynkevitch.net \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).