[vmkit-commits] [vmkit] r63513 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.cpp JavaJIT.h JavaJITOpcodes.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Feb 2 06:16:12 PST 2009


Author: geoffray
Date: Mon Feb  2 08:16:11 2009
New Revision: 63513

URL: http://llvm.org/viewvc/llvm-project?rev=63513&view=rev
Log:
Factorize code, no functionality changes.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=63513&r1=63512&r2=63513&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Mon Feb  2 08:16:11 2009
@@ -20,7 +20,6 @@
 #include <llvm/Instructions.h>
 #include <llvm/Module.h>
 #include <llvm/Type.h>
-#include <llvm/ExecutionEngine/GenericValue.h>
 #include <llvm/Support/CFG.h>
 
 #include "mvm/JIT.h"
@@ -37,9 +36,7 @@
 #include "JavaTypes.h"
 #include "JavaUpcalls.h"
 #include "Jnjvm.h"
-#include "JnjvmModuleProvider.h"
 #include "Reader.h"
-#include "Zip.h"
 
 using namespace jnjvm;
 using namespace llvm;
@@ -778,7 +775,7 @@
   compileOpcodes(&compilingClass->bytes->elements[start], codeLen); 
   
   assert(stack.size() == 0 && "Stack not empty after compiling bytecode");
-  // Fix a javac(?) bug where a method only throws an exception and des
+  // Fix a javac(?) bug where a method only throws an exception and does
   // not return.
   pred_iterator PI = pred_begin(endBlock);
   pred_iterator PE = pred_end(endBlock);
@@ -1378,20 +1375,9 @@
   BasicBlock* exit = createBasicBlock("verifyNullExit");
   BasicBlock* cont = createBasicBlock("verifyNullCont");
 
-  llvm::BranchInst::Create(exit, cont, test, currentBlock);
-  if (currentExceptionBlock != endExceptionBlock) {
-    Value** val = 0;
-    InvokeInst::Create(module->NullPointerExceptionFunction,
-                       unifiedUnreachable,
-                       currentExceptionBlock, val, val,
-                       "", exit);
-  } else {
-    llvm::CallInst::Create(module->NullPointerExceptionFunction,
-                           "", exit);
-    new UnreachableInst(exit);
-  }
-  
-
+  BranchInst::Create(exit, cont, test, currentBlock);
+  currentBlock = exit;
+  throwException(module->NullPointerExceptionFunction, 0, 0);
   currentBlock = cont;
   
 }
@@ -1415,18 +1401,9 @@
 
     branch(cmp, ifTrue, ifFalse, currentBlock);
     
+    currentBlock = ifFalse;
     Value* args[2] = { obj, index };
-    if (currentExceptionBlock != endExceptionBlock) {
-      InvokeInst::Create(module->IndexOutOfBoundsExceptionFunction,
-                         unifiedUnreachable,
-                         currentExceptionBlock, args, args + 2,
-                         "", ifFalse);
-    } else {
-      CallInst::Create(module->IndexOutOfBoundsExceptionFunction,
-                       args, args + 2, "", ifFalse);
-      new UnreachableInst(ifFalse);
-    }
-  
+    throwException(module->IndexOutOfBoundsExceptionFunction, args, 2);
     currentBlock = ifTrue;
   }
   
@@ -1486,18 +1463,6 @@
   }
 }
 
-void JavaJIT::branch(llvm::BasicBlock* dest, llvm::BasicBlock* insert) {
-  testPHINodes(dest, insert);
-  llvm::BranchInst::Create(dest, insert);
-}
-
-void JavaJIT::branch(llvm::Value* test, llvm::BasicBlock* ifTrue,
-                     llvm::BasicBlock* ifFalse, llvm::BasicBlock* insert) {  
-  testPHINodes(ifTrue, insert);
-  testPHINodes(ifFalse, insert);
-  llvm::BranchInst::Create(ifTrue, ifFalse, test, insert);
-}
-
 void JavaJIT::makeArgs(FunctionType::param_iterator it,
                        uint32 index, std::vector<Value*>& Args, uint32 nb) {
 #if defined(ISOLATE_SHARING)
@@ -2270,3 +2235,27 @@
     }
   }
 }
+
+void JavaJIT::throwException(llvm::Function* F, Value* arg1) {
+  if (currentExceptionBlock != endExceptionBlock) {
+    Value* exArgs[1] = { arg1 };
+    InvokeInst::Create(F, unifiedUnreachable,
+                       currentExceptionBlock, exArgs, exArgs + 1,
+                       "", currentBlock);
+  } else {
+    CallInst::Create(F, arg1, "", currentBlock);
+    new UnreachableInst(currentBlock);
+  }
+}
+
+void JavaJIT::throwException(llvm::Function* F, Value** args,
+                             uint32 nbArgs) {
+  if (currentExceptionBlock != endExceptionBlock) {
+    InvokeInst::Create(F, unifiedUnreachable,
+                       currentExceptionBlock, args, args + nbArgs,
+                       "", currentBlock);
+  } else {
+    CallInst::Create(F, args, args + nbArgs, "", currentBlock);
+    new UnreachableInst(currentBlock);
+  }
+}

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h?rev=63513&r1=63512&r2=63513&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Mon Feb  2 08:16:11 2009
@@ -117,8 +117,6 @@
                                  const llvm::Type* returnType,
                                  llvm::Value* addArg, bool doThrow = true);
  
