public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Extracting operand name and value from GIMPLE assignment statements
@ 2013-12-09 23:05 Sandeep K Chaudhary
  2013-12-10  2:14 ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-09 23:05 UTC (permalink / raw)
  To: gcc-help

Hi Guys,

I am writing a GCC plugin in which I need to extract the variable name
and the assigned value from the statements.

I am able to get the three operands from GIMPLE statements like this

        if(is_gimple_assign(stmt)) {
                tree lhsop = gimple_assign_lhs(stmt);
                tree rhsop1 = gimple_assign_rhs1(stmt);
                tree rhsop2 = gimple_assign_rhs2(stmt);
         }

I want to get the exact variable name from lhsop and value from rhsop1
(for statements such as
"var = value;", rhsop2 is 0 for such statements.). Some pointers to
example code or documentation would be great. I can't find anything
similar in

http://gcc.gnu.org/onlinedocs/gccint/Manipulating-GIMPLE-statements.html

Thanks a lot !

Regards,
Sandeep K Chaudhary.

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

* Re: Extracting operand name and value from GIMPLE assignment statements
  2013-12-09 23:05 Extracting operand name and value from GIMPLE assignment statements Sandeep K Chaudhary
@ 2013-12-10  2:14 ` Ian Lance Taylor
  2013-12-10  2:38   ` Sandeep K Chaudhary
       [not found]   ` <CAEEAEzXYNvovf4SPqJqBWFx96+qX1DQ2RHY5q5i+iDXNiBgzrQ@mail.gmail.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2013-12-10  2:14 UTC (permalink / raw)
  To: Sandeep K Chaudhary; +Cc: gcc-help

On Mon, Dec 9, 2013 at 3:05 PM, Sandeep K Chaudhary
<babbusandy2006@gmail.com> wrote:
>
> I am writing a GCC plugin in which I need to extract the variable name
> and the assigned value from the statements.
>
> I am able to get the three operands from GIMPLE statements like this
>
>         if(is_gimple_assign(stmt)) {
>                 tree lhsop = gimple_assign_lhs(stmt);
>                 tree rhsop1 = gimple_assign_rhs1(stmt);
>                 tree rhsop2 = gimple_assign_rhs2(stmt);
>          }
>
> I want to get the exact variable name from lhsop and value from rhsop1
> (for statements such as
> "var = value;", rhsop2 is 0 for such statements.). Some pointers to
> example code or documentation would be great.

Can you expand on what you mean by the variable name?  GCC freely
introduces and discards variables in GIMPLE.  Many GIMPLE variables do
not have any meaningful name.

Ian

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

* Re: Extracting operand name and value from GIMPLE assignment statements
  2013-12-10  2:14 ` Ian Lance Taylor
@ 2013-12-10  2:38   ` Sandeep K Chaudhary
       [not found]   ` <CAEEAEzXYNvovf4SPqJqBWFx96+qX1DQ2RHY5q5i+iDXNiBgzrQ@mail.gmail.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-10  2:38 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Hi Ian,

Thanks for the reply !

I mean that I am interested in knowing the name of variables from the
code. For example - if there is a statement in the C code like this -

"VAR_A = 100;"

I would like to know the name of the variable i.e. "VAR_A" in the
GIMPLE statement. Please let me know how this can be achieved.

Thanks and regards,
Sandeep.

On Mon, Dec 9, 2013 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Mon, Dec 9, 2013 at 3:05 PM, Sandeep K Chaudhary
> <babbusandy2006@gmail.com> wrote:
>>
>> I am writing a GCC plugin in which I need to extract the variable name
>> and the assigned value from the statements.
>>
>> I am able to get the three operands from GIMPLE statements like this
>>
>>         if(is_gimple_assign(stmt)) {
>>                 tree lhsop = gimple_assign_lhs(stmt);
>>                 tree rhsop1 = gimple_assign_rhs1(stmt);
>>                 tree rhsop2 = gimple_assign_rhs2(stmt);
>>          }
>>
>> I want to get the exact variable name from lhsop and value from rhsop1
>> (for statements such as
>> "var = value;", rhsop2 is 0 for such statements.). Some pointers to
>> example code or documentation would be great.
>
> Can you expand on what you mean by the variable name?  GCC freely
> introduces and discards variables in GIMPLE.  Many GIMPLE variables do
> not have any meaningful name.
>
> Ian



