From 02a71e7748355f393720189a7d4bc0b8f49c298e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 11 Oct 2004 22:21:39 +0000 Subject: [PATCH] Implement remove/eraseFromParent methods llvm-svn: 16922 --- llvm/lib/VMCore/BasicBlock.cpp | 9 +++++++++ llvm/lib/VMCore/Function.cpp | 8 ++++++++ llvm/lib/VMCore/Globals.cpp | 11 +++++++++-- llvm/lib/VMCore/Instruction.cpp | 7 +++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp index 32c86c4ce690..2e8560cb6577 100644 --- a/llvm/lib/VMCore/BasicBlock.cpp +++ b/llvm/lib/VMCore/BasicBlock.cpp @@ -105,6 +105,15 @@ void BasicBlock::setName(const std::string &name, SymbolTable *ST) { if (P && hasName()) P->getSymbolTable().insert(this); } +void BasicBlock::removeFromParent() { + getParent()->getBasicBlockList().remove(this); +} + +void BasicBlock::eraseFromParent() { + getParent()->getBasicBlockList().erase(this); +} + + TerminatorInst *BasicBlock::getTerminator() { if (InstList.empty()) return 0; return dyn_cast(&InstList.back()); diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index e918fd5878a0..ede2ca209747 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -147,6 +147,14 @@ const Type *Function::getReturnType() const { return getFunctionType()->getReturnType(); } +void Function::removeFromParent() { + getParent()->getFunctionList().remove(this); +} + +void Function::eraseFromParent() { + getParent()->getFunctionList().erase(this); +} + // dropAllReferences() - This function causes all the subinstructions to "let // go" of all references that they are maintaining. This allows one to // 'delete' a whole class at a time, even though there may be circular diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp index b84dbf7fd4a6..731f495c299d 100644 --- a/llvm/lib/VMCore/Globals.cpp +++ b/llvm/lib/VMCore/Globals.cpp @@ -106,9 +106,16 @@ void GlobalVariable::setName(const std::string &name, SymbolTable *ST) { if (P && hasName()) P->getSymbolTable().insert(this); } +void GlobalVariable::removeFromParent() { + getParent()->getGlobalList().remove(this); +} + +void GlobalVariable::eraseFromParent() { + getParent()->getGlobalList().erase(this); +} + void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To, - bool DisableChecking ) -{ + bool DisableChecking) { // If you call this, then you better know this GVar has a constant // initializer worth replacing. Enforce that here. assert(getNumOperands() == 1 && diff --git a/llvm/lib/VMCore/Instruction.cpp b/llvm/lib/VMCore/Instruction.cpp index f54acf5f03ed..4ea5775330a1 100644 --- a/llvm/lib/VMCore/Instruction.cpp +++ b/llvm/lib/VMCore/Instruction.cpp @@ -72,6 +72,13 @@ void Instruction::setName(const std::string &name, SymbolTable *ST) { if (PP && hasName()) PP->getSymbolTable().insert(this); } +void Instruction::removeFromParent() { + getParent()->getInstList().remove(this); +} + +void Instruction::eraseFromParent() { + getParent()->getInstList().erase(this); +} const char *Instruction::getOpcodeName(unsigned OpCode) { switch (OpCode) {