|
@ -14,12 +14,15 @@ namespace jit |
|
|
using namespace evmjit; |
|
|
using namespace evmjit; |
|
|
using instr_idx = uint64_t; |
|
|
using instr_idx = uint64_t; |
|
|
|
|
|
|
|
|
class BasicBlock |
|
|
class BasicBlock; |
|
|
{ |
|
|
|
|
|
public: |
|
|
|
|
|
class LocalStack |
|
|
class LocalStack |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
LocalStack(BasicBlock& _owner, Stack& _globalStack); |
|
|
|
|
|
LocalStack(LocalStack const&) = delete; |
|
|
|
|
|
void operator=(LocalStack const&) = delete; |
|
|
|
|
|
|
|
|
/// Pushes value on stack
|
|
|
/// Pushes value on stack
|
|
|
void push(llvm::Value* _value); |
|
|
void push(llvm::Value* _value); |
|
|
|
|
|
|
|
@ -34,14 +37,8 @@ public: |
|
|
void swap(size_t _index); |
|
|
void swap(size_t _index); |
|
|
|
|
|
|
|
|
size_t getMaxSize() const { return m_maxSize; } |
|
|
size_t getMaxSize() const { return m_maxSize; } |
|
|
int getDiff() const { return m_bblock.m_tosOffset; } |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
LocalStack(BasicBlock& _owner); |
|
|
|
|
|
LocalStack(LocalStack const&) = delete; |
|
|
|
|
|
void operator=(LocalStack const&) = delete; |
|
|
|
|
|
friend BasicBlock; |
|
|
|
|
|
|
|
|
|
|
|
/// Gets _index'th value from top (counting from 0)
|
|
|
/// Gets _index'th value from top (counting from 0)
|
|
|
llvm::Value* get(size_t _index); |
|
|
llvm::Value* get(size_t _index); |
|
|
|
|
|
|
|
@ -52,9 +49,13 @@ public: |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
BasicBlock& m_bblock; |
|
|
BasicBlock& m_bblock; |
|
|
|
|
|
Stack& m_global; |
|
|
size_t m_maxSize = 0; ///< Max size reached by the stack.
|
|
|
size_t m_maxSize = 0; ///< Max size reached by the stack.
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class BasicBlock |
|
|
|
|
|
{ |
|
|
|
|
|
public: |
|
|
explicit BasicBlock(instr_idx _firstInstrIdx, 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); |
|
|
explicit BasicBlock(std::string _name, llvm::Function* _mainFunc, llvm::IRBuilder<>& _builder, bool isJumpDest); |
|
|
|
|
|
|
|
@ -72,7 +73,7 @@ public: |
|
|
llvm::Value* getJumpTarget() const { return m_jumpTarget; } |
|
|
llvm::Value* getJumpTarget() const { return m_jumpTarget; } |
|
|
void setJumpTarget(llvm::Value* _jumpTarget) { m_jumpTarget = _jumpTarget; } |
|
|
void setJumpTarget(llvm::Value* _jumpTarget) { m_jumpTarget = _jumpTarget; } |
|
|
|
|
|
|
|
|
LocalStack& localStack() { return m_stack; } |
|
|
int getDiff() const { return m_tosOffset; } |
|
|
|
|
|
|
|
|
/// Optimization: propagates values between local stacks in basic blocks
|
|
|
/// Optimization: propagates values between local stacks in basic blocks
|
|
|
/// to avoid excessive pushing/popping on the EVM stack.
|
|
|
/// to avoid excessive pushing/popping on the EVM stack.
|
|
@ -93,10 +94,6 @@ private: |
|
|
|
|
|
|
|
|
llvm::BasicBlock* const m_llvmBB; |
|
|
llvm::BasicBlock* const m_llvmBB; |
|
|
|
|
|
|
|
|
/// Basic black state vector (stack) - current/end values and their positions on stack
|
|
|
|
|
|
/// @internal Must be AFTER m_llvmBB
|
|
|
|
|
|
LocalStack m_stack; |
|
|
|
|
|
|
|
|
|
|
|
llvm::IRBuilder<>& m_builder; |
|
|
llvm::IRBuilder<>& m_builder; |
|
|
|
|
|
|
|
|
/// This stack contains LLVM values that correspond to items found at
|
|
|
/// This stack contains LLVM values that correspond to items found at
|
|
@ -111,6 +108,7 @@ private: |
|
|
/// executes. It may grow on both sides, as the code pushes items on
|
|
|
/// executes. It may grow on both sides, as the code pushes items on
|
|
|
/// top of the stack or changes existing items.
|
|
|
/// top of the stack or changes existing items.
|
|
|
std::vector<llvm::Value*> m_currentStack; |
|
|
std::vector<llvm::Value*> m_currentStack; |
|
|
|
|
|
friend class LocalStack; |
|
|
|
|
|
|
|
|
/// How many items higher is the current stack than the initial one.
|
|
|
/// How many items higher is the current stack than the initial one.
|
|
|
/// May be negative.
|
|
|
/// May be negative.
|
|
@ -127,4 +125,3 @@ private: |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|