mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-26 23:32:58 +00:00
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
This commit is contained in:
parent
05804b7459
commit
e87e1c9aa9
@ -63,13 +63,15 @@ public:
|
|||||||
// MallocInst Class
|
// 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 = "",
|
MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
|
||||||
Instruction *InsertBefore = 0)
|
Instruction *InsertBefore = 0)
|
||||||
: AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
|
: AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
|
||||||
|
|
||||||
virtual Instruction *clone() const {
|
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:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
@ -87,13 +89,15 @@ struct MallocInst : public AllocationInst {
|
|||||||
// AllocaInst Class
|
// 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 = "",
|
AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
|
||||||
Instruction *InsertBefore = 0)
|
Instruction *InsertBefore = 0)
|
||||||
: AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
|
: AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
|
||||||
|
|
||||||
virtual Instruction *clone() const {
|
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:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
@ -329,13 +329,19 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
|
|||||||
case Instruction::Malloc:
|
case Instruction::Malloc:
|
||||||
if (Raw.NumOperands > 2) return true;
|
if (Raw.NumOperands > 2) return true;
|
||||||
V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
|
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;
|
return false;
|
||||||
|
|
||||||
case Instruction::Alloca:
|
case Instruction::Alloca:
|
||||||
if (Raw.NumOperands > 2) return true;
|
if (Raw.NumOperands > 2) return true;
|
||||||
V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
|
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;
|
return false;
|
||||||
|
|
||||||
case Instruction::Free:
|
case Instruction::Free:
|
||||||
|
@ -399,12 +399,14 @@ void MutateStructTypes::transformFunction(Function *m) {
|
|||||||
// Memory Instructions
|
// Memory Instructions
|
||||||
case Instruction::Alloca:
|
case Instruction::Alloca:
|
||||||
NewI =
|
NewI =
|
||||||
new AllocaInst(ConvertType(I.getType()),
|
new MallocInst(
|
||||||
|
ConvertType(cast<PointerType>(I.getType())->getElementType()),
|
||||||
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
|
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
|
||||||
break;
|
break;
|
||||||
case Instruction::Malloc:
|
case Instruction::Malloc:
|
||||||
NewI =
|
NewI =
|
||||||
new MallocInst(ConvertType(I.getType()),
|
new MallocInst(
|
||||||
|
ConvertType(cast<PointerType>(I.getType())->getElementType()),
|
||||||
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
|
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1639,8 +1639,7 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs,
|
|||||||
"Pool type should not be abstract anymore!");
|
"Pool type should not be abstract anymore!");
|
||||||
|
|
||||||
// Add an allocation and a free for each pool...
|
// Add an allocation and a free for each pool...
|
||||||
AllocaInst *PoolAlloc
|
AllocaInst *PoolAlloc = new AllocaInst(PI.PoolType, 0,
|
||||||
= new AllocaInst(PointerType::get(PI.PoolType), 0,
|
|
||||||
CurModule->getTypeName(PI.PoolType));
|
CurModule->getTypeName(PI.PoolType));
|
||||||
PI.Handle = PoolAlloc;
|
PI.Handle = PoolAlloc;
|
||||||
EntryNodeInsts.push_back(PoolAlloc);
|
EntryNodeInsts.push_back(PoolAlloc);
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
|
AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
|
||||||
const std::string &Name, Instruction *InsertBef)
|
const std::string &Name, Instruction *InsertBef)
|
||||||
: Instruction(Ty, iTy, Name, InsertBef) {
|
: Instruction(PointerType::get(Ty), iTy, Name, InsertBef) {
|
||||||
assert(isa<PointerType>(Ty) && "Can't allocate a non pointer type!");
|
|
||||||
|
|
||||||
// ArraySize defaults to 1.
|
// ArraySize defaults to 1.
|
||||||
if (!ArraySize) ArraySize = ConstantUInt::get(Type::UIntTy, 1);
|
if (!ArraySize) ArraySize = ConstantUInt::get(Type::UIntTy, 1);
|
||||||
@ -31,6 +30,16 @@ const Type *AllocationInst::getAllocatedType() const {
|
|||||||
return getType()->getElementType();
|
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
|
// FreeInst Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user