From 0a1a874d1f4659f02c0d4fdd6be69f1188bd0625 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 26 Sep 2002 05:03:22 +0000 Subject: [PATCH] - Add new ctor to BasicBlock to allow insertion before any BB, not just at the end of the function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3934 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/BasicBlock.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index bf7191c6593..2f1072dc336 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -67,6 +67,26 @@ BasicBlock::BasicBlock(const std::string &name, Function *Parent) Parent->getBasicBlockList().push_back(this); } +/// BasicBlock ctor - If the InsertBefore parameter is specified, the basic +/// block is automatically inserted right before the specified block. +/// +BasicBlock::BasicBlock(const std::string &Name, BasicBlock *InsertBefore) + : Value(Type::LabelTy, Value::BasicBlockVal, Name) { + // Initialize the instlist... + InstList.setItemParent(this); + + // Make sure that we get added to a function + LeakDetector::addGarbageObject(this); + + if (InsertBefore) { + assert(InsertBefore->getParent() && + "Cannot insert block before another block that is not embedded into" + " a function yet!"); + InsertBefore->getParent()->getBasicBlockList().insert(InsertBefore, this); + } +} + + BasicBlock::~BasicBlock() { dropAllReferences(); InstList.clear();