[LLVMdev] Extract operations as function
Duncan Sands
baldrick at free.fr
Thu May 12 02:05:11 PDT 2011
Hi Manish,
> Great!! Thanks Duncan.
> 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?
the minimum is to add a prototype for "func" to the module. For that you can
use getOrInsertFunction. If you want to insert the code defining "func" too,
then insert the prototype, add a basic block to it, use an IRBuilder to add
instructions to the basic block.
Ciao, Duncan.
>
>
> On Thu, May 12, 2011 at 1:22 AM, Duncan Sands <baldrick at free.fr
> <mailto:baldrick at free.fr>> wrote:
>
> Hi Manish,
>
> > I am planning to extract every operation as function.
> >
> > eg. z=x+y; ==> z=func(x,y,op);
> >
> > I wish to write a custom definition of op. Which I would like to define
> in func.
> >
> > It would be really helpful if someone could suggest passes already
> available in
> > llvm to look for or point some references how should one proceed on it.
>
> I think you should write your own pass that
> (1) adds a declaration of "func" to the module
> (2) iterates over all functions, and all instructions in the function. When it
> sees a binary operator ("isa<BinaryOperator>(Instruction)") it needs to first
> insert a call just in front of the instruction (see an IRBuilder to do this;
> use "SetInsertPoint(Instruction)" to tell it where to add the call; use
> CreateCall3 to create the call). Then use replaceAllUsesWith to replace every
> use of the binary operator with the call you just created. Finally, delete the
> original instruction (eraseFromParent).
>
> Ciao, Duncan.
>
> >
> > Is codeExtractor.cpp useful for this. I was also thinking of going like
> > loop-extract way. any other suggestion would be extremely helpful
> >
> >
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
More information about the llvm-dev
mailing list