aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Constants.cpp
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/Constants.cpp
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/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp173
1 files changed, 59 insertions, 114 deletions
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