Browse Source

Fix local stack max size calculation.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
7d1e35076f
  1. 3
      evmjit/libevmjit/BasicBlock.cpp
  2. 16
      evmjit/libevmjit/BasicBlock.h
  3. 4
      evmjit/libevmjit/Compiler.cpp

3
evmjit/libevmjit/BasicBlock.cpp

@ -44,7 +44,7 @@ void LocalStack::push(llvm::Value* _value)
{
assert(_value->getType() == Type::Word);
m_currentStack.push_back(_value);
m_maxSize = std::max(m_maxSize, m_currentStack.size()); // FIXME: This is wrong too. + add min size;
m_maxSize = std::max(m_maxSize, size());
}
llvm::Value* LocalStack::pop()
@ -57,6 +57,7 @@ llvm::Value* LocalStack::pop()
else
++m_globalPops;
m_minSize = std::min(m_minSize, size());
return item;
}

16
evmjit/libevmjit/BasicBlock.h

@ -36,11 +36,11 @@ public:
/// @param _index Index of value to be swaped. Must be > 0.
void swap(size_t _index);
ssize_t getDiff() const { return static_cast<ssize_t>(m_currentStack.size()) - static_cast<ssize_t>(m_globalPops); }
size_t getMaxSize() const { return m_maxSize; }
ssize_t size() const { return static_cast<ssize_t>(m_currentStack.size()) - static_cast<ssize_t>(m_globalPops); }
ssize_t minSize() const { return m_minSize; }
ssize_t maxSize() const { return m_maxSize; }
/// TODO: comment
/// TODO: It must be the same builder as in global stack.
/// Finalize local stack: check the requirements and update of the global stack.
void finalize(llvm::IRBuilder<>& _builder, llvm::BasicBlock& _bb);
private:
@ -63,9 +63,11 @@ private:
/// top of the stack or changes existing items.
std::vector<llvm::Value*> m_currentStack;
size_t m_globalPops = 0; ///< Number of items poped from global stack. In other words: global - local stack overlap.
Stack& m_global;
size_t m_maxSize = 0; ///< Max size reached by the stack.
Stack& m_global; ///< Reference to global stack.
size_t m_globalPops = 0; ///< Number of items poped from global stack. In other words: global - local stack overlap.
ssize_t m_minSize = 0; ///< Minimum reached local stack size. Can be negative.
ssize_t m_maxSize = 0; ///< Maximum reached local stack size.
};
class BasicBlock

4
evmjit/libevmjit/Compiler.cpp

@ -835,8 +835,8 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti
stack.finalize(m_builder, *_basicBlock.llvm()); // TODO: Use references
m_builder.SetInsertPoint(_basicBlock.llvm()->getFirstNonPHI());
_runtimeManager.checkStackLimit(stack.getMaxSize(), stack.getDiff());
m_builder.SetInsertPoint(_basicBlock.llvm()->getFirstNonPHI()); // TODO: Move to LocalStack::finalize
_runtimeManager.checkStackLimit(stack.maxSize(), stack.size());
}

Loading…
Cancel
Save