diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-07-08 23:22:50 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-07-08 23:22:50 +0000 |
| commit | 62ecb4a13712cd2e844d24cd07dc6497b234e458 (patch) | |
| tree | 0edb8a7d2989da239a0419d384dd110f978a3eaf /llvm/lib/VMCore/iMemory.cpp | |
| parent | 31feae855069992ad3806d44873e6b54c2f88e3e (diff) | |
| download | bcm5719-llvm-62ecb4a13712cd2e844d24cd07dc6497b234e458.tar.gz bcm5719-llvm-62ecb4a13712cd2e844d24cd07dc6497b234e458.zip | |
Implementation of Store & GetElementPtr
llvm-svn: 164
Diffstat (limited to 'llvm/lib/VMCore/iMemory.cpp')
| -rw-r--r-- | llvm/lib/VMCore/iMemory.cpp | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/llvm/lib/VMCore/iMemory.cpp b/llvm/lib/VMCore/iMemory.cpp index 41c14b04d55..4403224b880 100644 --- a/llvm/lib/VMCore/iMemory.cpp +++ b/llvm/lib/VMCore/iMemory.cpp @@ -7,8 +7,19 @@ #include "llvm/iMemory.h" #include "llvm/ConstPoolVals.h" -const Type *LoadInst::getIndexedType(const Type *Ptr, - const vector<ConstPoolVal*> &Idx) { +//===----------------------------------------------------------------------===// +// MemAccessInst Implementation +//===----------------------------------------------------------------------===// + +// 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. +// +const Type *MemAccessInst::getIndexedType(const Type *Ptr, + const vector<ConstPoolVal*> &Idx, + bool AllowStructLeaf = false) { if (!Ptr->isPointerType()) return 0; // Type isn't a pointer type! // Get the type pointed to... @@ -17,7 +28,8 @@ const Type *LoadInst::getIndexedType(const Type *Ptr, if (Ptr->isStructType()) { unsigned CurIDX = 0; while (Ptr->isStructType()) { - if (Idx.size() == CurIDX) return 0; // Can't load a whole structure! + if (Idx.size() == CurIDX) + return AllowStructLeaf ? Ptr : 0; // Can't load a whole structure!?!? if (Idx[CurIDX]->getType() != Type::UByteTy) return 0; // Illegal idx unsigned NextIdx = ((ConstPoolUInt*)Idx[CurIDX++])->getValue(); @@ -33,11 +45,49 @@ const Type *LoadInst::getIndexedType(const Type *Ptr, } +//===----------------------------------------------------------------------===// +// LoadInst Implementation +//===----------------------------------------------------------------------===// + LoadInst::LoadInst(Value *Ptr, const vector<ConstPoolVal*> &Idx, const string &Name = "") - : Instruction(getIndexedType(Ptr->getType(), Idx), Load, Name) { + : MemAccessInst(getIndexedType(Ptr->getType(), Idx), Load, Name) { assert(getIndexedType(Ptr->getType(), Idx) && "Load operands invalid!"); - assert(Ptr->getType()->isPointerType() && "Can't free nonpointer!"); + Operands.reserve(1+Idx.size()); + Operands.push_back(Use(Ptr, this)); + + for (unsigned i = 0, E = Idx.size(); i != E; ++i) + Operands.push_back(Use(Idx[i], this)); +} + + +//===----------------------------------------------------------------------===// +// StoreInst Implementation +//===----------------------------------------------------------------------===// + +StoreInst::StoreInst(Value *Val, Value *Ptr, const vector<ConstPoolVal*> &Idx, + const string &Name = "") + : MemAccessInst(Type::VoidTy, Store, Name) { + assert(getIndexedType(Ptr->getType(), Idx) && "Store operands invalid!"); + + Operands.reserve(2+Idx.size()); + Operands.push_back(Use(Val, this)); + Operands.push_back(Use(Ptr, this)); + + for (unsigned i = 0, E = Idx.size(); i != E; ++i) + Operands.push_back(Use(Idx[i], this)); +} + + +//===----------------------------------------------------------------------===// +// GetElementPtrInst Implementation +//===----------------------------------------------------------------------===// + +GetElementPtrInst::GetElementPtrInst(Value *Ptr, + const vector<ConstPoolVal*> &Idx, + const string &Name = "") + : MemAccessInst(PointerType::getPointerType(getIndexedType(Ptr->getType(), Idx, true)), GetElementPtr, Name) { + assert(getIndexedType(Ptr->getType(), Idx, true) && "gep operands invalid!"); Operands.reserve(1+Idx.size()); Operands.push_back(Use(Ptr, this)); |