-  /// testPHINodes - Update PHI nodes when branching to a new block.
-  void testPHINodes(llvm::BasicBlock* dest, llvm::BasicBlock* insert);
   
 
 //===--------------------------- Inline support ---------------------------===//
@@ -256,6 +254,11 @@
   /// unifiedUnreachable block as their normal destination.
   llvm::BasicBlock* unifiedUnreachable;
 
+  /// throwException - Emit code to throw a function.
+  void throwException(llvm::Function* F, llvm::Value** args,
+                      uint32 nbArgs);
+  void throwException(llvm::Function* F, llvm::Value* arg1);
+
 //===--------------------------- Control flow  ----------------------------===//
 
   /// opcodeInfos - The informations for each instruction.
@@ -271,10 +274,20 @@
   
   /// branch - Branch based on a boolean value. Update PHI nodes accordingly.
   void branch(llvm::Value* test, llvm::BasicBlock* ifTrue, 
-              llvm::BasicBlock* ifFalse, llvm::BasicBlock* insert);
+              llvm::BasicBlock* ifFalse, llvm::BasicBlock* insert) {
+    testPHINodes(ifTrue, insert);
+    testPHINodes(ifFalse, insert);
+    llvm::BranchInst::Create(ifTrue, ifFalse, test, insert);
+  }
 
   /// branch - Branch to a new block. Update PHI nodes accordingly.
-  void branch(llvm::BasicBlock* where, llvm::BasicBlock* insert);
+  void branch(llvm::BasicBlock* dest, llvm::BasicBlock* insert) {
+    testPHINodes(dest, insert);
+    llvm::BranchInst::Create(dest, insert);
+  }
+  
+  /// testPHINodes - Update PHI nodes when branching to a new block.
+  void testPHINodes(llvm::BasicBlock* dest, llvm::BasicBlock* insert);
 
  
 //===-------------------------- Synchronization  --------------------------===//

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=63513&r1=63512&r2=63513&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Mon Feb  2 08:16:11 2009
@@ -1904,17 +1904,7 @@
 
         BranchInst::Create(BB1, BB2, cmp, currentBlock);
         currentBlock = BB1;
-        if (currentExceptionBlock != endExceptionBlock) {
-          Value* exArgs[1] = { arg1 };
-          InvokeInst::Create(module->NegativeArraySizeExceptionFunction, 
-                             unifiedUnreachable,
-                             currentExceptionBlock, exArgs, exArgs + 1,
-                             "", currentBlock);
-        } else {
-          CallInst::Create(module->NegativeArraySizeExceptionFunction,
-                           arg1, "", currentBlock);
-          new UnreachableInst(currentBlock);
-        }
+        throwException(module->NegativeArraySizeExceptionFunction, arg1);
         currentBlock = BB2;
         
         cmp = new ICmpInst(ICmpInst::ICMP_SGT, arg1,
@@ -1926,17 +1916,7 @@
 
         BranchInst::Create(BB1, BB2, cmp, currentBlock);
         currentBlock = BB1;
-        if (currentExceptionBlock != endExceptionBlock) {
-          Value* exArgs[1] = { arg1 };
-          InvokeInst::Create(module->OutOfMemoryErrorFunction,
-                             unifiedUnreachable,
-                             currentExceptionBlock, exArgs, exArgs + 1,
-                             "", currentBlock);
-        } else {
-          CallInst::Create(module->OutOfMemoryErrorFunction, arg1, "",
-                           currentBlock);
-          new UnreachableInst(currentBlock);
-        }
+        throwException(module->OutOfMemoryErrorFunction, arg1);
         currentBlock = BB2;
         
         Value* mult = BinaryOperator::CreateMul(arg1, sizeElement, "",
@@ -1995,17 +1975,7 @@
 
       case ATHROW : {
         llvm::Value* arg = pop();
-        if (currentExceptionBlock != endExceptionBlock) {
-          Value* args[1] = { arg };
-          InvokeInst::Create(module->ThrowExceptionFunction,
-                             unifiedUnreachable,
-                             currentExceptionBlock, args, args + 1,
-                             "", currentBlock);
-        } else {
-          CallInst::Create(module->ThrowExceptionFunction, arg, "",
-                           currentBlock);
-          new UnreachableInst(currentBlock);
-        }
+        throwException(module->ThrowExceptionFunction, arg);
         break;
       }
 
@@ -2035,17 +2005,8 @@
           BasicBlock* ifFalse = createBasicBlock("non null checkcast");
 
           BranchInst::Create(endCheckcast, ifFalse, cmp, currentBlock);
-          
-          if (currentExceptionBlock != endExceptionBlock) {
-            InvokeInst::Create(module->ClassCastExceptionFunction,
-                               unifiedUnreachable,
-                               currentExceptionBlock, args, args + 2, "", 
-                               exceptionCheckcast);
-          } else {
-            CallInst::Create(module->ClassCastExceptionFunction,
-                             args, args + 2, "", exceptionCheckcast);
-            new UnreachableInst(exceptionCheckcast);
-          }
+          currentBlock = exceptionCheckcast;
+          throwException(module->ClassCastExceptionFunction, args, 2);
           currentBlock = ifFalse;
         }
         





More information about the vmkit-commits mailing list