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

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Fri May 17 02:40:34 PDT 2019


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.


More information about the llvm-dev mailing list