[LLVMdev] PHINode in entry block

Duncan Sands baldrick at free.fr
Tue Jul 15 08:18:27 PDT 2014


Hi William,

On 15/07/14 16:55, William Moses wrote:
> All,
>
> Consider the case where the entry block to a function acts like a loop (e.g. it
> ends with a conditional break to itself and somewhere else). How would one
> create a PHINode (representing an index perhaps) which has a constant index (say
> 0) when entering the function, and (oldval+1) when looping.
>
> I understand how to do this if the loop were not in the entry block (by simply
> using node->addIncoming(ConstantInt(...), entry),
> node->addIncoming(builder.CreateAdd(node,...),loopBlock) ).
>
> My question is how would one do this using the C++ API when there is no
> predecessor since it is the entry block.

phi nodes are not allowed in the entry block.  You need to create a block to put 
the phi node in, and have the entry block just be a branch to this block.

Ciao, Duncan.




More information about the llvm-dev mailing list