[LLVMdev] Extract operations as function

Duncan Sands baldrick at free.fr
Thu May 12 01:22:03 PDT 2011


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         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list