* Make AllocationInst ctor protected
authorChris Lattner <sabre@nondot.org>
Thu, 21 Mar 2002 22:37:01 +0000 (22:37 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 21 Mar 2002 22:37:01 +0000 (22:37 +0000)
* 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

index 7d919196deaf3285e5cd6d72e69a0fdb401ea2d6..35bce8ea3c0d8a507ae5dc45beceacb0286d5cbe 100644 (file)
 // 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"; }