diff options
| -rw-r--r-- | llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 26 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp | 15 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Interpreter.h | 6 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.h | 4 | 
5 files changed, 35 insertions, 21 deletions
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index 86af7bfafea..b920898230c 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp @@ -13,8 +13,6 @@  //===----------------------------------------------------------------------===//  #define DEBUG_TYPE "jit" -#include "Interpreter/Interpreter.h" -#include "JIT/JIT.h"  #include "llvm/Constants.h"  #include "llvm/DerivedTypes.h"  #include "llvm/Module.h" @@ -26,6 +24,7 @@  #include "llvm/Support/Debug.h"  #include "llvm/System/DynamicLibrary.h"  #include "llvm/Target/TargetData.h" +#include <iostream>  using namespace llvm;  namespace { @@ -33,6 +32,9 @@ namespace {    Statistic<> NumGlobals  ("lli", "Number of global vars initialized");  } +ExecutionEngine::EECtorFn ExecutionEngine::JITCtor = 0; +ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor = 0; +  ExecutionEngine::ExecutionEngine(ModuleProvider *P) :    CurMod(*P->getModule()), MP(P) {    assert(P && "ModuleProvider is null?"); @@ -163,24 +165,12 @@ ExecutionEngine *ExecutionEngine::create(ModuleProvider *MP,    ExecutionEngine *EE = 0;    // Unless the interpreter was explicitly selected, try making a JIT. -  if (!ForceInterpreter) -    EE = JIT::create(MP, IL); +  if (!ForceInterpreter && JITCtor) +    EE = JITCtor(MP, IL);    // If we can't make a JIT, make an interpreter instead. -  if (EE == 0) { -    try { -      Module *M = MP->materializeModule(); -      try { -        EE = Interpreter::create(M, IL); -      } catch (...) { -        std::cerr << "Error creating the interpreter!\n"; -      } -    } catch (std::string& errmsg) { -      std::cerr << "Error reading the bytecode file: " << errmsg << "\n"; -    } catch (...) { -      std::cerr << "Error reading the bytecode file!\n"; -    } -  } +  if (EE == 0 && InterpCtor) +    EE = InterpCtor(MP, IL);    if (EE == 0)      delete IL; diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp index af23bf11beb..0f73189a9e5 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp @@ -17,11 +17,24 @@  #include "llvm/CodeGen/IntrinsicLowering.h"  #include "llvm/DerivedTypes.h"  #include "llvm/Module.h" +#include "llvm/ModuleProvider.h"  using namespace llvm; +static struct RegisterInterp { +  RegisterInterp() { Interpreter::Register(); } +} InterpRegistrator; +  /// create - Create a new interpreter object.  This can never fail.  /// -ExecutionEngine *Interpreter::create(Module *M, IntrinsicLowering *IL) { +ExecutionEngine *Interpreter::create(ModuleProvider *MP, +                                     IntrinsicLowering *IL) { +  Module *M; +  try { +    M = MP->materializeModule(); +  } catch (...) { +    return 0;  // error materializing the module. +  } +      bool isLittleEndian = false;    switch (M->getEndianness()) {    case Module::LittleEndian: isLittleEndian = true; break; diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h index e45b4c64475..1b547a645bc 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -102,11 +102,15 @@ public:    ///    void runAtExitHandlers(); +  static void Register() { +    InterpCtor = create; +  } +      /// create - Create an interpreter ExecutionEngine. This can never fail.  The    /// specified IntrinsicLowering implementation will be deleted when the    /// Interpreter execution engine is destroyed.    /// -  static ExecutionEngine *create(Module *M, IntrinsicLowering *IL); +  static ExecutionEngine *create(ModuleProvider *M, IntrinsicLowering *IL);    /// run - Start execution with the specified function and arguments.    /// diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index 5eeaea576f8..66e0468f189 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -26,9 +26,12 @@  #include "llvm/Target/TargetMachine.h"  #include "llvm/Target/TargetJITInfo.h"  #include <iostream> -  using namespace llvm; +static struct RegisterJIT { +  RegisterJIT() { JIT::Register(); } +} JITRegistrator; +  JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)    : ExecutionEngine(MP), TM(tm), TJI(tji), state(MP) {    setTargetData(TM.getTargetData()); diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.h b/llvm/lib/ExecutionEngine/JIT/JIT.h index 4cce144712f..979cdc6c8e3 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.h +++ b/llvm/lib/ExecutionEngine/JIT/JIT.h @@ -60,6 +60,10 @@ class JIT : public ExecutionEngine {  public:    ~JIT(); +  static void Register() { +    JITCtor = create; +  } +      /// getJITInfo - Return the target JIT information structure.    ///    TargetJITInfo &getJITInfo() const { return TJI; }  | 