-- 
Thanks and regards,
Sandeep K Chaudhary.

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

* Re: Extracting operand name and value from GIMPLE assignment statements
       [not found]   ` <CAEEAEzXYNvovf4SPqJqBWFx96+qX1DQ2RHY5q5i+iDXNiBgzrQ@mail.gmail.com>
@ 2013-12-10  6:06     ` Ian Lance Taylor
  2013-12-10  8:21       ` Sandeep K Chaudhary
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2013-12-10  6:06 UTC (permalink / raw)
  To: Sandeep K Chaudhary; +Cc: gcc-help

On Mon, Dec 9, 2013 at 6:35 PM, Sandeep K Chaudhary
<babbusandy2006@gmail.com> wrote:
>
> I mean that I am interested in knowing the name of variables from the code.
> For example - if there is a statement in the C code like this -
>
> "VAR_A = 100;"
>
> I would like to know the name of the variable i.e. "VAR_A" in the GIMPLE
> statement. Please let me know how this can be achieved.

In general, when in GIMPLE, there is no answer to that question.
GIMPLE translates your program into SSA form, so every variable is set
only once.  It follows that every local variable is a temporary
variable, with no name that is meaningful in the source code.  There
is debug info to track variable values, but it is tracked separately
from the GIMPLE statements.

Ian




> On Mon, Dec 9, 2013 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>>
>> On Mon, Dec 9, 2013 at 3:05 PM, Sandeep K Chaudhary
>> <babbusandy2006@gmail.com> wrote:
>> >
>> > I am writing a GCC plugin in which I need to extract the variable name
>> > and the assigned value from the statements.
>> >
>> > I am able to get the three operands from GIMPLE statements like this
>> >
>> >         if(is_gimple_assign(stmt)) {
>> >                 tree lhsop = gimple_assign_lhs(stmt);
>> >                 tree rhsop1 = gimple_assign_rhs1(stmt);
>> >                 tree rhsop2 = gimple_assign_rhs2(stmt);
>> >          }
>> >
>> > I want to get the exact variable name from lhsop and value from rhsop1
>> > (for statements such as
>> > "var = value;", rhsop2 is 0 for such statements.). Some pointers to
>> > example code or documentation would be great.
>>
>> Can you expand on what you mean by the variable name?  GCC freely
>> introduces and discards variables in GIMPLE.  Many GIMPLE variables do
>> not have any meaningful name.
>>
>> Ian
>
>
>
>
> --
> Thanks and regards,
> Sandeep K Chaudhary.

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

* Re: Extracting operand name and value from GIMPLE assignment statements
  2013-12-10  6:06     ` Ian Lance Taylor
