[vmkit-commits] [vmkit] r77207 - in /vmkit/trunk/lib/JnJVM/Compiler: ExceptionsCheck.inc ExceptionsDwarf.inc JavaJIT.cpp JavaJIT.h JavaJITOpcodes.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Jul 27 10:14:27 PDT 2009


Author: geoffray
Date: Mon Jul 27 12:14:26 2009
New Revision: 77207

URL: http://llvm.org/viewvc/llvm-project?rev=77207&view=rev
Log:
Java stacks are now handled with Allocas instead of direcly. This allows to
declare values as being gc_root.


Modified:
    vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc
    vmkit/trunk/lib/JnJVM/Compiler/ExceptionsDwarf.inc
    vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp

Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc?rev=77207&r1=77206&r2=77207&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Mon Jul 27 12:14:26 2009
@@ -353,6 +353,7 @@
     
     // Set the Java handler for this exception.
     ex->javaHandler = opcodeInfos[ex->handlerpc].newBlock;
+    opcodeInfos[ex->handlerpc].handler = true;
     
     if (ex->javaHandler->empty()) {
       PHINode::Create(JnjvmModule::JavaObjectType, "", ex->javaHandler);

Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsDwarf.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsDwarf.inc?rev=77207&r1=77206&r2=77207&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsDwarf.inc (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsDwarf.inc Mon Jul 27 12:14:26 2009
@@ -267,6 +267,7 @@
     
     // Set the Java handler for this exception.
     ex->javaHandler = opcodeInfos[ex->handlerpc].newBlock;
+    opcodeInfos[ex->handlerpc].handler = true;
 
     // Set the native handler of this exception, which will catch the exception
     // object.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Mon Jul 27 12:14:26 2009
@@ -94,7 +94,7 @@
   const UTF8* name = 0;
   Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name);
 
-  Value* obj = stack[stack.size() - signature->nbArguments - 1].first;
+  Value* obj = objectStack[stack.size() - signature->nbArguments - 1];
   JavaObject* source = TheCompiler->getFinalObject(obj);
   if (source) {
     return invokeSpecial(index, source->getClass());
@@ -666,6 +666,24 @@
     }
   }
 }
+  
+static void removeUnusedObjects(std::vector<AllocaInst*>& objects,
+                                JnjvmModule* module) {
+  for (std::vector<AllocaInst*>::iterator i = objects.begin(),
+       e = objects.end(); i != e; ++i) {
+    AllocaInst* temp = *i;
+    if (temp->getNumUses()) {
+      Instruction* I = new BitCastInst(temp, module->ptrPtrType, "");
+      I->insertAfter(temp);
+      Value* GCArgs[2] = { I, module->constantPtrNull };
+      Instruction* C = CallInst::Create(module->llvm_gc_gcroot, GCArgs,
+                                        GCArgs + 2, "");
+      C->insertAfter(I);
+    } else {
+      temp->eraseFromParent();
+    }
+  }
+}
 
 Instruction* JavaJIT::inlineCompile(BasicBlock*& curBB,
                                     BasicBlock* endExBlock,
@@ -685,7 +703,7 @@
   }
 
   Reader reader(codeAtt, &(compilingClass->bytes));
-  /* uint16 maxStack = */ reader.readU2();
+  uint16 maxStack = reader.readU2();
   uint16 maxLocals = reader.readU2();
   uint32 codeLen = reader.readU4();
   uint32 start = reader.cursor;
@@ -722,6 +740,15 @@
       objectLocals.push_back(new AllocaInst(module->JavaObjectType, "",
                                           firstInstruction));
     }
+    for (int i = 0; i < maxStack; i++) {
+      objectStack.push_back(new AllocaInst(module->JavaObjectType, "",
+                                           firstInstruction));
+      intStack.push_back(new AllocaInst(Type::Int32Ty, "", firstInstruction));
+      doubleStack.push_back(new AllocaInst(Type::DoubleTy, "",
+                                           firstInstruction));
+      longStack.push_back(new AllocaInst(Type::Int64Ty, "", firstInstruction));
+      floatStack.push_back(new AllocaInst(Type::FloatTy, "", firstInstruction));
+    }
 
   } else {
     for (int i = 0; i < maxLocals; i++) {
@@ -732,6 +759,15 @@
       objectLocals.push_back(new AllocaInst(module->JavaObjectType, "",
                                             firstBB));
     }
+    
+    for (int i = 0; i < maxStack; i++) {
+      objectStack.push_back(new AllocaInst(module->JavaObjectType, "",
+                                           firstBB));
+      intStack.push_back(new AllocaInst(Type::Int32Ty, "", firstBB));
+      doubleStack.push_back(new AllocaInst(Type::DoubleTy, "", firstBB));
+      longStack.push_back(new AllocaInst(Type::Int64Ty, "", firstBB));
+      floatStack.push_back(new AllocaInst(Type::FloatTy, "", firstBB));
+    }
   }
       
   
