Change the MallocInst & AllocaInst ctors to take the allocated type, not the
authorChris Lattner <sabre@nondot.org>
Fri, 13 Sep 2002 22:28:50 +0000 (22:28 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 13 Sep 2002 22:28:50 +0000 (22:28 +0000)
pointer type returned.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3711 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/iMemory.h
lib/Bytecode/Reader/InstructionReader.cpp
lib/Transforms/IPO/MutateStructTypes.cpp
lib/Transforms/IPO/OldPoolAllocate.cpp
lib/VMCore/iMemory.cpp

index e2a1e1bd64e46fd061f0316c8b4ee0700b6bf046..c198aebd70c6d958bcc32de35d741e41b94ffb45 100644 (file)
@@ -63,13 +63,15 @@ public:
 //                                MallocInst Class
 //===----------------------------------------------------------------------===//
 
-struct MallocInst : public AllocationInst {
+class MallocInst : public AllocationInst {
+  MallocInst(const MallocInst &MI);
+public:
   MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
              Instruction *InsertBefore = 0)
     : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
 
   virtual Instruction *clone() const { 
-    return new MallocInst((Type*)getType(), (Value*)Operands[0].get());
+    return new MallocInst(*this);
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -87,13 +89,15 @@ struct MallocInst : public AllocationInst {
 //                                AllocaInst Class
 //===----------------------------------------------------------------------===//
 
-struct AllocaInst : public AllocationInst {
+class AllocaInst : public AllocationInst {
+  AllocaInst(const AllocaInst &);
+public:
   AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
              Instruction *InsertBefore = 0)
     : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
 
   virtual Instruction *clone() const { 
-    return new AllocaInst((Type*)getType(), (Value*)Operands[0].get());
+    return new AllocaInst(*this);
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
index 0b75c41b008abb86482009001898ab18b43daa1d..40360991f5c42cef9a05b4031b5e21e80dea19eb 100644 (file)
@@ -329,13 +329,19 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
   case Instruction::Malloc:
     if (Raw.NumOperands > 2) return true;
     V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
-    Res = new MallocInst(Raw.Ty, V);
+    if (const PointerType *PTy = dyn_cast<PointerType>(Raw.Ty))
+      Res = new MallocInst(PTy->getElementType(), V);
+    else
+      return true;
     return false;
 
   case Instruction::Alloca:
     if (Raw.NumOperands > 2) return true;
     V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
-    Res = new AllocaInst(Raw.Ty, V);
+    if (const PointerType *PTy = dyn_cast<PointerType>(Raw.Ty))
+      Res = new AllocaInst(PTy->getElementType(), V);
+    else
+      return true;
     return false;
 
   case Instruction::Free:
index e5bad67f5eadd7503b86b212c55d83ff3f39cac7..08ff6b8198d5c6665a88861ea90edfa799ad2544 100644 (file)
@@ -399,12 +399,14 @@ void MutateStructTypes::transformFunction(Function *m) {
         // Memory Instructions
       case Instruction::Alloca:
         NewI = 
-          new AllocaInst(ConvertType(I.getType()),
+          new MallocInst(
+                  ConvertType(cast<PointerType>(I.getType())->getElementType()),
                          I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
         break;
       case Instruction::Malloc:
         NewI = 
-          new MallocInst(ConvertType(I.getType()),
+          new MallocInst(
+                  ConvertType(cast<PointerType>(I.getType())->getElementType()),
                          I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
         break;
 
index 67ba0f12f1ec6fbc0cf642b5622b2c7aeef048b6..33110bd467f88ff3fc61885a345bcaaf3b7b8fe7 100644 (file)
@@ -1639,9 +1639,8 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs,
            "Pool type should not be abstract anymore!");
 
     // Add an allocation and a free for each pool...
-    AllocaInst *PoolAlloc
-      = new AllocaInst(PointerType::get(PI.PoolType), 0,
-                       CurModule->getTypeName(PI.PoolType));
+    AllocaInst *PoolAlloc = new AllocaInst(PI.PoolType, 0,
+                                           CurModule->getTypeName(PI.PoolType));
     PI.Handle = PoolAlloc;
     EntryNodeInsts.push_back(PoolAlloc);
     AllocationInst *AI = Allocs[i]->getAllocation();
index 1738d6e6a2f6050aef35943a8ec18b8b8b888d2b..dacb8fe2a23f9ac757d6cf5de71ade6384a2f4c1 100644 (file)
@@ -10,8 +10,7 @@
 
 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
                                const std::string &Name, Instruction *InsertBef)
-  : Instruction(Ty, iTy, Name, InsertBef) {
-  assert(isa<PointerType>(Ty) && "Can't allocate a non pointer type!");
+  : Instruction(PointerType::get(Ty), iTy, Name, InsertBef) {
 
   // ArraySize defaults to 1.
   if (!ArraySize) ArraySize = ConstantUInt::get(Type::UIntTy, 1);
@@ -31,6 +30,16 @@ const Type *AllocationInst::getAllocatedType() const {
   return getType()->getElementType();
 }
 
+AllocaInst::AllocaInst(const AllocaInst &AI)
+  : AllocationInst(AI.getType()->getElementType(), (Value*)AI.getOperand(0),
+                   Instruction::Alloca) {
+}
+
+MallocInst::MallocInst(const MallocInst &MI)
+  : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0),
+                   Instruction::Malloc) {
+}
+
 //===----------------------------------------------------------------------===//
 //                             FreeInst Implementation
 //===----------------------------------------------------------------------===//