[llvm-commits] CVS: llvm-java/lib/Compiler/OperandStack.cpp Locals.cpp Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue Jan 11 05:55:40 PST 2005



Changes in directory llvm-java/lib/Compiler:

OperandStack.cpp updated: 1.5 -> 1.6
Locals.cpp updated: 1.3 -> 1.4
Compiler.cpp updated: 1.182 -> 1.183
---
Log message:

Make OperandStack and Locals cast all pointer types to pointers to
java/lang/Object.


---
Diffs of the changes:  (+50 -30)

Index: llvm-java/lib/Compiler/OperandStack.cpp
diff -u llvm-java/lib/Compiler/OperandStack.cpp:1.5 llvm-java/lib/Compiler/OperandStack.cpp:1.6
--- llvm-java/lib/Compiler/OperandStack.cpp:1.5	Fri Dec 10 04:20:56 2004
+++ llvm-java/lib/Compiler/OperandStack.cpp	Tue Jan 11 07:55:29 2005
@@ -18,6 +18,7 @@
 #include <llvm/Function.h>
 #include <llvm/Instructions.h>
 #include <llvm/ADT/StringExtras.h>
+#include <llvm/Java/Compiler.h>
 
 using namespace llvm::Java;
 
@@ -26,12 +27,17 @@
   assert(currentDepth < TheStack.size() && "Pushing to a full stack!");
 
   const Type* valueTy = value->getType();
+  // All pointer types are cast to a pointer to
+  // llvm_java_lang_object_base.
+  if (isa<PointerType>(valueTy))
+    value = new CastInst(value, java_lang_Object_RefType,
+                         "to-object-base", insertAtEnd);
   // Values of jboolean, jbyte, jchar and jshort are extended to a
   // jint when pushed on the operand stack.
-  if (valueTy == Type::BoolTy ||
-      valueTy == Type::SByteTy ||
-      valueTy == Type::UShortTy ||
-      valueTy == Type::ShortTy)
+  else if (valueTy == Type::BoolTy ||
+	   valueTy == Type::SByteTy ||
+	   valueTy == Type::UShortTy ||
+	   valueTy == Type::ShortTy)
     value = new CastInst(value, Type::IntTy, "int-extend", insertAtEnd);
 
   // If we don't have an alloca already for this slot create one


Index: llvm-java/lib/Compiler/Locals.cpp
diff -u llvm-java/lib/Compiler/Locals.cpp:1.3 llvm-java/lib/Compiler/Locals.cpp:1.4
--- llvm-java/lib/Compiler/Locals.cpp:1.3	Wed Nov 24 14:32:18 2004
+++ llvm-java/lib/Compiler/Locals.cpp	Tue Jan 11 07:55:29 2005
@@ -18,6 +18,7 @@
 #include <llvm/Function.h>
 #include <llvm/Instructions.h>
 #include <llvm/ADT/StringExtras.h>
+#include <llvm/Java/Compiler.h>
 
 using namespace llvm::Java;
 
