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

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue Jan 25 15:46:45 PST 2005



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.199 -> 1.200
---
Log message:

Simplify code a bit by declaring frequently used functions up front.


---
Diffs of the changes:  (+29 -44)

 Compiler.cpp |   73 +++++++++++++++++++++++------------------------------------
 1 files changed, 29 insertions(+), 44 deletions(-)


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.199 llvm-java/lib/Compiler/Compiler.cpp:1.200
--- llvm-java/lib/Compiler/Compiler.cpp:1.199	Tue Jan 25 15:33:28 2005
+++ llvm-java/lib/Compiler/Compiler.cpp	Tue Jan 25 17:46:34 2005
@@ -41,16 +41,13 @@
 
 #define LLVM_JAVA_STATIC_INIT "llvm_java_static_init"
 
-#define LLVM_JAVA_ISINSTANCEOF  "llvm_java_IsInstanceOf"
-#define LLVM_JAVA_GETOBJECTCLASS "llvm_java_GetObjectClass"
-#define LLVM_JAVA_SETOBJECTCLASS "llvm_java_SetObjectClass"
-#define LLVM_JAVA_THROW "llvm_java_Throw"
-
 using namespace llvm;
 using namespace llvm::Java;
 
 Type* llvm::Java::ObjectBaseTy = OpaqueType::get();
 Type* llvm::Java::ObjectBaseRefTy = PointerType::get(ObjectBaseTy);
+Type* llvm::Java::VTableBaseTy = OpaqueType::get();
+Type* llvm::Java::VTableBaseRefTy = PointerType::get(ObjectBaseTy);
 
 namespace llvm { namespace Java { namespace {
 
@@ -75,6 +72,7 @@
     BasicBlock* currentBB_;
     Locals locals_;
     OperandStack opStack_;
+    Function *getObjectClass_, *setObjectClass_, *throw_, *isInstanceOf_;
 
     typedef SetVector<Function*> FunctionSet;
     FunctionSet toCompileFunctions_;
@@ -111,7 +109,6 @@
       typedef Method2IndexMap::const_iterator const_iterator;
       Method2IndexMap m2iMap;
 
-      static Type* VTableBaseTy;
       static StructType* VTableTy;
       static StructType* TypeInfoTy;
     };
@@ -130,6 +127,20 @@
                                       NULL,
                                       "llvm_java_JNIEnv",
                                       &module_);
+      module_.addTypeName("llvm_java_object_base", ObjectBaseTy);
+      module_.addTypeName("llvm_java_object_vtable", VTableBaseTy);
+      getObjectClass_ = module_.getOrInsertFunction(
+        "llvm_java_GetObjectClass", VTableBaseRefTy,
+        ObjectBaseRefTy, NULL);
+      setObjectClass_ = module_.getOrInsertFunction(
+        "llvm_java_SetObjectClass", Type::VoidTy,
+        ObjectBaseRefTy, VTableBaseRefTy, NULL);
+      throw_ = module_.getOrInsertFunction(
+        "llvm_java_Throw", Type::IntTy,
+        ObjectBaseRefTy, NULL);
+      isInstanceOf_ = module_.getOrInsertFunction(
+        "llvm_java_IsInstanceOf", Type::IntTy,
+        ObjectBaseRefTy, VTableBaseRefTy, NULL);
     }
 
   private:
@@ -407,8 +418,6 @@
       PATypeHolder holder = VTtype;
       cast<OpaqueType>(VTtype)->refineAbstractTypeTo(StructType::get(elements));
 
-      VTableInfo::VTableBaseTy = OpaqueType::get();
-      module_.addTypeName(LLVM_JAVA_OBJECT_VTABLE, VTableInfo::VTableBaseTy);
       VTableInfo::VTableTy = cast<StructType>(holder.get());
       module_.addTypeName("java/lang/Object<vtable>", VTableInfo::VTableTy);
 
@@ -1303,6 +1312,7 @@
            classMethodDesc.find("java/lang/Throwable$StaticData/<cl") == 0) &&
           classMethodDesc.find("java/lang/Exception") != 0 &&
           classMethodDesc.find("java/lang/IllegalArgumentException") != 0 &&
+          classMethodDesc.find("java/lang/IndexOutOfBoundsException") != 0 &&
           classMethodDesc.find("java/lang/RuntimeException") != 0 &&
           classMethodDesc.find("java/lang/Number") != 0 &&
           classMethodDesc.find("java/lang/Byte") != 0 &&
@@ -2045,10 +2055,7 @@
                             "this", currentBB_);
       Value* objBase =
         new CastInst(objRef, ObjectBaseRefTy, TMP, currentBB_);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_GETOBJECTCLASS, PointerType::get(VTableInfo::VTableBaseTy),
