|
|
@ -76,6 +76,7 @@ cl::opt<CacheMode> g_cache{"cache", cl::desc{"Cache compiled EVM code on disk"}, |
|
|
|
clEnumValN(CacheMode::read, "r", "Read only. No new objects are added to cache."), |
|
|
|
clEnumValN(CacheMode::write, "w", "Write only. No objects are loaded from cache."), |
|
|
|
clEnumValN(CacheMode::clear, "c", "Clear the cache storage. Cache is disabled."), |
|
|
|
clEnumValN(CacheMode::preload, "p", "Preload all cached objects."), |
|
|
|
clEnumValEnd)}; |
|
|
|
cl::opt<bool> g_stats{"st", cl::desc{"Statistics"}}; |
|
|
|
cl::opt<bool> g_dump{"dump", cl::desc{"Dump LLVM IR module"}}; |
|
|
@ -111,8 +112,15 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) |
|
|
|
std::unique_ptr<ExecStats> listener{new ExecStats}; |
|
|
|
listener->stateChanged(ExecState::Started); |
|
|
|
|
|
|
|
bool preloadCache = g_cache == CacheMode::preload; |
|
|
|
if (preloadCache) |
|
|
|
g_cache = CacheMode::on; |
|
|
|
|
|
|
|
// TODO: Do not pseudo-init the cache every time
|
|
|
|
auto objectCache = (g_cache != CacheMode::off && g_cache != CacheMode::clear) ? Cache::getObjectCache(g_cache, listener.get()) : nullptr; |
|
|
|
|
|
|
|
static std::unordered_map<std::string, uint64_t> funcCache; |
|
|
|
|
|
|
|
static std::unique_ptr<llvm::ExecutionEngine> ee; |
|
|
|
if (!ee) |
|
|
|
{ |
|
|
@ -138,6 +146,9 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) |
|
|
|
return ReturnCode::LLVMConfigError; |
|
|
|
module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module
|
|
|
|
ee->setObjectCache(objectCache); |
|
|
|
|
|
|
|
if (preloadCache) |
|
|
|
Cache::preload(*ee, funcCache); |
|
|
|
} |
|
|
|
|
|
|
|
static StatsCollector statsCollector; |
|
|
@ -146,10 +157,9 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) |
|
|
|
m_runtime.init(_data, _env); |
|
|
|
|
|
|
|
EntryFuncPtr entryFuncPtr = nullptr; |
|
|
|
static std::unordered_map<std::string, EntryFuncPtr> funcCache; |
|
|
|
auto it = funcCache.find(mainFuncName); |
|
|
|
if (it != funcCache.end()) |
|
|
|
entryFuncPtr = it->second; |
|
|
|
entryFuncPtr = (EntryFuncPtr) it->second; |
|
|
|
|
|
|
|
if (!entryFuncPtr) |
|
|
|
{ |
|
|
@ -177,7 +187,8 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) |
|
|
|
if (!CHECK(entryFuncPtr)) |
|
|
|
return ReturnCode::LLVMLinkError; |
|
|
|
|
|
|
|
funcCache[mainFuncName] = entryFuncPtr; |
|
|
|
if (it == funcCache.end()) |
|
|
|
funcCache[mainFuncName] = (uint64_t) entryFuncPtr; |
|
|
|
|
|
|
|
listener->stateChanged(ExecState::Execution); |
|
|
|
auto returnCode = entryFuncPtr(&m_runtime); |
|
|
|