@ 2013-12-10  8:21       ` Sandeep K Chaudhary
  2013-12-10 16:28         ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-10  8:21 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Hi Ian,

I understand that the variables in SSA are different but as you said
but I hoped to track the variables from the debug info. Is it not
feasible to track the debug info?

I have been able to achieve this kind of functionality with LLVM using
its LLVM IR of the program. The debug info is easily usable and
provides info about the IR statements with respect to the source code.
I want to write the pass in GCC that's why I hoped that I can somehow
achieve it in GCC. Please let me know your thoughts.

Thanks a lot !

Regards,
Sandeep.

On Tue, Dec 10, 2013 at 1:06 AM, Ian Lance Taylor <iant@google.com> wrote:
> On Mon, Dec 9, 2013 at 6:35 PM, Sandeep K Chaudhary
> <babbusandy2006@gmail.com> wrote:
>>
>> I mean that I am interested in knowing the name of variables from the code.
>> For example - if there is a statement in the C code like this -
>>
>> "VAR_A = 100;"
>>
>> I would like to know the name of the variable i.e. "VAR_A" in the GIMPLE
>> statement. Please let me know how this can be achieved.
>
> In general, when in GIMPLE, there is no answer to that question.
> GIMPLE translates your program into SSA form, so every variable is set
> only once.  It follows that every local variable is a temporary
> variable, with no name that is meaningful in the source code.  There
> is debug info to track variable values, but it is tracked separately
> from the GIMPLE statements.
>
> Ian
>
>
>
>
>> On Mon, Dec 9, 2013 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>>>
>>> On Mon, Dec 9, 2013 at 3:05 PM, Sandeep K Chaudhary
>>> <babbusandy2006@gmail.com> wrote:
>>> >
>>> > I am writing a GCC plugin in which I need to extract the variable name
>>> > and the assigned value from the statements.
>>> >
>>> > I am able to get the three operands from GIMPLE statements like this
>>> >
>>> >         if(is_gimple_assign(stmt)) {
>>> >                 tree lhsop = gimple_assign_lhs(stmt);
>>> >                 tree rhsop1 = gimple_assign_rhs1(stmt);
>>> >                 tree rhsop2 = gimple_assign_rhs2(stmt);
>>> >          }
>>> >
>>> > I want to get the exact variable name from lhsop and value from rhsop1
>>> > (for statements such as
>>> > "var = value;", rhsop2 is 0 for such statements.). Some pointers to
>>> > example code or documentation would be great.
>>>
>>> Can you expand on what you mean by the variable name?  GCC freely
>>> introduces and discards variables in GIMPLE.  Many GIMPLE variables do
>>> not have any meaningful name.
>>>
>>> Ian
>>
>>
>>
>>
>> --
>> Thanks and regards,
>> Sandeep K Chaudhary.



-- 
Thanks and regards,
Sandeep K Chaudhary.

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

* Re: Extracting operand name and value from GIMPLE assignment statements
  2013-12-10  8:21       ` Sandeep K Chaudhary
@ 2013-12-10 16:28         ` Ian Lance Taylor
  2013-12-10 22:39           ` Sandeep K Chaudhary
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2013-12-10 16:28 UTC (permalink / raw)
  To: Sandeep K Chaudhary; +Cc: gcc-help

On Tue, Dec 10, 2013 at 12:21 AM, Sandeep K Chaudhary
<babbusandy2006@gmail.com> wrote:
>
> I understand that the variables in SSA are different but as you said
> but I hoped to track the variables from the debug info. Is it not
> feasible to track the debug info?
>
> I have been able to achieve this kind of functionality with LLVM using
> its LLVM IR of the program. The debug info is easily usable and
> provides info about the IR statements with respect to the source code.
> I want to write the pass in GCC that's why I hoped that I can somehow
> achieve it in GCC. Please let me know your thoughts.

Please don't top-post.  Thanks.

Yes, you can track the debug info, you just can't do it by pulling
apart the GIMPLE instructions you are looking at.  You need to also
look for GIMPLE_DEBUG instructions.  The GIMPLE_DEBUG_BIND and
GIMPLE_DEBUG_SOURCE_BIND ops will help you map the gimple vars back to
the source vars.

This is not an area of the compiler that I know much about.

Ian

