Teach EmitBlock to put the target block immediately after the current block

(if there's a current block).  The chief advantage of doing this is that it
lets us pick blocks (e.g. EH blocks) to push to the end of the function so
that fallthrough happens consistently --- i.e. it gives us the flexibility
of ordering blocks as we please without having to change the order in which
we generate code.  There are standard (?) optimization passes which can do some
of that for us, but better to generate reasonable code to begin with.

llvm-svn: 101997
This commit is contained in:
John McCall 2010-04-21 10:29:06 +00:00
parent 2188696d98
commit e683359fc9
1 changed files with 6 additions and 1 deletions

View File

@ -225,7 +225,12 @@ void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
}
}
CurFn->getBasicBlockList().push_back(BB);
// Place the block after the current block, if possible, or else at
// the end of the function.
if (Builder.GetInsertBlock())
CurFn->getBasicBlockList().insertAfter(Builder.GetInsertBlock(), BB);
else
CurFn->getBasicBlockList().push_back(BB);
Builder.SetInsertPoint(BB);
}