@@ -800,24 +836,17 @@
   curBB = endBlock;
 
 
-  for (std::vector<AllocaInst*>::iterator i = objectLocals.begin(),
-       e = objectLocals.end(); i != e; ++i) {
-    AllocaInst* temp = *i;
-    if (temp->getNumUses()) {
-      Instruction* I = new BitCastInst(temp, module->ptrPtrType, "");
-      I->insertAfter(temp);
-      Value* GCArgs[2] = { I, module->constantPtrNull };
-      Instruction* C = CallInst::Create(module->llvm_gc_gcroot, GCArgs,
-                                        GCArgs + 2, "");
-      C->insertAfter(I);
-    } else {
-      temp->eraseFromParent();
-    }
-  }
   removeUnusedLocals(intLocals);
   removeUnusedLocals(doubleLocals);
   removeUnusedLocals(floatLocals);
   removeUnusedLocals(longLocals);
+  removeUnusedLocals(intStack);
+  removeUnusedLocals(doubleStack);
+  removeUnusedLocals(floatStack);
+  removeUnusedLocals(longStack);
+  
+  removeUnusedObjects(objectLocals, module);
+  removeUnusedObjects(objectStack, module);
 
 
   return endNode;
@@ -842,7 +871,7 @@
   }
 
   Reader reader(codeAtt, &(compilingClass->bytes));
-  /* uint16 maxStack = */ reader.readU2();
+  uint16 maxStack = reader.readU2();
   uint16 maxLocals = reader.readU2();
   uint32 codeLen = reader.readU4();
   uint32 start = reader.cursor;
@@ -884,6 +913,15 @@
                                           currentBlock));
   }
   
+  for (int i = 0; i < maxStack; i++) {
+    objectStack.push_back(new AllocaInst(module->JavaObjectType, "",
+                                         currentBlock));
+    intStack.push_back(new AllocaInst(Type::Int32Ty, "", currentBlock));
+    doubleStack.push_back(new AllocaInst(Type::DoubleTy, "", currentBlock));
+    longStack.push_back(new AllocaInst(Type::Int64Ty, "", currentBlock));
+    floatStack.push_back(new AllocaInst(Type::FloatTy, "", currentBlock));
+  }
+  
   uint32 index = 0;
   uint32 count = 0;
 #if defined(ISOLATE_SHARING)
@@ -1100,26 +1138,18 @@
   currentBlock = endExceptionBlock;
 
   finishExceptions();
-  
-  for (std::vector<AllocaInst*>::iterator i = objectLocals.begin(),
-       e = objectLocals.end(); i != e; ++i) {
-    AllocaInst* temp = *i;
-    if (temp->getNumUses()) {
-      Instruction* I = new BitCastInst(temp, module->ptrPtrType, "");
-      I->insertAfter(temp);
-      Value* GCArgs[2] = { I, module->constantPtrNull };
-      Instruction* C = CallInst::Create(module->llvm_gc_gcroot, GCArgs,
-                                        GCArgs + 2, "");
-      C->insertAfter(I);
-    } else {
-      temp->eraseFromParent();
-    }
-  }
-  
+   
   removeUnusedLocals(intLocals);
   removeUnusedLocals(doubleLocals);
   removeUnusedLocals(floatLocals);
   removeUnusedLocals(longLocals);
+  removeUnusedLocals(intStack);
+  removeUnusedLocals(doubleStack);
+  removeUnusedLocals(floatStack);
+  removeUnusedLocals(longStack);
+  
+  removeUnusedObjects(objectLocals, module);
+  removeUnusedObjects(objectStack, module);
   
   func->setLinkage(GlobalValue::ExternalLinkage);
   
@@ -1243,7 +1273,7 @@
     BasicBlock* ifTrue =  createBasicBlock("true verifyAndComputePtr");
     BasicBlock* ifFalse = createBasicBlock("false verifyAndComputePtr");
 
