aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2007-12-09 22:46:10 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2007-12-09 22:46:10 +0000
commited455c8fa25dd37a13b33f0afa66be03ac49b5bb (patch)
tree7bfa961474e22f830710a49d4ed015fe374967b7 /lib/VMCore
parent46a6e79e602b23ea3478027d5bdd1f904aea7924 (diff)
downloadexternal_llvm-ed455c8fa25dd37a13b33f0afa66be03ac49b5bb.zip
external_llvm-ed455c8fa25dd37a13b33f0afa66be03ac49b5bb.tar.gz
external_llvm-ed455c8fa25dd37a13b33f0afa66be03ac49b5bb.tar.bz2
Devirtualizing Value destructor (PR889). Patch by Pawel Kunio!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44747 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/BasicBlock.cpp38
-rw-r--r--lib/VMCore/Constants.cpp173
-rw-r--r--lib/VMCore/Function.cpp13
-rw-r--r--lib/VMCore/InlineAsm.cpp6
-rw-r--r--lib/VMCore/Instruction.cpp4
-rw-r--r--lib/VMCore/Instructions.cpp50
-rw-r--r--lib/VMCore/Value.cpp247
7 files changed, 334 insertions, 197 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index d45a1c4..ad9ad42 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -30,31 +30,9 @@ ilist_traits<Instruction>::getSymTab(BasicBlock *BB) {
return 0;
}
-
-namespace {
- /// DummyInst - An instance of this class is used to mark the end of the
- /// instruction list. This is not a real instruction.
- struct VISIBILITY_HIDDEN DummyInst : public Instruction {
- DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
- // This should not be garbage monitored.
- LeakDetector::removeGarbageObject(this);
- }
-
- Instruction *clone() const {
- assert(0 && "Cannot clone EOL");abort();
- return 0;
- }
- const char *getOpcodeName() const { return "*end-of-list-inst*"; }
-
- // Methods for support type inquiry through isa, cast, and dyn_cast...
- static inline bool classof(const DummyInst *) { return true; }
- static inline bool classof(const Instruction *I) {
- return I->getOpcode() == OtherOpsEnd;
- }
- static inline bool classof(const Value *V) {
- return isa<Instruction>(V) && classof(cast<Instruction>(V));
- }
- };
+DummyInst::DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(this);
}
Instruction *ilist_traits<Instruction>::createSentinel() {
@@ -88,10 +66,12 @@ BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
}
-BasicBlock::~BasicBlock() {
- assert(getParent() == 0 && "BasicBlock still linked into the program!");
- dropAllReferences();
- InstList.clear();
+void BasicBlock::destroyThis(BasicBlock*v)
+{
+ assert(v->getParent() == 0 && "BasicBlock still linked into the program!");
+ v->dropAllReferences();
+ v->InstList.clear();
+ Value::destroyThis(v);
}
void BasicBlock::setParent(Function *parent) {
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 49c27b8..fb51c3f 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -356,8 +356,9 @@ ConstantArray::ConstantArray(const ArrayType *T,
}
}
-ConstantArray::~ConstantArray() {
- delete [] OperandList;
+void ConstantArray::destroyThis(ConstantArray*v) {
+ delete [] v->OperandList;
+ Constant::destroyThis(v);
}
ConstantStruct::ConstantStruct(const StructType *T,
@@ -379,8 +380,9 @@ ConstantStruct::ConstantStruct(const StructType *T,
}
}
-ConstantStruct::~ConstantStruct() {
- delete [] OperandList;
+void ConstantStruct::destroyThis(ConstantStruct*v) {
+ delete [] v->OperandList;
+ Constant::destroyThis(v);
}
@@ -399,124 +401,67 @@ ConstantVector::ConstantVector(const VectorType *T,
}
}
-ConstantVector::~ConstantVector() {
- delete [] OperandList;
+void ConstantVector::destroyThis(ConstantVector*v) {
+ delete [] v->OperandList;
+ Constant::destroyThis(v);
}
-// We declare several classes private to this file, so use an anonymous
-// namespace
-namespace {
-
-/// UnaryConstantExpr - This class is private to Constants.cpp, and is used
-/// behind the scenes to implement unary constant exprs.
-class VISIBILITY_HIDDEN UnaryConstantExpr : public ConstantExpr {
- Use Op;
-public:
- UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty)
- : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {}
-};
-
-/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
-/// behind the scenes to implement binary constant exprs.
-class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr {
- Use Ops[2];
-public:
- BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
- : ConstantExpr(C1->getType(), Opcode, Ops, 2) {
- Ops[0].init(C1, this);
- Ops[1].init(C2, this);
- }
-};
-
-/// SelectConstantExpr - This class is private to Constants.cpp, and is used
-/// behind the scenes to implement select constant exprs.
-class VISIBILITY_HIDDEN SelectConstantExpr : public ConstantExpr {
- Use Ops[3];
-public:
- SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
- : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
- Ops[0].init(C1, this);
- Ops[1].init(C2, this);
- Ops[2].init(C3, this);
- }
-};
-
-/// ExtractElementConstantExpr - This class is private to
-/// Constants.cpp, and is used behind the scenes to implement
-/// extractelement constant exprs.
-class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr {
- Use Ops[2];
-public:
- ExtractElementConstantExpr(Constant *C1, Constant *C2)
- : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
- Instruction::ExtractElement, Ops, 2) {
- Ops[0].init(C1, this);
- Ops[1].init(C2, this);
- }
-};
+UnaryConstantExpr::UnaryConstantExpr(unsigned Opcode,
+ Constant *C, const Type *Ty)
+ : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {
+}
-/// InsertElementConstantExpr - This class is private to
-/// Constants.cpp, and is used behind the scenes to implement
-/// insertelement constant exprs.
-class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr {
- Use Ops[3];
-public:
- InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
- : ConstantExpr(C1->getType(), Instruction::InsertElement,
- Ops, 3) {
- Ops[0].init(C1, this);
- Ops[1].init(C2, this);
- Ops[2].init(C3, this);
- }
-};
+SelectConstantExpr::SelectConstantExpr(Constant *C1,
+ Constant *C2, Constant *C3)
+ : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
+ Ops[0].init(C1, this);
+ Ops[1].init(C2, this);
+ Ops[2].init(C3, this);
+}
-/// ShuffleVectorConstantExpr - This class is private to
-/// Constants.cpp, and is used behind the scenes to implement
-/// shufflevector constant exprs.
-class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr {
- Use Ops[3];
-public:
- ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
- : ConstantExpr(C1->getType(), Instruction::ShuffleVector,
- Ops, 3) {
- Ops[0].init(C1, this);
- Ops[1].init(C2, this);
- Ops[2].init(C3, this);
- }
-};
+ExtractElementConstantExpr::ExtractElementConstantExpr(Constant *C1,
+ Constant *C2)
+ : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
+ Instruction::ExtractElement, Ops, 2) {
+ Ops[0].init(C1, this);
+ Ops[1].init(C2, this);
+}
-/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
-/// used behind the scenes to implement getelementpr constant exprs.
-struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
- GetElementPtrConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
- const Type *DestTy)
- : ConstantExpr(DestTy, Instruction::GetElementPtr,
- new Use[IdxList.size()+1], IdxList.size()+1) {
- OperandList[0].init(C, this);
- for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
- OperandList[i+1].init(IdxList[i], this);
- }
- ~GetElementPtrConstantExpr() {
- delete [] OperandList;
- }
-};
+InsertElementConstantExpr::InsertElementConstantExpr(Constant *C1,
+ Constant *C2,
+ Constant *C3)
+ : ConstantExpr(C1->getType(), Instruction::InsertElement, Ops, 3) {
+ Ops[0].init(C1, this);
+ Ops[1].init(C2, this);
+ Ops[2].init(C3, this);
+}
-// CompareConstantExpr - This class is private to Constants.cpp, and is used
-// behind the scenes to implement ICmp and FCmp constant expressions. This is
-// needed in order to store the predicate value for these instructions.
-struct VISIBILITY_HIDDEN CompareConstantExpr : public ConstantExpr {
- unsigned short predicate;
- Use Ops[2];
- CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred,
- Constant* LHS, Constant* RHS)
- : ConstantExpr(Type::Int1Ty, opc, Ops, 2), predicate(pred) {
- OperandList[0].init(LHS, this);
- OperandList[1].init(RHS, this);
- }
-};
+ShuffleVectorConstantExpr::ShuffleVectorConstantExpr(Constant *C1,
+ Constant *C2,
+ Constant *C3)
+ : ConstantExpr(C1->getType(), Instruction::ShuffleVector, Ops, 3) {
+ Ops[0].init(C1, this);
+ Ops[1].init(C2, this);
+ Ops[2].init(C3, this);
+}
-} // end anonymous namespace
+CompareConstantExpr::CompareConstantExpr(unsigned opc, unsigned short pred,
+ Constant* LHS, Constant* RHS)
+ : ConstantExpr(Type::Int1Ty, opc, Ops, 2), predicate(pred) {
+ OperandList[0].init(LHS, this);
+ OperandList[1].init(RHS, this);
+}
+GetElementPtrConstantExpr::GetElementPtrConstantExpr(Constant *C,
+ const std::vector<Constant*>
+ &IdxList, const Type *DestTy)
+: ConstantExpr(DestTy, Instruction::GetElementPtr,
+ new Use[IdxList.size()+1], IdxList.size()+1)
+{
+ OperandList[0].init(C, this);
+ for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
+ OperandList[i+1].init(IdxList[i], this);
+}
// Utility function for determining if a ConstantExpr is a CastOp or not. This
// can't be inline because we don't want to #include Instruction.h into
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 04db3aa..b1405e5 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -287,16 +287,17 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
ParentModule->getFunctionList().push_back(this);
}
-Function::~Function() {
- dropAllReferences(); // After this it is safe to delete instructions.
+void Function::destroyThis(Function*v) {
+ v->dropAllReferences(); // After this it is safe to delete instructions.
// Delete all of the method arguments and unlink from symbol table...
- ArgumentList.clear();
- delete SymTab;
+ v->ArgumentList.clear();
+ delete v->SymTab;
// Drop our reference to the parameter attributes, if any.
- if (ParamAttrs)
- ParamAttrs->dropRef();
+ if (v->ParamAttrs)
+ v->ParamAttrs->dropRef();
+ GlobalValue::destroyThis(v);
}
void Function::BuildLazyArguments() const {
diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp
index ca4ecad..4b42237 100644
--- a/lib/VMCore/InlineAsm.cpp
+++ b/lib/VMCore/InlineAsm.cpp
@@ -17,12 +17,6 @@
#include <cctype>
using namespace llvm;
-// Implement the first virtual method in this class in this file so the
-// InlineAsm vtable is emitted here.
-InlineAsm::~InlineAsm() {
-}
-
-
// NOTE: when memoizing the function type, we have to be careful to handle the
// case when the type gets refined.
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index 7fc6245..fdee5e8 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -46,8 +46,8 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
// Out of line virtual method, so the vtable, etc has a home.
-Instruction::~Instruction() {
- assert(Parent == 0 && "Instruction still linked in the program!");
+void Instruction::destroyThis(Instruction*v) {
+ assert(v->Parent == 0 && "Instruction still linked in the program!");
}
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 0df0466..84adc50 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -67,20 +67,6 @@ bool CallSite::onlyReadsMemory() const {
}
-
-//===----------------------------------------------------------------------===//
-// TerminatorInst Class
-//===----------------------------------------------------------------------===//
-
-// Out of line virtual method, so the vtable, etc has a home.
-TerminatorInst::~TerminatorInst() {
-}
-
-// Out of line virtual method, so the vtable, etc has a home.
-UnaryInstruction::~UnaryInstruction() {
-}
-
-
//===----------------------------------------------------------------------===//
// PHINode Class
//===----------------------------------------------------------------------===//
@@ -96,8 +82,9 @@ PHINode::PHINode(const PHINode &PN)
}
}
-PHINode::~PHINode() {
- delete [] OperandList;
+void PHINode::destroyThis(PHINode*v) {
+ delete [] v->OperandList;
+ Instruction::destroyThis(v);
}
// removeIncomingValue - Remove an incoming value. This is useful if a
@@ -214,10 +201,11 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
// CallInst Implementation
//===----------------------------------------------------------------------===//
-CallInst::~CallInst() {
- delete [] OperandList;
- if (ParamAttrs)
- ParamAttrs->dropRef();
+void CallInst::destroyThis(CallInst*v) {
+ delete [] v->OperandList;
+ if (v->ParamAttrs)
+ v->ParamAttrs->dropRef();
+ Instruction::destroyThis(v);
}
void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
@@ -406,10 +394,11 @@ bool CallInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
// InvokeInst Implementation
//===----------------------------------------------------------------------===//
-InvokeInst::~InvokeInst() {
- delete [] OperandList;
- if (ParamAttrs)
- ParamAttrs->dropRef();
+void InvokeInst::destroyThis(InvokeInst*v) {
+ delete [] v->OperandList;
+ if (v->ParamAttrs)
+ v->ParamAttrs->dropRef();
+ TerminatorInst::destroyThis(v);
}
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
@@ -683,10 +672,6 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
setName(Name);
}
-// Out of line virtual method, so the vtable, etc has a home.
-AllocationInst::~AllocationInst() {
-}
-
bool AllocationInst::isArrayAllocation() const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
return CI->getZExtValue() != 1;
@@ -951,8 +936,8 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
setName(Name);
}
-GetElementPtrInst::~GetElementPtrInst() {
- delete[] OperandList;
+void GetElementPtrInst::destroyThis(GetElementPtrInst*v) {
+ delete[] v->OperandList;
}
// getIndexedType - Returns the type of the element that would be loaded with
@@ -2469,8 +2454,9 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
}
}
-SwitchInst::~SwitchInst() {
- delete [] OperandList;
+void SwitchInst::destroyThis(SwitchInst*v) {
+ delete [] v->OperandList;
+ TerminatorInst::destroyThis(v);
}
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index de6c16b..9b5100c 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -18,6 +18,11 @@
#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/LeakDetector.h"
+#include "llvm/Constants.h"
+#include "llvm/InlineAsm.h"
+#include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
+#include "llvm/InstrTypes.h"
#include <algorithm>
using namespace llvm;
@@ -39,7 +44,233 @@ Value::Value(const Type *ty, unsigned scid)
"Cannot create non-first-class values except for constants!");
}
-Value::~Value() {
+Value::~Value()
+{
+ switch(SubclassID)
+ {
+ case ArgumentVal:
+ Argument::destroyThis(cast<Argument>(this));
+ break;
+ case BasicBlockVal:
+ BasicBlock::destroyThis(cast<BasicBlock>(this));
+ break;
+ case FunctionVal:
+ Function::destroyThis(cast<Function>(this));
+ break;
+ case GlobalAliasVal:
+ GlobalAlias::destroyThis(cast<GlobalAlias>(this));
+ break;
+ case GlobalVariableVal:
+ GlobalVariable::destroyThis(cast<GlobalVariable>(this));
+ break;
+ case UndefValueVal:
+ UndefValue::destroyThis(cast<UndefValue>(this));
+ break;
+ case ConstantExprVal:
+ {
+ ConstantExpr* CE = dyn_cast<ConstantExpr>(this);
+ if(CE->getOpcode() == Instruction::GetElementPtr)
+ {
+ GetElementPtrConstantExpr* GECE =
+ dyn_cast<GetElementPtrConstantExpr>(CE);
+ GetElementPtrConstantExpr::destroyThis(GECE);
+ }
+ else if(CE->getOpcode() == Instruction::ExtractElement)
+ {
+ ExtractElementConstantExpr* EECE =
+ dyn_cast<ExtractElementConstantExpr>(CE);
+ ExtractElementConstantExpr::destroyThis(EECE);
+ }
+ else if(CE->getOpcode() == Instruction::InsertElement)
+ {
+ InsertElementConstantExpr* IECE =
+ dyn_cast<InsertElementConstantExpr>(CE);
+ InsertElementConstantExpr::destroyThis(IECE);
+ }
+ else if(CE->getOpcode() == Instruction::Select)
+ {
+ SelectConstantExpr* SCE = dyn_cast<SelectConstantExpr>(CE);
+ SelectConstantExpr::destroyThis(SCE);
+ }
+ else if(CE->getOpcode() == Instruction::ShuffleVector)
+ {
+ ShuffleVectorConstantExpr* SVCE =
+ dyn_cast<ShuffleVectorConstantExpr>(CE);
+ ShuffleVectorConstantExpr::destroyThis(SVCE);
+ }
+ else if(BinaryConstantExpr* BCE = dyn_cast<BinaryConstantExpr>(this))
+ BinaryConstantExpr::destroyThis(BCE);
+ else if(UnaryConstantExpr* UCE = dyn_cast<UnaryConstantExpr>(this))
+ UnaryConstantExpr::destroyThis(UCE);
+ else if(CompareConstantExpr* CCE = dyn_cast<CompareConstantExpr>(this))
+ CompareConstantExpr::destroyThis(CCE);
+ else
+ assert(0 && "Unknown ConstantExpr-inherited class in ~Value.");
+ }
+ break;
+ case ConstantAggregateZeroVal:
+ ConstantAggregateZero::destroyThis(cast<ConstantAggregateZero>(this));
+ break;
+ case ConstantIntVal:
+ ConstantInt::destroyThis(cast<ConstantInt>(this));
+ break;
+ case ConstantFPVal:
+ ConstantFP::destroyThis(cast<ConstantFP>(this));
+ break;
+ case ConstantArrayVal:
+ ConstantArray::destroyThis(cast<ConstantArray>(this));
+ break;
+ case ConstantStructVal:
+ ConstantStruct::destroyThis(cast<ConstantStruct>(this));
+ break;
+ case ConstantVectorVal:
+ ConstantVector::destroyThis(cast<ConstantVector>(this));
+ break;
+ case ConstantPointerNullVal:
+ ConstantPointerNull::destroyThis(cast<ConstantPointerNull>(this));
+ break;
+ case InlineAsmVal:
+ InlineAsm::destroyThis(cast<InlineAsm>(this));
+ break;
+
+ default:
+ if (BinaryOperator *BO = dyn_cast<BinaryOperator>(this))
+ BinaryOperator::destroyThis(BO);
+ else if (CallInst *CI = dyn_cast<CallInst>(this))
+ {
+ if(IntrinsicInst* II = dyn_cast<IntrinsicInst>(this))
+ {
+ if(DbgInfoIntrinsic* DII = dyn_cast<DbgInfoIntrinsic>(this))
+ {
+ if(DbgDeclareInst* DDI = dyn_cast<DbgDeclareInst>(this))
+ DbgDeclareInst::destroyThis(DDI);
+ else if(DbgFuncStartInst* DFSI = dyn_cast<DbgFuncStartInst>(this))
+ DbgFuncStartInst::destroyThis(DFSI);
+ else if(DbgRegionEndInst* DREI = dyn_cast<DbgRegionEndInst>(this))
+ DbgRegionEndInst::destroyThis(DREI);
+ else if(DbgRegionStartInst* DRSI = dyn_cast<DbgRegionStartInst>(this))
+ DbgRegionStartInst::destroyThis(DRSI);
+ else if(DbgStopPointInst* DSPI = dyn_cast<DbgStopPointInst>(this))
+ DbgStopPointInst::destroyThis(DSPI);
+ else
+ assert(0 && "Unknown DbgInfo-inherited class in ~Value.");
+ }
+ else if(MemIntrinsic* MI = dyn_cast<MemIntrinsic>(this))
+ {
+ if(MemCpyInst* MCI = dyn_cast<MemCpyInst>(this))
+ MemCpyInst::destroyThis(MCI);
+ else if(MemMoveInst* MMI = dyn_cast<MemMoveInst>(this))
+ MemMoveInst::destroyThis(MMI);
+ else if(MemSetInst* MSI = dyn_cast<MemSetInst>(this))
+ MemSetInst::destroyThis(MSI);
+ else
+ assert(0 && "Unknown MemIntrinsic-inherited class in ~Value.");
+ }
+ else
+ assert(0 && "Unknown IntrinsicInst-inherited class in ~Value.");
+ }
+ else
+ assert(0 && "Unknown CallInst-inherited class in ~Value.");
+ }
+ else if (CmpInst *CI = dyn_cast<CmpInst>(this))
+ {
+ if (FCmpInst *FCI = dyn_cast<FCmpInst>(this))
+ FCmpInst::destroyThis(FCI);
+ else if (ICmpInst *ICI = dyn_cast<ICmpInst>(this))
+ ICmpInst::destroyThis(ICI);
+ else
+ assert(0 && "Unknown CmpInst-inherited class in ~Value.");
+ }
+ else if (ExtractElementInst *EEI = dyn_cast<ExtractElementInst>(this))
+ ExtractElementInst::destroyThis(EEI);
+ else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(this))
+ GetElementPtrInst::destroyThis(GEP);
+ else if (InsertElementInst* IE = dyn_cast<InsertElementInst>(this))
+ InsertElementInst::destroyThis(IE);
+ else if (PHINode *PN = dyn_cast<PHINode>(this))
+ PHINode::destroyThis(PN);
+ else if (SelectInst *SI = dyn_cast<SelectInst>(this))
+ SelectInst::destroyThis(SI);
+ else if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(this))
+ ShuffleVectorInst::destroyThis(SVI);
+ else if (StoreInst *SI = dyn_cast<StoreInst>(this))
+ StoreInst::destroyThis(SI);
+ else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(this))
+ {
+ if (BranchInst* BI = dyn_cast<BranchInst>(this))
+ BranchInst::destroyThis(BI);
+ else if (InvokeInst* II = dyn_cast<InvokeInst>(this))
+ InvokeInst::destroyThis(II);
+ else if (ReturnInst* RI = dyn_cast<ReturnInst>(this))
+ ReturnInst::destroyThis(RI);
+ else if (SwitchInst *SI = dyn_cast<SwitchInst>(this))
+ SwitchInst::destroyThis(SI);
+ else if (UnreachableInst *UI = dyn_cast<UnreachableInst>(this))
+ UnreachableInst::destroyThis(UI);
+ else if (UnwindInst *UI = dyn_cast<UnwindInst>(this))
+ UnwindInst::destroyThis(UI);
+ else
+ assert(0 && "Unknown TerminatorInst-inherited class in ~Value.");
+ }
+ else if(UnaryInstruction* UI = dyn_cast<UnaryInstruction>(this))
+ {
+ if(AllocationInst* AI = dyn_cast<AllocationInst>(this))
+ {
+ if(AllocaInst* AI = dyn_cast<AllocaInst>(this))
+ AllocaInst::destroyThis(AI);
+ else if(MallocInst* MI = dyn_cast<MallocInst>(this))
+ MallocInst::destroyThis(MI);
+ else
+ assert(0 && "Unknown AllocationInst-inherited class in ~Value.");
+ }
+ else if(CastInst* CI = dyn_cast<CastInst>(this))
+ {
+ if(BitCastInst* BCI = dyn_cast<BitCastInst>(this))
+ BitCastInst::destroyThis(BCI);
+ else if(FPExtInst* FPEI = dyn_cast<FPExtInst>(this))
+ FPExtInst::destroyThis(FPEI);
+ else if(FPToSIInst* FPSII = dyn_cast<FPToSIInst>(this))
+ FPToSIInst::destroyThis(FPSII);
+ else if(FPToUIInst* FPUII = dyn_cast<FPToUIInst>(this))
+ FPToUIInst::destroyThis(FPUII);
+ else if(FPTruncInst* FPTI = dyn_cast<FPTruncInst>(this))
+ FPTruncInst::destroyThis(FPTI);
+ else if(IntToPtrInst* I2PI = dyn_cast<IntToPtrInst>(this))
+ IntToPtrInst::destroyThis(I2PI);
+ else if(PtrToIntInst* P2II = dyn_cast<PtrToIntInst>(this))
+ PtrToIntInst::destroyThis(P2II);
+ else if(SExtInst* SEI = dyn_cast<SExtInst>(this))
+ SExtInst::destroyThis(SEI);
+ else if(SIToFPInst* SIFPI = dyn_cast<SIToFPInst>(this))
+ SIToFPInst::destroyThis(SIFPI);
+ else if(TruncInst* TI = dyn_cast<TruncInst>(this))
+ TruncInst::destroyThis(TI);
+ else if(UIToFPInst* UIFPI = dyn_cast<UIToFPInst>(this))
+ UIToFPInst::destroyThis(UIFPI);
+ else if(ZExtInst* ZEI = dyn_cast<ZExtInst>(this))
+ ZExtInst::destroyThis(ZEI);
+ else
+ assert(0 && "Unknown CastInst-inherited class in ~Value.");
+ }
+ else if(FreeInst* FI = dyn_cast<FreeInst>(this))
+ FreeInst::destroyThis(FI);
+ else if(LoadInst* LI = dyn_cast<LoadInst>(this))
+ LoadInst::destroyThis(LI);
+ else if(VAArgInst* VAI = dyn_cast<VAArgInst>(this))
+ VAArgInst::destroyThis(VAI);
+ else
+ assert(0 && "Unknown UnaryInstruction-inherited class in ~Value.");
+ }
+ else if (DummyInst *DI = dyn_cast<DummyInst>(this))
+ DummyInst::destroyThis(DI);
+ else
+ assert(0 && "Unknown Instruction-inherited class in ~Value.");
+ break;
+ }
+}
+
+void Value::destroyThis(Value*v)
+{
#ifndef NDEBUG // Only in -g mode...
// Check to make sure that there are no uses of this value that are still
// around when the value is destroyed. If there are, then we have a dangling
@@ -47,22 +278,22 @@ Value::~Value() {
// still being referenced. The value in question should be printed as
// a <badref>
//
- if (!use_empty()) {
- DOUT << "While deleting: " << *Ty << " %" << Name << "\n";
- for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
+ if (!v->use_empty()) {
+ DOUT << "While deleting: " << *v->Ty << " %" << v->Name << "\n";
+ for (use_iterator I = v->use_begin(), E = v->use_end(); I != E; ++I)
DOUT << "Use still stuck around after Def is destroyed:"
<< **I << "\n";
}
#endif
- assert(use_empty() && "Uses remain when a value is destroyed!");
+ assert(v->use_empty() && "Uses remain when a value is destroyed!");
// If this value is named, destroy the name. This should not be in a symtab
// at this point.
- if (Name)
- Name->Destroy();
+ if (v->Name)
+ v->Name->Destroy();
// There should be no uses of this object anymore, remove it.
- LeakDetector::removeGarbageObject(this);
+ LeakDetector::removeGarbageObject(v);
}
/// hasNUses - Return true if this Value has exactly N users.