aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/iMemory.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-08 23:22:50 +0000
committerChris Lattner <sabre@nondot.org>2001-07-08 23:22:50 +0000
commitab5ac6bb384ec1e4f1cbc4e0ad0fb32d39eb7ff3 (patch)
tree1f05b07519bbc5138edde0c8dc04302c47d1f987 /lib/VMCore/iMemory.cpp
parent0bd654a049490a56b6c39f56acf7c8e634085c23 (diff)
Implementation of Store & GetElementPtr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/iMemory.cpp')
-rw-r--r--lib/VMCore/iMemory.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp
index 41c14b04d5..4403224b88 100644
--- a/lib/VMCore/iMemory.cpp
+++ b/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));