mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Refactor / rename
This commit is contained in:
parent
bb37986cad
commit
098632804d
3 changed files with 15 additions and 15 deletions
|
|
@ -61,7 +61,7 @@ public:
|
||||||
BasicBlock(const BasicBlock&) = delete;
|
BasicBlock(const BasicBlock&) = delete;
|
||||||
void operator=(const BasicBlock&) = delete;
|
void operator=(const BasicBlock&) = delete;
|
||||||
|
|
||||||
operator llvm::BasicBlock*() { return m_llvmBB; }
|
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; }
|
ProgramCounter begin() { return m_beginInstIdx; }
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
if (isEnd)
|
if (isEnd)
|
||||||
{
|
{
|
||||||
auto nextIdx = next - _bytecode.begin();
|
auto nextIdx = next - _bytecode.begin();
|
||||||
auto p = 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(beginIdx, nextIdx, m_mainFunc, m_builder));
|
||||||
if (nextJumpDest)
|
if (nextJumpDest)
|
||||||
p.first->second.markAsJumpDest();
|
p.first->second.markAsJumpDest();
|
||||||
nextJumpDest = false;
|
nextJumpDest = false;
|
||||||
|
|
@ -103,7 +103,7 @@ llvm::BasicBlock* Compiler::getJumpTableBlock()
|
||||||
m_builder.SetInsertPoint(m_jumpTableBlock->llvm());
|
m_builder.SetInsertPoint(m_jumpTableBlock->llvm());
|
||||||
auto dest = m_jumpTableBlock->localStack().pop();
|
auto dest = m_jumpTableBlock->localStack().pop();
|
||||||
auto switchInstr = m_builder.CreateSwitch(dest, getBadJumpBlock());
|
auto switchInstr = m_builder.CreateSwitch(dest, getBadJumpBlock());
|
||||||
for (auto&& p : basicBlocks)
|
for (auto&& p : m_basicBlocks)
|
||||||
{
|
{
|
||||||
if (p.second.isJumpDest())
|
if (p.second.isJumpDest())
|
||||||
switchInstr->addCase(Constant::get(p.first), p.second.llvm());
|
switchInstr->addCase(Constant::get(p.first), p.second.llvm());
|
||||||
|
|
@ -148,14 +148,14 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode, std::str
|
||||||
Stack stack(m_builder, runtimeManager);
|
Stack stack(m_builder, runtimeManager);
|
||||||
Arith256 arith(m_builder);
|
Arith256 arith(m_builder);
|
||||||
|
|
||||||
m_builder.CreateBr(basicBlocks.empty() ? m_stopBB : basicBlocks.begin()->second);
|
m_builder.CreateBr(m_basicBlocks.empty() ? m_stopBB : m_basicBlocks.begin()->second);
|
||||||
|
|
||||||
for (auto basicBlockPairIt = basicBlocks.begin(); basicBlockPairIt != basicBlocks.end(); ++basicBlockPairIt)
|
for (auto basicBlockPairIt = m_basicBlocks.begin(); basicBlockPairIt != m_basicBlocks.end(); ++basicBlockPairIt)
|
||||||
{
|
{
|
||||||
auto& basicBlock = basicBlockPairIt->second;
|
auto& basicBlock = basicBlockPairIt->second;
|
||||||
auto iterCopy = basicBlockPairIt;
|
auto iterCopy = basicBlockPairIt;
|
||||||
++iterCopy;
|
++iterCopy;
|
||||||
auto nextBasicBlock = (iterCopy != basicBlocks.end()) ? iterCopy->second.llvm() : nullptr;
|
auto nextBasicBlock = (iterCopy != m_basicBlocks.end()) ? iterCopy->second.llvm() : nullptr;
|
||||||
compileBasicBlock(basicBlock, _bytecode, runtimeManager, arith, memory, ext, gasMeter, nextBasicBlock);
|
compileBasicBlock(basicBlock, _bytecode, runtimeManager, arith, memory, ext, gasMeter, nextBasicBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode, std::str
|
||||||
if (m_options.optimizeStack)
|
if (m_options.optimizeStack)
|
||||||
{
|
{
|
||||||
std::vector<BasicBlock*> blockList;
|
std::vector<BasicBlock*> blockList;
|
||||||
for (auto& entry : basicBlocks)
|
for (auto& entry : m_basicBlocks)
|
||||||
blockList.push_back(&entry.second);
|
blockList.push_back(&entry.second);
|
||||||
|
|
||||||
if (m_jumpTableBlock)
|
if (m_jumpTableBlock)
|
||||||
|
|
@ -182,7 +182,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode, std::str
|
||||||
dumpCFGifRequired("blocks-opt.dot");
|
dumpCFGifRequired("blocks-opt.dot");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& entry : basicBlocks)
|
for (auto& entry : m_basicBlocks)
|
||||||
entry.second.synchronizeLocalStack(stack);
|
entry.second.synchronizeLocalStack(stack);
|
||||||
if (m_jumpTableBlock)
|
if (m_jumpTableBlock)
|
||||||
m_jumpTableBlock->synchronizeLocalStack(stack);
|
m_jumpTableBlock->synchronizeLocalStack(stack);
|
||||||
|
|
@ -557,8 +557,8 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
if (c.ult(_bytecode.size()))
|
if (c.ult(_bytecode.size()))
|
||||||
{
|
{
|
||||||
auto v = c.getZExtValue();
|
auto v = c.getZExtValue();
|
||||||
auto it = basicBlocks.find(v);
|
auto it = m_basicBlocks.find(v);
|
||||||
if (it != basicBlocks.end() && it->second.isJumpDest())
|
if (it != m_basicBlocks.end() && it->second.isJumpDest())
|
||||||
targetBlock = it->second.llvm();
|
targetBlock = it->second.llvm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -825,13 +825,13 @@ void Compiler::removeDeadBlocks()
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
sthErased = false;
|
sthErased = false;
|
||||||
for (auto it = basicBlocks.begin(); it != basicBlocks.end();)
|
for (auto it = m_basicBlocks.begin(); it != m_basicBlocks.end();)
|
||||||
{
|
{
|
||||||
auto llvmBB = it->second.llvm();
|
auto llvmBB = it->second.llvm();
|
||||||
if (llvm::pred_begin(llvmBB) == llvm::pred_end(llvmBB))
|
if (llvm::pred_begin(llvmBB) == llvm::pred_end(llvmBB))
|
||||||
{
|
{
|
||||||
llvmBB->eraseFromParent();
|
llvmBB->eraseFromParent();
|
||||||
basicBlocks.erase(it++);
|
m_basicBlocks.erase(it++);
|
||||||
sthErased = true;
|
sthErased = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -859,7 +859,7 @@ void Compiler::dumpCFGtoStream(std::ostream& _out)
|
||||||
<< " entry [share=record, label=\"entry block\"];\n";
|
<< " entry [share=record, label=\"entry block\"];\n";
|
||||||
|
|
||||||
std::vector<BasicBlock*> blocks;
|
std::vector<BasicBlock*> blocks;
|
||||||
for (auto& pair : basicBlocks)
|
for (auto& pair : m_basicBlocks)
|
||||||
blocks.push_back(&pair.second);
|
blocks.push_back(&pair.second);
|
||||||
if (m_jumpTableBlock)
|
if (m_jumpTableBlock)
|
||||||
blocks.push_back(m_jumpTableBlock.get());
|
blocks.push_back(m_jumpTableBlock.get());
|
||||||
|
|
@ -898,7 +898,7 @@ void Compiler::dumpCFGtoStream(std::ostream& _out)
|
||||||
|
|
||||||
void Compiler::dump()
|
void Compiler::dump()
|
||||||
{
|
{
|
||||||
for (auto& entry : basicBlocks)
|
for (auto& entry : m_basicBlocks)
|
||||||
entry.second.dump();
|
entry.second.dump();
|
||||||
if (m_jumpTableBlock != nullptr)
|
if (m_jumpTableBlock != nullptr)
|
||||||
m_jumpTableBlock->dump();
|
m_jumpTableBlock->dump();
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ private:
|
||||||
llvm::IRBuilder<> m_builder;
|
llvm::IRBuilder<> m_builder;
|
||||||
|
|
||||||
/// Maps a program counter pc to a basic block that starts at pc (if any).
|
/// Maps a program counter pc to a basic block that starts at pc (if any).
|
||||||
std::map<ProgramCounter, BasicBlock> basicBlocks;
|
std::map<ProgramCounter, BasicBlock> m_basicBlocks;
|
||||||
|
|
||||||
/// Stop basic block - terminates execution with STOP code (0)
|
/// Stop basic block - terminates execution with STOP code (0)
|
||||||
llvm::BasicBlock* m_stopBB = nullptr;
|
llvm::BasicBlock* m_stopBB = nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue