mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Have the stack optimization in the code transform only reuse slots that are reachable.
This commit is contained in:
parent
c9fd97ecae
commit
13401bed87
@ -226,16 +226,24 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
|
|||||||
else
|
else
|
||||||
m_variablesScheduledForDeletion.insert(&var);
|
m_variablesScheduledForDeletion.insert(&var);
|
||||||
}
|
}
|
||||||
else if (m_unusedStackSlots.empty())
|
|
||||||
atTopOfStack = false;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto slot = static_cast<size_t>(*m_unusedStackSlots.begin());
|
bool foundUnusedSlot = false;
|
||||||
m_unusedStackSlots.erase(m_unusedStackSlots.begin());
|
for (auto it = m_unusedStackSlots.begin(); it != m_unusedStackSlots.end(); ++it)
|
||||||
m_context->variableStackHeights[&var] = slot;
|
{
|
||||||
if (size_t heightDiff = variableHeightDiff(var, varName, true))
|
if (m_assembly.stackHeight() - *it > 17)
|
||||||
m_assembly.appendInstruction(evmasm::swapInstruction(static_cast<unsigned>(heightDiff - 1)));
|
continue;
|
||||||
m_assembly.appendInstruction(evmasm::Instruction::POP);
|
foundUnusedSlot = true;
|
||||||
|
m_unusedStackSlots.erase(it);
|
||||||
|
auto slot = static_cast<size_t>(*it);
|
||||||
|
m_context->variableStackHeights[&var] = slot;
|
||||||
|
if (size_t heightDiff = variableHeightDiff(var, varName, true))
|
||||||
|
m_assembly.appendInstruction(evmasm::swapInstruction(static_cast<unsigned>(heightDiff - 1)));
|
||||||
|
m_assembly.appendInstruction(evmasm::Instruction::POP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!foundUnusedSlot)
|
||||||
|
atTopOfStack = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user