diff options
author | Gabor Greif <ggreif@gmail.com> | 2008-04-06 20:25:17 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2008-04-06 20:25:17 +0000 |
commit | 051a950000e21935165db56695e35bade668193b (patch) | |
tree | 76db4bc690c153a1cfbd2989849c3b1d95500390 /lib/VMCore/Constants.cpp | |
parent | d963ab1f58adb6daa028533ff3285841d7e45f80 (diff) | |
download | external_llvm-051a950000e21935165db56695e35bade668193b.zip external_llvm-051a950000e21935165db56695e35bade668193b.tar.gz external_llvm-051a950000e21935165db56695e35bade668193b.tar.bz2 |
API changes for class Use size reduction, wave 1.
Specifically, introduction of XXX::Create methods
for Users that have a potentially variable number of
Uses.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49277 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 470e247..78d24ef 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -410,8 +410,13 @@ 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 { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Op; public: + // allocate space for exactly one operand + void *operator new(size_t s) { + return User::operator new(s, 1); + } UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty) : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {} }; @@ -419,8 +424,13 @@ public: /// 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 { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Ops[2]; public: + // allocate space for exactly two operands + void *operator new(size_t s) { + return User::operator new(s, 2); + } BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2) : ConstantExpr(C1->getType(), Opcode, Ops, 2) { Ops[0].init(C1, this); @@ -431,8 +441,13 @@ public: /// 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 { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Ops[3]; public: + // allocate space for exactly three operands + void *operator new(size_t s) { + return User::operator new(s, 3); + } SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3) : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) { Ops[0].init(C1, this); @@ -445,8 +460,13 @@ public: /// Constants.cpp, and is used behind the scenes to implement /// extractelement constant exprs. class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Ops[2]; public: + // allocate space for exactly two operands + void *operator new(size_t s) { + return User::operator new(s, 2); + } ExtractElementConstantExpr(Constant *C1, Constant *C2) : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(), Instruction::ExtractElement, Ops, 2) { @@ -459,8 +479,13 @@ public: /// Constants.cpp, and is used behind the scenes to implement /// insertelement constant exprs. class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Ops[3]; public: + // allocate space for exactly three operands + void *operator new(size_t s) { + return User::operator new(s, 3); + } InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3) : ConstantExpr(C1->getType(), Instruction::InsertElement, Ops, 3) { @@ -474,8 +499,13 @@ public: /// Constants.cpp, and is used behind the scenes to implement /// shufflevector constant exprs. class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT Use Ops[3]; public: + // allocate space for exactly three operands + void *operator new(size_t s) { + return User::operator new(s, 3); + } ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3) : ConstantExpr(C1->getType(), Instruction::ShuffleVector, Ops, 3) { @@ -487,7 +517,7 @@ public: /// 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 { +class VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr { GetElementPtrConstantExpr(Constant *C, const std::vector<Constant*> &IdxList, const Type *DestTy) : ConstantExpr(DestTy, Instruction::GetElementPtr, @@ -496,6 +526,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr { for (unsigned i = 0, E = IdxList.size(); i != E; ++i) OperandList[i+1].init(IdxList[i], this); } +public: + static GetElementPtrConstantExpr *Create(Constant *C, const std::vector<Constant*> &IdxList, + const Type *DestTy) { + return new(IdxList.size() + 1/*FIXME*/) GetElementPtrConstantExpr(C, IdxList, DestTy); + } ~GetElementPtrConstantExpr() { delete [] OperandList; } @@ -505,6 +540,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr { // 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 { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT + // allocate space for exactly two operands + void *operator new(size_t s) { + return User::operator new(s, 2); + } unsigned short predicate; Use Ops[2]; CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred, @@ -771,7 +811,8 @@ namespace llvm { template<class ConstantClass, class TypeClass, class ValType> struct VISIBILITY_HIDDEN ConstantCreator { static ConstantClass *create(const TypeClass *Ty, const ValType &V) { - return new ConstantClass(Ty, V); + unsigned FIXME; // = traits<ValType>::uses(V) + return new(FIXME) ConstantClass(Ty, V); } }; @@ -1433,7 +1474,7 @@ namespace llvm { V.operands[2]); if (V.opcode == Instruction::GetElementPtr) { std::vector<Constant*> IdxList(V.operands.begin()+1, V.operands.end()); - return new GetElementPtrConstantExpr(V.operands[0], IdxList, Ty); + return GetElementPtrConstantExpr::Create(V.operands[0], IdxList, Ty); } // The compare instructions are weird. We have to encode the predicate |