[LLVMdev] Cloning block for newbie
Michael Ilseman
michael at lunarg.com
Thu Jun 21 11:25:16 PDT 2012
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
>
More information about the llvm-dev
mailing list