mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
Stack cleanups
This commit is contained in:
parent
a338b88588
commit
1cbb9d57aa
3 changed files with 20 additions and 16 deletions
|
|
@ -186,7 +186,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
||||||
auto ext = Ext(builder, module.get());
|
auto ext = Ext(builder, module.get());
|
||||||
|
|
||||||
BasicBlock* currentBlock = &basicBlocks.find(0)->second; // Any value, just to create branch for %entry to %Instr.0
|
BasicBlock* currentBlock = &basicBlocks.find(0)->second; // Any value, just to create branch for %entry to %Instr.0
|
||||||
BBStack stack(builder, extStack); // Stack for current block
|
BBStack stack; // Stack for current block
|
||||||
|
|
||||||
for (auto pc = bytecode.cbegin(); pc != bytecode.cend(); ++pc)
|
for (auto pc = bytecode.cbegin(); pc != bytecode.cend(); ++pc)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,6 @@
|
||||||
namespace evmcc
|
namespace evmcc
|
||||||
{
|
{
|
||||||
|
|
||||||
BBStack::BBStack(llvm::IRBuilder<>& _builder, Stack& _extStack):
|
|
||||||
m_extStack(_extStack),
|
|
||||||
m_builder(_builder)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void BBStack::push(llvm::Value* _value)
|
void BBStack::push(llvm::Value* _value)
|
||||||
{
|
{
|
||||||
m_block->getState().push_back(_value);
|
m_block->getState().push_back(_value);
|
||||||
|
|
@ -37,11 +32,11 @@ llvm::Value* BBStack::pop()
|
||||||
if (state.empty())
|
if (state.empty())
|
||||||
{
|
{
|
||||||
// Create PHI node
|
// Create PHI node
|
||||||
auto first = m_block->llvm()->getFirstNonPHI();
|
auto i256Ty = llvm::Type::getIntNTy(m_block->llvm()->getContext(), 256);
|
||||||
auto llvmBB = m_block->llvm();
|
auto llvmBB = m_block->llvm();
|
||||||
if (llvmBB->getInstList().empty())
|
if (llvmBB->getInstList().empty())
|
||||||
return llvm::PHINode::Create(m_builder.getIntNTy(256), 0, {}, m_block->llvm());
|
return llvm::PHINode::Create(i256Ty, 0, {}, m_block->llvm());
|
||||||
return llvm::PHINode::Create(m_builder.getIntNTy(256), 0, {}, llvmBB->getFirstNonPHI());
|
return llvm::PHINode::Create(i256Ty, 0, {}, llvmBB->getFirstNonPHI());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto top = state.back();
|
auto top = state.back();
|
||||||
|
|
|
||||||
|
|
@ -37,22 +37,31 @@ private:
|
||||||
class BBStack
|
class BBStack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BBStack(llvm::IRBuilder<>& _builder, Stack& _extStack);
|
BBStack() = default;
|
||||||
|
BBStack(const BBStack&) = delete;
|
||||||
void push(llvm::Value* _value);
|
void operator=(const BBStack&) = delete;
|
||||||
llvm::Value* pop();
|
|
||||||
void dup(size_t _index);
|
|
||||||
void swap(size_t _index);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Changes current basic block with a new one with empty state.
|
Changes current basic block (if any) with a new one with empty state.
|
||||||
*/
|
*/
|
||||||
void setBasicBlock(BasicBlock& _newBlock);
|
void setBasicBlock(BasicBlock& _newBlock);
|
||||||
|
|
||||||
|
void push(llvm::Value* _value);
|
||||||
|
llvm::Value* pop();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Duplicates _index'th value on stack.
|
||||||
|
*/
|
||||||
|
void dup(size_t _index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Swaps _index'th value on stack with a value on stack top.
|
||||||
|
@param _index Index of value to be swaped. Cannot be 0.
|
||||||
|
*/
|
||||||
|
void swap(size_t _index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stack& m_extStack; ///< External (global) stack
|
|
||||||
BasicBlock* m_block = nullptr; ///< Current basic block
|
BasicBlock* m_block = nullptr; ///< Current basic block
|
||||||
llvm::IRBuilder<>& m_builder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue