top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Extracting operand name and value from GIMPLE assignment statements

0 votes
274 views

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

posted Jun 26, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+5 votes

I have a C code like this:

int foo(void)
{ 
 int phase;
 . . .
 phase = 1;
 phase = 2;
 phase = 3;
 . . .
}

In case of -O0 gcc generates machine instructions for every assignment 'phase = ...'. But in case of -O2 gcc does not generate instructions for some assignments. Of course, this is correct. However, is there any way to tell gcc that 'phase' object is inspected by another thread, so it should not remove such statements?

+5 votes

Even I have similar problem:

int (*pfun)(void);
int *pInt = 0;
void fun1()
{
    int i = 5; /* Local to fun1*/

    printf("Outer function");
    pInt = &i; /* As I know address of local variable is valid till function execution */

    int fun2()
    {
      printf("innerfunction");
      printf("%d", *pInt);
    }
    /* fun2 address assign to pfun so that It can be called even after completion of fun1 */
    pfun = fun2;
}

int main()
{
    fun1();
    pfun();
    return 0;
}

Can someone please explain ? I am getting *pInt value 5.

+4 votes

in case if is it possible, how you can change and pls explain with some example.

+1 vote

I am building a shared library which will be distributed to clients in binary form only. I am attempting to make the same binary run on as many Linux variants as possible, and so when I build it I specify the
options -shared and -fPIC. As part of the effort of making the library as independent as possible, I also link both the C and C++ standard libraries statically into the final shared library. I want to do this because I use
C++11 features internally, and I don't want to force the users of my library to have a C++11 compiler handy.

When doing this, do I need to build libstdc++ and libgcc from source with -fPIC as well? Or is it okay to link with the static versions of these libraries that are provided in my Ubuntu 13.04 gcc package?

To clarify, no exceptions are thrown over library boundaries; all exceptions used internally in the library are caught and processed behind the scenes. None of them ever reach the client code, as the client communicates with the library using a plain C interface.

My exact build flags are as follows:

g++ -fvisibility=hidden -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc -s -DNDEBUG -std=c++11 -Wall -shared -fPIC -o libtest.so test.cpp -lpthread -O2

0 votes

I wanted to run individual test from gcc/testsuite/c-c++-common/ directory, but unfortunately there is no *.exp file as it is in other directories. This prevents me from running it as for i386 e.g.: make check RUNTESTFLAGS="i386.exp=avx512*".

I also couldn't find anything related to those tests in documentation. Is there any special approach for that?


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...