forked from OSchip/llvm-project
* Make AllocationInst ctor protected
* Move AllocationInst ctor to iMemory.cpp * AllocationInst's always have one operand, even if it is a uint 1 llvm-svn: 1938
This commit is contained in:
parent
8a36ae8ab9
commit
d713541ffd
|
@ -19,32 +19,21 @@
|
||||||
// AllocaInst.
|
// AllocaInst.
|
||||||
//
|
//
|
||||||
class AllocationInst : public Instruction {
|
class AllocationInst : public Instruction {
|
||||||
public:
|
protected:
|
||||||
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
|
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
|
||||||
const std::string &Name = "")
|
const std::string &Name = "");
|
||||||
: Instruction(Ty, iTy, Name) {
|
public:
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// isArrayAllocation - Return true if there is an allocation size parameter
|
// isArrayAllocation - Return true if there is an allocation size parameter
|
||||||
// to the allocation instruction that is not 1.
|
// to the allocation instruction that is not 1.
|
||||||
//
|
//
|
||||||
bool isArrayAllocation() const;
|
bool isArrayAllocation() const;
|
||||||
|
|
||||||
inline const Value *getArraySize() const {
|
// getArraySize - Get the number of element allocated, for a simple allocation
|
||||||
assert(isArrayAllocation()); return Operands[0];
|
// of a single element, this will return a constant 1 value.
|
||||||
}
|
//
|
||||||
inline Value *getArraySize() {
|
inline const Value *getArraySize() const { return Operands[0]; }
|
||||||
assert(isArrayAllocation()); return Operands[0];
|
inline Value *getArraySize() { return Operands[0]; }
|
||||||
}
|
|
||||||
|
|
||||||
// getType - Overload to return most specific pointer type...
|
// getType - Overload to return most specific pointer type...
|
||||||
inline const PointerType *getType() const {
|
inline const PointerType *getType() const {
|
||||||
|
@ -81,8 +70,7 @@ public:
|
||||||
: AllocationInst(Ty, ArraySize, Malloc, Name) {}
|
: AllocationInst(Ty, ArraySize, Malloc, Name) {}
|
||||||
|
|
||||||
virtual Instruction *clone() const {
|
virtual Instruction *clone() const {
|
||||||
return new MallocInst(getType(),
|
return new MallocInst(getType(), (Value*)Operands[0].get());
|
||||||
Operands.size() ? (Value*)Operands[0].get() : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *getOpcodeName() const { return "malloc"; }
|
virtual const char *getOpcodeName() const { return "malloc"; }
|
||||||
|
@ -108,8 +96,7 @@ public:
|
||||||
: AllocationInst(Ty, ArraySize, Alloca, Name) {}
|
: AllocationInst(Ty, ArraySize, Alloca, Name) {}
|
||||||
|
|
||||||
virtual Instruction *clone() const {
|
virtual Instruction *clone() const {
|
||||||
return new AllocaInst(getType(),
|
return new AllocaInst(getType(), (Value*)Operands[0].get());
|
||||||
Operands.size() ? (Value*)Operands[0].get() : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *getOpcodeName() const { return "alloca"; }
|
virtual const char *getOpcodeName() const { return "alloca"; }
|
||||||
|
|
Loading…
Reference in New Issue