[LLVMdev] Identifying the instructions that uses a pointer used as a function argument

Arnamoy Bhattacharyya arnamoy at ualberta.ca
Tue Nov 5 02:59:51 PST 2013


Hello all;

So here is my goal:

*** If there is a Call instruction to myFunction(int * val), I need to
identify all the instructions that uses val in the IR and replace the
uses with a newly created pointer.  I will also be changing the
argument of myFunction to the new pointer.

int * val = malloc/calloc;
...
myFunction(val);
....
*val = 45;

becomes==

int * val = malloc/calloc;
int * val1 = malloc/calloc;
...
myFunction(val1);
....
*val1 = 45;

I thought traversing the use-def chain of the function argument will
give me the uses of the pointer but it is giving me only one use.
(the call instruction to myFunc())

Is it happening because val is a pointer and the value is stored into
register first?  How can I identify the uses of val in the IR?  (And
if again val is assigned to a new pointer, the uses of that new
pointer?  e.g int * new_val = val; all the uses of new_val)

**I don't know if this is the right path to go, but if I could get the
name of the pointer used as an function argument, I could match the
name against other instructions that use the same named pointer.  But
this is also not working because first the pointer is loaded into
register and then the register is passed in the argument.

Sorry if the question does not make sense.  Any pointer or explanation
will be appreciated.

Thanks a lot!!
-- 
Arnamoy Bhattacharyya
Athabasca Hall 143
Department of Computing Science - University of Alberta
Edmonton, Alberta, Canada, T6G 2E8
587-710-7073



More information about the llvm-dev mailing list