Browse Source

Fix cache key and do not compile to LLVM module when it is not needed

cl-refactor
Paweł Bylica 10 years ago
parent
commit
70348d9586
  1. 5
      libevmjit/Cache.h
  2. 13
      libevmjit/ExecutionEngine.cpp
  3. 2
      libevmjit/Utils.h

5
libevmjit/Cache.h

@ -19,7 +19,10 @@ public:
llvm::Function* entryFunc = nullptr; llvm::Function* entryFunc = nullptr;
ExecBundle() = default; ExecBundle() = default;
ExecBundle(ExecBundle&&) = default; ExecBundle(ExecBundle&& _other):
engine(std::move(_other.engine)),
entryFunc(_other.entryFunc) {}
ExecBundle(ExecBundle const&) = delete; ExecBundle(ExecBundle const&) = delete;
void operator=(ExecBundle) = delete; void operator=(ExecBundle) = delete;
}; };

13
libevmjit/ExecutionEngine.cpp

@ -35,18 +35,18 @@ namespace jit
ReturnCode ExecutionEngine::run(bytes const& _code, RuntimeData* _data, Env* _env) ReturnCode ExecutionEngine::run(bytes const& _code, RuntimeData* _data, Env* _env)
{ {
std::string key{reinterpret_cast<char const*>(_code.data()), _code.size()};
if (auto cachedExec = Cache::findExec(key))
{
return run(*cachedExec, _data, _env);
}
auto module = Compiler({}).compile(_code); auto module = Compiler({}).compile(_code);
return run(std::move(module), _data, _env, _code); return run(std::move(module), _data, _env, _code);
} }
ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env, bytes const& _code) ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env, bytes const& _code)
{ {
std::string key{reinterpret_cast<char const*>(_code.data()), _code.size()};
if (auto cachedExec = Cache::findExec(std::move(key)))
{
return run(*cachedExec, _data, _env);
}
auto module = _module.get(); // Keep ownership of the module in _module auto module = _module.get(); // Keep ownership of the module in _module
llvm::sys::PrintStackTraceOnErrorSignal(); llvm::sys::PrintStackTraceOnErrorSignal();
@ -94,6 +94,7 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
if (!exec.entryFunc) if (!exec.entryFunc)
return ReturnCode::LLVMLinkError; return ReturnCode::LLVMLinkError;
std::string key{reinterpret_cast<char const*>(_code.data()), _code.size()};
auto& cachedExec = Cache::registerExec(key, std::move(exec)); auto& cachedExec = Cache::registerExec(key, std::move(exec));
auto returnCode = run(cachedExec, _data, _env); auto returnCode = run(cachedExec, _data, _env);

2
libevmjit/Utils.h

@ -12,7 +12,7 @@ namespace jit
struct JIT: public NoteChannel { static const char* name() { return "JIT"; } }; struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
//#define clog(CHANNEL) std::cerr //#define clog(CHANNEL) std::cerr
#define clog(CHANNEL) std::ostream({}) #define clog(CHANNEL) std::ostream(nullptr)
u256 llvm2eth(i256); u256 llvm2eth(i256);
i256 eth2llvm(u256); i256 eth2llvm(u256);

Loading…
Cancel
Save