@@ -29,6 +30,13 @@
 
 void Locals::store(unsigned i, Value* value, BasicBlock* insertAtEnd)
 {
+  const Type* valueTy = value->getType();
+  // All pointer types are cast to a pointer to
+  // llvm_java_lang_object_base.
+  if (isa<PointerType>(valueTy))
+    value = new CastInst(value, java_lang_Object_RefType,
+                         "to-object-base", insertAtEnd);
+
   if (!TheLocals[i] ||
       TheLocals[i]->getType()->getElementType() != value->getType()) {
     // Insert the alloca at the beginning of the entry block.


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.182 llvm-java/lib/Compiler/Compiler.cpp:1.183
--- llvm-java/lib/Compiler/Compiler.cpp:1.182	Fri Dec 17 18:47:33 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Tue Jan 11 07:55:29 2005
@@ -48,6 +48,9 @@
 using namespace llvm;
 using namespace llvm::Java;
 
+Type* llvm::Java::java_lang_Object_Type;
+Type* llvm::Java::java_lang_Object_RefType;
+
 namespace llvm { namespace Java { namespace {
 
   const std::string TMP("tmp");
@@ -329,6 +332,9 @@
             << *ci.type << " to type map\n");
       module_.addTypeName("java/lang/Object", ci.type);
 
+      java_lang_Object_Type = ci.type;
+      java_lang_Object_RefType = PointerType::get(ci.type);
+
       assert(ci.type && "ClassInfo not initialized properly!");
       emitStaticInitializers(cf);
       DEBUG(std::cerr << "Built ClassInfo for: java/lang/Object\n");
@@ -1545,18 +1551,19 @@
       push(val);
     }
 
-    void do_iaload() { do_aload_common(); }
-    void do_laload() { do_aload_common(); }
-    void do_faload() { do_aload_common(); }
-    void do_daload() { do_aload_common(); }
-    void do_aaload() { do_aload_common(); }
-    void do_baload() { do_aload_common(); }
-    void do_caload() { do_aload_common(); }
-    void do_saload() { do_aload_common(); }
+    void do_iaload() { do_aload_common(getPrimitiveArrayInfo(INT).type); }
+    void do_laload() { do_aload_common(getPrimitiveArrayInfo(LONG).type); }
+    void do_faload() { do_aload_common(getPrimitiveArrayInfo(FLOAT).type); }
+    void do_daload() { do_aload_common(getPrimitiveArrayInfo(DOUBLE).type); }
+    void do_aaload() { do_aload_common(getObjectArrayInfo().type); }
+    void do_baload() { do_aload_common(getPrimitiveArrayInfo(BYTE).type); }
+    void do_caload() { do_aload_common(getPrimitiveArrayInfo(CHAR).type); }
+    void do_saload() { do_aload_common(getPrimitiveArrayInfo(SHORT).type); }
 
-    void do_aload_common() {
+    void do_aload_common(Type* arrayTy) {
       Value* index = pop();
-      Value* arrayRef = pop();
+      Value* arrayRef =	new CastInst(pop(), PointerType::get(arrayTy),
+				     "cast-to-array", currentBB_);
 
       std::vector<Value*> indices;
       indices.reserve(3);
@@ -1580,25 +1587,20 @@
       currentLocals_->store(index, val, currentBB_);
     }
 
-    void do_iastore() { do_astore_common(); }
-    void do_lastore() { do_astore_common(); }
-    void do_fastore() { do_astore_common(); }
-    void do_dastore() { do_astore_common(); }
-    void do_aastore() {
-      do_astore_common(
-        PointerType::get(
-          getClassInfo(ClassFile::get("java/lang/Object")).type));
-    }
-    void do_bastore() { do_astore_common(Type::SByteTy); }
-    void do_castore() { do_astore_common(Type::UShortTy); }
-    void do_sastore() { do_astore_common(Type::ShortTy); }
+    void do_iastore() { do_astore_common(getPrimitiveArrayInfo(INT).type); }
+    void do_lastore() { do_astore_common(getPrimitiveArrayInfo(LONG).type); }
+    void do_fastore() { do_astore_common(getPrimitiveArrayInfo(FLOAT).type); }
+    void do_dastore() { do_astore_common(getPrimitiveArrayInfo(DOUBLE).type); }
+    void do_aastore() { do_astore_common(getObjectArrayInfo().type); }
+    void do_bastore() { do_astore_common(getPrimitiveArrayInfo(BYTE).type); }
+    void do_castore() { do_astore_common(getPrimitiveArrayInfo(CHAR).type); }
+    void do_sastore() { do_astore_common(getPrimitiveArrayInfo(SHORT).type); }
 
-    void do_astore_common(Type* castTo = NULL) {
+    void do_astore_common(Type* arrayTy) {
       Value* value = pop();
-      if (castTo)
-        value = new CastInst(value, castTo, TMP, currentBB_);
       Value* index = pop();
-      Value* arrayRef = pop();
+      Value* arrayRef = new CastInst(pop(), PointerType::get(arrayTy),
+				     "cast-to-array", currentBB_);
 
       std::vector<Value*> indices;
       indices.reserve(3);
@@ -1607,6 +1609,10 @@
       indices.push_back(index);
       Value* elementPtr =
         new GetElementPtrInst(arrayRef, indices, TMP, currentBB_);
+
+      const Type* elementTy =
+	cast<PointerType>(elementPtr->getType())->getElementType();
+      value = new CastInst(value, elementTy, TMP, currentBB_);
       new StoreInst(value, elementPtr, currentBB_);
     }
 






More information about the llvm-commits mailing list