-    branch(cmp, ifTrue, ifFalse, currentBlock);
+    BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
     
     currentBlock = ifFalse;
     Value* args[2] = { obj, index };
@@ -1262,51 +1292,6 @@
 
 }
 
-void JavaJIT::testPHINodes(BasicBlock* dest, BasicBlock* insert) {
-  if(dest->empty()) {
-    for (std::vector< std::pair<Value*, bool> >::iterator i = stack.begin(),
-         e = stack.end(); i!= e; ++i) {
-      Value* cur = i->first;
-      bool unsign = i->second;
-      PHINode* node = 0;
-      const Type* type = cur->getType();
-      if (unsign) {
-        node = llvm::PHINode::Create(Type::Int32Ty, "", dest);
-        cur = new ZExtInst(cur, Type::Int32Ty, "", currentBlock);
-      } else if (type == Type::Int8Ty || type == Type::Int16Ty) {
-        node = llvm::PHINode::Create(Type::Int32Ty, "", dest);
-        cur = new SExtInst(cur, Type::Int32Ty, "", currentBlock);
-      } else {
-        node = llvm::PHINode::Create(cur->getType(), "", dest);
-      }
-      assert(node->getType() == cur->getType() && "wrong 1");
-      node->addIncoming(cur, insert);
-    }
-  } else {
-    std::vector< std::pair<Value*, bool> >::iterator stackit = stack.begin();
-    for (BasicBlock::iterator i = dest->begin(), e = dest->end(); i != e;
-         ++i) {
-      if (!(isa<PHINode>(i))) {
-        break;
-      } else {
-        Instruction* ins = i;
-        Value* cur = stackit->first;
-        const Type* type = cur->getType();
-        bool unsign = stackit->second;
-        
-        if (unsign) {
-          cur = new ZExtInst(cur, Type::Int32Ty, "", currentBlock);
-        } else if (type == Type::Int8Ty || type == Type::Int16Ty) {
-          cur = new SExtInst(cur, Type::Int32Ty, "", currentBlock);
-        }
-        assert(ins->getType() == cur->getType() && "wrong 2");
-        ((PHINode*)ins)->addIncoming(cur, insert);
-        ++stackit;
-      }
-    }
-  }
-}
-
 void JavaJIT::makeArgs(FunctionType::param_iterator it,
                        uint32 index, std::vector<Value*>& Args, uint32 nb) {
 #if defined(ISOLATE_SHARING)
@@ -1327,7 +1312,7 @@
     if (it->get() == Type::Int64Ty || it->get() == Type::DoubleTy) {
       pop();
     }
-    bool unsign = topSign();
+    bool unsign = topIsUnsigned();
     Value* tmp = pop();
     
     const Type* type = it->get();
@@ -1344,6 +1329,53 @@
   
 }
 
