|
@ -1,6 +1,7 @@ |
|
|
#include "evmjit/JIT.h" |
|
|
#include "evmjit/JIT.h" |
|
|
|
|
|
|
|
|
#include <array> |
|
|
#include <array> |
|
|
|
|
|
#include <mutex> |
|
|
|
|
|
|
|
|
#include "preprocessor/llvm_includes_start.h" |
|
|
#include "preprocessor/llvm_includes_start.h" |
|
|
#include <llvm/IR/Module.h> |
|
|
#include <llvm/IR/Module.h> |
|
@ -82,6 +83,7 @@ void parseOptions() |
|
|
class JITImpl |
|
|
class JITImpl |
|
|
{ |
|
|
{ |
|
|
std::unique_ptr<llvm::ExecutionEngine> m_engine; |
|
|
std::unique_ptr<llvm::ExecutionEngine> m_engine; |
|
|
|
|
|
mutable std::mutex x_codeMap; |
|
|
std::unordered_map<h256, ExecFunc> m_codeMap; |
|
|
std::unordered_map<h256, ExecFunc> m_codeMap; |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
@ -136,6 +138,7 @@ JITImpl::JITImpl() |
|
|
|
|
|
|
|
|
ExecFunc JITImpl::getExecFunc(h256 const& _codeHash) const |
|
|
ExecFunc JITImpl::getExecFunc(h256 const& _codeHash) const |
|
|
{ |
|
|
{ |
|
|
|
|
|
std::lock_guard<std::mutex> lock{x_codeMap}; |
|
|
auto it = m_codeMap.find(_codeHash); |
|
|
auto it = m_codeMap.find(_codeHash); |
|
|
if (it != m_codeMap.end()) |
|
|
if (it != m_codeMap.end()) |
|
|
return it->second; |
|
|
return it->second; |
|
@ -144,6 +147,7 @@ ExecFunc JITImpl::getExecFunc(h256 const& _codeHash) const |
|
|
|
|
|
|
|
|
void JITImpl::mapExecFunc(h256 _codeHash, ExecFunc _funcAddr) |
|
|
void JITImpl::mapExecFunc(h256 _codeHash, ExecFunc _funcAddr) |
|
|
{ |
|
|
{ |
|
|
|
|
|
std::lock_guard<std::mutex> lock{x_codeMap}; |
|
|
m_codeMap.emplace(std::move(_codeHash), _funcAddr); |
|
|
m_codeMap.emplace(std::move(_codeHash), _funcAddr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -181,6 +185,14 @@ bool JIT::isCodeReady(h256 const& _codeHash) |
|
|
return JITImpl::instance().getExecFunc(_codeHash) != nullptr; |
|
|
return JITImpl::instance().getExecFunc(_codeHash) != nullptr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void JIT::compile(byte const* _code, uint64_t _codeSize, h256 const& _codeHash) |
|
|
|
|
|
{ |
|
|
|
|
|
auto& jit = JITImpl::instance(); |
|
|
|
|
|
auto execFunc = jit.compile(_code, _codeSize, _codeHash); |
|
|
|
|
|
if (execFunc) // FIXME: What with error?
|
|
|
|
|
|
jit.mapExecFunc(_codeHash, execFunc); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ReturnCode JIT::exec(ExecutionContext& _context) |
|
|
ReturnCode JIT::exec(ExecutionContext& _context) |
|
|
{ |
|
|
{ |
|
|
//std::unique_ptr<ExecStats> listener{new ExecStats};
|
|
|
//std::unique_ptr<ExecStats> listener{new ExecStats};
|
|
|