[vmkit-commits] [vmkit] r55438 - in /vmkit/branches/isolate/lib/JnJVM/VMCore: JavaJIT.cpp JavaJIT.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed Aug 27 15:29:52 PDT 2008
Author: geoffray
Date: Wed Aug 27 17:29:52 2008
New Revision: 55438
URL: http://llvm.org/viewvc/llvm-project?rev=55438&view=rev
Log:
Factorize code for getting constant pool values.
Modified:
vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.cpp
vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.h
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.cpp?rev=55438&r1=55437&r2=55438&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.cpp Wed Aug 27 17:29:52 2008
@@ -63,7 +63,6 @@
#if !defined(WITHOUT_VTABLE) && !defined(MULTIPLE_VM)
- Constant* zero = mvm::jit::constantZero;
Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index);
std::vector<Value*> args; // size = [signature->nbIn + 3];
LLVMSignatureInfo* LSI = module->getSignatureInfo(signature);
@@ -82,34 +81,9 @@
indexes2.push_back(LMI->getOffset());
} else {
- Value* val = getConstantPoolAt(index);
- val = new PtrToIntInst(val, Type::Int32Ty, "", currentBlock);
-
- Value * cmp = new ICmpInst(ICmpInst::ICMP_NE, val, zero, "", currentBlock);
- BasicBlock* ifTrue = createBasicBlock("true vtable");
- BasicBlock* ifFalse = createBasicBlock("false vtable");
- BasicBlock* endBlock = createBasicBlock("end vtable");
- PHINode * node = llvm::PHINode::Create(Type::Int32Ty, "", endBlock);
- llvm::BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
-
- currentBlock = ifTrue;
- node->addIncoming(val, currentBlock);
- llvm::BranchInst::Create(endBlock, currentBlock);
-
- currentBlock = ifFalse;
- std::vector<Value*> Args;
- LLVMClassInfo* LCI =
- (LLVMClassInfo*)module->getClassInfo(compilingClass);
- Args.push_back(LCI->getVar(this));
- Constant* CI = ConstantInt::get(Type::Int32Ty, index);
- Args.push_back(CI);
- Args.push_back(args[0]);
- val = invoke(JnjvmModule::VirtualLookupFunction, Args, "", currentBlock);
- node->addIncoming(val, currentBlock);
- llvm::BranchInst::Create(endBlock, currentBlock);
-
- currentBlock = endBlock;
- indexes2.push_back(node);
+ Value* val = getConstantPoolAt(index, JnjvmModule::VirtualLookupFunction,
+ args[0], true);
+ indexes2.push_back(val);
}
Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2.begin(),
@@ -1107,39 +1081,9 @@
if (type == JavaConstantPool::ConstantString) {
#ifdef MULTIPLE_VM
// Lookup the constant pool cache
- Constant* nil = mvm::jit::constantPtrNull;
- Value* val = getConstantPoolAt(index);
- Value* cmp = new ICmpInst(ICmpInst::ICMP_NE, nil, val, "", currentBlock);
- BasicBlock* ifTrue = createBasicBlock("true string");
- BasicBlock* ifFalse = createBasicBlock("false string");
- BasicBlock* endBlock = createBasicBlock("end string");
-
- PHINode * node = PHINode::Create(JnjvmModule::JavaObjectType, "", endBlock);
- BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
-
- // ---------- In case we already resolved something --------------------- //
- currentBlock = ifTrue;
- val = new BitCastInst(val, JnjvmModule::JavaObjectType, "", currentBlock);
- node->addIncoming(val, currentBlock);
- BranchInst::Create(endBlock, currentBlock);
-
- // ---------------- In case we have to resolve -------------------------- //
- currentBlock = ifFalse;
- LLVMClassInfo* LCI = (LLVMClassInfo*)module->getClassInfo(compilingClass);
- Value* v = LCI->getVar(this);
- std::vector<Value*> Args;
- Args.push_back(v);
- Args.push_back(ConstantInt::get(Type::Int32Ty, index));
- CallInst* C = llvm::CallInst::Create(JnjvmModule::StringLookupFunction,
- Args.begin(), Args.end(),
- "", currentBlock);
- node->addIncoming(C, currentBlock);
- BranchInst::Create(endBlock, currentBlock);
-
- // ---------------------------- The end ----------------------------------//
- currentBlock = endBlock;
- push(node, AssessorDesc::dRef);
-
+ Value* val = getConstantPoolAt(index, JnjvmModule::StringLookupFunction,
+ 0, true);
+ push(node, AssessorDesc::dRef);
#else
const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]);
JavaString* str = JavaThread::get()->isolate->UTF8ToStr(utf8);
@@ -1603,7 +1547,9 @@
}
}
-Value* JavaJIT::getConstantPoolAt(uint32 index) {
+Value* JavaJIT::getConstantPoolAt(uint32 index, Function* resolver,
+ Value* additionalArg, bool doThrow) {
+ const Type* returnType = resolver->getReturnType();
JavaConstantPool* ctp = compilingClass->ctpInfo;
LLVMConstantPoolInfo* LCPI = module->getConstantPoolInfo(ctp);
Value* CTP = LCPI->getDelegatee(this);
@@ -1616,44 +1562,51 @@
// We set as volatile because "readnone" calls may alter
// the constant pool cache.
arg1 = new LoadInst(arg1, "", true, currentBlock);
+ Value* test = new ICmpInst(ICmpInst::ICMP_EQ, arg1, mvm::jit::constantPtrNull,
+ "", currentBlock);
+
+ if (returnType == Type::Int32Ty) {
+ arg1 = new PtrToIntInst(arg1, returnType, "", currentBlock);
+ } else if (returnType != arg1->getType()) {
+ arg1 = new BitCastInst(arg1, returnType, "", currentBlock);
+ }
+ BasicBlock* trueCl = createBasicBlock("Ctp OK");
+ BasicBlock* falseCl = createBasicBlock("Ctp Not OK");
+ PHINode* node = llvm::PHINode::Create(returnType, "", trueCl);
+ node->addIncoming(arg1, currentBlock);
+ llvm::BranchInst::Create(falseCl, trueCl, test, currentBlock);
+
+ currentBlock = falseCl;
+ std::vector<Value*> Args;
+ LLVMClassInfo* LCI = (LLVMClassInfo*)module->getClassInfo(compilingClass);
+ Value* v = LCI->getVar(this);
+ Args.push_back(v);
+ ConstantInt* CI = ConstantInt::get(Type::Int32Ty, index);
+ Args.push_back(CI);
+
+ if (additionalArg)
+ Args.push_back(additionalArg);
+
+ Value* res = 0;
+ if (doThrow) {
+ res = invoke(resolver, Args, "", currentBlock);
+ } else {
+ res = CallInst::Create(resolver, Args.begin(), Args.end(), "",
+ currentBlock);
+ }
+ node->addIncoming(res, currentBlock);
+
+ llvm::BranchInst::Create(trueCl, currentBlock);
+ currentBlock = trueCl;
- return arg1;
+ return node;
}
Value* JavaJIT::getResolvedClass(uint16 index, bool clinit, bool doThrow) {
- Value* arg1 = getConstantPoolAt(index);
- arg1 = new BitCastInst(arg1, JnjvmModule::JavaClassType, "", currentBlock);
- Value* test = new ICmpInst(ICmpInst::ICMP_EQ, arg1,
- JnjvmModule::JavaClassNullConstant, "",
- currentBlock);
+ Value* node = getConstantPoolAt(index, JnjvmModule::ClassLookupFunction,
+ 0, doThrow);
- BasicBlock* trueCl = createBasicBlock("Cl OK");
- BasicBlock* falseCl = createBasicBlock("Cl Not OK");
- PHINode* node = llvm::PHINode::Create(JnjvmModule::JavaClassType, "",
- trueCl);
- node->addIncoming(arg1, currentBlock);
- llvm::BranchInst::Create(falseCl, trueCl, test, currentBlock);
-
- currentBlock = falseCl;
-
- std::vector<Value*> Args;
- LLVMClassInfo* LCI = (LLVMClassInfo*)module->getClassInfo(compilingClass);
- Value* v = LCI->getVar(this);
- Args.push_back(v);
- ConstantInt* CI = ConstantInt::get(Type::Int32Ty, index);
- Args.push_back(CI);
- Value* res = 0;
- if (doThrow) {
- res = invoke(JnjvmModule::ClassLookupFunction, Args, "", currentBlock);
- } else {
- res = CallInst::Create(JnjvmModule::ClassLookupFunction, Args.begin(),
- Args.end(), "", currentBlock);
- }
- node->addIncoming(res, currentBlock);
-
- llvm::BranchInst::Create(trueCl, currentBlock);
- currentBlock = trueCl;
if (clinit)
return invoke(JnjvmModule::InitialisationCheckFunction, node, "",
currentBlock);
@@ -1767,59 +1720,20 @@
const Type* Pty = mvm::jit::arrayPtrType;
Constant* zero = mvm::jit::constantZero;
- Constant* nil = mvm::jit::constantPtrNull;
-
- Value* val = getConstantPoolAt(index);
- // a virtual field can never be zero.
- Value * cmp = new ICmpInst(ICmpInst::ICMP_NE, val, nil, "", currentBlock);
- BasicBlock* ifTrue = createBasicBlock("true ldResolved");
- BasicBlock* ifFalse = createBasicBlock("false ldResolved");
- BasicBlock* endBlock = createBasicBlock("end ldResolved");
- PHINode * node = llvm::PHINode::Create(mvm::jit::ptrType, "", endBlock);
- llvm::BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
-
- // ---------- In case we already resolved something --------------------- //
- currentBlock = ifTrue;
- Value* resPtr = 0;
- if (object) {
- Value* ptr = new BitCastInst(object, Pty, "", currentBlock);
- val = new PtrToIntInst(val, Type::Int32Ty, "", currentBlock);
- std::vector<Value*> gepArgs; // size = 1
- gepArgs.push_back(zero);
- gepArgs.push_back(val);
- resPtr = llvm::GetElementPtrInst::Create(ptr, gepArgs.begin(), gepArgs.end(),
- "", currentBlock);
- } else {
- resPtr = val;
- }
-
- node->addIncoming(resPtr, currentBlock);
- llvm::BranchInst::Create(endBlock, currentBlock);
-
- // ---------- In case we have to resolve -------------------------------- //
- currentBlock = ifFalse;
- std::vector<Value*> args;
- LLVMClassInfo* LCI = (LLVMClassInfo*)module->getClassInfo(compilingClass);
- args.push_back(LCI->getVar(this));
- Constant* CI = ConstantInt::get(Type::Int32Ty, index);
- args.push_back(CI);
Function* func = stat ? JnjvmModule::StaticFieldLookupFunction :
JnjvmModule::VirtualFieldLookupFunction;
- Value* tmp = invoke(func, args, "", currentBlock);
+ Value* ptr = getConstantPoolAt(index, func, 0, true);
if (!stat) {
- Value* ptr = new BitCastInst(object, Pty, "", currentBlock);
- args.clear();
+ Value* tmp = new BitCastInst(object, Pty, "", currentBlock);
+ std::vector<Value*> args;
args.push_back(zero);
- args.push_back(tmp);
- tmp = GetElementPtrInst::Create(ptr, args.begin(), args.end(), "",
+ args.push_back(ptr);
+ ptr = GetElementPtrInst::Create(tmp, args.begin(), args.end(), "",
currentBlock);
}
- node->addIncoming(tmp, currentBlock);
- llvm::BranchInst::Create(endBlock, currentBlock);
- currentBlock = endBlock;;
- return new BitCastInst(node, fieldTypePtr, "", currentBlock);
+ return new BitCastInst(ptr, fieldTypePtr, "", currentBlock);
}
void JavaJIT::convertValue(Value*& val, const Type* t1, BasicBlock* currentBlock,
@@ -2027,7 +1941,8 @@
uint64_t (enveloppe)),
JnjvmModule::EnveloppeType);
#else
- llvmEnv = getConstantPoolAt(index);
+ llvmEnv = getConstantPoolAt(index, JnjvmModule::EnveloppeLookupFunction,
+ 0, false);
#endif
std::vector<Value*> args1;
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.h?rev=55438&r1=55437&r2=55438&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJIT.h Wed Aug 27 17:29:52 2008
@@ -58,7 +58,8 @@
class JavaJIT {
private:
- llvm::Value* getConstantPoolAt(uint32 index);
+ llvm::Value* getConstantPoolAt(uint32 index, llvm::Function* resolver,
+ llvm::Value* addArg, bool doThrow = true);
public:
More information about the vmkit-commits
mailing list