[llvm-branch-commits] [llvm-branch] r96858 - in /llvm/branches/Apple/Hermes: include/llvm/ExecutionEngine/ExecutionEngine.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Reader/BitcodeReader.h lib/ExecutionEngine/ExecutionEngine.cpp lib/VMCore/ModuleProvider.cpp tools/lli/lli.cpp

Evan Cheng evan.cheng at apple.com
Mon Feb 22 18:06:59 PST 2010


Author: evancheng
Date: Mon Feb 22 20:06:59 2010
New Revision: 96858

URL: http://llvm.org/viewvc/llvm-project?rev=96858&view=rev
Log:
- Add EngineBuilder(ModuleProvider*) variant to provide backward compatibility.
- More update to BitcodeReader to make sure it really behaves like ModuleProvider.
- Update lli.cpp to test EngineBuilder(ModuleProvider*).

Modified:
    llvm/branches/Apple/Hermes/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.h
    llvm/branches/Apple/Hermes/lib/ExecutionEngine/ExecutionEngine.cpp
    llvm/branches/Apple/Hermes/lib/VMCore/ModuleProvider.cpp
    llvm/branches/Apple/Hermes/tools/lli/lli.cpp

Modified: llvm/branches/Apple/Hermes/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/branches/Apple/Hermes/include/llvm/ExecutionEngine/ExecutionEngine.h Mon Feb 22 20:06:59 2010
@@ -18,6 +18,7 @@
 #include <vector>
 #include <map>
 #include <string>
+#include "llvm/ModuleProvider.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/ValueMap.h"
@@ -37,7 +38,6 @@
 class JITMemoryManager;
 class MachineCodeInfo;
 class Module;
-class ModuleProvider;
 class MutexGuard;
 class TargetData;
 class Type;
@@ -188,6 +188,13 @@
 				    CodeModel::Model CMM =
 				      CodeModel::Default);
 
+  /// addModuleProvider - Add a ModuleProvider to the list of modules that we
+  /// can JIT from.  Note that this takes ownership of the ModuleProvider: when
+  /// the ExecutionEngine is destroyed, it destroys the MP as well.
+  virtual void addModuleProvider(ModuleProvider *P) {
+    Modules.push_back(P->getModule());
+  }
+  
   /// addModule - Add a Module to the list of modules that we can JIT from.
   /// Note that this takes ownership of the Module: when the ExecutionEngine is
   /// destroyed, it destroys the Module as well.
@@ -200,6 +207,13 @@
   const TargetData *getTargetData() const { return TD; }
 
 
+
+  /// removeModuleProvider - Remove a ModuleProvider from the list of modules.
+  /// Relases the Module from the ModuleProvider, materializing it in the
+  /// process, and returns the materialized Module.
+  virtual Module* removeModuleProvider(ModuleProvider *P,
+                                       std::string *ErrInfo = 0);
+
   /// removeModule - Remove a Module from the list of modules.  Returns true if
   /// M is found.
   virtual bool removeModule(Module *M);
@@ -457,6 +471,13 @@
 
  public:
   /// EngineBuilder - Constructor for EngineBuilder.  If create() is called and
+  /// is successful, the created engine takes ownership of the module
+  /// provider.
+  EngineBuilder(ModuleProvider *mp) : M(mp->getModule()) {
+    InitEngine();
+  }
+
+  /// EngineBuilder - Constructor for EngineBuilder.  If create() is called and
   /// is successful, the created engine takes ownership of the module.
   EngineBuilder(Module *m) : M(m) {
     InitEngine();

Modified: llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.cpp?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.cpp Mon Feb 22 20:06:59 2010
@@ -1559,6 +1559,10 @@
       if (TheModule)
         return Error("Multiple MODULE_BLOCKs in same stream");
       TheModule = M;
+      if (!TheModule) {
+        TheModule = new Module(Buffer->getBufferIdentifier(), Context);
+        TheModule->setMaterializer(this);
+      }
       if (ParseModule())
         return true;
       break;

Modified: llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.h?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/branches/Apple/Hermes/lib/Bitcode/Reader/BitcodeReader.h Mon Feb 22 20:06:59 2010
@@ -124,7 +124,6 @@
 
 class BitcodeReader : public GVMaterializer, public ModuleProvider {
   LLVMContext &Context;
-  Module *TheModule;
   MemoryBuffer *Buffer;
   bool BufferOwned;
   BitstreamReader StreamFile;
@@ -174,7 +173,7 @@
   
 public:
   explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
-    : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false),
+    : Context(C), Buffer(buffer), BufferOwned(false),
       ErrorString(0), ValueList(C), MDValueList(C) {
     HasReversedFunctionsWithBodies = false;
   }

Modified: llvm/branches/Apple/Hermes/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/ExecutionEngine/ExecutionEngine.cpp?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/ExecutionEngine/ExecutionEngine.cpp Mon Feb 22 20:06:59 2010
@@ -18,6 +18,7 @@
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
+#include "llvm/ModuleProvider.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Debug.h"
@@ -73,6 +74,23 @@
   return new char[GVSize];
 }
 
