summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-01 21:22:04 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-01 21:22:04 +0000
commit17cbb97882f3466452310bcc8c5e1c046aebe788 (patch)
treef4446a2c7b98132491e2887c9b721b631053c00e /llvm/lib/IR/BasicBlock.cpp
parent254f8729d041ad2a35196c8ac31453a45967f663 (diff)
downloadbcm5719-llvm-17cbb97882f3466452310bcc8c5e1c046aebe788.tar.gz
bcm5719-llvm-17cbb97882f3466452310bcc8c5e1c046aebe788.zip
IR: Add BasicBlock::insertInto()
Although unlinked `BasicBlock`s can be created, there's currently no way to insert them into `Function`s after the fact. In particular, `moveAfter()` and `moveBefore()` require that the basic block is already linked. Extract the logic for initially linking a `BasicBlock` out of the constructor and into a member function that can be used for lazy insertion. - Asserts that the basic block is currently unlinked. - Matches the logic of the constructor. - Changed the constructor to use it since the logic matches. This is needed in a follow-up commit for PR5680. llvm-svn: 214563
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r--llvm/lib/IR/BasicBlock.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index ba07433103b..1ec977811ce 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -50,17 +50,24 @@ BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
// 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
OpenPOWER on IntegriCloud