Hello everybody. I'm quite new to LLVM and I'm encontering problems with cloning basic blocks. My two basic blocks are in the same function and it doesn't really matter how the cloned one behave for the moment. Of course, to do so, I used the cloning.h 's method "CloneBasicBlock" but I have the "Instruction does not dominate all uses!" error. I know what it means, I just don't know how to get rid of it without getting more complicated errors. (I tried manipulating the VMap, the metadatas, cloning each instruction one by one,...). Is there a way to know if an instruction is a definition (so I could remove or rename the value)? Is there a VMap book for newbies? Is there some documentations I forgot to look at? Thank you. virtual BasicBlock* createAlteredBasicBlock(BasicBlock * basicBlock, const Twine & Name = "", Function * F = 0){ ValueToValueMapTy VMap; BasicBlock * alteredBB = llvm::CloneBasicBlock (basicBlock, VMap, Name, F); return alteredBB; } -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120621/169acc2e/attachment.html>
CloneBasicBlock does a fairly shallow cloning; the instructions themselves are cloned but their operands are not replaced with any previously cloned values. Example: orig: %a = ... %b = fadd %a, ... clone: %a.clone = ... %b.clone = fadd %a, ... ; Note that this references the old %a and not %a.clone! You can loop over the instruction's operands to see if they are contained in VMap and replace them if need be. You'll find it helpful to view the IR after doing the clone, e.g. "alteredBB->dump()". You may also need to update phi nodes in the cloned block and elsewhere, depending on how you plan on inserting the clone into your CFG. On Thu, Jun 21, 2012 at 11:47 AM, Nileih Cimeil <nileih at gmail.com> wrote:> Hello everybody. > > I'm quite new to LLVM and I'm encontering problems with cloning basic > blocks. My two basic blocks are in the same function and it doesn't really > matter how the cloned one behave for the moment. Of course, to do so, I used > the cloning.h 's method "CloneBasicBlock" but I have the "Instruction does > not dominate all uses!" error. > I know what it means, I just don't know how to get rid of it without getting > more complicated errors. (I tried manipulating the VMap, the metadatas, > cloning each instruction one by one,...). > > Is there a way to know if an instruction is a definition (so I could remove > or rename the value)? > Is there a VMap book for newbies? > Is there some documentations I forgot to look at? > > > Thank you. > > > > virtual BasicBlock* createAlteredBasicBlock(BasicBlock * basicBlock, const > Twine & Name = "", Function * F = 0){ > > ValueToValueMapTy VMap; > BasicBlock * alteredBB = llvm::CloneBasicBlock (basicBlock, > VMap, Name, F); > > return alteredBB; > } > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Please reply-all so that the thread is kept on llvmdev. The LLVM Programmer's Manual has examples of how to iterate over many common structures, such as instructions in a basic block[1]. Other than that, you can check the source code or doxygen[2]. Basically, you loop over the instructions as detailed in the programmer's manual[1], and loop over the operands using User's op_iterators[2] checking to see if they have entries in ValueMap[3]. If they do, you set that operand to use ValueMap's entry. [1] http://llvm.org/docs/ProgrammersManual.html#iterate_basicblock [2] http://llvm.org/doxygen/classllvm_1_1User.html [3] http://llvm.org/doxygen/classllvm_1_1ValueMap.html On Thu, Jun 21, 2012 at 1:49 PM, Nileih Cimeil <nileih at gmail.com> wrote:> Thank you for your quick answer... > > > "You can loop over the instruction's operands to see if they are > contained in VMap" > > I have no clue of to do that, do you have an example ? > > > > 2012/6/21 Michael Ilseman <michael at lunarg.com> >> >> CloneBasicBlock does a fairly shallow cloning; the instructions >> themselves are cloned but their operands are not replaced with any >> previously cloned values. >> >> Example: >> orig: >> %a = ... >> %b = fadd %a, ... >> >> clone: >> %a.clone = ... >> %b.clone = fadd %a, ... ; Note that this references the old %a and >> not %a.clone! >> >> You can loop over the instruction's operands to see if they are >> contained in VMap and replace them if need be. You'll find it helpful >> to view the IR after doing the clone, e.g. "alteredBB->dump()". You >> may also need to update phi nodes in the cloned block and elsewhere, >> depending on how you plan on inserting the clone into your CFG. >> >> On Thu, Jun 21, 2012 at 11:47 AM, Nileih Cimeil <nileih at gmail.com> wrote: >> > Hello everybody. >> > >> > I'm quite new to LLVM and I'm encontering problems with cloning basic >> > blocks. My two basic blocks are in the same function and it doesn't >> > really >> > matter how the cloned one behave for the moment. Of course, to do so, I >> > used >> > the cloning.h 's method "CloneBasicBlock" but I have the "Instruction >> > does >> > not dominate all uses!" error. >> > I know what it means, I just don't know how to get rid of it without >> > getting >> > more complicated errors. (I tried manipulating the VMap, the metadatas, >> > cloning each instruction one by one,...). >> > >> > Is there a way to know if an instruction is a definition (so I could >> > remove >> > or rename the value)? >> > Is there a VMap book for newbies? >> > Is there some documentations I forgot to look at? >> > >> > >> > Thank you. >> > >> > >> > >> > virtual BasicBlock* createAlteredBasicBlock(BasicBlock * basicBlock, >> > const >> > Twine & Name = "", Function * F = 0){ >> > >> > ValueToValueMapTy VMap; >> > BasicBlock * alteredBB = llvm::CloneBasicBlock (basicBlock, >> > VMap, Name, F); >> > >> > return alteredBB; >> > } >> > >> > >> > _______________________________________________ >> > LLVM Developers mailing list >> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > > >
Thank you for your help. It's working now. I wasn't aware of the usefulness of the User class. The ValueMapper.cpp's "RemapInstruction()" also helped me a lot to remap phi nodes and metadatas. Thank you very much. 2012/6/21 Michael Ilseman <michael at lunarg.com>> Please reply-all so that the thread is kept on llvmdev. > > The LLVM Programmer's Manual has examples of how to iterate over many > common structures, such as instructions in a basic block[1]. Other > than that, you can check the source code or doxygen[2]. > > Basically, you loop over the instructions as detailed in the > programmer's manual[1], and loop over the operands using User's > op_iterators[2] checking to see if they have entries in ValueMap[3]. > If they do, you set that operand to use ValueMap's entry. > > [1] http://llvm.org/docs/ProgrammersManual.html#iterate_basicblock > [2] http://llvm.org/doxygen/classllvm_1_1User.html > [3] http://llvm.org/doxygen/classllvm_1_1ValueMap.html > > On Thu, Jun 21, 2012 at 1:49 PM, Nileih Cimeil <nileih at gmail.com> wrote: > > Thank you for your quick answer... > > > > > > "You can loop over the instruction's operands to see if they are > > contained in VMap" > > > > I have no clue of to do that, do you have an example ? > > > > > > > > 2012/6/21 Michael Ilseman <michael at lunarg.com> > >> > >> CloneBasicBlock does a fairly shallow cloning; the instructions > >> themselves are cloned but their operands are not replaced with any > >> previously cloned values. > >> > >> Example: > >> orig: > >> %a = ... > >> %b = fadd %a, ... > >> > >> clone: > >> %a.clone = ... > >> %b.clone = fadd %a, ... ; Note that this references the old %a and > >> not %a.clone! > >> > >> You can loop over the instruction's operands to see if they are > >> contained in VMap and replace them if need be. You'll find it helpful > >> to view the IR after doing the clone, e.g. "alteredBB->dump()". You > >> may also need to update phi nodes in the cloned block and elsewhere, > >> depending on how you plan on inserting the clone into your CFG. > >> > >> On Thu, Jun 21, 2012 at 11:47 AM, Nileih Cimeil <nileih at gmail.com> > wrote: > >> > Hello everybody. > >> > > >> > I'm quite new to LLVM and I'm encontering problems with cloning basic > >> > blocks. My two basic blocks are in the same function and it doesn't > >> > really > >> > matter how the cloned one behave for the moment. Of course, to do so, > I > >> > used > >> > the cloning.h 's method "CloneBasicBlock" but I have the "Instruction > >> > does > >> > not dominate all uses!" error. > >> > I know what it means, I just don't know how to get rid of it without > >> > getting > >> > more complicated errors. (I tried manipulating the VMap, the > metadatas, > >> > cloning each instruction one by one,...). > >> > > >> > Is there a way to know if an instruction is a definition (so I could > >> > remove > >> > or rename the value)? > >> > Is there a VMap book for newbies? > >> > Is there some documentations I forgot to look at? > >> > > >> > > >> > Thank you. > >> > > >> > > >> > > >> > virtual BasicBlock* createAlteredBasicBlock(BasicBlock * basicBlock, > >> > const > >> > Twine & Name = "", Function * F = 0){ > >> > > >> > ValueToValueMapTy VMap; > >> > BasicBlock * alteredBB = llvm::CloneBasicBlock > (basicBlock, > >> > VMap, Name, F); > >> > > >> > return alteredBB; > >> > } > >> > > >> > > >> > _______________________________________________ > >> > 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/20120622/fbe825cb/attachment.html>