[LLVMdev] Basic Block Chaining

Reid Spencer reid at x10sys.com
Thu Nov 20 02:40:03 PST 2003


Newbie Question .. (sorry if its redundant/silly) ..

As I've started to develop Stacker, I  had assumed that simply adding
BasicBlocks to a function in sequence would imply that there is an
implicit unconditional branch from the end of one basic block to the
start of the next block. Based on the assertion checks that I get when I
tried this, I assume that it is required to place a terminating
instruction at the end of every basic block even if that should simply
be a branch to the start of the next block. Is this indeed the case?

If it is, it would be "user friendly" to simply supply the branch
instruction.  That is, provide a method on Function that appends a
BasicBlock to the end of the block list. If the existing final basic
block doesn't have a terminating instruction, simply add one that points
to the block being appended.  Is this the RightThing(tm) or are there
good reasons this can't or shouldn't be done?  

The method I'm thinking of is something like:


Function::chainBasicBlock( BasicBlock* bb )
{
    BasicBlock& previous = this->back();
    TerminatorInst* terminator = previous.getTerminator();
    if ( ! terminator )
    {
        BranchInst* branch = new BranchInst(bb);
        previous.push_back( branch );
    }
    BranchList.push_back( bb );
}

Reid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031120/caf0f79e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031120/caf0f79e/attachment.sig>


More information about the llvm-dev mailing list