[vmkit-commits] [vmkit] r145016 - in /vmkit/trunk/lib: J3/Compiler/JavaJIT.cpp J3/Compiler/JavaJIT.h J3/Compiler/JavaJITOpcodes.cpp J3/Compiler/JavaLLVMCompiler.cpp Mvm/Compiler/LoopSafePoints.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Nov 20 14:08:33 PST 2011
Author: geoffray
Date: Sun Nov 20 16:08:32 2011
New Revision: 145016
URL: http://llvm.org/viewvc/llvm-project?rev=145016&view=rev
Log:
Remove the non-working safepoint loop pass (where objects could end up still being live in registers during the safe point), in favor of a back edge recognition in Java opcodes.
Removed:
vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp
Modified:
vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/J3/Compiler/JavaJIT.h
vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=145016&r1=145015&r2=145016&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sun Nov 20 16:08:32 2011
@@ -75,6 +75,23 @@
return true;
}
+void JavaJIT::checkYieldPoint() {
+ if (!TheCompiler->useCooperativeGC()) return;
+ Value* YieldPtr = getDoYieldPtr(getMutatorThreadPtr());
+
+ Value* Yield = new LoadInst(YieldPtr, "", currentBlock);
+
+ BasicBlock* continueBlock = createBasicBlock("After safe point");
+ BasicBlock* yieldBlock = createBasicBlock("In safe point");
+ BranchInst::Create(yieldBlock, continueBlock, Yield, currentBlock);
+
+ currentBlock = yieldBlock;
+ CallInst::Create(intrinsics->conditionalSafePoint, "", currentBlock);
+ BranchInst::Create(continueBlock, currentBlock);
+
+ currentBlock = continueBlock;
+}
+
bool JavaJIT::canBeInlined(JavaMethod* meth, bool customizing) {
if (inlineMethods[meth]) return false;
if (isSynchro(meth->access)) return false;
@@ -1099,27 +1116,13 @@
if (returnType != Type::getVoidTy(*llvmContext)) {
endNode = llvm::PHINode::Create(returnType, 0, "", endBlock);
}
+
+ checkYieldPoint();
if (isSynchro(compilingMethod->access)) {
beginSynchronize();
}
- if (TheCompiler->useCooperativeGC()) {
- Value* YieldPtr = getDoYieldPtr(getMutatorThreadPtr());
-
- Value* Yield = new LoadInst(YieldPtr, "", currentBlock);
-
- BasicBlock* continueBlock = createBasicBlock("After safe point");
- BasicBlock* yieldBlock = createBasicBlock("In safe point");
- BranchInst::Create(yieldBlock, continueBlock, Yield, currentBlock);
-
- currentBlock = yieldBlock;
- CallInst::Create(intrinsics->conditionalSafePoint, "", currentBlock);
- BranchInst::Create(continueBlock, currentBlock);
-
- currentBlock = continueBlock;
- }
-
if (TheCompiler->hasExceptionsEnabled() &&
!mvm::System::SupportsHardwareStackOverflow()) {
// Variables have been allocated and the lock has been taken. Do the stack
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=145016&r1=145015&r2=145016&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sun Nov 20 16:08:32 2011
@@ -64,6 +64,9 @@
/// stack - The stack at this location if there is a new block
///
std::vector<MetaInfo> stack;
+
+ /// backEdge - If this block is a back edge.
+ bool backEdge;
};
/// JavaJIT - The compilation engine of J3. Parses the bycode and returns
Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=145016&r1=145015&r2=145016&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Sun Nov 20 16:08:32 2011
@@ -142,6 +142,10 @@
stack = opinfo->stack;
currentStackIndex = stack.size();
}
+
+ if (opinfo->backEdge) {
+ checkYieldPoint();
+ }
}
currentExceptionBlock = opinfo->exceptionBlock;
@@ -2572,12 +2576,15 @@
case IF_ICMPLE :
case IF_ACMPEQ :
case IF_ACMPNE :
- case GOTO : {
+ case GOTO :
+ case IFNULL :
+ case IFNONNULL : {
uint32 tmp = i;
uint16 index = tmp + reader.readU2();
+ if (index < i) opcodeInfos[index].backEdge = true;
i += 2;
if (!(opcodeInfos[index].newBlock))
- opcodeInfos[index].newBlock = createBasicBlock("GOTO or IF*");
+ opcodeInfos[index].newBlock = createBasicBlock("");
break;
}
@@ -2716,17 +2723,6 @@
wide = true;
break;
- case IFNULL :
- case IFNONNULL : {
- uint32 tmp = i;
- uint16 index = tmp + reader.readU2();
- i += 2;
- if (!(opcodeInfos[index].newBlock))
- opcodeInfos[index].newBlock = createBasicBlock("true IF*NULL");
- break;
- }
-
-
default : {
fprintf(stderr, "I haven't verified your class file and it's malformed:"
" unknown bytecode %d in %s.%s!\n", bytecode,
Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=145016&r1=145015&r2=145016&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Sun Nov 20 16:08:32 2011
@@ -21,9 +21,10 @@
#include "j3/JavaLLVMCompiler.h"
-using namespace j3;
using namespace llvm;
+namespace j3 {
+
JavaLLVMCompiler::JavaLLVMCompiler(const std::string& str) :
TheModule(new llvm::Module(str, *(new LLVMContext()))),
DebugFactory(new DIBuilder(*TheModule)) {
@@ -103,26 +104,18 @@
delete Context;
}
-namespace mvm {
- llvm::LoopPass* createLoopSafePointsPass();
-}
-
-namespace j3 {
- llvm::FunctionPass* createLowerConstantCallsPass(JavaLLVMCompiler* I);
-}
+llvm::FunctionPass* createLowerConstantCallsPass(JavaLLVMCompiler* I);
void JavaLLVMCompiler::addJavaPasses() {
JavaNativeFunctionPasses = new FunctionPassManager(TheModule);
JavaNativeFunctionPasses->add(new TargetData(TheModule));
+
J3FunctionPasses = new FunctionPassManager(TheModule);
J3FunctionPasses->add(createLowerConstantCallsPass(this));
- if (cooperativeGC)
- J3FunctionPasses->add(mvm::createLoopSafePointsPass());
-
- // Add other passes after the loop pass, because safepoints may move objects.
- // Moving objects disable many optimizations.
JavaFunctionPasses = new FunctionPassManager(TheModule);
JavaFunctionPasses->add(new TargetData(TheModule));
mvm::MvmModule::addCommandLinePasses(JavaFunctionPasses);
}
+
+} // end namespace j3
Removed: vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp?rev=145015&view=auto
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/LoopSafePoints.cpp (removed)
@@ -1,117 +0,0 @@
-//===------- LoopSafePoints.cpp - Add safe points in loop headers ---------===//
-//
-// The VMKit project
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "llvm/Module.h"
-#include "llvm/Analysis/LoopPass.h"
-#include "llvm/Support/CallSite.h"
-#include "llvm/Support/Compiler.h"
-
-using namespace llvm;
-
-namespace {
-
- class LoopSafePoints : public LoopPass {
- public:
- static char ID;
-
- LoopSafePoints() : LoopPass(ID) {}
-
- virtual bool runOnLoop(Loop* L, LPPassManager& LPM);
-
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<LoopInfo>();
- }
-
-
- private:
- void insertSafePoint(BasicBlock* BB, Function* SafeFunction,
- Value* YieldPtr, Loop* L, LoopInfo* LI);
- };
-
- char LoopSafePoints::ID = 0;
-
-void LoopSafePoints::insertSafePoint(BasicBlock* BB, Function* SafeFunction,
- Value* YieldPtr, Loop* L, LoopInfo* LI) {
- Instruction* I = BB->getFirstNonPHI();
- BasicBlock* NBB = BB->splitBasicBlock(I);
- L->addBasicBlockToLoop(NBB, LI->getBase());
-
- NBB = NBB->getSinglePredecessor();
- I = NBB->getTerminator();
- BasicBlock* SU = (static_cast<BranchInst*>(I))->getSuccessor(0);
- I->eraseFromParent();
-
- Value* Ld = new LoadInst(YieldPtr, "", NBB);
- BasicBlock* yield = BasicBlock::Create(SafeFunction->getContext(), "",
- BB->getParent());
-
- BranchInst::Create(yield, SU, Ld, NBB);
-
- CallInst::Create(SafeFunction, "", yield);
- BranchInst::Create(SU, yield);
-
- L->addBasicBlockToLoop(yield, LI->getBase());
-}
-
-
-bool LoopSafePoints::runOnLoop(Loop* L, LPPassManager& LPM) {
-
- LoopInfo* LI = &getAnalysis<LoopInfo>();
- BasicBlock* Header = L->getHeader();
- Function *F = Header->getParent();
- Function* SafeFunction =
- F->getParent()->getFunction("conditionalSafePoint");
- if (!SafeFunction) return false;
-
- Value* YieldPtr = 0;
-
- // Lookup the yield pointer.
- 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;) {
- Instruction *I = II;
- II++;
- if (I->getOpcode() != Instruction::Call &&
- I->getOpcode() != Instruction::Invoke) {
- continue;
- }
-
- CallSite Call(I);
- if (Call.getCalledValue() == SafeFunction) {
- if (BasicBlock* Incoming = Cur->getSinglePredecessor()) {
- if (BranchInst* T = dyn_cast<BranchInst>(Incoming->getTerminator())) {
- if (LoadInst* LI = dyn_cast<LoadInst>(T->getCondition())) {
- YieldPtr = LI->getPointerOperand();
- break;
- }
- }
- }
- }
- }
- if (YieldPtr) break;
- }
-
- if (!YieldPtr) return false;
-
- insertSafePoint(Header, SafeFunction, YieldPtr, L, LI);
- return true;
-}
-
-}
-
-
-namespace mvm {
-
-LoopPass* createLoopSafePointsPass() {
- return new LoopSafePoints();
-}
-
-}
More information about the vmkit-commits
mailing list