<div dir="ltr">Hi Ashuntosh,<div><br></div><div>Indeed, this is deliberate. When performing cloning operations, often the user requires quite a lot of flexibility. Perhaps by editing the remapping map before remapping is performed (clone with remapping, but change so that %A -> %B).</div><div><br></div><div>The RemapInstructionsInBlocks function does what you want:</div><div><br></div><div>  ValueToValueMapTy VM;</div><div>  CloneBasicBlock(BB,  VM, ...);</div><div>  RemapInstructionsInBlocks({BB}, VM);</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 5 May 2016 at 09:48 Nema, Ashutosh via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div>
<font face="Calibri" size="2"><span style="font-size:11pt">
<div>Hi,</div>
<div> </div>
<div>Found CloneBasicBlock utility only does the cloning without any remapping.</div>
<div> </div>
<div>Consider below example:</div>
<div> </div>
<div><b><u>Input block:</u></b></div>
<div>sw.epilog:                                        ; preds = %sw.bb20, %sw.bb15, %sw.bb10, %sw.bb6, %sw.bb2, %<a href="http://sw.bb" target="_blank">sw.bb</a>, %while.body, %if.end29</div>
<div>  %no_final.1 = phi i32 [ %no_final.055, %while.body ], [ 1, %if.end29 ], [ %no_final.055, %sw.bb20 ], [ %no_final.055, %sw.bb15 ], [ %no_final.055, %sw.bb10 ], [ %no_final.055, %sw.bb6 ], [ %no_final.055, %sw.bb2 ], [ %no_final.055, %<a href="http://sw.bb" target="_blank">sw.bb</a> ]</div>
<div>  %locinput.1 = phi i8* [ %locinput.057, %while.body ], [ %incdec.ptr, %if.end29 ], [ %locinput.057, %sw.bb20 ], [ %locinput.057, %sw.bb15 ], [ %locinput.057, %sw.bb10 ], [ %locinput.057, %sw.bb6 ], [ %locinput.057, %sw.bb2 ], [ %locinput.057, %<a href="http://sw.bb" target="_blank">sw.bb</a> ]</div>
<div>  %next30 = getelementptr inbounds %struct.Node, %struct.Node* %scan.056, i64 0, i32 0, !dbg !91</div>
<div>  %8 = load %struct.Node*, %struct.Node** %next30, align 8, !dbg !91, !tbaa !92</div>
<div>  tail call void @llvm.dbg.value(metadata %struct.Node* %8, i64 0, metadata !28, metadata !34), !dbg !41</div>
<div>  %cmp = icmp eq %struct.Node* %8, null, !dbg !52</div>
<div>  br i1 %cmp, label %no_silent.loopexit, label %while.body, !dbg !54</div>
<div> </div>
<div><b><u>Clone Block:</u></b></div>
<div>sw.epilog.jl:                                     ; No predecessors!</div>
<div>  %no_final.1.jl = phi i32 [ %no_final.055, %while.body ], [ 1, %if.end29 ], [ %no_final.055, %sw.bb20 ], [ %no_final.055, %sw.bb15 ], [ %no_final.055, %sw.bb10 ], [ %no_final.055, %sw.bb6 ], [ %no_final.055, %sw.bb2 ], [ %no_final.055, %<a href="http://sw.bb" target="_blank">sw.bb</a> ]</div>
<div>  %locinput.1.jl = phi i8* [ %locinput.057, %while.body ], [ %incdec.ptr, %if.end29 ], [ %locinput.057, %sw.bb20 ], [ %locinput.057, %sw.bb15 ], [ %locinput.057, %sw.bb10 ], [ %locinput.057, %sw.bb6 ], [ %locinput.057, %sw.bb2 ], [ %locinput.057, %<a href="http://sw.bb" target="_blank">sw.bb</a>
]</div>
<div>  %next30.jl = getelementptr inbounds %struct.Node, %struct.Node* %scan.056, i64 0, i32 0, !dbg !91</div>
<div>  <span style="background-color:silver">%9 = load %struct.Node*, %struct.Node** </span><font color="red"><span style="background-color:silver">%next30</span></font><span style="background-color:silver">, align 8, !dbg !91, !tbaa !92</span></div>
<div>  tail call void @llvm.dbg.value(metadata %struct.Node* %8, i64 0, metadata !28, metadata !34), !dbg !41</div>
<div>  <span style="background-color:silver">%cmp.jl = icmp eq %struct.Node* </span><font color="red"><span style="background-color:silver">%8</span></font><span style="background-color:silver">, null, !dbg !52</span></div>
<div>  <span style="background-color:silver">br i1 %</span><font color="red"><span style="background-color:silver">cmp</span></font><span style="background-color:silver">, label %no_silent.loopexit, label %while.body, !dbg !54</span></div>
<div> </div>
<div><b><u>Highlighted instruction should be:</u></b></div>
<div>%9 = load %struct.Node*, %struct.Node** <font color="red">%next30.jl</font>, align 8, !dbg !91, !tbaa !92</div>
<div>%cmp.jl = icmp eq %struct.Node* <font color="red">%9</font>, null, !dbg !52</div>
<div>br i1 <font color="red">%cmp.jl</font>, label %no_silent.loopexit, label %while.body, !dbg !54</div>
<div> </div>
<div>I can see in the comments of this function it clearly mentioned it doesn’t remap the clone instructions.</div>
<div>Wondering why its kept like this, is there any specific reason, cloning without remapping may not be correct always.</div>
<div> </div>
<div>Is there any other utility which does both cloning and remapping ?</div>
<div> </div>
<div>Thanks,</div>
<div>Ashutosh</div>
<div> </div>
</span></font>
</div>

_______________________________________________<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>
</blockquote></div>