[vmkit-commits] [vmkit] r101933 - in /vmkit/trunk/lib: J3/Compiler/JavaJIT.cpp J3/Compiler/JavaLLVMCompiler.cpp J3/Compiler/LowerConstantCalls.cpp Mvm/Compiler/LoopSafePoints.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Apr 20 12:32:41 PDT 2010


Author: geoffray
Date: Tue Apr 20 14:32:41 2010
New Revision: 101933

URL: http://llvm.org/viewvc/llvm-project?rev=101933&view=rev
Log:
Inser the yield point im loops before doing any optimization.


Modified:
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp
    vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=101933&r1=101932&r2=101933&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Apr 20 14:32:41 2010
@@ -1195,29 +1195,6 @@
   
   if (isSynchro(compilingMethod->access))
     beginSynchronize();
- 
-  if (TheCompiler->hasExceptionsEnabled()) {
-    // Variables have been allocated and the lock has been taken. Do the stack
-    // check now: if there is an exception, we will go to the lock release code.
-    currentExceptionBlock = opcodeInfos[0].exceptionBlock;
-    Value* FrameAddr = CallInst::Create(intrinsics->llvm_frameaddress,
-                                       	intrinsics->constantZero, "", currentBlock);
-    FrameAddr = new PtrToIntInst(FrameAddr, intrinsics->pointerSizeType, "",
-                                 currentBlock);
-    Value* stackCheck = 
-      BinaryOperator::CreateAnd(FrameAddr, intrinsics->constantStackOverflowMask,
-                                "", currentBlock);
-
-    stackCheck = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, stackCheck,
-                              intrinsics->constantPtrZero, "");
-    BasicBlock* stackOverflow = createBasicBlock("stack overflow");
-    BasicBlock* noStackOverflow = createBasicBlock("no stack overflow");
-    BranchInst::Create(stackOverflow, noStackOverflow, stackCheck,
-                       currentBlock);
-    currentBlock = stackOverflow;
-    throwException(intrinsics->StackOverflowErrorFunction, 0, 0);
-    currentBlock = noStackOverflow;
-  }
   
   if (TheCompiler->useCooperativeGC()) {
     Value* threadId = getCurrentThread(intrinsics->MutatorThreadType);
@@ -1240,6 +1217,29 @@
 
     currentBlock = continueBlock;
   }
+  
+  if (TheCompiler->hasExceptionsEnabled()) {
+    // Variables have been allocated and the lock has been taken. Do the stack
+    // check now: if there is an exception, we will go to the lock release code.
+    currentExceptionBlock = opcodeInfos[0].exceptionBlock;
+    Value* FrameAddr = CallInst::Create(intrinsics->llvm_frameaddress,
+                                       	intrinsics->constantZero, "", currentBlock);
+    FrameAddr = new PtrToIntInst(FrameAddr, intrinsics->pointerSizeType, "",
+                                 currentBlock);
+    Value* stackCheck = 
+      BinaryOperator::CreateAnd(FrameAddr, intrinsics->constantStackOverflowMask,
+                                "", currentBlock);
+
+    stackCheck = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, stackCheck,
+                              intrinsics->constantPtrZero, "");
+    BasicBlock* stackOverflow = createBasicBlock("stack overflow");
+    BasicBlock* noStackOverflow = createBasicBlock("no stack overflow");
+    BranchInst::Create(stackOverflow, noStackOverflow, stackCheck,
+                       currentBlock);
+    currentBlock = stackOverflow;
+    throwException(intrinsics->StackOverflowErrorFunction, 0, 0);
+    currentBlock = noStackOverflow;
+  }
 
   compileOpcodes(&compilingClass->bytes->elements[start], codeLen); 
   

Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=101933&r1=101932&r2=101933&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Tue Apr 20 14:32:41 2010
@@ -113,7 +113,7 @@
 }
 
 namespace j3 {
-  llvm::FunctionPass* createLowerConstantCallsPass(J3Intrinsics* I);
+  llvm::FunctionPass* createLowerConstantCallsPass(JavaLLVMCompiler* I);
 }
 
 void JavaLLVMCompiler::addJavaPasses() {
@@ -121,15 +121,17 @@
   JavaNativeFunctionPasses->add(new TargetData(TheModule));
   // Lower constant calls to lower things like getClass used
   // on synchronized methods.
-  JavaNativeFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
+  JavaNativeFunctionPasses->add(createLowerConstantCallsPass(this));
   
   JavaFunctionPasses = new FunctionPassManager(TheModule);
-  mvm::MvmModule::addCommandLinePasses(JavaFunctionPasses);
   if (cooperativeGC)
     JavaFunctionPasses->add(mvm::createLoopSafePointsPass());
+  // Add other passes after the loop pass, because safepoints may move objects.
+  // Moving objects disable many optimizations.
+  mvm::MvmModule::addCommandLinePasses(JavaFunctionPasses);
 
   // Re-enable this when the pointers in stack-allocated objects can
   // be given to the GC.
   //JavaFunctionPasses->add(mvm::createEscapeAnalysisPass());
-  JavaFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
+  JavaFunctionPasses->add(createLowerConstantCallsPass(this));
 }

Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=101933&r1=101932&r2=101933&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Tue Apr 20 14:32:41 2010
@@ -17,6 +17,7 @@
 #include "llvm/Support/Debug.h"
 
 #include "JavaClass.h"
