mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Free variables directly after visiting RHS of Variable Declarations during EVMCodeTransform.
This commit is contained in:
@@ -141,7 +141,7 @@ bool CodeTransform::unreferenced(Scope::Variable const& _var) const
|
||||
return !m_context->variableReferences.count(&_var) || m_context->variableReferences[&_var] == 0;
|
||||
}
|
||||
|
||||
void CodeTransform::freeUnusedVariables()
|
||||
void CodeTransform::freeUnusedVariables(bool _popUnusedSlotsAtStackTop)
|
||||
{
|
||||
if (!m_allowStackOpt)
|
||||
return;
|
||||
@@ -154,11 +154,12 @@ void CodeTransform::freeUnusedVariables()
|
||||
deleteVariable(var);
|
||||
}
|
||||
|
||||
while (m_unusedStackSlots.count(m_assembly.stackHeight() - 1))
|
||||
{
|
||||
yulAssert(m_unusedStackSlots.erase(m_assembly.stackHeight() - 1), "");
|
||||
m_assembly.appendInstruction(evmasm::Instruction::POP);
|
||||
}
|
||||
if (_popUnusedSlotsAtStackTop)
|
||||
while (m_unusedStackSlots.count(m_assembly.stackHeight() - 1))
|
||||
{
|
||||
yulAssert(m_unusedStackSlots.erase(m_assembly.stackHeight() - 1), "");
|
||||
m_assembly.appendInstruction(evmasm::Instruction::POP);
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTransform::deleteVariable(Scope::Variable const& _var)
|
||||
@@ -181,6 +182,7 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
|
||||
{
|
||||
std::visit(*this, *_varDecl.value);
|
||||
expectDeposit(static_cast<int>(numVariables), static_cast<int>(heightAtStart));
|
||||
freeUnusedVariables(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -161,8 +161,9 @@ protected:
|
||||
bool unreferenced(Scope::Variable const& _var) const;
|
||||
/// Marks slots of variables that are not used anymore
|
||||
/// and were defined in the current scope for reuse.
|
||||
/// Also POPs unused topmost stack slots.
|
||||
void freeUnusedVariables();
|
||||
/// Also POPs unused topmost stack slots,
|
||||
/// unless @a _popUnusedSlotsAtStackTop is set to false.
|
||||
void freeUnusedVariables(bool _popUnusedSlotsAtStackTop = true);
|
||||
/// Marks the stack slot of @a _var to be reused.
|
||||
void deleteVariable(Scope::Variable const& _var);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user