<div dir="ltr"><div>Actually, it's quite the opposite. This is happening because the allocas <br>weren't promoted to registers references. To do so, you should run the SSA <br>construction pass. This is done by running "opt -mem2reg" on your <br>
bytecode file.<br><br>Good luck.<br><br></div>H.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 5, 2013 at 11:26 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">Thanks for the reply.<br>
<br>
For the source code:<br>
<br>
int main()<br>
{<br>
int a = 0;<br>
int *p;<br>
p = &a;<br>
call_arnamoy(p);<br>
int *p1;<br>
p1 = p;<br>
return 1;<br>
}<br>
<br>
The bit code:<br>
<br>
  %retval = alloca i32, align 4<br>
  %a = alloca i32, align 4<br>
%p = alloca i32*, align 8<br>
 %p1 = alloca i32*, align 8<br>
 store i32 0, i32* %retval<br>
store i32 0, i32* %a, align 4<br>
store i32* %a, i32** %p, align 8<br>
%0 = load i32** %p, align 8<br>
%call = call i32 @arnamoy(i32* %0)<br>
%1 = load i32** %p, align 8<br>
store i32* %1, i32** %p1, align 8<br>
ret i32 1<br>
<br>
I need to know where the pointer "p" is used in the IR.  But when I<br>
try to run the use_iterator on callInst->getArgOperand(0), it return<br>
only one instruct that is the Call instruction itself.  But not the<br>
store i32* %a, i32** %p, align 8, %1 = load i32** %p, align 8 and %0 =<br>
load i32** %p, align 8  I need all of those.  I am guessing this is<br>
happening because the argument is promoted to register.  Is there a<br>
way of knowing the name of the variable the value of which is stored<br>
in the register?<br>
<br>
If it's not possible, any work-around suggestions?<br>
<br>
Thanks a lot again;<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Nov 5, 2013 at 12:41 PM, Henrique Santos<br>
<<a href="mailto:henrique.nazare.santos@gmail.com">henrique.nazare.santos@gmail.com</a>> wrote:<br>
> 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<br>
> 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>
><br>
> H.<br>
><br>
><br>
><br>
> On Tue, Nov 5, 2013 at 8:59 AM, Arnamoy Bhattacharyya <<a href="mailto:arnamoy@ualberta.ca">arnamoy@ualberta.ca</a>><br>
> wrote:<br>
>><br>
>> 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>
>> --<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>
><br>
><br>
<br>
<br>
<br>
--<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>
</div></div></blockquote></div><br></div>