[LLVMdev] [PATCH] BasicBlock::getFirstNonPHI

Nick Lewycky nicholas at mxc.ca
Sun Jun 4 12:05:16 PDT 2006


Chris Lattner wrote:
> On Sun, 4 Jun 2006, Vladimir Prus wrote:
> 
>> everytime one has to add instruction at the beginning of a basic
>> block, one
>> has to skip past PHI nodes that are already there. How about adding a new
>> method to BasicBlock, to get that first non-PHI instruction? So,
>> adding an
>> instruction will be as simple as:
>>
>>      new SomeInstruction(............., BB->getFirstNonPHI())
> 
> 2. There is no need to check for running off the end of the basic block,
> you are guaranteed that a block has a terminator, which is not a PHI.

Assuming it's a valid BasicBlock. Which, if I understand correctly,
isn't always true in mid-transformation. Perhaps you should turn it into
an assert instead, to minimize surprises?

I can't check if this actually happens with llvm.org seemingly down, but
I do recall a situation like that. Maybe it was the BB list within a
function?

Nick



More information about the llvm-dev mailing list