aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/JIT/JIT.cpp
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2009-02-18 08:31:02 +0000
committerNate Begeman <natebegeman@mac.com>2009-02-18 08:31:02 +0000
commitd6b7a242d345fd79a337afd384bb586c5619cfe7 (patch)
treecc149d70595f6859c7607a5129ce01ce9a98e0bb /lib/ExecutionEngine/JIT/JIT.cpp
parent98c507ed5c2883bc8ef487d952e851da37f8b32f (diff)
Add support to the JIT for true non-lazy operation. When a call to a function
that has not been JIT'd yet, the callee is put on a list of pending functions to JIT. The call is directed through a stub, which is updated with the address of the function after it has been JIT'd. A new interface for allocating and updating empty stubs is provided. Add support for removing the ModuleProvider the JIT was created with, which would otherwise invalidate the JIT's PassManager, which is initialized with the ModuleProvider's Module. Add support under a new ExecutionEngine flag for emitting the infomration necessary to update Function and GlobalVariable stubs after JITing them, by recording the address of the stub and the name of the GlobalValue. This allows code to be copied from one address space to another, where libraries may live at different virtual addresses, and have the stubs updated with their new correct target addresses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp70
1 files changed, 61 insertions, 9 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 008c5907d8..6940d85d75 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -289,11 +289,28 @@ Module *JIT::removeModuleProvider(ModuleProvider *MP, std::string *E) {
Module *result = ExecutionEngine::removeModuleProvider(MP, E);
MutexGuard locked(lock);
- if (Modules.empty()) {
+
+ if (jitstate->getMP() == MP) {
delete jitstate;
jitstate = 0;
}
+ if (!jitstate && !Modules.empty()) {
+ jitstate = new JITState(Modules[0]);
+
+ FunctionPassManager &PM = jitstate->getPM(locked);
+ PM.add(new TargetData(*TM.getTargetData()));
+
+ // Turn the machine code intermediate representation into bytes in memory
+ // that may be executed.
+ if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) {
+ cerr << "Target does not support machine code emission!\n";
+ abort();
+ }
+
+ // Initialize passes.
+ PM.doInitialization();
+ }
return result;
}
@@ -304,10 +321,28 @@ void JIT::deleteModuleProvider(ModuleProvider *MP, std::string *E) {
ExecutionEngine::deleteModuleProvider(MP, E);
MutexGuard locked(lock);
- if (Modules.empty()) {
+
+ if (jitstate->getMP() == MP) {
delete jitstate;
jitstate = 0;
}
+
+ if (!jitstate && !Modules.empty()) {
+ jitstate = new JITState(Modules[0]);
+
+ FunctionPassManager &PM = jitstate->getPM(locked);
+ PM.add(new TargetData(*TM.getTargetData()));
+
+ // Turn the machine code intermediate representation into bytes in memory
+ // that may be executed.
+ if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) {
+ cerr << "Target does not support machine code emission!\n";
+ abort();
+ }
+
+ // Initialize passes.
+ PM.doInitialization();
+ }
}
/// run - Start execution with the specified function and arguments.
@@ -488,14 +523,26 @@ void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) {
jitstate->getPM(locked).run(*F);
isAlreadyCodeGenerating = false;
- // If the function referred to a global variable that had not yet been
- // emitted, it allocates memory for the global, but doesn't emit it yet. Emit
- // all of these globals now.
- while (!jitstate->getPendingGlobals(locked).empty()) {
- const GlobalVariable *GV = jitstate->getPendingGlobals(locked).back();
- jitstate->getPendingGlobals(locked).pop_back();
- EmitGlobalVariable(GV);
+ // If the function referred to another function that had not yet been
+ // read from bitcode, but we are jitting non-lazily, emit it now.
+ while (!jitstate->getPendingFunctions(locked).empty()) {
+ Function *PF = jitstate->getPendingFunctions(locked).back();
+ jitstate->getPendingFunctions(locked).pop_back();
+
+ // JIT the function
+ isAlreadyCodeGenerating = true;
+ jitstate->getPM(locked).run(*PF);
+ isAlreadyCodeGenerating = false;
+
+ // Now that the function has been jitted, ask the JITEmitter to rewrite
+ // the stub with real address of the function.
+ updateFunctionStub(PF);
}
+
+ // If the JIT is configured to emit info so that dlsym can be used to
+ // rewrite stubs to external globals, do so now.
+ if (areDlsymStubsEnabled() && isLazyCompilationDisabled())
+ updateDlsymStubTable();
}
/// getPointerToFunction - This method is used to get the address of the
@@ -644,3 +691,8 @@ char* JIT::getMemoryForGV(const GlobalVariable* GV) {
return new char[GVSize];
}
}
+
+void JIT::addPendingFunction(Function *F) {
+ MutexGuard locked(lock);
+ jitstate->getPendingFunctions(locked).push_back(F);
+}