[LLVMdev] Cloning BasicBlock

Tanya Lattner tonic at nondot.org
Tue Nov 22 09:29:23 PST 2005


>  I am trying to clone a BasicBlock. I want both to co-exist and I have introduced
>  a conditional branch to the original or the cloned BB.
>  I tried mapping the original instruction and the clone as below :
>    Instruction *NewInst = II->clone();
>    if (II->hasName())
>       NewInst->setName(II->getName());
>    NewBB->getInstList().push_back(NewInst);
>    ValueMap[II] = NewInst;
>  what I got from this is ,
>             --> eventhough I have set the same name , a new name is set for the clone.
>                    original :
>                      %CS1 = call fastcc int %add( int %tmp.5, int %tmp.6 ) ; <int> [#uses=1]
>                   clone :
>                       %CS11 = call fastcc int %add( int %tmp.5, int %tmp.6 ) ; <int> [#uses=1]
>               --> the verifier gives the following error
>                              Instruction does not dominate all uses!
>                    for the original instruction.

>  Is it possible to have the instructions in the clone to have the same name
>  as the original BB ?

No. Names must be unique.

>  Is it possible to make the uses of the original instruction to be the
>  uses of the cloned instruction at the same time ?

No. You need to clone all the uses and have them use the cloned def. Then 
depending upon your CFG you will probably need a phi node if the two paths 
merge back together.

>  What makes the above error ?
>  Is it because of SSA ?

Yes. This means that you defined an instruction in a basicblock that does 
not dominate all uses. This is a property of SSA.

-Tanya




More information about the llvm-dev mailing list