Browse Source

Use code (and code size) as constants

cl-refactor
Paweł Bylica 10 years ago
parent
commit
99b7607ae2
  1. 2
      evmjit/libevmjit/Compiler.cpp
  2. 1
      evmjit/libevmjit/ExecutionEngine.cpp
  3. 13
      evmjit/libevmjit/RuntimeManager.cpp
  4. 7
      evmjit/libevmjit/RuntimeManager.h

2
evmjit/libevmjit/Compiler.cpp

@ -142,7 +142,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_itera
createBasicBlocks(_begin, _end);
// Init runtime structures.
RuntimeManager runtimeManager(m_builder);
RuntimeManager runtimeManager(m_builder, _begin, _end);
GasMeter gasMeter(m_builder, runtimeManager);
Memory memory(runtimeManager, gasMeter);
Ext ext(runtimeManager, memory);

1
evmjit/libevmjit/ExecutionEngine.cpp

@ -174,6 +174,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
std::unique_ptr<llvm::SectionMemoryManager> memoryManager(new llvm::SectionMemoryManager);
builder.setMCJITMemoryManager(memoryManager.get());
builder.setOptLevel(llvm::CodeGenOpt::None);
builder.setVerifyModules(true);
auto triple = llvm::Triple(llvm::sys::getProcessTriple());
if (triple.getOS() == llvm::Triple::OSType::Win32)

13
evmjit/libevmjit/RuntimeManager.cpp

@ -87,7 +87,10 @@ llvm::Twine getName(RuntimeData::Index _index)
}
}
RuntimeManager::RuntimeManager(llvm::IRBuilder<>& _builder): CompilerHelper(_builder)
RuntimeManager::RuntimeManager(llvm::IRBuilder<>& _builder, code_iterator _codeBegin, code_iterator _codeEnd):
CompilerHelper(_builder),
m_codeBegin(_codeBegin),
m_codeEnd(_codeEnd)
{
m_longjmp = llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::longjmp);
@ -191,14 +194,14 @@ llvm::Value* RuntimeManager::getCallData()
llvm::Value* RuntimeManager::getCode()
{
return get(RuntimeData::Code);
// OPT Check what is faster
//return get(RuntimeData::Code);
return m_builder.CreateGlobalStringPtr({reinterpret_cast<char const*>(m_codeBegin), static_cast<size_t>(m_codeEnd - m_codeBegin)}, "code");
}
llvm::Value* RuntimeManager::getCodeSize()
{
auto value = get(RuntimeData::CodeSize);
assert(value->getType() == Type::Size);
return getBuilder().CreateZExt(value, Type::Word);
return Constant::get(m_codeEnd - m_codeBegin);
}
llvm::Value* RuntimeManager::getCallDataSize()

7
evmjit/libevmjit/RuntimeManager.h

@ -15,11 +15,11 @@ namespace jit
class RuntimeManager: public CompilerHelper
{
public:
RuntimeManager(llvm::IRBuilder<>& _builder);
RuntimeManager(llvm::IRBuilder<>& _builder, code_iterator _codeBegin, code_iterator _codeEnd);
llvm::Value* getRuntimePtr();
llvm::Value* getDataPtr();
llvm::Value* getEnvPtr(); // TODO: Can we make it const?
llvm::Value* getEnvPtr();
llvm::Value* get(RuntimeData::Index _index);
llvm::Value* get(Instruction _inst);
@ -47,6 +47,9 @@ private:
llvm::Function* m_longjmp = nullptr;
llvm::Value* m_dataPtr = nullptr;
llvm::Value* m_envPtr = nullptr;
code_iterator m_codeBegin = {};
code_iterator m_codeEnd = {};
};
}

Loading…
Cancel
Save