From 05c0e9e562de11be51938ac3124330177ccc00ff Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 21 Mar 2002 22:37:01 +0000 Subject: * Make AllocationInst ctor protected * Move AllocationInst ctor to iMemory.cpp * AllocationInst's always have one operand, even if it is a uint 1 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1938 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/iMemory.h | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'include/llvm/iMemory.h') diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index 7d919196de..35bce8ea3c 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -19,32 +19,21 @@ // AllocaInst. // class AllocationInst : public Instruction { -public: +protected: AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, - const std::string &Name = "") - : Instruction(Ty, iTy, Name) { - assert(Ty->isPointerType() && "Can't allocate a non pointer type!"); - - if (ArraySize) { - assert(ArraySize->getType() == Type::UIntTy && - "Malloc/Allocation array size != UIntTy!"); - - Operands.reserve(1); - Operands.push_back(Use(ArraySize, this)); - } - } + const std::string &Name = ""); +public: // isArrayAllocation - Return true if there is an allocation size parameter // to the allocation instruction that is not 1. // bool isArrayAllocation() const; - inline const Value *getArraySize() const { - assert(isArrayAllocation()); return Operands[0]; - } - inline Value *getArraySize() { - assert(isArrayAllocation()); return Operands[0]; - } + // getArraySize - Get the number of element allocated, for a simple allocation + // of a single element, this will return a constant 1 value. + // + inline const Value *getArraySize() const { return Operands[0]; } + inline Value *getArraySize() { return Operands[0]; } // getType - Overload to return most specific pointer type... inline const PointerType *getType() const { @@ -81,8 +70,7 @@ public: : AllocationInst(Ty, ArraySize, Malloc, Name) {} virtual Instruction *clone() const { - return new MallocInst(getType(), - Operands.size() ? (Value*)Operands[0].get() : 0); + return new MallocInst(getType(), (Value*)Operands[0].get()); } virtual const char *getOpcodeName() const { return "malloc"; } @@ -108,8 +96,7 @@ public: : AllocationInst(Ty, ArraySize, Alloca, Name) {} virtual Instruction *clone() const { - return new AllocaInst(getType(), - Operands.size() ? (Value*)Operands[0].get() : 0); + return new AllocaInst(getType(), (Value*)Operands[0].get()); } virtual const char *getOpcodeName() const { return "alloca"; } -- cgit v1.2.3