public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GIMPLE pass - Assignment evaluation
@ 2013-12-16 21:10 Sandeep K Chaudhary
  2013-12-17  1:33 ` David Malcolm
  0 siblings, 1 reply; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-16 21:10 UTC (permalink / raw)
  To: gcc-help, gcc

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.

Thanks and regards,
Sandeep.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-12-16 21:10 GIMPLE pass - Assignment evaluation Sandeep K Chaudhary
@ 2013-12-17  1:33 ` David Malcolm
  2013-12-17  6:24   ` Sandeep K Chaudhary
  0 siblings, 1 reply; 10+ messages in thread
From: David Malcolm @ 2013-12-17  1:33 UTC (permalink / raw)
  To: Sandeep K Chaudhary; +Cc: gcc-help, gcc

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-12-17  1:33 ` David Malcolm
@ 2013-12-17  6:24   ` Sandeep K Chaudhary
  2013-12-17  6:41     ` Uday P. Khedker
  0 siblings, 1 reply; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-17  6:24 UTC (permalink / raw)
  To: David Malcolm; +Cc: gcc-help, gcc

Thank you so much for the reply, David !

I am not sure where exactly my pass gets invoked. I will try to find it.
But the pass get invoked somewhere in the GIMPLE stage as shown in the
GCC architecture[1].
How is it that one can dictate where the pass can be invoked? Can you
please provide some pointers/links about this?

But looking at the GCC architecture[1], I can see that the
optimization passes come into picture only after GIMPLE and SSA stage.
 I dumped the IR and other related files using -fdump-tree-all with
optimization flag -O1, and saw that the assignments have not been
evaluated for test.c.004t.gimple as well as test.c.018t.ssa.

Also, in test.c.025t.forwprop1 and test.c.029t.copyprop1, they totally
get rid of everything in the assignments i.e. they only have the final
evaluation of the variables which is not what I want as I need
evaluation for individual statements.

[2] provides a nice diagrammatic understanding of the relative
invocations of GCC opt passes. It is quite helpful for understanding
the relative positions of the passes.

Thanks and regards,
Sandeep.

[1] http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture
[2] https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-12-17  6:24   ` Sandeep K Chaudhary
@ 2013-12-17  6:41     ` Uday P. Khedker
  2013-12-17  7:26       ` Sandeep K Chaudhary
  0 siblings, 1 reply; 10+ messages in thread
From: Uday P. Khedker @ 2013-12-17  6:41 UTC (permalink / raw)
  To: Sandeep K Chaudhary, David Malcolm; +Cc: gcc-help, gcc

You may also want to go through the slides at http://www.cse.iitb.ac.in/grc/gcc-workshop-13/index.php?page=slides.

In particular, http://www.cse.iitb.ac.in/grc/gcc-workshop-13/downloads/slides/Day1/gccw13-gimple-manipulation.pdf and http://www.cse.iitb.ac.in/grc/gcc-workshop-13/downloads/slides/Day2/gccw13-code-view.pdf may be of help.

Unfortunately there is some problem with playing the videos of the lectures (http://www.cse.iitb.ac.in/grc/gcc-workshop-12/index.php?page=videos) but we are working on that.

Uday Khedker.

Sandeep K Chaudhary wrote, On Tuesday 17 December 2013 11:54 AM:
> Thank you so much for the reply, David !
>
> I am not sure where exactly my pass gets invoked. I will try to find it.
> But the pass get invoked somewhere in the GIMPLE stage as shown in the
> GCC architecture[1].
> How is it that one can dictate where the pass can be invoked? Can you
> please provide some pointers/links about this?
>
> But looking at the GCC architecture[1], I can see that the
> optimization passes come into picture only after GIMPLE and SSA stage.
>   I dumped the IR and other related files using -fdump-tree-all with
> optimization flag -O1, and saw that the assignments have not been
> evaluated for test.c.004t.gimple as well as test.c.018t.ssa.
>
> Also, in test.c.025t.forwprop1 and test.c.029t.copyprop1, they totally
> get rid of everything in the assignments i.e. they only have the final
> evaluation of the variables which is not what I want as I need
> evaluation for individual statements.
>
> [2] provides a nice diagrammatic understanding of the relative
> invocations of GCC opt passes. It is quite helpful for understanding
> the relative positions of the passes.
>
> Thanks and regards,
> Sandeep.
>
> [1] http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture
> [2] https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-12-17  6:41     ` Uday P. Khedker
@ 2013-12-17  7:26       ` Sandeep K Chaudhary
  0 siblings, 0 replies; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-17  7:26 UTC (permalink / raw)
  To: Uday P. Khedker; +Cc: David Malcolm, gcc-help, gcc

Thank you so much, Prof. Khedkar !

I will go through the slides and other resources that you pointed out.
GRC workshops/tutorials are great. These helped me get started with
GCC when I knew almost nothing about GCC internals.

I will get back with specific queries (if any) after going through these.

Thanks and regards,
Sandeep.

On Tue, Dec 17, 2013 at 1:41 AM, Uday P. Khedker <uday@cse.iitb.ac.in> wrote:
> You may also want to go through the slides at
> http://www.cse.iitb.ac.in/grc/gcc-workshop-13/index.php?page=slides.
>
> In particular,
> http://www.cse.iitb.ac.in/grc/gcc-workshop-13/downloads/slides/Day1/gccw13-gimple-manipulation.pdf
> and
> http://www.cse.iitb.ac.in/grc/gcc-workshop-13/downloads/slides/Day2/gccw13-code-view.pdf
> may be of help.
>
> Unfortunately there is some problem with playing the videos of the lectures
> (http://www.cse.iitb.ac.in/grc/gcc-workshop-12/index.php?page=videos) but we
> are working on that.
>
> Uday Khedker.
>
> Sandeep K Chaudhary wrote, On Tuesday 17 December 2013 11:54 AM:
>
>> Thank you so much for the reply, David !
>>
>> I am not sure where exactly my pass gets invoked. I will try to find it.
>> But the pass get invoked somewhere in the GIMPLE stage as shown in the
>> GCC architecture[1].
>> How is it that one can dictate where the pass can be invoked? Can you
>> please provide some pointers/links about this?
>>
>> But looking at the GCC architecture[1], I can see that the
>> optimization passes come into picture only after GIMPLE and SSA stage.
>>   I dumped the IR and other related files using -fdump-tree-all with
>> optimization flag -O1, and saw that the assignments have not been
>> evaluated for test.c.004t.gimple as well as test.c.018t.ssa.
>>
>> Also, in test.c.025t.forwprop1 and test.c.029t.copyprop1, they totally
>> get rid of everything in the assignments i.e. they only have the final
>> evaluation of the variables which is not what I want as I need
>> evaluation for individual statements.
>>
>> [2] provides a nice diagrammatic understanding of the relative
>> invocations of GCC opt passes. It is quite helpful for understanding
>> the relative positions of the passes.
>>
>> Thanks and regards,
>> Sandeep.
>>
>> [1]
>> http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture
>> [2]
>> https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
>>
>
>



-- 
Thanks and regards,
Sandeep K Chaudhary.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* GIMPLE pass - Assignment evaluation
@ 2013-12-09 23:05 Sandeep K Chaudhary
  0 siblings, 0 replies; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-09 23:05 UTC (permalink / raw)
  To: gcc-help

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.

Thanks and regards,
Sandeep.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-07-02 17:09   ` Sandeep K Chaudhary
@ 2013-07-10  8:18     ` Sandeep K Chaudhary
  0 siblings, 0 replies; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-07-10  8:18 UTC (permalink / raw)
  To: gcc-help

Hi everyone,

Can someone please help me with this?

To briefly reiterate my issue (referring to my original post), how can
I get the calculations on RHS in GIMPLE pass using some optimizations
if possible? I tried to use the optimization flags as suggested by
Marc but it does not work.

Thanks and regards,
Sandeep.

On Tue, Jul 2, 2013 at 1:09 PM, Sandeep K Chaudhary
<babbusandy2006@gmail.com> wrote:
> Hi Marc ! Thanks for the reply.
>
> 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
>
> Am I supposed to use "-O1" differently to invoke the CCP pass?
>
> Regards,
> Sandeep.
>
> On Tue, Jul 2, 2013 at 1:44 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> On Mon, 1 Jul 2013, 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?
>>
>>
>> -O1 (or higher) enables the CCP pass which propagates the constants. Note
>> that only the last value will be left after that. If you need the
>> intermediate ones for some reason, maybe you could look into the CCP pass
>> and modify it for your needs?
>>
>> --
>> Marc Glisse
>
>
>
> --
> Thanks and regards,
> Sandeep K Chaudhary.



-- 
Thanks and regards,
Sandeep K Chaudhary.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-07-02  5:44 ` Marc Glisse
@ 2013-07-02 17:09   ` Sandeep K Chaudhary
  2013-07-10  8:18     ` Sandeep K Chaudhary
  0 siblings, 1 reply; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-07-02 17:09 UTC (permalink / raw)
  To: gcc-help

