/// right after \p MovePos in the function \p MovePos lives in.
void moveAfter(BasicBlock *MovePos);
+ /// \brief Insert unlinked basic block into a function.
+ ///
+ /// Inserts an unlinked basic block into \c Parent. If \c InsertBefore is
+ /// provided, inserts before that basic block, otherwise inserts at the end.
+ ///
+ /// \pre \a getParent() is \c nullptr.
+ void insertInto(Function *Parent, BasicBlock *InsertBefore = nullptr);
/// \brief Return the predecessor of this block if it has a single predecessor
/// block. Otherwise return a null pointer.
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);
- if (InsertBefore) {
- assert(NewParent &&
+ if (NewParent)
+ insertInto(NewParent, InsertBefore);
+ else
+ assert(!InsertBefore &&
"Cannot insert block before another block with no function!");
- NewParent->getBasicBlockList().insert(InsertBefore, this);
- } else if (NewParent) {
- NewParent->getBasicBlockList().push_back(this);
- }
setName(Name);
}
+void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
+ assert(NewParent && "Expected a parent");
+ assert(!Parent && "Already has a parent");
+
+ if (InsertBefore)
+ NewParent->getBasicBlockList().insert(InsertBefore, this);
+ else
+ NewParent->getBasicBlockList().push_back(this);
+}
BasicBlock::~BasicBlock() {
// If the address of the block is taken and it is being deleted (e.g. because