Hi, 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. Is codeExtractor.cpp useful for this. I was also thinking of going like loop-extract way. any other suggestion would be extremely helpful -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110511/ad96143c/attachment.html>
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
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? On Thu, May 12, 2011 at 1:22 AM, Duncan Sands <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 http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110512/5c8b8047/attachment.html>
Reasonably Related Threads
- [LLVMdev] Extract operations as function
- [LLVMdev] Extract operations as function
- [LLVMdev] Extract operations as function
- [LLVMdev] [PATCH] Split init.trampoline into init.trampoline & adjust.trampoline
- [RFC] Setting the current debug loc when the insertion point changes