Duplicating a Basic Block


I want to duplicate a set of basic blocks and finally modify the structure of CFG.
But if I just duplicate a block then name of all the temporaries will be same as in original block.

So is there a way to rename all the temporaries in a basic block or I will have to do it instruction by instruction?

Thanks and Regards,

CloneBasicBlock in llvm/Transforms/Utils/Cloning.h should perform
cloning without having to worry about names. In general, LLVM will
automatically rename an instruction if there is already an instruction
with the same name in a function. How are you trying to duplicate the


Actually I have pointers to two blocks in CFG, and I want to duplicate all the blocks starting from the first to second pointer.
Now if I do this duplication using CloneBasicBlock then it will rename the instructions as you said but will I have to duplicate them block by block ?
And also when I add this duplicated set of blocks to CFG it will create a new merge node which may require new phi insertions so is there a function which can do this too.

Eli Friedman wrote: