[LLVMdev] Moving instructions from functions

Misha Brukman brukman at gmail.com
Wed Jul 29 07:13:39 PDT 2009

2009/7/29 Amr Yehia <yehia at iss.rwth-aachen.de>

> I want to move a block of instructions from its original function, form
> a new function, and place these instructions in the new function.
> these blocks of instructions are not bound by Basic Blocks, i mean i can
> cut Basic Blocks and move only part of it to the new function.
> I guess the solution can be either clone the whole function and start
> deleting instructions from the two functions (from source and from
> destination).
> or i can cut basic blocks and start cloning them to the new function,
> then delete them from the original function.
> both ways are not straight forward, i wanted to check if there is an
> easier straight forward way to do this.

Take a look at llvm/include/llvm/Transforms/Utils/FunctionUtils.h .
If you just want to extract a couple BasicBlocks, you can use

If you want to extract code that lives inside a BasicBlock, first split the
block into several smaller blocks, and then call ExtractBasicBlock() on the
block you want to extract.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090729/ace08d30/attachment.html>

More information about the llvm-dev mailing list