From 82d8277ad5862b54341808812bb4016e52347060 Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Wed, 3 Sep 2003 20:34:19 +0000 Subject: [PATCH] ExecutionEngine.cpp: Move execution engine creation stuff into a new static method here. Remove some extra blank lines. ExecutionEngine.h: Add its prototype. lli.cpp: Call it. Make creation method for each type of EE into a static method of its own subclass. Interpreter/Interpreter.cpp: ExecutionEngine::createInterpreter --> Interpreter::create Interpreter/Interpreter.h: Likewise. JIT/JIT.cpp: ExecutionEngine::createJIT --> VM::create JIT/VM.h: Likewise. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8343 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ExecutionEngine/ExecutionEngine.h | 3 +++ lib/ExecutionEngine/ExecutionEngine.cpp | 18 ++++++++++++++++-- .../Interpreter/Interpreter.cpp | 6 ++---- lib/ExecutionEngine/Interpreter/Interpreter.h | 9 +++++++-- lib/ExecutionEngine/JIT/JIT.cpp | 7 +++---- lib/ExecutionEngine/JIT/JIT.h | 5 +++++ lib/ExecutionEngine/JIT/VM.h | 5 +++++ tools/lli/lli.cpp | 12 +++--------- 8 files changed, 44 insertions(+), 21 deletions(-) diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h index e2d43c97f43..a0e54c14508 100644 --- a/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -48,6 +48,9 @@ public: const std::vector &Args, const char ** envp) = 0; + static ExecutionEngine *create (Module *M, bool ForceInterpreter, + bool DebugMode, bool TraceMode); + /// createJIT - Create an return a new JIT compiler if there is one available /// for the current target. Otherwise it returns null. /// diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 89d9e162892..5691a248a06 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -15,9 +15,25 @@ #include "Support/Debug.h" #include "Support/Statistic.h" #include "Config/dlfcn.h" +#include "JIT/VM.h" +#include "Interpreter/Interpreter.h" Statistic<> NumInitBytes("lli", "Number of bytes of global vars initialized"); +ExecutionEngine *ExecutionEngine::create (Module *M, bool ForceInterpreter, + bool DebugMode, bool TraceMode) { + ExecutionEngine *EE = 0; + + // If there is nothing that is forcing us to use the interpreter, make a JIT. + if (!ForceInterpreter && !DebugMode && !TraceMode) + EE = VM::create(M); + + // If we can't make a JIT, make an interpreter instead. + if (EE == 0) + EE = Interpreter::create(M, DebugMode, TraceMode); + return EE; +} + // getPointerToGlobal - This returns the address of the specified global // value. This may involve code generation if it's a function. // @@ -29,7 +45,6 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { return GlobalAddress[GV]; } - GenericValue ExecutionEngine::getConstantValue(const Constant *C) { GenericValue Result; @@ -259,7 +274,6 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, return Result; } - // InitializeMemory - Recursive function to apply a Constant value into the // specified memory location... // diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/lib/ExecutionEngine/Interpreter/Interpreter.cpp index 950e6a57273..6f540e2d1a8 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.cpp +++ b/lib/ExecutionEngine/Interpreter/Interpreter.cpp @@ -9,11 +9,9 @@ #include "Interpreter.h" #include "llvm/Module.h" -/// createInterpreter - Create a new interpreter object. This can never fail. +/// create - Create a new interpreter object. This can never fail. /// -ExecutionEngine *ExecutionEngine::createInterpreter(Module *M, - bool DebugMode, - bool TraceMode) { +ExecutionEngine *Interpreter::create(Module *M, bool DebugMode, bool TraceMode){ bool isLittleEndian; switch (M->getEndianness()) { case Module::LittleEndian: isLittleEndian = true; break; diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h index 89581e0fd5f..459904da6db 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -91,8 +91,13 @@ public: bool DebugMode, bool TraceMode); inline ~Interpreter() { CW.setModule(0); } - // getExitCode - return the code that should be the exit code for the lli - // utility. + /// create - Create an interpreter ExecutionEngine. This can never fail. + /// + static ExecutionEngine *create(Module *M, bool DebugMode, bool TraceMode); + + /// getExitCode - return the code that should be the exit code for the lli + /// utility. + /// inline int getExitCode() const { return ExitCode; } /// run - Start execution with the specified function and arguments. diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 57d7b89d8f2..9a2dc1aacb7 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -41,11 +41,10 @@ namespace { #endif /* NO_JITS_ENABLED */ } -/// createJIT - Create an return a new JIT compiler if there is one available -/// for the current target. Otherwise it returns null. +/// create - Create an return a new JIT compiler if there is one available +/// for the current target. Otherwise, return null. /// -ExecutionEngine *ExecutionEngine::createJIT(Module *M) { - +ExecutionEngine *VM::create(Module *M) { TargetMachine* (*TargetMachineAllocator)(const Module &) = 0; // Allow a command-line switch to override what *should* be the default target diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h index e886a194122..764afcf66fe 100644 --- a/lib/ExecutionEngine/JIT/JIT.h +++ b/lib/ExecutionEngine/JIT/JIT.h @@ -26,6 +26,11 @@ public: VM(Module *M, TargetMachine *tm); ~VM(); + /// create - Create an return a new JIT compiler if there is one available + /// for the current target. Otherwise, return null. + /// + static ExecutionEngine *create(Module *M); + /// run - Start execution with the specified function and arguments. /// virtual int run(const std::string &FnName, diff --git a/lib/ExecutionEngine/JIT/VM.h b/lib/ExecutionEngine/JIT/VM.h index e886a194122..764afcf66fe 100644 --- a/lib/ExecutionEngine/JIT/VM.h +++ b/lib/ExecutionEngine/JIT/VM.h @@ -26,6 +26,11 @@ public: VM(Module *M, TargetMachine *tm); ~VM(); + /// create - Create an return a new JIT compiler if there is one available + /// for the current target. Otherwise, return null. + /// + static ExecutionEngine *create(Module *M); + /// run - Start execution with the specified function and arguments. /// virtual int run(const std::string &FnName, diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 3b9414a8773..36af42168ad 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -59,15 +59,9 @@ int main(int argc, char** argv, const char ** envp) { exit(1); } - ExecutionEngine *EE = 0; - - // If there is nothing that is forcing us to use the interpreter, make a JIT. - if (!ForceInterpreter && !DebugMode && !TraceMode) - EE = ExecutionEngine::createJIT(M); - - // If we can't make a JIT, make an interpreter instead. - if (EE == 0) - EE = ExecutionEngine::createInterpreter(M, DebugMode, TraceMode); + ExecutionEngine *EE = + ExecutionEngine::create (M, ForceInterpreter, DebugMode, TraceMode); + assert (EE && "Couldn't create an ExecutionEngine, not even an interpreter?"); // Add the module name to the start of the argv vector... // But delete .bc first, since programs (and users) might not expect to