[llvm] r272455 - [MCJIT] Update MCJIT and get the fibonacci example working again.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 10 22:47:04 PDT 2016


Author: lhames
Date: Sat Jun 11 00:47:04 2016
New Revision: 272455

URL: http://llvm.org/viewvc/llvm-project?rev=272455&view=rev
Log:
[MCJIT] Update MCJIT and get the fibonacci example working again.

MCJIT will now set the DataLayout on a module when it is added to the JIT,
rather than waiting until it is codegen'd, and the runFunction method will
finalize the module containing the function to be run before running it.

The fibonacci example has been updated to include and link against MCJIT.


Modified:
    llvm/trunk/examples/Fibonacci/CMakeLists.txt
    llvm/trunk/examples/Fibonacci/fibonacci.cpp
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp

Modified: llvm/trunk/examples/Fibonacci/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Fibonacci/CMakeLists.txt?rev=272455&r1=272454&r2=272455&view=diff
==============================================================================
--- llvm/trunk/examples/Fibonacci/CMakeLists.txt (original)
+++ llvm/trunk/examples/Fibonacci/CMakeLists.txt Sat Jun 11 00:47:04 2016
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
   ExecutionEngine
   Interpreter
   MC
+  MCJIT
   Support
   nativecodegen
   )

Modified: llvm/trunk/examples/Fibonacci/fibonacci.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Fibonacci/fibonacci.cpp?rev=272455&r1=272454&r2=272455&view=diff
==============================================================================
--- llvm/trunk/examples/Fibonacci/fibonacci.cpp (original)
+++ llvm/trunk/examples/Fibonacci/fibonacci.cpp Sat Jun 11 00:47:04 2016
@@ -27,6 +27,7 @@
 #include "llvm/IR/Verifier.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/ExecutionEngine/MCJIT.h"
 #include "llvm/IR/Argument.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
@@ -103,6 +104,7 @@ int main(int argc, char **argv) {
   int n = argc > 1 ? atol(argv[1]) : 24;
 
   InitializeNativeTarget();
+  InitializeNativeTargetAsmPrinter();
   LLVMContext Context;
 
   // Create some module to put our function into it.

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=272455&r1=272454&r2=272455&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Sat Jun 11 00:47:04 2016
@@ -85,6 +85,9 @@ MCJIT::MCJIT(std::unique_ptr<Module> M,
   std::unique_ptr<Module> First = std::move(Modules[0]);
   Modules.clear();
 
+  if (First->getDataLayout().isDefault())
+    First->setDataLayout(getDataLayout());
+
   OwnedModules.addModule(std::move(First));
   RegisterJITEventListener(JITEventListener::createGDBRegistrationListener());
 }
@@ -103,6 +106,10 @@ MCJIT::~MCJIT() {
 
 void MCJIT::addModule(std::unique_ptr<Module> M) {
   MutexGuard locked(lock);
+
+  if (M->getDataLayout().isDefault())
+    M->setDataLayout(getDataLayout());
+
   OwnedModules.addModule(std::move(M));
 }
 
@@ -192,11 +199,7 @@ void MCJIT::generateCodeForModule(Module
   if (ObjCache)
     ObjectToLoad = ObjCache->getObject(M);
 
-  if (M->getDataLayout().isDefault()) {
-    M->setDataLayout(getDataLayout());
-  } else {
-    assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
-  }
+  assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
 
   // If the cache did not contain a suitable object, compile the object
   if (!ObjectToLoad) {
@@ -490,6 +493,7 @@ GenericValue MCJIT::runFunction(Function
   assert(F && "Function *F was null at entry to run()");
 
   void *FPtr = getPointerToFunction(F);
+  finalizeModule(F->getParent());
   assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
   FunctionType *FTy = F->getFunctionType();
   Type *RetTy = FTy->getReturnType();




More information about the llvm-commits mailing list