[LLVMdev] Copy Instruction from one Basic block to another

Frits van Bommel fvbommel at gmail.com
Wed Nov 17 01:49:41 PST 2010


On Wed, Nov 17, 2010 at 7:31 AM, Soumya Prasad Ukil
<ukil.soumya at gmail.com> wrote:
> I want to do the following:
>
> suppose the program structure:
>
>                                                     bb
>                                                  /       \
>                                             bb1          bb2
>                                                 \         /
>                                                    bb3
>                                                      |
>                                                     bb4
>               Now I want to create a new basic block, say bb5 between bb2 &
> bb3, copy some instructions from bb3 to bb5. Then I want to add between bb2
> and bb3, then outgoing edge from bb5 is to be attached with bb4. Finally my
> program will look like :
>
>
>                                                     bb
>                                                  /        \
>                                             bb1          bb2
>                                                 \            /
>                                                 bb3      bb5
>                                                      \    /
>                                                      bb4
>
>
>                      Can you please help me out? How to proceed onto it?

Sounds like what the jump threading pass does (IIRC) if it figures out
that the terminator of bb3 can be simplified if control enters it from
bb2 (and bb3 is simple enough). Maybe you should have a look at
lib/Transforms/Scalar/JumpThreading.cpp?

Don't forget to handle the case where any of bb3's instructions are
used outside bb3; you'll need to insert a PHI node in bb4 for each
such instruction, merging the original and the copy.




More information about the llvm-dev mailing list