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