Detailed help with cloning the basic blocks of a function

Hi,

Thank you guys for helping me out with my previous questions.
I am new to LLVM, and I'm getting stuck trying to do some basic stuff:

Currently, I'm trying to move all the basic blocks of one function into
another one,
and at some point insert a branch into the moved function's entry point.

The best way which I've found is to use CloneBasicBlock (from Cloning.h).
However, I don't know how to get the cloned basic block not to use the
values
of the old basic block. I realize that it has something to do with the
ValueMap that I pass
to the function, but I'm not sure how to use it.

Can someone please show me a short code snippet which does that sort of
thing?
It would really help me a lot.

Also, if someone here has an idea for a better way of doing what I'm doing
(copying/moving
the basics blocks of one function into another), I'd love to hear that.

Thanks a lot,
Guy

guyadini wrote:

Hi,

Thank you guys for helping me out with my previous questions.
I am new to LLVM, and I'm getting stuck trying to do some basic stuff:

Currently, I'm trying to move all the basic blocks of one function into
another one,
and at some point insert a branch into the moved function's entry point.

The best way which I've found is to use CloneBasicBlock (from Cloning.h).
However, I don't know how to get the cloned basic block not to use the
values
of the old basic block. I realize that it has something to do with the
ValueMap that I pass
to the function, but I'm not sure how to use it.

Can someone please show me a short code snippet which does that sort of
thing?
It would really help me a lot.

Also, if someone here has an idea for a better way of doing what I'm doing
(copying/moving
the basics blocks of one function into another), I'd love to hear that.

If you want to move all basic blocks out of one function into another, use:

   NewFunc->getBasicBlockList().splice(NewFunc->begin(), OldFunc->getBasicBlockList());

This will leave OldFunc empty.

Nick