+void JavaJIT::addFakePHINodes(BasicBlock* dest, BasicBlock* insert) {
+  if(dest->empty()) {
+    for (std::vector<StackTypeInfo>::iterator i = stack.begin(),
+         e = stack.end(); i!= e; ++i) {
+      switch (*i) {
+        case Int : {
+          PHINode* node = PHINode::Create(Type::Int32Ty, "", dest);
+          node->addIncoming(llvmContext->getNullValue(Type::Int32Ty), insert);
+          break;
+        }
+        case Float : {
+          PHINode* node = PHINode::Create(Type::FloatTy, "", dest);
+          node->addIncoming(llvmContext->getNullValue(Type::FloatTy), insert);
+          break;
+        }
+        case Double : {
+          PHINode* node = PHINode::Create(Type::DoubleTy, "", dest);
+          node->addIncoming(llvmContext->getNullValue(Type::DoubleTy), insert);
+          break;
+        }
+        case Long : {
+          PHINode* node = PHINode::Create(Type::Int64Ty, "", dest);
+          node->addIncoming(llvmContext->getNullValue(Type::Int64Ty), insert);
+          break;
+        }
+        case Object : {
+          PHINode* node = PHINode::Create(module->JavaObjectType, "", dest);
+          node->addIncoming(llvmContext->getNullValue(module->JavaObjectType),
+                            insert);
+          break;
+        }
+        default :
+          abort();
+      }
+    }
+  } else {
+    for (BasicBlock::iterator i = dest->begin(), e = dest->end(); i != e; ++i) {
+      if (PHINode* node = dyn_cast<PHINode>(i)) {
+        node->addIncoming(llvmContext->getNullValue(node->getType()), insert);
+      } else {
+        break;
+      }
+    }
+  }
+}
+
+
 Instruction* JavaJIT::lowerMathOps(const UTF8* name, 
                                    std::vector<Value*>& args) {
   JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader;
@@ -1847,7 +1879,7 @@
  
 
 void JavaJIT::setStaticField(uint16 index) {
-  bool unsign = topSign();
+  bool unsign = topIsUnsigned();
   Value* val = pop(); 
   
   Typedef* sign = compilingClass->ctpInfo->infoOfField(index);
@@ -1934,7 +1966,7 @@
 }
 
 void JavaJIT::setVirtualField(uint16 index) {
-  bool unsign = topSign();
+  bool unsign = topIsUnsigned();
   Value* val = pop();
   Typedef* sign = compilingClass->ctpInfo->infoOfField(index);
   LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo(sign);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Mon Jul 27 12:14:26 2009
@@ -45,7 +45,12 @@
   /// exceptionBlock - Never null, the exception destination of the
   /// instruction.
   ///
-  llvm::BasicBlock* exceptionBlock; 
+  llvm::BasicBlock* exceptionBlock;
+
+  /// handler - If the instruction is the first instruction of a Java exception
+  /// handler.
+  ///
+  bool handler;
 };
 
 
@@ -67,6 +72,7 @@
     inlining = false;
     callsStackWalker = false;
     endNode = 0;
+    currentStackIndex = 0;
   }
 
   /// javaCompile - Compile the Java method.
@@ -180,37 +186,105 @@
   
 
 //===------------------------- Stack manipulation -------------------------===//
- 
-  /// stack - The compiler stack. We store the value and its sign.
-  std::vector< std::pair<llvm::Value*, bool> > stack;
+
+  typedef enum {
+    Int = 0,
+    Float,
+    Double,
+    Long,
+    Object
+  } StackTypeInfo;
+
+
+  std::map<llvm::BasicBlock*, std::vector<StackTypeInfo>* > StackBlockInfo;
+
+  /// stack - The compiler stack.
+  std::vector<StackTypeInfo> stack;
+  uint32 currentStackIndex;
+  std::vector<llvm::AllocaInst*> objectStack;
+  std::vector<llvm::AllocaInst*> intStack;
+  std::vector<llvm::AllocaInst*> longStack;
+  std::vector<llvm::AllocaInst*> floatStack;
+  std::vector<llvm::AllocaInst*> doubleStack;
 
   /// push - Push a new value in the stack.
   void push(llvm::Value* val, bool unsign) {
-    stack.push_back(std::make_pair(val, unsign));
+    const llvm::Type* type = val->getType();
+    if (unsign) {
+      val = new llvm::ZExtInst(val, llvm::Type::Int32Ty, "", currentBlock);
+      new llvm::StoreInst(val, intStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Int);
+    } else if (type == llvm::Type::Int8Ty || type == llvm::Type::Int16Ty) {
+      val = new llvm::SExtInst(val, llvm::Type::Int32Ty, "", currentBlock);
+      new llvm::StoreInst(val, intStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Int);
+    } else if (type == llvm::Type::Int32Ty) {
+      new llvm::StoreInst(val, intStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Int);
+    } else if (type == llvm::Type::Int64Ty) {
+      new llvm::StoreInst(val, longStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Long);
+    } else if (type == llvm::Type::FloatTy) {
+      new llvm::StoreInst(val, floatStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Float);
+    } else if (type == llvm::Type::DoubleTy) {
+      new llvm::StoreInst(val, doubleStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Double);
+    } else {
+      assert(type == module->JavaObjectType && "Can't handle this type");
+      new llvm::StoreInst(val, objectStack[currentStackIndex++], false,
+                          currentBlock);
+      stack.push_back(Object);
+    }
   }
 
