diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Instruction.h | 3 | ||||
-rw-r--r-- | include/llvm/iMemory.h | 95 |
2 files changed, 86 insertions, 12 deletions
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index cce9662..031730a 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -102,8 +102,7 @@ public: Alloca, // Stack management instruction Load, Store, // Memory manipulation instructions. - - GetField, PutField, // Structure manipulation instructions + GetElementPtr, // Get addr of Structure or Array element NumMemoryOps }; diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index dc8d759..feed3a2 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -11,6 +11,13 @@ #include "llvm/Instruction.h" #include "llvm/DerivedTypes.h" +//===----------------------------------------------------------------------===// +// AllocationInst Class +//===----------------------------------------------------------------------===// +// +// AllocationInst - This class is the common base class of MallocInst and +// AllocaInst. +// class AllocationInst : public Instruction { public: AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, @@ -38,6 +45,10 @@ public: }; +//===----------------------------------------------------------------------===// +// MallocInst Class +//===----------------------------------------------------------------------===// + class MallocInst : public AllocationInst { public: MallocInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "") @@ -51,6 +62,10 @@ public: }; +//===----------------------------------------------------------------------===// +// AllocaInst Class +//===----------------------------------------------------------------------===// + class AllocaInst : public AllocationInst { public: AllocaInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "") @@ -64,6 +79,10 @@ public: }; +//===----------------------------------------------------------------------===// +// FreeInst Class +//===----------------------------------------------------------------------===// + class FreeInst : public Instruction { public: FreeInst(Value *Ptr, const string &Name = "") @@ -79,8 +98,36 @@ public: }; -class LoadInst : public Instruction { - LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) { +//===----------------------------------------------------------------------===// +// MemAccessInst Class +//===----------------------------------------------------------------------===// +// +// MemAccessInst - Common base class of LoadInst, StoreInst, and +// GetElementPtrInst... +// +class MemAccessInst : public Instruction { +protected: + inline MemAccessInst(const Type *Ty, unsigned Opcode, const string &Nam = "") + : Instruction(Ty, Opcode, Nam) {} +public: + // getIndexedType - Returns the type of the element that would be loaded with + // a load instruction with the specified parameters. + // + // A null type is returned if the indices are invalid for the specified + // pointer type. + // + static const Type *getIndexedType(const Type *Ptr, + const vector<ConstPoolVal*> &Indices, + bool AllowStructLeaf = false); +}; + + +//===----------------------------------------------------------------------===// +// LoadInst Class +//===----------------------------------------------------------------------===// + +class LoadInst : public MemAccessInst { + LoadInst(const LoadInst &LI) : MemAccessInst(LI.getType(), Load) { Operands.reserve(LI.Operands.size()); for (unsigned i = 0, E = LI.Operands.size(); i != E; ++i) Operands.push_back(Use(LI.Operands[i], this)); @@ -90,15 +137,43 @@ public: const string &Name = ""); virtual Instruction *clone() const { return new LoadInst(*this); } virtual const char *getOpcodeName() const { return "load"; } +}; - // getIndexedType - Returns the type of the element that would be loaded with - // a load instruction with the specified parameters. - // - // A null type is returned if the indices are invalid for the specified - // pointer type. - // - static const Type *getIndexedType(const Type *Ptr, - const vector<ConstPoolVal*> &); + +//===----------------------------------------------------------------------===// +// StoreInst Class +//===----------------------------------------------------------------------===// + +class StoreInst : public MemAccessInst { + StoreInst(const StoreInst &SI) : MemAccessInst(SI.getType(), Store) { + Operands.reserve(SI.Operands.size()); + for (unsigned i = 0, E = SI.Operands.size(); i != E; ++i) + Operands.push_back(Use(SI.Operands[i], this)); + } +public: + StoreInst(Value *Val, Value *Ptr, const vector<ConstPoolVal*> &Idx, + const string &Name = ""); + virtual Instruction *clone() const { return new StoreInst(*this); } + virtual const char *getOpcodeName() const { return "store"; } +}; + + +//===----------------------------------------------------------------------===// +// GetElementPtrInst Class +//===----------------------------------------------------------------------===// + +class GetElementPtrInst : public MemAccessInst { + GetElementPtrInst(const GetElementPtrInst &EPI) + : MemAccessInst(EPI.getType(), GetElementPtr) { + Operands.reserve(EPI.Operands.size()); + for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i) + Operands.push_back(Use(EPI.Operands[i], this)); + } +public: + GetElementPtrInst(Value *Ptr, const vector<ConstPoolVal*> &Idx, + const string &Name = ""); + virtual Instruction *clone() const { return new GetElementPtrInst(*this); } + virtual const char *getOpcodeName() const { return "getelementptr"; } }; #endif // LLVM_IMEMORY_H |