This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question about pointer use-def/def-use information operation and maintainance


Hi, all
  Now I am developing a GCC(verion 4.6.2) optimization plugin(it is
inserted after ccp2 or ssa) for redundant memory access elimination.
But I don't know how to handle pointer use-def/def-use information
when a redundant statement is found.
  For example,

//original C code example
int foo()
{
int a =1, b=2, d=0;
int c;
char *p1;
char *p2;
const char *addr = 0x400000;

Read(addr, &p1); //Read for p1, (R1). Read will allocate memory for p1
a = *p1;
a++;

Read(addr, &p2); // Read for p2, (R2). Read will allocate memory for p2.
b = *p2;
d = *(p2+1);
b++;

c = a+b+d;
return c;
}

------------intermediate code dump after ccp2----------------
;; Function foo (foo)

foo ()
{
  char * p2;
  char * p1;
  int c;
  int d;
  int b;
  int a;
  int D.3300;
  char D.3298;
  char D.3296;
  char * p2.1;
  char D.3294;
  char * p1.0;

<bb 2>:
  Read (4194304B, &p1);
  p1.0_5 = p1;
  D.3294_6 = *p1.0_5;
  a_7 = (int) D.3294_6;
  a_8 = a_7 + 1;
  Read (4194304B, &p2);
  p2.1_9 = p2;
  D.3296_10 = *p2.1_9;
  b_11 = (int) D.3296_10;
  p2.1_12 = p2;
  D.3298_14 = MEM[(char *)p2.1_12 + 1B];
  d_15 = (int) D.3298_14;
  b_16 = b_11 + 1;
  D.3300_17 = a_8 + b_16;
  c_18 = D.3300_17 + d_15;
  return c_18;

}
------------------------------------------------------------

In this example code, R1 and R2 are redundant, and thus R2 will be
eliminated and all the referenced p2 should be replaced by p1. But how
can I find all the referenced locations of p2 and replace them with
p1?  This is my first question.

  My preliminary idea is as follows
1.Iterate all the gimple statements after R2 and find out whose right
handside operator contain an reference to p2.
2. replace reference to p2 with p1.

Another possible methods is that insert a gimple statements p2 = p1 in
the original location of R2.

However, for the two possible solution mentioned above, I have still
have two questions:
1. whether there is need to maintain use-def/def-use information for
p1 and p2 after the replacing is done.
2. if maintainance for use-def/def-use information for pointer p1 and
p2, what is the exact timing to do so and which APIs is available to
do this ?


Thank you
Wang Tao


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]