-  /// push - Push a new value in the stack.
-  void push(std::pair<llvm::Value*, bool> pair) {
-    stack.push_back(pair);
-  }
-  
   /// pop - Pop a value from the stack and return it.
   llvm::Value* pop() {
-    llvm::Value * ret = top();
+    llvm::Value* res = top();
+    --currentStackIndex;
     stack.pop_back();
-    return ret; 
+    return res;
   }
 
   /// top - Return the value on top of the stack.
   llvm::Value* top() {
-    return stack.back().first;
+    StackTypeInfo STI = stack.back();
+    switch (STI) {
+      case Int:
+        return new llvm::LoadInst(intStack[currentStackIndex - 1], false,
+                                  currentBlock);
+      case Float:
+        return new llvm::LoadInst(floatStack[currentStackIndex - 1], false,
+                                  currentBlock);
+      case Double:
+        return new llvm::LoadInst(doubleStack[currentStackIndex - 1], false,
+                                  currentBlock);
+      case Long:
+        return new llvm::LoadInst(longStack[currentStackIndex - 1], false,
+                                  currentBlock);
+      case Object:
+        return new llvm::LoadInst(objectStack[currentStackIndex - 1], false,
+                                  currentBlock);
+      default:
+        assert(0 && "Can not be here");
+    }
   }
   