+#include "j3/JavaLLVMCompiler.h"
 #include "j3/J3Intrinsics.h"
 
 using namespace llvm;
@@ -26,9 +27,9 @@
   class VISIBILITY_HIDDEN LowerConstantCalls : public FunctionPass {
   public:
     static char ID;
-    J3Intrinsics* intrinsics;
-    LowerConstantCalls(J3Intrinsics* I) : FunctionPass((intptr_t)&ID),
-      intrinsics(I) { }
+    JavaLLVMCompiler* TheCompiler;
+    LowerConstantCalls(JavaLLVMCompiler* Compiler) : FunctionPass((intptr_t)&ID),
+      TheCompiler(Compiler) { }
 
     virtual bool runOnFunction(Function &F);
   private:
@@ -124,6 +125,9 @@
 bool LowerConstantCalls::runOnFunction(Function& F) {
   LLVMContext* Context = &F.getContext();
   bool Changed = false;
+  J3Intrinsics* intrinsics = TheCompiler->getIntrinsics();
+  JavaMethod* meth = TheCompiler->getJavaMethod(&F);
+  assert(meth && "Method not registered");
   for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { 
     BasicBlock *Cur = BI; 
     for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) {
@@ -133,16 +137,12 @@
       if (ICmpInst* Cmp = dyn_cast<ICmpInst>(I)) {
         if (Cmp->getOperand(1) == intrinsics->JavaObjectNullConstant) {
           Value* Arg = Cmp->getOperand(0);
-      
-#if 0
-          // Re-enable this once we can get access of the JavaMethod again.
           if (isVirtual(meth->access) && Arg == F.arg_begin()) {
             Changed = true;
             Cmp->replaceAllUsesWith(ConstantInt::getFalse(*Context));
             Cmp->eraseFromParent();
             break;
           }
-#endif
           
           CallSite Ca = CallSite::get(Arg);
           Instruction* CI = Ca.getInstruction();
@@ -785,8 +785,8 @@
 }
 
 
-FunctionPass* createLowerConstantCallsPass(J3Intrinsics* M) {
-  return new LowerConstantCalls(M);
+FunctionPass* createLowerConstantCallsPass(JavaLLVMCompiler* Compiler) {
+  return new LowerConstantCalls(Compiler);
 }
 
 }

Modified: vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp?rev=101933&r1=101932&r2=101933&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp Tue Apr 20 14:32:41 2010
@@ -99,31 +99,6 @@
 
   if (!YieldPtr) return false;
 
-  TerminatorInst* TI = Header->getTerminator();
-  
-  // Insert the check after the entry block if the entry block does the
-  // loop exit.
-  if (BranchInst* BI = dyn_cast<BranchInst>(TI)) {
-    if (BI->isConditional()) {
-
-      BasicBlock* First = BI->getSuccessor(0);
-      BasicBlock* Second = BI->getSuccessor(1);
-
-      bool containsFirst = L->contains(First);
-      bool containsSecond = L->contains(Second);
-
-      if (!containsFirst) {
-        insertSafePoint(Second, SafeFunction, YieldPtr, L, LI);
-        return true;
-      }
-      
-      if (!containsSecond) {
-        insertSafePoint(First, SafeFunction, YieldPtr, L, LI);
-        return true;
-      }
-    }
-  }
-  
   insertSafePoint(Header, SafeFunction, YieldPtr, L, LI);
   return true;
 }





More information about the vmkit-commits mailing list