Great!! Thanks Duncan.<div>By step 1 that you mentioned it seems I can write my function func(x,y,op) in mypass.cpp itself. Please elaborate how can add it to the module?</div><div><br></div><div><br><div class="gmail_quote">

On Thu, May 12, 2011 at 1:22 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi Manish,<br>
<div class="im"><br>
> I am planning to extract every operation as function.<br>
><br>
> eg. z=x+y; ==> z=func(x,y,op);<br>
><br>
> I wish to write a custom definition of op. Which I would like to define in func.<br>
><br>
> It would be really helpful if someone could suggest passes already available in<br>
> llvm to look for or point some references how should one proceed on it.<br>
<br>
</div>I think you should write your own pass that<br>
(1) adds a declaration of "func" to the module<br>
(2) iterates over all functions, and all instructions in the function.  When it<br>
sees a binary operator ("isa<BinaryOperator>(Instruction)") it needs to first<br>
insert a call just in front of the instruction (see an IRBuilder to do this;<br>
use "SetInsertPoint(Instruction)" to tell it where to add the call; use<br>
CreateCall3 to create the call).  Then use replaceAllUsesWith to replace every<br>
use of the binary operator with the call you just created.  Finally, delete the<br>
original instruction (eraseFromParent).<br>
<br>
Ciao, Duncan.<br>
<div class="im"><br>
><br>
> Is codeExtractor.cpp useful for this. I was also thinking of going like<br>
> loop-extract way. any other suggestion would be extremely helpful<br>
><br>
><br>
><br>
</div>> _______________________________________________<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>
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>
</blockquote></div><br></div>