[llvm-commits] [llvm] r128052 - in /llvm/trunk/lib/ExecutionEngine: MCJIT/MCJIT.cpp MCJIT/MCJIT.h RuntimeDyld/RuntimeDyld.cpp

Jim Grosbach grosbach at apple.com
Mon Mar 21 18:06:42 PDT 2011


Author: grosbach
Date: Mon Mar 21 20:06:42 2011
New Revision: 128052

URL: http://llvm.org/viewvc/llvm-project?rev=128052&view=rev
Log:
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.


Modified:
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=128052&r1=128051&r2=128052&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Mon Mar 21 20:06:42 2011
@@ -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 @@
   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::getPointerToFunction(Function *F) {
-  return 0;
+  Twine Name = TM->getMCAsmInfo()->getGlobalPrefix() + F->getName();
+  return Dyld.getSymbolAddress(Name.str());
 }
 
 void *MCJIT::recompileAndRelinkFunction(Function *F) {

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h?rev=128052&r1=128051&r2=128052&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h Mon Mar 21 20:06:42 2011
@@ -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 @@
   SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
   raw_svector_ostream OS;
 
+  RuntimeDyld Dyld;
+
 public:
   ~MCJIT();
 

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=128052&r1=128051&r2=128052&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Mar 21 20:06:42 2011
@@ -145,6 +145,10 @@
     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 @@
     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())





More information about the llvm-commits mailing list