summaryrefslogtreecommitdiff
path: root/include/llvm/iMemory.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
committerChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
commitc8b25d40cbec063b1ca99cc1adf794399c6d05c0 (patch)
tree8ad1468cb632eb9770206b1bd4bdd45d4e037898 /include/llvm/iMemory.h
parentf0d0e9c262b668cf362fbaa8111bb6cc15268909 (diff)
downloadllvm-c8b25d40cbec063b1ca99cc1adf794399c6d05c0.tar.gz
llvm-c8b25d40cbec063b1ca99cc1adf794399c6d05c0.tar.bz2
llvm-c8b25d40cbec063b1ca99cc1adf794399c6d05c0.tar.xz
Changed the fundemental architecture of Operands for Instructions. Now
Operands are maintained as a vector<Use> in the User class, and operator iterators are provided as before. Getting an operand no longer requires a virtual function call. WARNING: getOperand(x) where x >= getNumOperands() will now assert instead of returning null! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/iMemory.h')
-rw-r--r--include/llvm/iMemory.h107
1 files changed, 24 insertions, 83 deletions
diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h
index 077266de94..fafe4c311a 100644
--- a/include/llvm/iMemory.h
+++ b/include/llvm/iMemory.h
@@ -10,31 +10,24 @@
#include "llvm/Instruction.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/ConstPoolVals.h"
-
-class ConstPoolType;
class AllocationInst : public Instruction {
-protected:
- UseTy<ConstPoolType> TyVal;
- Use ArraySize;
public:
- AllocationInst(ConstPoolType *tyVal, Value *arrSize, unsigned iTy,
- const string &Name = "")
- : Instruction(tyVal->getValue(), iTy, Name),
- TyVal(tyVal, this), ArraySize(arrSize, this) {
-
- // Make sure they didn't try to specify a size for an invalid type...
- assert(arrSize == 0 ||
- (getType()->getValueType()->isArrayType() &&
- ((const ArrayType*)getType()->getValueType())->isUnsized()) &&
- "Trying to allocate something other than unsized array, with size!");
-
- // Make sure that if a size is specified, that it is a uint!
- assert(arrSize == 0 || arrSize->getType() == Type::UIntTy &&
- "Malloc SIZE is not a 'uint'!");
+ AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
+ const string &Name = "")
+ : Instruction(Ty, iTy, Name) {
+ assert(Ty->isPointerType() && "Can't allocate a non pointer type!");
+
+ if (ArraySize) {
+ // Make sure they didn't try to specify a size for !(unsized array) type...
+ assert((getType()->getValueType()->isArrayType() &&
+ ((const ArrayType*)getType()->getValueType())->isUnsized()) &&
+ "Trying to allocate something other than unsized array, with size!");
+
+ Operands.reserve(1);
+ Operands.push_back(Use(ArraySize, this));
+ }
}
- inline ~AllocationInst() {}
// getType - Overload to return most specific pointer type...
inline const PointerType *getType() const {
@@ -42,46 +35,15 @@ public:
}
virtual Instruction *clone() const = 0;
-
- inline virtual void dropAllReferences() { TyVal = 0; ArraySize = 0; }
- virtual bool setOperand(unsigned i, Value *Val) {
- if (i == 0) {
- assert(!Val || Val->getValueType() == Value::ConstantVal);
- TyVal = (ConstPoolType*)Val;
- return true;
- } else if (i == 1) {
- // Make sure they didn't try to specify a size for an invalid type...
- assert(Val == 0 ||
- (getType()->getValueType()->isArrayType() &&
- ((const ArrayType*)getType()->getValueType())->isUnsized()) &&
- "Trying to allocate something other than unsized array, with size!");
-
- // Make sure that if a size is specified, that it is a uint!
- assert(Val == 0 || Val->getType() == Type::UIntTy &&
- "Malloc SIZE is not a 'uint'!");
-
- ArraySize = Val;
- return true;
- }
- return false;
- }
-
- virtual unsigned getNumOperands() const { return 2; }
-
- virtual const Value *getOperand(unsigned i) const {
- return i == 0 ? TyVal : (i == 1 ? ArraySize : 0);
- }
};
class MallocInst : public AllocationInst {
public:
- MallocInst(ConstPoolType *tyVal, Value *ArraySize = 0,
- const string &Name = "")
- : AllocationInst(tyVal, ArraySize, Instruction::Malloc, Name) {}
- inline ~MallocInst() {}
+ MallocInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
+ : AllocationInst(Ty, ArraySize, Instruction::Malloc, Name) {}
virtual Instruction *clone() const {
- return new MallocInst(TyVal, ArraySize);
+ return new MallocInst(getType(), Operands.size() ? Operands[1] : 0);
}
virtual string getOpcode() const { return "malloc"; }
@@ -89,13 +51,11 @@ public:
class AllocaInst : public AllocationInst {
public:
- AllocaInst(ConstPoolType *tyVal, Value *ArraySize = 0,
- const string &Name = "")
- : AllocationInst(tyVal, ArraySize, Instruction::Alloca, Name) {}
- inline ~AllocaInst() {}
+ AllocaInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
+ : AllocationInst(Ty, ArraySize, Instruction::Alloca, Name) {}
virtual Instruction *clone() const {
- return new AllocaInst(TyVal, ArraySize);
+ return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0);
}
virtual string getOpcode() const { return "alloca"; }
@@ -104,35 +64,16 @@ public:
class FreeInst : public Instruction {
-protected:
- Use Pointer;
public:
FreeInst(Value *Ptr, const string &Name = "")
- : Instruction(Type::VoidTy, Instruction::Free, Name),
- Pointer(Ptr, this) {
-
+ : Instruction(Type::VoidTy, Instruction::Free, Name) {
assert(Ptr->getType()->isPointerType() && "Can't free nonpointer!");
+ Operands.reserve(1);
+ Operands.push_back(Use(Ptr, this));
}
inline ~FreeInst() {}
- virtual Instruction *clone() const { return new FreeInst(Pointer); }
-
- inline virtual void dropAllReferences() { Pointer = 0; }
-
- virtual bool setOperand(unsigned i, Value *Val) {
- if (i == 0) {
- assert(!Val || Val->getType()->isPointerType() &&
- "Can't free nonpointer!");
- Pointer = Val;
- return true;
- }
- return false;
- }
-
- virtual unsigned getNumOperands() const { return 1; }
- virtual const Value *getOperand(unsigned i) const {
- return i == 0 ? Pointer : 0;
- }
+ virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
virtual string getOpcode() const { return "free"; }
};