Browse Source

Fix stack swap or dup not generating PHI nodes

cl-refactor
Paweł Bylica 10 years ago
parent
commit
a5e264d385
  1. 29
      evmcc/BasicBlock.cpp
  2. 2
      evmcc/BasicBlock.h

29
evmcc/BasicBlock.cpp

@ -33,17 +33,27 @@ void BasicBlock::Stack::push(llvm::Value* _value)
llvm::Value* BasicBlock::Stack::pop() llvm::Value* BasicBlock::Stack::pop()
{ {
if (m_backend.empty()) auto top = get(0);
m_backend.pop_back();
return top;
}
llvm::Value* BasicBlock::Stack::get(size_t _index)
{
if (_index >= m_backend.size())
{ {
// Create PHI node // Create PHI node for missing values
if (m_llvmBB->empty()) auto nMissingVals = _index - m_backend.size() + 1;
return llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB); m_backend.insert(m_backend.begin(), nMissingVals, nullptr);
return llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB->getFirstNonPHI()); for (decltype(nMissingVals) i = 0; i < nMissingVals; ++i)
{
m_backend[i] = m_llvmBB->empty() ?
llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB) :
llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB->getFirstNonPHI());
}
} }
auto top = m_backend.back(); return *(m_backend.rbegin() + _index);
m_backend.pop_back();
return top;
} }
void BasicBlock::Stack::dup(size_t _index) void BasicBlock::Stack::dup(size_t _index)
@ -54,7 +64,8 @@ void BasicBlock::Stack::dup(size_t _index)
void BasicBlock::Stack::swap(size_t _index) void BasicBlock::Stack::swap(size_t _index)
{ {
assert(_index != 0); assert(_index != 0);
std::swap(get(0), get(_index)); get(_index); // Create PHI nodes
std::swap(*m_backend.rbegin(), *(m_backend.rbegin() + _index));
} }
} }

2
evmcc/BasicBlock.h

@ -21,7 +21,7 @@ public:
llvm::Value* pop(); llvm::Value* pop();
/// Gets _index'th value from top (counting from 0) /// Gets _index'th value from top (counting from 0)
llvm::Value*& get(size_t _index) { return *(m_backend.rbegin() + _index); } llvm::Value* get(size_t _index);
/// Duplicates _index'th value on stack. /// Duplicates _index'th value on stack.
void dup(size_t _index); void dup(size_t _index);

Loading…
Cancel
Save