This is the mail archive of the gcc-help@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: GIMPLE pass - Assignment evaluation


On Mon, 2013-12-16 at 16:10 -0500, Sandeep K Chaudhary wrote:
> Hi Guys,
> 
> I am writing a GIMPLE pass in which I need to inspect the assignments.
> For example, for the below statements, I need to find the value of the
> second and third assignments which are '2' and '7'.
> 
> VAR1 = 1;
> VAR1++;
> VAR1 = VAR1 + 5;
> 
> But the GIMPLE IR only has the following statements i.e. no optimization.
> 
>   VAR1_2 = 1;
>   VAR1_3 = VAR1_2 + 1;
>   VAR1_4 = VAR1_3 + 5;
> 
> How can I make it perform calculations on RHS? Are there some flags
> that I can enable?
> 
> I tried -O1 and higher optimization levels but I don't see any
> difference. This is how I am building and loading my plugin...
> 
> g++ -I`g++ -print-file-name=plugin`/include -fPIC -shared -O1
> gimple_pass.c -o plugin.so
> g++ -fplugin=/home/sandeep/myplugin/gimple/plugin.so -O1 -c test.c
> 
> Also, I thought of going with RTL passes but RTL IR seems too complex
> for my use and also it's not suitable for high level optimizations.
> Please suggest.

Your plugin is registering a new gimple pass - but *when* does the pass
get run, relative to other passes?

It may be that you simply need to register your pass to run later on
than it's currently registered.

FWIW I used my gcc-python-plugin to create a diagram showing (roughly)
how the pass fit together; see:
https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
(the diagram actually shows gcc 4.6, but hopefully it's still useful).

You may find it helpful to invoke your plugin with -fdump-tree-all -
this will generate dozens of dump files of the form test.c.SUFFIX,
dumping the state of the IR at each pre-existing pass.  A careful
examination of these dumps may give you insight into what each pass is
doing.  My guess is that (assuming optimizations are on) one of the
"forwprop" or "copyprop" invocations ought to be turning your
assignments from sums into assignments with constants [1] - allowing you
to update your pass registration accordingly.

Hope this is helpful - good luck!
Dave

[1] and perhaps then getting eliminated as dead stores in a later pass,
for the intermediates, at least.


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