summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-13 22:28:50 +0000
committerChris Lattner <sabre@nondot.org>2002-09-13 22:28:50 +0000
commite87e1c9aa947e6558412b6517308410cd0f5aea4 (patch)
treee64b7d79741476bd0070c8284ac6757ee0be1a83 /lib
parent05804b74590ab8714bd7695d8cd0d98819c092f9 (diff)
downloadllvm-e87e1c9aa947e6558412b6517308410cd0f5aea4.tar.gz
llvm-e87e1c9aa947e6558412b6517308410cd0f5aea4.tar.bz2
llvm-e87e1c9aa947e6558412b6517308410cd0f5aea4.tar.xz
Change the MallocInst & AllocaInst ctors to take the allocated type, not the
pointer type returned. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp10
-rw-r--r--lib/Transforms/IPO/MutateStructTypes.cpp6
-rw-r--r--lib/Transforms/IPO/OldPoolAllocate.cpp5
-rw-r--r--lib/VMCore/iMemory.cpp13
4 files changed, 25 insertions, 9 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index 0b75c41b00..40360991f5 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -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:
diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp
index e5bad67f5e..08ff6b8198 100644
--- a/lib/Transforms/IPO/MutateStructTypes.cpp
+++ b/lib/Transforms/IPO/MutateStructTypes.cpp
@@ -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;
diff --git a/lib/Transforms/IPO/OldPoolAllocate.cpp b/lib/Transforms/IPO/OldPoolAllocate.cpp
index 67ba0f12f1..33110bd467 100644
--- a/lib/Transforms/IPO/OldPoolAllocate.cpp
+++ b/lib/Transforms/IPO/OldPoolAllocate.cpp
@@ -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();
diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp
index 1738d6e6a2..dacb8fe2a2 100644
--- a/lib/VMCore/iMemory.cpp
+++ b/lib/VMCore/iMemory.cpp
@@ -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
//===----------------------------------------------------------------------===//