mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Fix stack swap or dup not generating PHI nodes
This commit is contained in:
parent
973e0a2204
commit
09a5899adc
2 changed files with 22 additions and 11 deletions
|
|
@ -33,19 +33,29 @@ 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);
|
||||||
{
|
|
||||||
// Create PHI node
|
|
||||||
if (m_llvmBB->empty())
|
|
||||||
return llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB);
|
|
||||||
return llvm::PHINode::Create(Type::i256, 0, {}, m_llvmBB->getFirstNonPHI());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto top = m_backend.back();
|
|
||||||
m_backend.pop_back();
|
m_backend.pop_back();
|
||||||
return top;
|
return top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Value* BasicBlock::Stack::get(size_t _index)
|
||||||
|
{
|
||||||
|
if (_index >= m_backend.size())
|
||||||
|
{
|
||||||
|
// Create PHI node for missing values
|
||||||
|
auto nMissingVals = _index - m_backend.size() + 1;
|
||||||
|
m_backend.insert(m_backend.begin(), nMissingVals, nullptr);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *(m_backend.rbegin() + _index);
|
||||||
|
}
|
||||||
|
|
||||||
void BasicBlock::Stack::dup(size_t _index)
|
void BasicBlock::Stack::dup(size_t _index)
|
||||||
{
|
{
|
||||||
m_backend.push_back(get(_index));
|
m_backend.push_back(get(_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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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…
Reference in a new issue