mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Clean up ExecutionEngine
This commit is contained in:
parent
de024259c2
commit
28a062318c
3 changed files with 3 additions and 76 deletions
|
|
@ -10,42 +10,10 @@ 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 "
|
||||
#define LOG(...) std::ostream(nullptr)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ObjectCache* Cache::getObjectCache()
|
||||
{
|
||||
static ObjectCache objectCache;
|
||||
|
|
|
|||
|
|
@ -13,24 +13,6 @@ namespace eth
|
|||
namespace jit
|
||||
{
|
||||
|
||||
/// A bundle of objects and information needed for a contract execution
|
||||
class ExecBundle
|
||||
{
|
||||
public:
|
||||
llvm::ExecutionEngine* engine = nullptr;
|
||||
std::string mainFuncName;
|
||||
|
||||
ExecBundle() = default;
|
||||
ExecBundle(ExecBundle&& _other):
|
||||
engine(std::move(_other.engine)),
|
||||
mainFuncName(std::move(_other.mainFuncName))
|
||||
{}
|
||||
|
||||
ExecBundle(ExecBundle const&) = delete;
|
||||
void operator=(ExecBundle) = delete;
|
||||
};
|
||||
|
||||
|
||||
class ObjectCache : public llvm::ObjectCache
|
||||
{
|
||||
public:
|
||||
|
|
@ -51,11 +33,6 @@ private:
|
|||
class Cache
|
||||
{
|
||||
public:
|
||||
using Key = std::string;
|
||||
|
||||
static ExecBundle& registerExec(Key _key, ExecBundle&& _exec);
|
||||
static ExecBundle* findExec(Key _key);
|
||||
|
||||
static ObjectCache* getObjectCache();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,6 @@
|
|||
|
||||
#include <chrono>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#include <llvm/IR/LLVMContext.h>
|
||||
#include <llvm/IR/Module.h>
|
||||
#include <llvm/ADT/Triple.h>
|
||||
#include <llvm/ExecutionEngine/ExecutionEngine.h>
|
||||
|
|
@ -13,12 +9,8 @@
|
|||
#include <llvm/ExecutionEngine/GenericValue.h>
|
||||
#include <llvm/ExecutionEngine/MCJIT.h>
|
||||
#include <llvm/Support/TargetSelect.h>
|
||||
#include <llvm/Support/Signals.h>
|
||||
#include <llvm/Support/PrettyStackTrace.h>
|
||||
#include <llvm/Support/Host.h>
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "Runtime.h"
|
||||
#include "Memory.h"
|
||||
#include "Stack.h"
|
||||
|
|
@ -42,7 +34,6 @@ ReturnCode ExecutionEngine::run(bytes const& _code, RuntimeData* _data, Env* _en
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
typedef ReturnCode(*EntryFuncPtr)(Runtime*);
|
||||
|
||||
ReturnCode runEntryFunc(EntryFuncPtr _mainFunc, Runtime* _runtime)
|
||||
|
|
@ -59,7 +50,6 @@ ReturnCode runEntryFunc(EntryFuncPtr _mainFunc, Runtime* _runtime)
|
|||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeData* _data, Env* _env, bytes const& _code)
|
||||
|
|
@ -72,12 +62,8 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
|
|||
static std::unique_ptr<llvm::ExecutionEngine> ee; // TODO: Use Managed Objects from LLVM?
|
||||
|
||||
EntryFuncPtr entryFuncPtr{};
|
||||
|
||||
|
||||
|
||||
Runtime runtime(_data, _env);
|
||||
|
||||
auto&& mainFuncName = _module->getModuleIdentifier();
|
||||
Runtime runtime(_data, _env); // TODO: I don't know why but it must be created before getFunctionAddress() calls
|
||||
|
||||
if (!ee)
|
||||
{
|
||||
|
|
@ -118,22 +104,18 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
|
|||
}
|
||||
assert(entryFuncPtr);
|
||||
|
||||
|
||||
auto executionStartTime = std::chrono::high_resolution_clock::now();
|
||||
//auto mainFunc = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName);
|
||||
|
||||
auto returnCode = runEntryFunc(entryFuncPtr, &runtime);
|
||||
if (returnCode == ReturnCode::Return)
|
||||
this->returnData = runtime.getReturnData();
|
||||
|
||||
auto executionEndTime = std::chrono::high_resolution_clock::now();
|
||||
clog(JIT) << " + " << std::chrono::duration_cast<std::chrono::milliseconds>(executionEndTime - executionStartTime).count() << " ms ";
|
||||
|
||||
clog(JIT) << "\n";
|
||||
clog(JIT) << " + " << std::chrono::duration_cast<std::chrono::milliseconds>(executionEndTime - executionStartTime).count() << " ms\n";
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue