Extracting operand name and value from GIMPLE assignment statements

Ian Lance Taylor iant@google.com
Tue Dec 10 16:28:00 GMT 2013


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.



More information about the Gcc-help mailing list