Browse Source

Add first instruction index to BasicBlock

cl-refactor
Paweł Bylica 10 years ago
parent
commit
27ca018c35
  1. 1
      CMakeLists.txt
  2. 9
      libevmjit/BasicBlock.cpp
  3. 17
      libevmjit/BasicBlock.h
  4. 5
      libevmjit/Compiler.cpp
  5. 2
      libevmjit/Compiler.h

1
CMakeLists.txt

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(evmjit)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_AUTOMOC OFF)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
else()

9
libevmjit/BasicBlock.cpp

@ -18,13 +18,14 @@ namespace eth
namespace jit
{
const char* BasicBlock::NamePrefix = "Instr.";
static const char* jumpDestName = "JmpDst.";
static const char* basicBlockName = "Instr.";
BasicBlock::BasicBlock(code_iterator _begin, code_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest) :
BasicBlock::BasicBlock(instr_idx _firstInstrIdx, code_iterator _begin, code_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest) :
m_firstInstrIdx{_firstInstrIdx},
m_begin(_begin),
m_end(_end),
// TODO: Add begin index to name
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), NamePrefix, _mainFunc)),
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), {isJumpDest ? jumpDestName : basicBlockName, std::to_string(_firstInstrIdx)}, _mainFunc)),
m_stack(*this),
m_builder(_builder),
m_isJumpDest(isJumpDest)

17
libevmjit/BasicBlock.h

@ -11,7 +11,7 @@ namespace eth
namespace jit
{
using ProgramCounter = uint64_t; // TODO: Rename
using instr_idx = uint64_t;
class BasicBlock
{
@ -50,10 +50,7 @@ public:
BasicBlock& m_bblock;
};
/// Basic block name prefix. The rest is instruction index.
static const char* NamePrefix;
explicit BasicBlock(code_iterator _begin, code_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest);
explicit BasicBlock(instr_idx _firstInstrIdx, code_iterator _begin, code_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest);
explicit BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest);
BasicBlock(const BasicBlock&) = delete;
@ -61,8 +58,9 @@ public:
llvm::BasicBlock* llvm() { return m_llvmBB; }
code_iterator begin() { return m_begin; }
code_iterator end() { return m_end; }
instr_idx firstInstrIdx() const { return m_firstInstrIdx; }
code_iterator begin() const { return m_begin; }
code_iterator end() const { return m_end; }
bool isJumpDest() const { return m_isJumpDest; }
@ -84,8 +82,9 @@ public:
void dump(std::ostream& os, bool _dotOutput = false);
private:
code_iterator const m_begin = {};
code_iterator const m_end = {};
instr_idx const m_firstInstrIdx = 0; ///< Code index of first instruction in the block
code_iterator const m_begin = {}; ///< Iterator pointing code beginning of the block
code_iterator const m_end = {}; ///< Iterator pointing code end of the block
llvm::BasicBlock* const m_llvmBB;

5
libevmjit/Compiler.cpp

@ -85,7 +85,7 @@ void Compiler::createBasicBlocks(code_iterator _codeBegin, code_iterator _codeEn
{
auto beginIdx = begin - _codeBegin;
m_basicBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(beginIdx),
std::forward_as_tuple(begin, next, m_mainFunc, m_builder, nextJumpDest));
std::forward_as_tuple(beginIdx, begin, next, m_mainFunc, m_builder, nextJumpDest));
nextJumpDest = false;
begin = next;
}
@ -138,7 +138,6 @@ std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_itera
auto entryBlock = llvm::BasicBlock::Create(m_builder.getContext(), "entry", m_mainFunc);
m_builder.SetInsertPoint(entryBlock);
m_codeBegin = _begin;
createBasicBlocks(_begin, _end);
// Init runtime structures.
@ -623,7 +622,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti
case Instruction::PC:
{
auto value = Constant::get(it - m_codeBegin);
auto value = Constant::get(it - _basicBlock.begin() + _basicBlock.firstInstrIdx());
stack.push(value);
break;
}

2
libevmjit/Compiler.h

@ -76,8 +76,6 @@ private:
/// Main program function
llvm::Function* m_mainFunc = nullptr;
code_iterator m_codeBegin = {};
};
}

Loading…
Cancel
Save