mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fix it again
This commit is contained in:
parent
d89c5638f0
commit
ddf1d023bd
@ -45,9 +45,9 @@ void UnusedAssignEliminator::run(OptimiserStepContext& _context, Block& _ast)
|
|||||||
UnusedAssignEliminator rae{_context.dialect};
|
UnusedAssignEliminator rae{_context.dialect};
|
||||||
rae(_ast);
|
rae(_ast);
|
||||||
|
|
||||||
rae.m_storesToRemove += move(rae.m_potentiallyUnusedStores);
|
rae.m_storesToRemove += rae.m_allStores - rae.m_usedStores;
|
||||||
|
|
||||||
StatementRemover remover{rae.m_storesToRemove};
|
StatementRemover remover{std::set<Statement const*>{rae.m_storesToRemove.begin(), rae.m_storesToRemove.end()}};
|
||||||
remover(_ast);
|
remover(_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ void UnusedAssignEliminator::visit(Statement const& _statement)
|
|||||||
// by adding a test where one var is used but not the other)
|
// by adding a test where one var is used but not the other)
|
||||||
if (SideEffectsCollector{m_dialect, *assignment->value}.movable())
|
if (SideEffectsCollector{m_dialect, *assignment->value}.movable())
|
||||||
{
|
{
|
||||||
m_potentiallyUnusedStores.insert(&_statement);
|
m_allStores.insert(&_statement);
|
||||||
for (auto const& var: assignment->variableNames)
|
for (auto const& var: assignment->variableNames)
|
||||||
m_activeStores[var.name] = {&_statement};
|
m_activeStores[var.name] = {&_statement};
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ void UnusedAssignEliminator::shortcutNestedLoop(ActiveStores const& _zeroRuns)
|
|||||||
auto zeroIt = _zeroRuns.find(variable);
|
auto zeroIt = _zeroRuns.find(variable);
|
||||||
if (zeroIt != _zeroRuns.end() && zeroIt->second.count(assignment))
|
if (zeroIt != _zeroRuns.end() && zeroIt->second.count(assignment))
|
||||||
continue;
|
continue;
|
||||||
m_potentiallyUnusedStores.erase(assignment);
|
m_usedStores.insert(assignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +148,6 @@ void UnusedAssignEliminator::finalizeFunctionDefinition(FunctionDefinition const
|
|||||||
void UnusedAssignEliminator::markUsed(YulString _variable)
|
void UnusedAssignEliminator::markUsed(YulString _variable)
|
||||||
{
|
{
|
||||||
for (auto& assignment: m_activeStores[_variable])
|
for (auto& assignment: m_activeStores[_variable])
|
||||||
m_potentiallyUnusedStores.erase(assignment);
|
m_usedStores.insert(assignment);
|
||||||
m_activeStores.erase(_variable);
|
m_activeStores.erase(_variable);
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,16 @@ void UnusedStoreBase::operator()(Switch const& _switch)
|
|||||||
|
|
||||||
void UnusedStoreBase::operator()(FunctionDefinition const& _functionDefinition)
|
void UnusedStoreBase::operator()(FunctionDefinition const& _functionDefinition)
|
||||||
{
|
{
|
||||||
|
ScopedSaveAndRestore allStores(m_allStores, {});
|
||||||
|
ScopedSaveAndRestore usedStoresStores(m_usedStores, {});
|
||||||
ScopedSaveAndRestore outerAssignments(m_activeStores, {});
|
ScopedSaveAndRestore outerAssignments(m_activeStores, {});
|
||||||
ScopedSaveAndRestore forLoopInfo(m_forLoopInfo, {});
|
ScopedSaveAndRestore forLoopInfo(m_forLoopInfo, {});
|
||||||
ScopedSaveAndRestore forLoopNestingDepth(m_forLoopNestingDepth, 0);
|
ScopedSaveAndRestore forLoopNestingDepth(m_forLoopNestingDepth, 0);
|
||||||
ScopedSaveAndRestore potentiallyUnused(m_potentiallyUnusedStores, {});
|
|
||||||
|
|
||||||
(*this)(_functionDefinition.body);
|
(*this)(_functionDefinition.body);
|
||||||
|
|
||||||
finalizeFunctionDefinition(_functionDefinition);
|
finalizeFunctionDefinition(_functionDefinition);
|
||||||
m_storesToRemove += move(m_potentiallyUnusedStores);
|
m_storesToRemove += m_allStores - m_usedStores;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnusedStoreBase::operator()(ForLoop const& _forLoop)
|
void UnusedStoreBase::operator()(ForLoop const& _forLoop)
|
||||||
|
@ -74,11 +74,12 @@ protected:
|
|||||||
static void merge(ActiveStores& _target, std::vector<ActiveStores>&& _source);
|
static void merge(ActiveStores& _target, std::vector<ActiveStores>&& _source);
|
||||||
|
|
||||||
Dialect const& m_dialect;
|
Dialect const& m_dialect;
|
||||||
/// Set of stores that unused. Once a store is deemed used, it is removed from here.
|
/// Set of all stores encountered during the traversal (in the current function).
|
||||||
std::set<Statement const*> m_potentiallyUnusedStores;
|
std::set<Statement const*> m_allStores;
|
||||||
/// Statements are moved from m_potentiallUnusedStores to m_storesToRemove at the
|
/// Set of stores that are marked as being used (in the current function).
|
||||||
/// end of each function.
|
std::set<Statement const*> m_usedStores;
|
||||||
std::set<Statement const*> m_storesToRemove;
|
/// List of stores that can be removed (globally).
|
||||||
|
std::vector<Statement const*> m_storesToRemove;
|
||||||
/// Active (undecided) stores in the current branch.
|
/// Active (undecided) stores in the current branch.
|
||||||
ActiveStores m_activeStores;
|
ActiveStores m_activeStores;
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ void UnusedStoreEliminator::run(OptimiserStepContext& _context, Block& _ast)
|
|||||||
else
|
else
|
||||||
rse.markActiveAsUsed(Location::Memory);
|
rse.markActiveAsUsed(Location::Memory);
|
||||||
rse.markActiveAsUsed(Location::Storage);
|
rse.markActiveAsUsed(Location::Storage);
|
||||||
rse.m_storesToRemove += move(rse.m_potentiallyUnusedStores);
|
rse.m_storesToRemove += rse.m_allStores - rse.m_usedStores;
|
||||||
|
|
||||||
StatementRemover remover{rse.m_storesToRemove};
|
StatementRemover remover{std::set<Statement const*>{rse.m_storesToRemove.begin(), rse.m_storesToRemove.end()}};
|
||||||
remover(_ast);
|
remover(_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ void UnusedStoreEliminator::visit(Statement const& _statement)
|
|||||||
if (!allowReturndatacopyToBeRemoved)
|
if (!allowReturndatacopyToBeRemoved)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_potentiallyUnusedStores.insert(&_statement);
|
m_allStores.insert(&_statement);
|
||||||
vector<Operation> operations = operationsFromFunctionCall(*funCall);
|
vector<Operation> operations = operationsFromFunctionCall(*funCall);
|
||||||
yulAssert(operations.size() == 1, "");
|
yulAssert(operations.size() == 1, "");
|
||||||
if (operations.front().location == Location::Storage)
|
if (operations.front().location == Location::Storage)
|
||||||
@ -268,7 +268,7 @@ void UnusedStoreEliminator::applyOperation(UnusedStoreEliminator::Operation cons
|
|||||||
if (_operation.effect == Effect::Read && !knownUnrelated(storeOperation, _operation))
|
if (_operation.effect == Effect::Read && !knownUnrelated(storeOperation, _operation))
|
||||||
{
|
{
|
||||||
// This store is read from, mark it as used and remove it from the active set.
|
// This store is read from, mark it as used and remove it from the active set.
|
||||||
m_potentiallyUnusedStores.erase(statement);
|
m_usedStores.insert(statement);
|
||||||
it = active.erase(it);
|
it = active.erase(it);
|
||||||
}
|
}
|
||||||
else if (_operation.effect == Effect::Write && knownCovered(storeOperation, _operation))
|
else if (_operation.effect == Effect::Write && knownCovered(storeOperation, _operation))
|
||||||
@ -403,10 +403,10 @@ void UnusedStoreEliminator::markActiveAsUsed(
|
|||||||
{
|
{
|
||||||
if (_onlyLocation == nullopt || _onlyLocation == Location::Memory)
|
if (_onlyLocation == nullopt || _onlyLocation == Location::Memory)
|
||||||
for (Statement const* statement: activeMemoryStores())
|
for (Statement const* statement: activeMemoryStores())
|
||||||
m_potentiallyUnusedStores.erase(statement);
|
m_usedStores.insert(statement);
|
||||||
if (_onlyLocation == nullopt || _onlyLocation == Location::Storage)
|
if (_onlyLocation == nullopt || _onlyLocation == Location::Storage)
|
||||||
for (Statement const* statement: activeStorageStores())
|
for (Statement const* statement: activeStorageStores())
|
||||||
m_potentiallyUnusedStores.erase(statement);
|
m_usedStores.insert(statement);
|
||||||
clearActive(_onlyLocation);
|
clearActive(_onlyLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user