<div dir="ltr"><div>I think I understood the problem you're trying to solve. I didn't, however,<br>understand the problems you are having (maybe you're not running mem2reg?).<br>I do have a little piece of code that I think does (more or less) what you want.<br>
Take a look at it, try understanding it, and see if it helps you out.<br>You might have to change it a bit since you're replacing uses after an<br>instruction and not a basic block.<br>Replace the "auto"s with the iterator types if you're not using C++0x.<br>
Also, sorry for the lack of comments. : )<br><br>void replaceUsesOfWithAfter(Value *V, Value *R, BasicBlock *BB) {<br>  set<Instruction*> Replace;<br>  for (auto UI = V->use_begin(), UE = V->use_end(); UI != UE; ++UI)<br>
    if (Instruction *I = dyn_cast<Instruction>(*UI)) {<br>      if (I != R && DT_->dominates(BB, I->getParent()))<br>        Replace.insert(I);<br>      else if (PHINode *Phi = dyn_cast<PHINode>(*UI))<br>
        for (unsigned Idx = 0; Idx < Phi->getNumIncomingValues(); ++Idx)<br>          if (Phi->getIncomingValue(Idx) == V &&<br>              DT_->dominates(BB, Phi->getIncomingBlock(Idx)))<br>            Phi->setIncomingValue(Idx, R);<br>
    }<br><br>  for (auto& I : Replace)<br>    I->replaceUsesOfWith(V, R);<br>}<br><br>If this doesn't help, you could try showing us the actual IR you're running<br>the transformation on.<br><br>Just FMI, is it okay to post code on this mailing list?<br>
</div><div><br>H.<br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 5, 2013 at 8:59 AM, Arnamoy Bhattacharyya <span dir="ltr"><<a href="mailto:arnamoy@ualberta.ca" target="_blank">arnamoy@ualberta.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all;<br>
<br>
So here is my goal:<br>
<br>
*** If there is a Call instruction to myFunction(int * val), I need to<br>
identify all the instructions that uses val in the IR and replace the<br>
uses with a newly created pointer.  I will also be changing the<br>
argument of myFunction to the new pointer.<br>
<br>
int * val = malloc/calloc;<br>
...<br>
myFunction(val);<br>
....<br>
*val = 45;<br>
<br>
becomes==<br>
<br>
int * val = malloc/calloc;<br>
int * val1 = malloc/calloc;<br>
...<br>
myFunction(val1);<br>
....<br>
*val1 = 45;<br>
<br>
I thought traversing the use-def chain of the function argument will<br>
give me the uses of the pointer but it is giving me only one use.<br>
(the call instruction to myFunc())<br>
<br>
Is it happening because val is a pointer and the value is stored into<br>
register first?  How can I identify the uses of val in the IR?  (And<br>
if again val is assigned to a new pointer, the uses of that new<br>
pointer?  e.g int * new_val = val; all the uses of new_val)<br>
<br>
**I don't know if this is the right path to go, but if I could get the<br>
name of the pointer used as an function argument, I could match the<br>
name against other instructions that use the same named pointer.  But<br>
this is also not working because first the pointer is loaded into<br>
register and then the register is passed in the argument.<br>
<br>
Sorry if the question does not make sense.  Any pointer or explanation<br>
will be appreciated.<br>
<br>
Thanks a lot!!<br>
<span class="HOEnZb"><font color="#888888">--<br>
Arnamoy Bhattacharyya<br>
Athabasca Hall 143<br>
Department of Computing Science - University of Alberta<br>
Edmonton, Alberta, Canada, T6G 2E8<br>
<a href="tel:587-710-7073" value="+15877107073">587-710-7073</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</font></span></blockquote></div><br></div>