GCC Plugins - CC1 - Multiple processes on PLUGIN_FINISH_TYPE

2012-04-24 Thread Brett Foster
Hi all,

I've been working on a plugin that processes some data. My plugin
grabs some data from the tree. I'm trying to understand a certain
"weird" behaviour I am seeing. And yeah, I'm new to the mailing list
and gcc's innards! Be forgiving! :) I appreciate the help!

When I add:

register_callback (BaseName, PLUGIN_FINISH_TYPE, CinsGcc_CB_Type, NULL);

The plugin appears to be loaded by a 2nd process, initialized, and
provided with what appears to be much the same data (at least from my
view). Other plugin events do not appear to cause this behaviour.

The command line is..,

gcc -fplugin=./out/cins.so -c -o ./out/tests/test_0.o test/test_0.c \
 -fplugin-arg-cins-error=./out/tests/test_0.o_err.txt \
 -fplugin-arg-cins-output=./out/tests/test_0.o_out.txt

The extended log file written to disk says:
(001E:31D1) INFO
src/plugin/gcc_core.c:0092  plugin_init CINS
silencing console now.

The console says:
 CINS silencing console now.

31D1 and 31CD are different PIDs.
001E is the identifier indicating the log count (i.e. there were
0x1E prints that came before)

As well, __progname == 'cc1'.

gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)


Re: GCC Plugins - CC1 - Multiple processes on PLUGIN_FINISH_TYPE

2012-04-25 Thread Brett Foster
Ah! I see what might be happening. I was using assert(0) in the
callback to stop the program's execution (to examine the output at
that location). When I do this, I get the funky results.

(I was surprised it was seen as HTML seeing as it was sent from my
blackberry (no html e-mail editing). The content type claimed
text/plain.)

On Wed, Apr 25, 2012 at 7:23 AM, Diego Novillo  wrote:
> [ Please do not send html mail.  It will be rejected by the list server. ]
>
> On Wed, Apr 25, 2012 at 10:16,  wrote:
>
>> That much I understand. But it's cc1 that is in two processes, and gcc -v
>> only shows it being invoked once. Finally the output on stderr is only from
>> one of the two processes.
>
> cc1 is just one process.  You will need to show us the output of 'gcc -v'.
>
>
>> (To clarify terminology: gcc app being the driver here? I didn't think the
>> plugins were loaded in the 'gcc' driver? Strictly from the compiler?)
>
> They are not.  They are loaded by cc1.
>
>
> Diego.


Traversing trees in a plugin...

2012-06-02 Thread Brett Foster
Hi all,

I'm working on a GCC plugin, having made a lot of progress on that
front. So far running my plugin works 'more or less' on things like
the linux kernel. On the other hand running it on the plugin itself
causes problems. Given that some of the data structures are pretty
complicated in GCC I'm not surprised.

So the question I have (w.r.t. TREE data structures) are:

1) How to marking a node as visited by my algorithm (without screwing
up the compiler!)

2) How to associate additional data (perhaps a pointer to something
else) to a node (like a unique identifier, or a pointer to a data
structure).

Thoughts:

1) The general overview of my current algorithm:
a) When a node can be uniquely identified (has an identifier or
position information) I can use a look up.
b) However with types (especially those that are anonymous) I find it
challenging to do so. I assign such a node an anonymous identifier or
try to assign a general data type (i.e. integer) when the type is
internal.
c) When I arrive at a node and it is identifiable and it is found in
the lookup table I can infer that its children have also been visited.
d) However there may be cases when I cannot identify where a node has
been visited, and processing is duplicated.
e) This method seems quite inefficient, error prone.

2) Can memory addresses be used to uniquely identify nodes? I believe
this may be the case for identifier nodes.

3) Other ideas? I tuned my process based on trial and error, and
focused on what worked at the time. I think I'm doing it in the wrong
way.

Brett


Re: Traversing trees in a plugin...

2012-06-02 Thread Brett Foster
On Sat, Jun 2, 2012 at 11:31 AM, Basile Starynkevitch
 wrote:
> In the MELT meta-plugin (recall that MELT is a high-level domain specific 
> language to
> extend GCC, see http://gcc-melt.org/ for more) we extensively use associative 
> hash-tables
> for that. MELT offers homogeneous hash-tables, e.g. hash-table associating 
> tree (i.e.
> non-null tree pointers) to arbitrary non-null MELT values (e.g. MELT 
> closures, or MELT
> lists, or MELT objects, etc etc), or hash-table associating (non null) gimple 
> to non
> null MELT values.
>
> So you can have e.g. an hash-table associating each tree (every tree is in 
> GCC a non-null
> pointer to a structure) with data associated to it. Once it has some data you 
> know that
> this tree has been visited.

I'll poke around the MELT source code -

In Melt, where in source code may I have a look to see how trees and
mapped to the hash table? Are you able to summarize the basics? I.e.
the hash for a specific node tree is derived from what data? Pointer
address?

Thanks for the info.