summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/iMemory.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-08 21:10:27 +0000
committerChris Lattner <sabre@nondot.org>2001-07-08 21:10:27 +0000
commitd8bebcd5173802ff51cca2ac62170c1ff44d8e6c (patch)
tree641414a223bfba9a2f6c11cf83946a5aa90496c0 /llvm/lib/VMCore/iMemory.cpp
parent49c643262e94bd720c5ded918f9a0487976340df (diff)
downloadbcm5719-llvm-d8bebcd5173802ff51cca2ac62170c1ff44d8e6c.tar.gz
bcm5719-llvm-d8bebcd5173802ff51cca2ac62170c1ff44d8e6c.zip
Implemented shl, shl, & load instructions
llvm-svn: 161
Diffstat (limited to 'llvm/lib/VMCore/iMemory.cpp')
-rw-r--r--llvm/lib/VMCore/iMemory.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/iMemory.cpp b/llvm/lib/VMCore/iMemory.cpp
new file mode 100644
index 00000000000..41c14b04d55
--- /dev/null
+++ b/llvm/lib/VMCore/iMemory.cpp
@@ -0,0 +1,47 @@
+//===-- iMemory.cpp - Implement Memory instructions --------------*- C++ -*--=//
+//
+// This file implements the various memory related classes defined in iMemory.h
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/iMemory.h"
+#include "llvm/ConstPoolVals.h"
+
+const Type *LoadInst::getIndexedType(const Type *Ptr,
+ const vector<ConstPoolVal*> &Idx) {
+ if (!Ptr->isPointerType()) return 0; // Type isn't a pointer type!
+
+ // Get the type pointed to...
+ Ptr = ((const PointerType*)Ptr)->getValueType();
+
+ if (Ptr->isStructType()) {
+ unsigned CurIDX = 0;
+ while (Ptr->isStructType()) {
+ if (Idx.size() == CurIDX) return 0; // Can't load a whole structure!
+ if (Idx[CurIDX]->getType() != Type::UByteTy) return 0; // Illegal idx
+ unsigned NextIdx = ((ConstPoolUInt*)Idx[CurIDX++])->getValue();
+
+ const StructType *ST = (const StructType *)Ptr;
+ Ptr = ST->getElementTypes()[NextIdx];
+ }
+ return Ptr;
+ } else if (Ptr->isArrayType()) {
+ assert(0 && "Loading from arrays not implemented yet!");
+ } else {
+ return (Idx.size() == 0) ? Ptr : 0; // Load directly through ptr
+ }
+}
+
+
+LoadInst::LoadInst(Value *Ptr, const vector<ConstPoolVal*> &Idx,
+ const string &Name = "")
+ : Instruction(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));
+}
+
OpenPOWER on IntegriCloud