[llvm-dev] Copy Function from one LLVM IR file to another

Kell Maresh via llvm-dev llvm-dev at lists.llvm.org
Sat May 18 23:50:54 PDT 2019

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 ValueToValueMapTy
<https://llvm.org/doxygen/classllvm_1_1ValueMap.html> &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.

On Fri, 17 May 2019 at 14:40, Tim Northover <t.p.northover at gmail.com> wrote:

> Hi,
> On Fri, 17 May 2019 at 07:40, Kell Maresh via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > 2. Then I read the (.ll) file created by the "llvm-extract" tool using:
> That seems a bit pointless.
> > I get Segmentation Fault if I use ReplaceInstWithInst instruction.
> At the very least, I think doing that replacement will disrupt the
> iterator going through the source function because it has to remove
> the instruction. But just because two functions have the same number
> of instructions doesn't mean they can be replaced one at a time in a
> compatible manner. That would only work if the type of every
> instruction matches up perfectly too.
> What you should probably be doing is erasing the body of the new
> function entirely and cloning the instructions into it. You could roll
> your own cloning code, but there are helpers already written to do it
> properly in include/llvm/Transforms/Utils/Cloning.h. CloneFunctionInto
> looks especially relevant to your situation.
> Cheers.
> Tim.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190519/7e2fcca9/attachment.html>

More information about the llvm-dev mailing list