mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Use iterators in BasicBlock
This commit is contained in:
parent
be7713ac33
commit
f0008a3124
3 changed files with 19 additions and 25 deletions
|
|
@ -20,17 +20,16 @@ namespace jit
|
||||||
|
|
||||||
const char* BasicBlock::NamePrefix = "Instr.";
|
const char* BasicBlock::NamePrefix = "Instr.";
|
||||||
|
|
||||||
BasicBlock::BasicBlock(ProgramCounter _beginInstIdx, ProgramCounter _endInstIdx, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder) :
|
BasicBlock::BasicBlock(bytes::const_iterator _begin, bytes::const_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder) :
|
||||||
m_beginInstIdx(_beginInstIdx),
|
m_begin(_begin),
|
||||||
m_endInstIdx(_endInstIdx),
|
m_end(_end),
|
||||||
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), {NamePrefix, std::to_string(_beginInstIdx)}, _mainFunc)),
|
// TODO: Add begin index to name
|
||||||
|
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), NamePrefix, _mainFunc)),
|
||||||
m_stack(*this),
|
m_stack(*this),
|
||||||
m_builder(_builder)
|
m_builder(_builder)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BasicBlock::BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder) :
|
BasicBlock::BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder) :
|
||||||
m_beginInstIdx(0),
|
|
||||||
m_endInstIdx(0),
|
|
||||||
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), _name, _mainFunc)),
|
m_llvmBB(llvm::BasicBlock::Create(_mainFunc->getContext(), _name, _mainFunc)),
|
||||||
m_stack(*this),
|
m_stack(*this),
|
||||||
m_builder(_builder)
|
m_builder(_builder)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <llvm/IR/BasicBlock.h>
|
#include <llvm/IR/BasicBlock.h>
|
||||||
|
#include "Common.h"
|
||||||
#include "Stack.h"
|
#include "Stack.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
|
|
@ -52,10 +50,10 @@ public:
|
||||||
BasicBlock& m_bblock;
|
BasicBlock& m_bblock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Basic block name prefix. The rest is beging instruction index.
|
/// Basic block name prefix. The rest is instruction index.
|
||||||
static const char* NamePrefix;
|
static const char* NamePrefix;
|
||||||
|
|
||||||
explicit BasicBlock(ProgramCounter _beginInstIdx, ProgramCounter _endInstIdx, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder);
|
explicit BasicBlock(bytes::const_iterator _begin, bytes::const_iterator _end, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder);
|
||||||
explicit BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder);
|
explicit BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder);
|
||||||
|
|
||||||
BasicBlock(const BasicBlock&) = delete;
|
BasicBlock(const BasicBlock&) = delete;
|
||||||
|
|
@ -64,8 +62,8 @@ public:
|
||||||
operator llvm::BasicBlock*() { return m_llvmBB; } // TODO: Remove it
|
operator llvm::BasicBlock*() { return m_llvmBB; } // TODO: Remove it
|
||||||
llvm::BasicBlock* llvm() { return m_llvmBB; }
|
llvm::BasicBlock* llvm() { return m_llvmBB; }
|
||||||
|
|
||||||
ProgramCounter begin() { return m_beginInstIdx; }
|
bytes::const_iterator begin() { return m_begin; }
|
||||||
ProgramCounter end() { return m_endInstIdx; }
|
bytes::const_iterator end() { return m_end; }
|
||||||
|
|
||||||
bool isJumpDest() const { return m_isJumpDest; }
|
bool isJumpDest() const { return m_isJumpDest; }
|
||||||
void markAsJumpDest() { m_isJumpDest = true; }
|
void markAsJumpDest() { m_isJumpDest = true; }
|
||||||
|
|
@ -85,8 +83,8 @@ public:
|
||||||
void dump(std::ostream& os, bool _dotOutput = false);
|
void dump(std::ostream& os, bool _dotOutput = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProgramCounter const m_beginInstIdx;
|
bytes::const_iterator const m_begin;
|
||||||
ProgramCounter const m_endInstIdx;
|
bytes::const_iterator const m_end;
|
||||||
|
|
||||||
llvm::BasicBlock* const m_llvmBB;
|
llvm::BasicBlock* const m_llvmBB;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
return _curr + offset;
|
return _curr + offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
ProgramCounter beginIdx = 0;
|
auto begin = _bytecode.begin();
|
||||||
bool nextJumpDest = false;
|
bool nextJumpDest = false;
|
||||||
for (auto curr = _bytecode.begin(), next = curr; curr != _bytecode.end(); curr = next)
|
for (auto curr = begin, next = begin; curr != _bytecode.end(); curr = next)
|
||||||
{
|
{
|
||||||
next = skipPushDataAndGetNext(curr, _bytecode.end());
|
next = skipPushDataAndGetNext(curr, _bytecode.end());
|
||||||
|
|
||||||
|
|
@ -82,12 +82,12 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
|
|
||||||
if (isEnd)
|
if (isEnd)
|
||||||
{
|
{
|
||||||
auto nextIdx = next - _bytecode.begin();
|
auto beginIdx = begin - _bytecode.begin();
|
||||||
auto p = m_basicBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(beginIdx), std::forward_as_tuple(beginIdx, nextIdx, m_mainFunc, m_builder));
|
auto p = m_basicBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(beginIdx), std::forward_as_tuple(begin, next, m_mainFunc, m_builder));
|
||||||
if (nextJumpDest)
|
if (nextJumpDest)
|
||||||
p.first->second.markAsJumpDest();
|
p.first->second.markAsJumpDest();
|
||||||
nextJumpDest = false;
|
nextJumpDest = false;
|
||||||
beginIdx = nextIdx;
|
begin = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,10 +212,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
m_builder.SetInsertPoint(_basicBlock.llvm());
|
m_builder.SetInsertPoint(_basicBlock.llvm());
|
||||||
auto& stack = _basicBlock.localStack();
|
auto& stack = _basicBlock.localStack();
|
||||||
|
|
||||||
auto begin = _bytecode.begin() + _basicBlock.begin();
|
for (auto it = _basicBlock.begin(); it != _basicBlock.end(); ++it)
|
||||||
auto end = _bytecode.begin() + _basicBlock.end();
|
|
||||||
|
|
||||||
for (auto it = begin; it != end; ++it)
|
|
||||||
{
|
{
|
||||||
auto inst = Instruction(*it);
|
auto inst = Instruction(*it);
|
||||||
|
|
||||||
|
|
@ -479,7 +476,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
|
|
||||||
case Instruction::ANY_PUSH:
|
case Instruction::ANY_PUSH:
|
||||||
{
|
{
|
||||||
auto value = readPushData(it, end);
|
auto value = readPushData(it, _basicBlock.end());
|
||||||
stack.push(Constant::get(value));
|
stack.push(Constant::get(value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue