<div dir="ltr"><div dir="ltr"><div>Hi,</div><div>Thanks a lot for your response. I was successfully able to use CloneFunctionInto for copying the function over when the number of arguments to both the functions are same. Can CloneFunctionInto be used when the number of arguments of the functions are not equal? If yes, how do I provide the <a class="gmail-code" href="https://llvm.org/doxygen/classllvm_1_1ValueMap.html">ValueToValueMapTy</a> &VMap argument to the CloneIntoFunction in that case? When the number of arguments of both functions are equal, the VMap is just a map from each of the function's arguments to the other.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 17 May 2019 at 14:40, Tim Northover <<a href="mailto:t.p.northover@gmail.com">t.p.northover@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Fri, 17 May 2019 at 07:40, Kell Maresh via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> 2. Then I read the (.ll) file created by the "llvm-extract" tool using:<br>
<br>
That seems a bit pointless.<br>
<br>
> I get Segmentation Fault if I use ReplaceInstWithInst instruction.<br>
<br>
At the very least, I think doing that replacement will disrupt the<br>
iterator going through the source function because it has to remove<br>
the instruction. But just because two functions have the same number<br>
of instructions doesn't mean they can be replaced one at a time in a<br>
compatible manner. That would only work if the type of every<br>
instruction matches up perfectly too.<br>
<br>
What you should probably be doing is erasing the body of the new<br>
function entirely and cloning the instructions into it. You could roll<br>
your own cloning code, but there are helpers already written to do it<br>
properly in include/llvm/Transforms/Utils/Cloning.h. CloneFunctionInto<br>
looks especially relevant to your situation.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote></div></div>