This is the mail archive of the
mailing list for the GCC project.
Question about pointer use-def/def-use information operation and maintainance
- From: toddy wang <wenwangtoddy at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 18 May 2012 01:11:30 +0800
- Subject: Question about pointer use-def/def-use information operation and maintainance
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.
//original C code example
int a =1, b=2, d=0;
const char *addr = 0x400000;
Read(addr, &p1); //Read for p1, (R1). Read will allocate memory for p1
a = *p1;
Read(addr, &p2); // Read for p2, (R2). Read will allocate memory for p2.
b = *p2;
d = *(p2+1);
c = a+b+d;
------------intermediate code dump after ccp2----------------
;; Function foo (foo)
char * p2;
char * p1;
char * p2.1;
char * p1.0;
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;
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 ?