-  /// topSign - Return the sign of the value on top of the stack.
-  bool topSign() {
-    return stack.back().second;  
+  /// topTypeInfo - Return the type of the value on top of the stack.
+  StackTypeInfo topTypeInfo() {
+    return stack.back();
   }
  
+  bool topIsUnsigned() {
+    return false;
+  }
+
   /// stackSize - Return the size of the stack.
   uint32 stackSize() {
     return stack.size();    
@@ -219,25 +293,7 @@
   /// popAsInt - Pop a value from the stack and returns it as a Java
   /// int, ie signed int32.
   llvm::Value* popAsInt() {
-    llvm::Value * ret = top();
-    bool unsign = topSign();
-    stack.pop_back();
-
-    if (ret->getType() != llvm::Type::Int32Ty) {
-      if (unsign) {
-        ret = new llvm::ZExtInst(ret, llvm::Type::Int32Ty, "", currentBlock);
-      } else {
-        ret = new llvm::SExtInst(ret, llvm::Type::Int32Ty, "", currentBlock);
-      }
-    }
-    return ret;
-  }
-
-  /// popPair - Pop the pair on the stack and return it.
-  std::pair<llvm::Value*, bool> popPair() {
-    std::pair<llvm::Value*, bool> ret = stack.back();
-    stack.pop_back();
-    return ret;
+    return pop();
   }
 
 //===------------------------- Exception support --------------------------===//
@@ -278,25 +334,24 @@
   llvm::BasicBlock* createBasicBlock(const char* name = "") {
     return llvm::BasicBlock::Create(name, llvmFunction);  
   }
-  
+ 
   /// 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) {
-    testPHINodes(ifTrue, insert);
-    testPHINodes(ifFalse, insert);
+    addFakePHINodes(ifTrue, insert);
+    addFakePHINodes(ifFalse, insert);
     llvm::BranchInst::Create(ifTrue, ifFalse, test, insert);
   }
 
   /// branch - Branch to a new block. Update PHI nodes accordingly.
   void branch(llvm::BasicBlock* dest, llvm::BasicBlock* insert) {
-    testPHINodes(dest, insert);
+    addFakePHINodes(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);
-
- 
+  void addFakePHINodes(llvm::BasicBlock* dest, llvm::BasicBlock* insert);
+  
 //===-------------------------- Synchronization  --------------------------===//
   
   /// beginSynchronize - Emit synchronization code to acquire the instance
@@ -404,6 +459,9 @@
   /// method.
   uint32 nbEnveloppes;
 
+//===--------------------- Yield point support  ---------------------------===//
+
+  void checkYieldPoint();
  
 
 #if defined(ISOLATE_SHARING)

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Mon Jul 27 12:14:26 2009
@@ -135,22 +135,43 @@
     PRINT_DEBUG(JNJVM_COMPILE, 1, LIGHT_BLUE, "\n");
     
     Opinfo* opinfo = &(opcodeInfos[i]);
+    
     if (opinfo->newBlock) {
       if (currentBlock->getTerminator() == 0) {
         branch(opinfo->newBlock, currentBlock);
       }
       
+      currentBlock = opinfo->newBlock;
+      
       stack.clear();
+      currentStackIndex = 0;
       for (BasicBlock::iterator i = opinfo->newBlock->begin(),
            e = opinfo->newBlock->end(); i != e; ++i) {
         if (!(isa<PHINode>(i))) {
           break;
         } else {
-          stack.push_back(std::make_pair(i, false));
+          ++currentStackIndex;
+          const Type* Ty = i->getType();
+          if (Ty == Type::Int32Ty) {
+            stack.push_back(Int);
+          } else if (Ty == Type::Int64Ty) {
+            stack.push_back(Long);
+          } else if (Ty == Type::FloatTy) {
+            stack.push_back(Float);
+          } else if (Ty == Type::DoubleTy) {
+            stack.push_back(Double);
+          } else if (Ty == module->JavaObjectType) {
+            stack.push_back(Object);
+            if (opinfo->handler) {
+              // If it's a handler, put the exception object in the stack.
+              new StoreInst(i, objectStack[currentStackIndex - 1], "",
+                            currentBlock);
+            }
+          } else {
+            abort();
+          }
         }
       }
-  
-      currentBlock = opinfo->newBlock;
     }
     currentExceptionBlock = opinfo->exceptionBlock;
     
@@ -749,71 +770,78 @@
         break;
 
       case DUP :
-        push(top(), topSign());
+        push(top(), topIsUnsigned());
         break;
 
       case DUP_X1 : {
-        std::pair<Value*, bool> one = popPair();
-        std::pair<Value*, bool> two = popPair();
-        push(one);
-        push(two);
-        push(one);
+        Value* one = pop();
+        Value* two = pop();
+        
+        push(one, false);
+        push(two, false);
+        push(one, false);
         break;
       }
 
       case DUP_X2 : {
-        std::pair<Value*, bool> one = popPair();
-        std::pair<Value*, bool> two = popPair();
-        std::pair<Value*, bool> three = popPair();
-        push(one);
-        push(three);
-        push(two);
-        push(one);
+        Value* one = pop();
+        Value* two = pop();
+        Value* three = pop();
+        push(one, false);
+        push(three, false);
+        push(two, false);
+        push(one, false);
         break;
       }
 
-      case DUP2 :
-        push(stack[stackSize() - 2]);
-        push(stack[stackSize() - 2]);
+      case DUP2 : {
+        Value* one = pop();
+        Value* two = pop();
+        
+        push(two, false);
+        push(one, false);
+        push(two, false);
+        push(one, false);
         break;
+      }
 
       case DUP2_X1 : {
-        std::pair<Value*, bool> one = popPair();
-        std::pair<Value*, bool> two = popPair();
-        std::pair<Value*, bool> three = popPair();
-
-        push(two);
-        push(one);
-
-        push(three);
-        push(two);
-        push(one);
+        Value* one = pop();
+        Value* two = pop();
+        Value* three = pop();
+
+        push(two, false);
+        push(one, false);
+
+        push(three, false);
+        push(two, false);
+        push(one, false);
 
         break;
       }
 
       case DUP2_X2 : {
-        std::pair<Value*, bool> one = popPair();
-        std::pair<Value*, bool> two = popPair();
-        std::pair<Value*, bool> three = popPair();
-        std::pair<Value*, bool> four = popPair();
-
-        push(two);
-        push(one);
-        
-        push(four);
-        push(three);
-        push(two);
-        push(one);
+        Value* one = pop();
+        Value* two = pop();
+        Value* three = pop();
+        Value* four = pop();
+
+        push(two, false);
+        push(one, false);
+        
+        push(four, false);
+        push(three, false);
+        push(two, false);
+        push(one, false);
 
         break;
       }
 
       case SWAP : {
-        std::pair<Value*, bool> one = popPair();
-        std::pair<Value*, bool> two = popPair();
-        push(one);
-        push(two);
+        Value* one = pop();
+        Value* two = pop();
+        push(one, false);
+        push(two, false);
         break;
       }
 
@@ -1776,7 +1804,7 @@
         BasicBlock* def = opcodeInfos[tmp + readU4(bytecodes, i)].newBlock;
         uint32 nbs = readU4(bytecodes, i);
         
-        bool unsign = topSign();
+        bool unsign = topIsUnsigned();
         Value* key = pop();
         const Type* type = key->getType();
         if (unsign) {
@@ -1798,7 +1826,7 @@
         break;
       }
       case IRETURN : {
-        bool unsign = topSign();
+        bool unsign = topIsUnsigned();
         Value* val = pop();
         assert(val->getType()->isInteger());
         convertValue(val, endNode->getType(), currentBlock, unsign);





More information about the vmkit-commits mailing list