> On Tue, Dec 10, 2013 at 1:06 AM, Ian Lance Taylor <iant@google.com> wrote:
>> On Mon, Dec 9, 2013 at 6:35 PM, Sandeep K Chaudhary
>> <babbusandy2006@gmail.com> wrote:
>>>
>>> I mean that I am interested in knowing the name of variables from the code.
>>> For example - if there is a statement in the C code like this -
>>>
>>> "VAR_A = 100;"
>>>
>>> I would like to know the name of the variable i.e. "VAR_A" in the GIMPLE
>>> statement. Please let me know how this can be achieved.
>>
>> In general, when in GIMPLE, there is no answer to that question.
>> GIMPLE translates your program into SSA form, so every variable is set
>> only once.  It follows that every local variable is a temporary
>> variable, with no name that is meaningful in the source code.  There
>> is debug info to track variable values, but it is tracked separately
>> from the GIMPLE statements.
>>
>> Ian
>>
>>
>>
>>
>>> On Mon, Dec 9, 2013 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>>>>
>>>> On Mon, Dec 9, 2013 at 3:05 PM, Sandeep K Chaudhary
>>>> <babbusandy2006@gmail.com> wrote:
>>>> >
>>>> > I am writing a GCC plugin in which I need to extract the variable name
>>>> > and the assigned value from the statements.
>>>> >
>>>> > I am able to get the three operands from GIMPLE statements like this
>>>> >
>>>> >         if(is_gimple_assign(stmt)) {
>>>> >                 tree lhsop = gimple_assign_lhs(stmt);
>>>> >                 tree rhsop1 = gimple_assign_rhs1(stmt);
>>>> >                 tree rhsop2 = gimple_assign_rhs2(stmt);
>>>> >          }
>>>> >
>>>> > I want to get the exact variable name from lhsop and value from rhsop1
>>>> > (for statements such as
>>>> > "var = value;", rhsop2 is 0 for such statements.). Some pointers to
>>>> > example code or documentation would be great.
>>>>
>>>> Can you expand on what you mean by the variable name?  GCC freely
>>>> introduces and discards variables in GIMPLE.  Many GIMPLE variables do
>>>> not have any meaningful name.
>>>>
>>>> Ian
>>>
>>>
>>>
>>>
>>> --
>>> Thanks and regards,
>>> Sandeep K Chaudhary.
>
>
>
> --
> Thanks and regards,
> Sandeep K Chaudhary.

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

* Re: Extracting operand name and value from GIMPLE assignment statements
  2013-12-10 16:28         ` Ian Lance Taylor
@ 2013-12-10 22:39           ` Sandeep K Chaudhary
  0 siblings, 0 replies; 8+ messages in thread
From: Sandeep K Chaudhary @ 2013-12-10 22:39 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Ok, thanks a lot for the info, Ian ! I will look into these and try to
figure things out.

Thanks and regards,
Sandeep.

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

* Extracting operand name and value from GIMPLE assignment statements
@ 2013-06-26  1:08 Sandeep K Chaudhary
  0 siblings, 0 replies; 8+ messages in thread
From: Sandeep K Chaudhary @ 2013-06-26  1:08 UTC (permalink / raw)
  To: gcc-help

Hi Guys,

I am writing a GCC plugin in which I need to extract the variable name
and the assigned value from the statements.

I am able to get the three operands from GIMPLE statements like this

        if(is_gimple_assign(stmt)) {
                tree lhsop = gimple_assign_lhs(stmt);
                tree rhsop1 = gimple_assign_rhs1(stmt);
                tree rhsop2 = gimple_assign_rhs2(stmt);
         }

I want to get the exact variable name from lhsop and value from rhsop1
(for statements such as
"var = value;", rhsop2 is 0 for such statements.). Some pointers to
example code or documentation would be great. I can't find anything
similar in

http://gcc.gnu.org/onlinedocs/gccint/Manipulating-GIMPLE-statements.html

Thanks a lot !

Regards,
Sandeep K Chaudhary.

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

end of thread, other threads:[~2013-12-10 22:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-09 23:05 Extracting operand name and value from GIMPLE assignment statements Sandeep K Chaudhary
2013-12-10  2:14 ` Ian Lance Taylor
2013-12-10  2:38   ` Sandeep K Chaudhary
     [not found]   ` <CAEEAEzXYNvovf4SPqJqBWFx96+qX1DQ2RHY5q5i+iDXNiBgzrQ@mail.gmail.com>
2013-12-10  6:06     ` Ian Lance Taylor
2013-12-10  8:21       ` Sandeep K Chaudhary
2013-12-10 16:28         ` Ian Lance Taylor
2013-12-10 22:39           ` Sandeep K Chaudhary
  -- strict thread matches above, loose matches on Subject: below --
2013-06-26  1:08 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).