Browse Source

Cache key is contract code. Does not work

cl-refactor
Paweł Bylica 10 years ago
parent
commit
da02a1869d
  1. 2
      evmcc/evmcc.cpp
  2. 6
      libevmjit/Cache.cpp
  3. 10
      libevmjit/Cache.h
  4. 10
      libevmjit/ExecutionEngine.cpp
  5. 4
      libevmjit/ExecutionEngine.h

2
evmcc/evmcc.cpp

@ -196,7 +196,7 @@ int main(int argc, char** argv)
data.code = bytecode.data();
// BROKEN: env_* functions must be implemented & RuntimeData struct created
auto result = engine.run(std::move(module), &data, nullptr);
auto result = engine.run(std::move(module), &data, nullptr, bytecode);
return static_cast<int>(result);
}
}

6
libevmjit/Cache.cpp

@ -27,7 +27,7 @@ ExecBundle& Cache::registerExec(Cache::Key _key, ExecBundle&& _exec)
auto& map = getCacheMap();
auto r = map.insert(std::make_pair(_key, std::move(_exec)));
assert(r.second && "Updating cached objects not supported");
LOG() << "add " << _key << "\n";
LOG() << "add\n";
return r.first->second; // return exec, now owned by cache
}
@ -37,10 +37,10 @@ ExecBundle* Cache::findExec(Cache::Key _key)
auto it = map.find(_key);
if (it != map.end())
{
LOG() << "hit " << _key << "\n";
LOG() << "hit\n";
return &it->second;
}
LOG() << "miss " << _key << "\n";
LOG() << "miss\n";
return nullptr;
}

10
libevmjit/Cache.h

@ -12,16 +12,22 @@ namespace jit
{
/// A bundle of objects and information needed for a contract execution
struct ExecBundle
class ExecBundle
{
public:
std::unique_ptr<llvm::ExecutionEngine> engine;
llvm::Function* entryFunc = nullptr;
ExecBundle() = default;
ExecBundle(ExecBundle&&) = default;
ExecBundle(ExecBundle const&) = delete;
void operator=(ExecBundle) = delete;
};
class Cache
{
public:
using Key = void const*;
using Key = std::string;
static ExecBundle& registerExec(Key _key, ExecBundle&& _exec);
static ExecBundle* findExec(Key _key);

10
libevmjit/ExecutionEngine.cpp

@ -36,13 +36,13 @@ namespace jit
ReturnCode ExecutionEngine::run(bytes const& _code, RuntimeData* _data, Env* _env)
{
auto module = Compiler({}).compile(_code);
return run(std::move(module), _data, _env);
return run(std::move(module), _data, _env, _code);
}
ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env)
ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env, bytes const& _code)
{
auto key = _data->code; // TODO: Change cache key
if (auto cachedExec = Cache::findExec(key))
std::string key{reinterpret_cast<char const*>(_code.data()), _code.size()};
if (auto cachedExec = Cache::findExec(std::move(key)))
{
return run(*cachedExec, _data, _env);
}
@ -94,7 +94,7 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
if (!exec.entryFunc)
return ReturnCode::LLVMLinkError;
auto& cachedExec = Cache::registerExec(_data->code, std::move(exec));
auto& cachedExec = Cache::registerExec(key, std::move(exec));
auto returnCode = run(cachedExec, _data, _env);
auto executionEndTime = std::chrono::high_resolution_clock::now();

4
libevmjit/ExecutionEngine.h

@ -13,7 +13,7 @@ namespace eth
{
namespace jit
{
struct ExecBundle;
class ExecBundle;
class ExecutionEngine
{
@ -23,7 +23,7 @@ public:
void operator=(ExecutionEngine) = delete;
ReturnCode run(bytes const& _code, RuntimeData* _data, Env* _env);
ReturnCode run(std::unique_ptr<llvm::Module> module, RuntimeData* _data, Env* _env);
ReturnCode run(std::unique_ptr<llvm::Module> module, RuntimeData* _data, Env* _env, bytes const& _code);
bytes returnData;

Loading…
Cancel
Save