<div dir="ltr"><div><div>It's a bit unclear what exactly you're looking to do. The subject talks about moving instructions and the subsequent question mentions copying them.<br><br></div>I imagine you can get a pretty good example of how moving is done by looking at `splitBasicBlock()` for the moving case (it may in fact turn out that you actually want `llvm::splitBlock()` from lib/Transforms/Utils). You might want to look at the numerous uses of `IRBuilder` if you're looking to create new instructions that replicate the existing ones.<br><br><br></div>If none of this leads you to the answer, feel free to clarify the question a bit and re-post. If you specify exactly why you want this, you may get very good input in terms of how best to achieve the actual goal.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 26, 2017 at 8:39 AM, Jajoo, Malhar via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div id="m_-6706252521785537517divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" dir="ltr">
<p>Hi,</p>
<p><br>
</p>
<p>I have been trying to move some instructions between basic blocks , </p>
<p><br>
</p>
<p>After looking at the API , I found<i> llvm::Instruction::<wbr>clone() </i> but there </p>
<p>is no result value for this.</p>
<p><br>
</p>
<p><br>
</p>
<p>For example- </p>
<p><br>
</p>
<p><u><b>source Basic block :</b></u></p>
<p><br>
</p>
<p></p>
<div>continuation:                                     ; preds = %else, %then</div>
<div>  %iftmp = phi i32 [ 5, %then ], [ 9, %else ]</div>
<div>  store i32 %iftmp, i32* %datasize</div>
<div><br>
</div>
<div><b style="font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px"> <span style="color:rgb(255,0,0)">; 3 instructions below
 being copied</span></b><br>
</div>
<div> <b> store i8000000 0, i8000000* %res <span style="color:rgb(255,0,0)"></span></b></div>
<div><b>  %res4 = load i8000000, i8000000* %res</b></div>
<div><b>  ret i8000000 %res4</b></div>
<div><br>
</div>
<div><br>
</div>
<div>After copying the 3 instructions above to destination basic block.</div>
<div><br>
</div>
<u><b>destination basic block :</b></u>
<p></p>
<p><br>
</p>
<p></p>
<div>else:                                             ; preds = %entry</div>
<div>  store i8000000 0, i8000000* %res</div>
<div><b> <span style="color:rgb(255,0,0)"> %1---->issue</span></b> = load i8000000, i8000000* %res</div>
<div>  ret i8000000 <b><span style="color:rgb(255,0,0)">%res4 -----> issue , need to get result of instruction above. </span></b></div>
<div>  br label %continuation</div>
<div><br>
</div>
<br>
<p></p>
<p><br>
</p>
<p><br>
</p>
<p>I had tried using a simple Instruction::insert() earlier but ran </p>
<p>into an assertion error complaining that the Function contained duplicated instruction.</p>
<p><br>
</p>
<p><u><b>My Question</b></u> : How to copy an instruction ( along with it's name , or the LHS of the instruction ) </p>
<p>Is it possible to do name the LHS of the instruction using clone()  ?</p>
<p><br>
</p>
<p>Thanks,</p>
<p>Malhar</p>
<p><br>
</p>
</div>
</div>

<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>