-        objBase->getType(), NULL);
-      Value* vtable = new CallInst(f, objBase, TMP, currentBB_);
+      Value* vtable = new CallInst(getObjectClass_, objBase, TMP, currentBB_);
       vtable = new CastInst(vtable, vi->vtable->getType(),
                             className + "<vtable>", currentBB_);
       std::vector<Value*> indices(1, ConstantUInt::get(Type::UIntTy, 0));
@@ -2128,10 +2135,7 @@
                             "this", currentBB_);
       Value* objBase =
         new CastInst(objRef, ObjectBaseRefTy, TMP, currentBB_);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_GETOBJECTCLASS, PointerType::get(VTableInfo::VTableBaseTy),
-        objBase->getType(), NULL);
-      Value* vtable = new CallInst(f, objBase, TMP, currentBB_);
+      Value* vtable = new CallInst(getObjectClass_, objBase, TMP, currentBB_);
       vtable = new CastInst(vtable, PointerType::get(VTableInfo::VTableTy),
                             TMP, currentBB_);
       // get the interfaces array of vtables
@@ -2173,13 +2177,9 @@
       Value* objRef = new MallocInst(ci.type, NULL, TMP, currentBB_);
       Value* objBase = new CastInst(objRef, ObjectBaseRefTy, TMP, currentBB_);
       Value* vtable = new CastInst(vi.vtable,
-                                   PointerType::get(VTableInfo::VTableBaseTy),
+                                   VTableBaseRefTy,
                                    TMP, currentBB_);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_SETOBJECTCLASS, Type::VoidTy,
-        ObjectBaseRefTy,
-        PointerType::get(VTableInfo::VTableBaseTy), NULL);
-      new CallInst(f, objBase, vtable, "", currentBB_);
+      new CallInst(setObjectClass_, objBase, vtable, "", currentBB_);
       push(objRef);
     }
 
@@ -2251,13 +2251,9 @@
       Value* objBase = new CastInst(objRef, ObjectBaseRefTy,
                                     TMP, currentBB_);
       Value* vtable = new CastInst(vi.vtable,
-                                   PointerType::get(VTableInfo::VTableBaseTy),
+                                   VTableBaseRefTy,
                                    TMP, currentBB_);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_SETOBJECTCLASS, Type::VoidTy,
-        ObjectBaseRefTy,
-        PointerType::get(VTableInfo::VTableBaseTy), NULL);
-      new CallInst(f, objBase, vtable, "", currentBB_);
+      new CallInst(setObjectClass_, objBase, vtable, "", currentBB_);
       push(objRef);
     }
 
@@ -2271,10 +2267,7 @@
 
     void do_athrow() {
       Value* objRef = pop(ObjectBaseRefTy);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_THROW, Type::IntTy,
-        ObjectBaseRefTy, NULL);
-      new CallInst(f, objRef, TMP, currentBB_);
+      new CallInst(throw_, objRef, TMP, currentBB_);
       new UnreachableInst(currentBB_);
     }
 
@@ -2286,13 +2279,10 @@
       tie(ci, vi) = getInfo(classRef->getName()->str());
 
       Value* objRef = pop(ObjectBaseRefTy);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_ISINSTANCEOF, Type::IntTy,
-        ObjectBaseRefTy, PointerType::get(VTableInfo::VTableBaseTy), NULL);
       Value* vtable = new CastInst(vi->vtable,
-                                   PointerType::get(VTableInfo::VTableBaseTy),
+                                   VTableBaseRefTy,
                                    TMP, currentBB_);
-      Value* r = new CallInst(f, objRef, vtable, TMP, currentBB_);
+      Value* r = new CallInst(isInstanceOf_, objRef, vtable, TMP, currentBB_);
 
       Value* b = new SetCondInst(Instruction::SetEQ,
                                  r, ConstantSInt::get(Type::IntTy, 1),
@@ -2309,13 +2299,9 @@
       tie(ci, vi) = getInfo(classRef->getName()->str());
 
       Value* objRef = pop(ObjectBaseRefTy);
-      Function* f = module_.getOrInsertFunction(
-        LLVM_JAVA_ISINSTANCEOF, Type::IntTy,
-        ObjectBaseRefTy, PointerType::get(VTableInfo::VTableBaseTy), NULL);
-      Value* vtable = new CastInst(vi->vtable,
-                                   PointerType::get(VTableInfo::VTableBaseTy),
+      Value* vtable = new CastInst(vi->vtable, VTableBaseRefTy,
                                    TMP, currentBB_);
-      Value* r = new CallInst(f, objRef, vtable, TMP, currentBB_);
+      Value* r = new CallInst(isInstanceOf_, objRef, vtable, TMP, currentBB_);
       push(r);
     }
 
@@ -2333,7 +2319,6 @@
   };
 
   unsigned Compiler::ClassInfo::InterfaceCount = 0;
-  Type* Compiler::VTableInfo::VTableBaseTy;
   StructType* Compiler::VTableInfo::VTableTy;
   StructType* Compiler::VTableInfo::TypeInfoTy;
 






More information about the llvm-commits mailing list