Hi Marc ! Thanks for the reply.

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

Am I supposed to use "-O1" differently to invoke the CCP pass?

Regards,
Sandeep.

On Tue, Jul 2, 2013 at 1:44 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Mon, 1 Jul 2013, 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?
>
>
> -O1 (or higher) enables the CCP pass which propagates the constants. Note
> that only the last value will be left after that. If you need the
> intermediate ones for some reason, maybe you could look into the CCP pass
> and modify it for your needs?
>
> --
> Marc Glisse



-- 
Thanks and regards,
Sandeep K Chaudhary.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GIMPLE pass - Assignment evaluation
  2013-07-02  3:24 Sandeep K Chaudhary
@ 2013-07-02  5:44 ` Marc Glisse
  2013-07-02 17:09   ` Sandeep K Chaudhary
  0 siblings, 1 reply; 10+ messages in thread
From: Marc Glisse @ 2013-07-02  5:44 UTC (permalink / raw)
  To: Sandeep K Chaudhary; +Cc: gcc-help

On Mon, 1 Jul 2013, 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?

-O1 (or higher) enables the CCP pass which propagates the constants. Note 
that only the last value will be left after that. If you need the 
intermediate ones for some reason, maybe you could look into the CCP pass 
and modify it for your needs?

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 10+ messages in thread

* GIMPLE pass - Assignment evaluation
@ 2013-07-02  3:24 Sandeep K Chaudhary
  2013-07-02  5:44 ` Marc Glisse
  0 siblings, 1 reply; 10+ messages in thread
From: Sandeep K Chaudhary @ 2013-07-02  3:24 UTC (permalink / raw)
  To: gcc-help

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?

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.

--
Thanks and regards,
Sandeep K Chaudhary.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-12-17  7:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-16 21:10 GIMPLE pass - Assignment evaluation Sandeep K Chaudhary
2013-12-17  1:33 ` David Malcolm
2013-12-17  6:24   ` Sandeep K Chaudhary
2013-12-17  6:41     ` Uday P. Khedker
2013-12-17  7:26       ` Sandeep K Chaudhary
  -- strict thread matches above, loose matches on Subject: below --
2013-12-09 23:05 Sandeep K Chaudhary
2013-07-02  3:24 Sandeep K Chaudhary
2013-07-02  5:44 ` Marc Glisse
2013-07-02 17:09   ` Sandeep K Chaudhary
2013-07-10  8:18     ` Sandeep K Chaudhary

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).