[vmkit-commits] [vmkit] r137017 - in /vmkit/trunk: include/j3/J3Intrinsics.h include/j3/JavaAOTCompiler.h include/j3/JavaLLVMCompiler.h include/mvm/JIT.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/JavaLLVMCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/Mvm/Compiler/InlineMalloc.cpp lib/Mvm/Compiler/JIT.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sat Aug 6 05:01:51 PDT 2011
Author: geoffray
Date: Sat Aug 6 07:01:50 2011
New Revision: 137017
URL: http://llvm.org/viewvc/llvm-project?rev=137017&view=rev
Log:
Major cleanup in the MvmModule class: no need to create global variables shared across compilers.
Modified:
vmkit/trunk/include/j3/J3Intrinsics.h
vmkit/trunk/include/j3/JavaAOTCompiler.h
vmkit/trunk/include/j3/JavaLLVMCompiler.h
vmkit/trunk/include/mvm/JIT.h
vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp
vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
Modified: vmkit/trunk/include/j3/J3Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/include/j3/J3Intrinsics.h (original)
+++ vmkit/trunk/include/j3/J3Intrinsics.h Sat Aug 6 07:01:50 2011
@@ -17,6 +17,8 @@
class J3Intrinsics : public mvm::BaseIntrinsics {
public:
+ void init(llvm::Module* M);
+
llvm::Type* JavaArrayUInt8Type;
llvm::Type* JavaArraySInt8Type;
llvm::Type* JavaArrayUInt16Type;
@@ -149,12 +151,6 @@
llvm::Function* ArrayStoreExceptionFunction;
llvm::Function* ArithmeticExceptionFunction;
llvm::Function* ThrowExceptionFromJITFunction;
-
-
- J3Intrinsics(llvm::Module*);
-
- static void initialise();
-
};
}
Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaAOTCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sat Aug 6 07:01:50 2011
@@ -78,8 +78,6 @@
virtual ~JavaAOTCompiler() {}
- virtual void* loadMethod(void* handle, const char* symbol);
-
virtual CommonClass* getUniqueBaseClass(CommonClass* cl);
private:
Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sat Aug 6 07:01:50 2011
@@ -48,6 +48,7 @@
llvm::Module* TheModule;
llvm::DIBuilder* DebugFactory;
J3Intrinsics JavaIntrinsics;
+ const llvm::TargetData* TheTargetData;
private:
bool enabledException;
@@ -180,7 +181,7 @@
return I->second;
}
}
-
+
virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl) = 0;
virtual JavaObject* getFinalObject(llvm::Value* C) = 0;
virtual llvm::Constant* getNativeClass(CommonClass* cl) = 0;
Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sat Aug 6 07:01:50 2011
@@ -65,7 +65,7 @@
public:
- explicit BaseIntrinsics(llvm::Module*);
+ void init(llvm::Module*);
llvm::Function* exceptionEndCatch;
llvm::Function* exceptionBeginCatch;
@@ -181,24 +181,16 @@
class MvmModule {
public:
- static llvm::GCStrategy* TheGCStrategy;
static mvm::LockRecursive protectEngine;
- static llvm::Module *globalModule;
- static const llvm::TargetData* TheTargetData;
- static mvm::BumpPtrAllocator* Allocator;
- static llvm::ExecutionEngine* executionEngine;
- //static unsigned MetadataTypeKind;
- static uint64 getTypeSize(llvm::Type* type);
static void runPasses(llvm::Function* func, llvm::FunctionPassManager*);
- static void initialise(llvm::CodeGenOpt::Level = llvm::CodeGenOpt::Default,
- llvm::Module* TheModule = 0,
- llvm::TargetMachine* TheTarget = 0);
+ static void initialise();
static Frames* addToVM(VirtualMachine* VM,
llvm::GCFunctionInfo* GFI,
llvm::JIT* jit,
- mvm::BumpPtrAllocator& allocator);
+ mvm::BumpPtrAllocator& allocator,
+ void* meta);
static int disassemble(unsigned int* addr);
Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sat Aug 6 07:01:50 2011
@@ -31,8 +31,9 @@
}
}
-J3Intrinsics::J3Intrinsics(llvm::Module* module) :
- BaseIntrinsics(module) {
+void J3Intrinsics::init(llvm::Module* module) {
+ BaseIntrinsics::init(module);
+
j3::llvm_runtime::makeLLVMModuleContents(module);
LLVMContext& Context = module->getContext();
@@ -231,6 +232,5 @@
GetLockFunction = module->getFunction("getLock");
ThrowExceptionFromJITFunction =
- module->getFunction("j3ThrowExceptionFromJIT");
-
+ module->getFunction("j3ThrowExceptionFromJIT");
}
Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Aug 6 07:01:50 2011
@@ -14,6 +14,8 @@
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetRegistry.h"
#include "mvm/UTF8.h"
#include "mvm/Threads/Thread.h"
@@ -1813,7 +1815,17 @@
JavaAOTCompiler::JavaAOTCompiler(const std::string& ModuleID) :
JavaLLVMCompiler(ModuleID) {
-
+
+ std::string Error;
+ const Target* TheTarget(TargetRegistry::lookupTarget(mvm::MvmModule::getHostTriple(), Error));
+ TargetMachine* TM = TheTarget->createTargetMachine(mvm::MvmModule::getHostTriple(), "", "");
+ TheTargetData = TM->getTargetData();
+ TheModule->setDataLayout(TheTargetData->getStringRepresentation());
+ TheModule->setTargetTriple(TM->getTargetTriple());
+ JavaIntrinsics.init(TheModule);
+ initialiseAssessorInfo();
+
+
generateStubs = true;
assumeCompiled = false;
compileRT = false;
@@ -1888,7 +1900,7 @@
Module* Mod = getLLVMModule();
for (Module::const_global_iterator i = Mod->global_begin(),
e = Mod->global_end(); i != e; ++i) {
- size += mvm::MvmModule::getTypeSize(i->getType());
+ size += TheTargetData->getTypeAllocSize(i->getType());
}
fprintf(stdout, "%lluB\n", (unsigned long long int)size);
}
@@ -2489,20 +2501,6 @@
}
-
-// Use a FakeFunction to return from loadMethod, so that the compiler thinks
-// the method is defined by J3.
-extern "C" void __JavaAOTFakeFunction__() {}
-
-void* JavaAOTCompiler::loadMethod(void* handle, const char* symbol) {
- Function* F = mvm::MvmModule::globalModule->getFunction(symbol);
- if (F) {
- return (void*)(uintptr_t)__JavaAOTFakeFunction__;
- }
-
- return JavaCompiler::loadMethod(handle, symbol);
-}
-
// TODO: clean up to have a better interface with the fake GC.
#include <set>
extern std::set<gc*> __InternalSet__;
Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Aug 6 07:01:50 2011
@@ -22,6 +22,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
#include <../lib/ExecutionEngine/JIT/JIT.h>
#include "MvmGC.h"
@@ -43,14 +44,11 @@
void *Code, size_t Size,
const EmittedFunctionDetails &Details) {
- // The following is necessary for -load-bc.
- if (F.getParent() != TheCompiler->getLLVMModule()) return;
assert(F.hasGC());
- if (TheCompiler->GCInfo != NULL) {
- assert(TheCompiler->GCInfo == Details.MF->getGMI());
- return;
+ if (TheCompiler->GCInfo == NULL) {
+ TheCompiler->GCInfo = Details.MF->getGMI();
}
- TheCompiler->GCInfo = Details.MF->getGMI();
+ assert(TheCompiler->GCInfo == Details.MF->getGMI());
}
@@ -163,6 +161,11 @@
executionEngine = ExecutionEngine::createJIT(TheModule, 0,
0, llvm::CodeGenOpt::Default, false);
executionEngine->RegisterJITEventListener(&listener);
+ TheTargetData = executionEngine->getTargetData();
+ TheModule->setDataLayout(TheTargetData->getStringRepresentation());
+ TheModule->setTargetTriple(mvm::MvmModule::getHostTriple());
+ JavaIntrinsics.init(TheModule);
+ initialiseAssessorInfo();
addJavaPasses();
}
@@ -306,13 +309,10 @@
void* res = executionEngine->getPointerToGlobal(func);
if (!func->isDeclaration()) {
- llvm::GCFunctionInfo* GFI = &(GCInfo->getFunctionInfo(*func));
- assert((GFI != NULL) && "No GC information");
+ llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*func);
Jnjvm* vm = JavaThread::get()->getJVM();
- mvm::Frames* frames = mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator);
- meth->frames = frames;
- meth->updateFrames();
+ meth->frames = mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth);
}
// Now that it's compiled, we don't need the IR anymore
func->deleteBody();
@@ -324,11 +324,10 @@
mvm::MvmModule::protectIR();
void* res = executionEngine->getPointerToGlobal(F);
- llvm::GCFunctionInfo* GFI = &(GCInfo->getFunctionInfo(*F));
- assert((GFI != NULL) && "No GC information");
+ llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F);
Jnjvm* vm = JavaThread::get()->getJVM();
- mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator);
+ mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL);
// Now that it's compiled, we don't need the IR anymore
F->deleteBody();
Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Sat Aug 6 07:01:50 2011
@@ -26,12 +26,10 @@
JavaLLVMCompiler::JavaLLVMCompiler(const std::string& str) :
TheModule(new llvm::Module(str, *(new LLVMContext()))),
- DebugFactory(new DIBuilder(*TheModule)),
- JavaIntrinsics(TheModule) {
+ DebugFactory(new DIBuilder(*TheModule)) {
enabledException = true;
cooperativeGC = true;
- initialiseAssessorInfo();
}
void JavaLLVMCompiler::resolveVirtualClass(Class* cl) {
@@ -125,6 +123,7 @@
JavaFunctionPasses->add(mvm::createLoopSafePointsPass());
// Add other passes after the loop pass, because safepoints may move objects.
// Moving objects disable many optimizations.
+ JavaFunctionPasses->add(new TargetData(TheModule));
mvm::MvmModule::addCommandLinePasses(JavaFunctionPasses);
// Re-enable this when the pointers in stack-allocated objects can
Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Aug 6 07:01:50 2011
@@ -38,7 +38,7 @@
Type* LLVMClassInfo::getVirtualType() {
if (!virtualType) {
std::vector<llvm::Type*> fields;
- const TargetData* targetData = mvm::MvmModule::TheTargetData;
+ const TargetData* targetData = Compiler->TheTargetData;
const StructLayout* sl = 0;
StructType* structType = 0;
LLVMContext& context = Compiler->getLLVMModule()->getContext();
@@ -68,7 +68,7 @@
}
- uint64 size = mvm::MvmModule::getTypeSize(structType);
+ uint64 size = targetData->getTypeAllocSize(structType);
virtualSizeConstant = ConstantInt::get(Type::getInt32Ty(context), size);
// TODO: put that elsewhere.
@@ -109,7 +109,7 @@
StructType* structType = StructType::get(context, fields, false);
staticType = PointerType::getUnqual(structType);
- const TargetData* targetData = mvm::MvmModule::TheTargetData;
+ const TargetData* targetData = Compiler->TheTargetData;
const StructLayout* sl = targetData->getStructLayout(structType);
// TODO: put that elsewhere.
@@ -120,7 +120,7 @@
field.ptrOffset = sl->getElementOffset(i);
}
- uint64 size = mvm::MvmModule::getTypeSize(structType);
+ uint64 size = targetData->getTypeAllocSize(structType);
cl->staticSize = size;
}
}
Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Sat Aug 6 07:01:50 2011
@@ -16,6 +16,7 @@
#include "llvm/Support/CallSite.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "mvm/JIT.h"
@@ -41,6 +42,7 @@
Function* ArrayWriteBarrier = F.getParent()->getFunction("arrayWriteBarrier");
Function* NonHeapWriteBarrier = F.getParent()->getFunction("nonHeapWriteBarrier");
bool Changed = false;
+ const TargetData *TD = getAnalysisIfAvailable<TargetData>();
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;) {
@@ -54,14 +56,14 @@
Function* Temp = Call.getCalledFunction();
if (Temp == Malloc) {
if (dyn_cast<Constant>(Call.getArgument(0))) {
- InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData);
+ InlineFunctionInfo IFI(NULL, TD);
Changed |= InlineFunction(Call, IFI);
break;
}
} else if (Temp == FieldWriteBarrier ||
Temp == NonHeapWriteBarrier ||
Temp == ArrayWriteBarrier) {
- InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData);
+ InlineFunctionInfo IFI(NULL, TD);
Changed |= InlineFunction(Call, IFI);
break;
}
Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=137017&r1=137016&r2=137017&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Aug 6 07:01:50 2011
@@ -66,26 +66,7 @@
return LLVM_HOSTTRIPLE;
}
-class MvmJITListener : public llvm::JITEventListener {
-public:
- virtual void NotifyFunctionEmitted(const Function &F,
- void *Code, size_t Size,
- const EmittedFunctionDetails &Details) {
- assert(F.getParent() == MvmModule::globalModule);
- assert(F.hasGC());
- // We know the last GC info is for this method.
- GCStrategy::iterator I = mvm::MvmModule::TheGCStrategy->end();
- I--;
- DEBUG(errs() << (*I)->getFunction().getName() << '\n');
- DEBUG(errs() << F.getName() << '\n');
- assert(&(*I)->getFunction() == &F &&
- "GC Info and method do not correspond");
- llvm::GCFunctionInfo* GFI = *I;
- MvmModule::addToVM(mvm::Thread::get()->MyVM, GFI, (JIT*)MvmModule::executionEngine, *MvmModule::Allocator);
- }
-};
-
-Frames* MvmModule::addToVM(VirtualMachine* VM, GCFunctionInfo* FI, JIT* jit, BumpPtrAllocator& allocator) {
+Frames* MvmModule::addToVM(VirtualMachine* VM, GCFunctionInfo* FI, JIT* jit, BumpPtrAllocator& allocator, void* meta) {
JITCodeEmitter* JCE = jit->getCodeEmitter();
int NumDescriptors = 0;
for (GCFunctionInfo::iterator J = FI->begin(), JE = FI->end(); J != JE; ++J) {
@@ -107,7 +88,7 @@
frame->NumLiveOffsets = LiveCount;
frame->FrameSize = FI->getFrameSize();
- frame->Metadata = NULL;
+ frame->Metadata = meta;
frame->SourceIndex = I->Loc.getLine();
frame->ReturnAddress = reinterpret_cast<void*>(JCE->getLabelAddress(I->Label));
int i = 0;
@@ -130,13 +111,7 @@
return frames;
}
-static MvmJITListener JITListener;
-
-typedef void (*BootType)(uintptr_t Plan);
-typedef void (*BootHeapType)(intptr_t initial, intptr_t max);
-
-void MvmModule::initialise(CodeGenOpt::Level level, Module* M,
- TargetMachine* T) {
+void MvmModule::initialise() {
mvm::linkVmkitGC();
llvm_start_multithreaded();
@@ -150,38 +125,13 @@
const char* commands[2] = { "vmkit", "-disable-branch-fold" };
llvm::cl::ParseCommandLineOptions(2, const_cast<char**>(commands));
- if (!M) {
- globalModule = new Module("bootstrap module", *(new LLVMContext()));
-
- InitializeNativeTarget();
-
- executionEngine = ExecutionEngine::createJIT(globalModule, 0,
- 0, level, false);
-
- Allocator = new BumpPtrAllocator();
- executionEngine->RegisterJITEventListener(&JITListener);
- std::string str =
- executionEngine->getTargetData()->getStringRepresentation();
- globalModule->setDataLayout(str);
- globalModule->setTargetTriple(getHostTriple());
-
- TheTargetData = executionEngine->getTargetData();
- } else {
- globalModule = M;
- TheTargetData = T->getTargetData();
- }
-
- //LLVMContext& Context = globalModule->getContext();
- //MetadataTypeKind = Context.getMDKindID("HighLevelType");
-
+ InitializeNativeTarget();
}
extern "C" void MMTk_InlineMethods(llvm::Module* module);
-BaseIntrinsics::BaseIntrinsics(llvm::Module* module) {
+void BaseIntrinsics::init(llvm::Module* module) {
- module->setDataLayout(MvmModule::globalModule->getDataLayout());
- module->setTargetTriple(MvmModule::globalModule->getTargetTriple());
LLVMContext& Context = module->getContext();
MMTk_InlineMethods(module);
@@ -319,17 +269,7 @@
NonHeapWriteBarrierFunction = module->getFunction("nonHeapWriteBarrier");
}
-const llvm::TargetData* MvmModule::TheTargetData;
-llvm::GCStrategy* MvmModule::TheGCStrategy;
-llvm::Module *MvmModule::globalModule;
-llvm::ExecutionEngine* MvmModule::executionEngine;
mvm::LockRecursive MvmModule::protectEngine;
-mvm::BumpPtrAllocator* MvmModule::Allocator;
-//unsigned MvmModule::MetadataTypeKind;
-
-uint64 MvmModule::getTypeSize(llvm::Type* type) {
- return TheTargetData->getTypeAllocSize(type);
-}
void MvmModule::runPasses(llvm::Function* func,
llvm::FunctionPassManager* pm) {
@@ -402,8 +342,6 @@
}
void MvmModule::addCommandLinePasses(FunctionPassManager* PM) {
- addPass(PM, new TargetData(*MvmModule::TheTargetData));
-
addPass(PM, createVerifierPass()); // Verify that input is correct
addPass(PM, createCFGSimplificationPass()); // Clean up disgusting code
More information about the vmkit-commits
mailing list