Moving instructions from functions

Dear all,

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.

thank you.

2009/7/29 Amr Yehia <yehia@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 ExtractCodeRegion().

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.