+/// removeModuleProvider - Remove a ModuleProvider from the list of modules.
+/// Relases the Module from the ModuleProvider, materializing it in the
+/// process, and returns the materialized Module.
+Module* ExecutionEngine::removeModuleProvider(ModuleProvider *P, 
+                                              std::string *ErrInfo) {
+  for(SmallVector<Module *, 1>::iterator I = Modules.begin(), 
+        E = Modules.end(); I != E; ++I) {
+    Module *Found = *I;
+    if (Found == P->getModule()) {
+      Modules.erase(I);
+      clearGlobalMappingsFromModule(P->getModule());
+      return P->getModule();
+    }
+  }
+  return NULL;
+}
+
 /// removeModule - Remove a Module from the list of modules.
 bool ExecutionEngine::removeModule(Module *M) {
   for(SmallVector<Module *, 1>::iterator I = Modules.begin(), 

Modified: llvm/branches/Apple/Hermes/lib/VMCore/ModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/VMCore/ModuleProvider.cpp?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/VMCore/ModuleProvider.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/VMCore/ModuleProvider.cpp Mon Feb 22 20:06:59 2010
@@ -20,7 +20,7 @@
 ModuleProvider::ModuleProvider() : TheModule(0) { }
 
 /// dtor - when we leave, we take our Module with us
-///
+/// NOTE: Not in this version. ModuleProvider is here to provide JIT backward
+/// compatibility. ExecutionEngine is manually deleting the modules.
 ModuleProvider::~ModuleProvider() {
-  delete TheModule;
 }

Modified: llvm/branches/Apple/Hermes/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/tools/lli/lli.cpp?rev=96858&r1=96857&r2=96858&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/tools/lli/lli.cpp (original)
+++ llvm/branches/Apple/Hermes/tools/lli/lli.cpp Mon Feb 22 20:06:59 2010
@@ -15,6 +15,7 @@
 
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
+#include "llvm/ModuleProvider.h"
 #include "llvm/Type.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
@@ -125,28 +126,28 @@
   
   // Load the bitcode...
   std::string ErrorMsg;
-  Module *Mod = NULL;
+  ModuleProvider *MP = NULL;
   if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
-    Mod = getLazyBitcodeModule(Buffer, Context, &ErrorMsg);
-    if (!Mod) delete Buffer;
+    MP = getBitcodeModuleProvider(Buffer, Context, &ErrorMsg);
+    if (!MP) delete Buffer;
   }
   
-  if (!Mod) {
+  if (!MP) {
     errs() << argv[0] << ": error loading program '" << InputFile << "': "
            << ErrorMsg << "\n";
     exit(1);
   }
 
-  // If not jitting lazily, load the whole bitcode file eagerly too.
-  if (NoLazyCompilation) {
-    if (Mod->MaterializeAllPermanently(&ErrorMsg)) {
-      errs() << argv[0] << ": bitcode didn't read correctly.\n";
-      errs() << "Reason: " << ErrorMsg << "\n";
-      exit(1);
-    }
+  // Get the module as the MP could go away once EE takes over.
+  Module *Mod = NoLazyCompilation
+    ? MP->materializeModule(&ErrorMsg) : MP->getModule();
+  if (!Mod) {
+    errs() << argv[0] << ": bitcode didn't read correctly.\n";
+    errs() << "Reason: " << ErrorMsg << "\n";
+    exit(1);
   }
 
-  EngineBuilder builder(Mod);
+  EngineBuilder builder(MP);
   builder.setMArch(MArch);
   builder.setMCPU(MCPU);
   builder.setMAttrs(MAttrs);





More information about the llvm-branch-commits mailing list