You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
842 B
49 lines
842 B
#include "Cache.h"
|
|
#include <unordered_map>
|
|
#include <cassert>
|
|
#include <iostream>
|
|
|
|
namespace dev
|
|
{
|
|
namespace eth
|
|
{
|
|
namespace jit
|
|
{
|
|
namespace
|
|
{
|
|
using CacheMap = std::unordered_map<Cache::Key, ExecBundle>;
|
|
|
|
CacheMap& getCacheMap()
|
|
{
|
|
static CacheMap map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
#define LOG(...) std::cerr << "CACHE "
|
|
|
|
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\n";
|
|
return r.first->second; // return exec, now owned by cache
|
|
}
|
|
|
|
ExecBundle* Cache::findExec(Cache::Key _key)
|
|
{
|
|
auto& map = getCacheMap();
|
|
auto it = map.find(_key);
|
|
if (it != map.end())
|
|
{
|
|
LOG() << "hit\n";
|
|
return &it->second;
|
|
}
|
|
LOG() << "miss\n";
|
|
return nullptr;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|