summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2011-03-22 01:06:42 +0000
committerJim Grosbach <grosbach@apple.com>2011-03-22 01:06:42 +0000
commit348a54838144c0b5525edf33be457c50a9257628 (patch)
treecfdab61b01a8e041b378fb0d8cdfd166570dafed /llvm/lib/ExecutionEngine
parentc6f4af028d48bdd2d588405f59422643f5236448 (diff)
downloadbcm5719-llvm-348a54838144c0b5525edf33be457c50a9257628.tar.gz
bcm5719-llvm-348a54838144c0b5525edf33be457c50a9257628.zip
Hook up the MCJIT to the RuntimeDyld library.
Lots of cleanup to make the interfaces prettier, use the JITMemoryManager, handle multiple functions and modules, etc.. This gets far enough that the MCJIT compiles and runs code, though. llvm-svn: 128052
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp12
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/MCJIT.h3
-rw-r--r--llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp10
3 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 5eda88d1a38..2225ea6a15f 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -11,8 +11,11 @@
#include "llvm/Function.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/ExecutionEngine/JITMemoryManager.h"
+#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetData.h"
using namespace llvm;
@@ -81,6 +84,12 @@ MCJIT::MCJIT(Module *m, TargetMachine *tm, TargetJITInfo &tji,
PM.run(*M);
// Flush the output buffer so the SmallVector gets its data.
OS.flush();
+
+ // Load the object into the dynamic linker.
+ // FIXME: It would be nice to avoid making yet another copy.
+ MemoryBuffer *MB = MemoryBuffer::getMemBufferCopy(StringRef(Buffer.data(),
+ Buffer.size()));
+ Dyld.loadObject(MB);
}
MCJIT::~MCJIT() {
@@ -92,7 +101,8 @@ void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {
}
void *MCJIT::getPointerToFunction(Function *F) {
- return 0;
+ Twine Name = TM->getMCAsmInfo()->getGlobalPrefix() + F->getName();
+ return Dyld.getSymbolAddress(Name.str());
}
void *MCJIT::recompileAndRelinkFunction(Function *F) {
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
index e81e7c7d347..947f7c78e38 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -12,6 +12,7 @@
#include "llvm/PassManager.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/raw_ostream.h"
@@ -37,6 +38,8 @@ class MCJIT : public ExecutionEngine {
SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
raw_svector_ostream OS;
+ RuntimeDyld Dyld;
+
public:
~MCJIT();
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 3186bf26b2d..a57055eb8d2 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -145,6 +145,10 @@ loadSegment32(const MachOObject *Obj,
SymbolTable[Name] = Address;
}
+ // We've loaded the section; now mark the functions in it as executable.
+ // FIXME: We really should use the JITMemoryManager for this.
+ sys::Memory::setRangeExecutable(Data.base(), Data.size());
+
delete SectionBases;
return false;
}
@@ -220,12 +224,14 @@ loadSegment64(const MachOObject *Obj,
SymbolTable[Name] = Address;
}
+ // We've loaded the section; now mark the functions in it as executable.
+ // FIXME: We really should use the JITMemoryManager for this.
+ sys::Memory::setRangeExecutable(Data.base(), Data.size());
+
delete SectionBases;
return false;
}
-
-
bool RuntimeDyldImpl::loadObject(MemoryBuffer *InputBuffer) {
// If the linker is in an error state, don't do anything.
if (hasError())
OpenPOWER on IntegriCloud