public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Sandeep K Chaudhary <babbusandy2006@gmail.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: Extracting operand name and value from GIMPLE assignment statements
Date: Tue, 10 Dec 2013 16:28:00 -0000	[thread overview]
Message-ID: <CAKOQZ8w_XWSrsUfX6Ocis7a+DXRBr=Uu0=Q=NK6TpC6wE7xshw@mail.gmail.com> (raw)
In-Reply-To: <CAEEAEzV1m8FzhW=po5aWCrtCrJz2tHkO869UnZ_KWN=a2wTM9Q@mail.gmail.com>

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.

  reply	other threads:[~2013-12-10 16:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-09 23:05 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 [this message]
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

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='CAKOQZ8w_XWSrsUfX6Ocis7a+DXRBr=Uu0=Q=NK6TpC6wE7xshw@mail.gmail.com' \
    --to=iant@google.com \
    --cc=babbusandy2006@gmail.com \
    --cc=gcc-help@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).