<div>Ah ok. So you really don't want to clone the instructions. You can build new ones using IRBuilder. </div><div><br></div><div>I suppose you can clone the first one, then use the resulting llvm::Value to build the next one. And so on. </div><div><br><div class="gmail_quote"><div>On Fri, May 26, 2017 at 10:49 AM Jajoo, Malhar <<a href="mailto:malhar.jajoo14@imperial.ac.uk">malhar.jajoo14@imperial.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>

<div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi Nemanja,</p>
<p><br>
</p>
<p>Thanks for your response.</p>
<p><br>
</p>
<p>Sorry for the confusion ,</p>
<p><br>
</p>
<p>I am trying to </p>
<p><br>
</p>
<p></p>
<ol style="margin-bottom:0px;margin-top:0px">
<li><span 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">copy </span><span 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">a
 set of instructions from source Basic block to 2 or more destination basic blocks</span><br>
</li><li><span 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">After copying I wish to remove the instructions from the
 source basic block.</span></li><li><span 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">delete source basic block.<br>
<br>
</span></li></ol>
<div>After struggling a bit with the API I get the following result - <br>
<br>
<br>
//========== destination basic blocks ==========</div>
<div><br>
<div>then:                                             ; preds = %entry</div></div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div>
<div>  store i8000000 0, i8000000* %res</div>
<div><br>
</div>
</div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><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(114,50,173)">;after copying</span></b></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)"> Issue-----></span></b><b><span style="color:rgb(255,0,0)">
 %res45</span> = load i8000000, i8000000* %res</b></div>
<div><b>  ret i8000000 <span style="color:rgb(255,0,0)">%res4<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)"><-----
 Issue</span></b></span></b></div>
<div><b>  br label %continuation</b></div></div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div>
<div><br>
</div>
<div>else:                                             ; preds = %entry</div>
<div>  store i8000000 0, i8000000* %res</div>
<div><b><br>
</b></div>
</div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div><div><b><span style="color:rgb(255,0,0)"><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(114,50,173)">;after
 copying</span></b><br>
</span></b></div>
<div> <b><span style="color:rgb(255,0,0)"> Issue----->%res46-</span> = load i8000000, i8000000* %res</b></div>
<div><b>  ret i8000000 <span style="color:rgb(255,0,0)">%res4 <----- Issue</span></b></div>
<div><b>  br label %continuation</b></div>
<div><br>
</div>
<div>//==============  source basic block ===============</div></div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div>
<br>
<div>continuation:                                     ; preds = %else, %then</div>
<div>  %iftmp = phi i32 [ 5, %then ], [ 9, %else ]</div>
<div>  store i32 %iftmp, i32* %datasize</div>
<div><b><br>
</b></div>
</div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div><div><b><span style="color:rgb(255,0,0)">; 3 lines below to be copied and then
</span><span style="color:rgb(255,0,0)">this whole basic block needs to be deleted</span><span style="color:rgb(255,0,0)">.</span></b></div></div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div>
<div><b><span style="color:rgb(0,0,0)">  </span><span style="color:rgb(0,0,0)">store i8000000 0, i8000000* %res</span></b></div>
<div><span style="color:rgb(255,0,0)"><b><span style="color:rgb(0,0,0)">  %res4 = load i8000000, i8000000* %res</span></b></span></div>
<div><span style="color:rgb(255,0,0)"><b><span style="color:rgb(0,0,0)">  ret i8000000 %res4</span></b></span></div>
<div>}</div>
<div><br>
</div>
<br>
</div></div></div><div><div id="m_-2684315701302447992divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif"><div><b>My issue:</b> </div>
<div><br>
</div>
<div>I have been using Instruction::clone() to copy the instructions and then set a name for this clone.</div>
<div><br>
</div>
<div>As seen marked issue , the "ret" instruction is returning the old "%res" value.</div>
<div>How can I make sure that "%res" returns the "res45" and "res46" in each of the destination basic blocks ?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Malhar<br>
<br>
</div>
<p></p>
</div>
<hr style="display:inline-block;width:98%">
<div id="m_-2684315701302447992divRplyFwdMsg"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Nemanja Ivanovic <<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.com</a>><br>
<b>Sent:</b> Friday, May 26, 2017 3:53:52 PM<br>
<b>To:</b> Jajoo, Malhar<br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Moving instructions from source Basic Block to dest Basic Block</font>
<div> </div>
</div></div><div>
<div>
<div>
<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><<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>
<div id="m_-2684315701302447992m_-6706252521785537517divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif">
<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::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>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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/mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div></blockquote></div></div>