Rename RedundantAssignEliminator to UnusedAssignEliminator.

This commit is contained in:
chriseth 2021-11-23 10:37:12 +01:00
parent defc74c8a2
commit bd321b9f1f
38 changed files with 52 additions and 52 deletions

View File

@ -173,10 +173,10 @@ add_library(yul
optimiser/OptimizerUtilities.h optimiser/OptimizerUtilities.h
optimiser/ReasoningBasedSimplifier.cpp optimiser/ReasoningBasedSimplifier.cpp
optimiser/ReasoningBasedSimplifier.h optimiser/ReasoningBasedSimplifier.h
optimiser/RedundantAssignEliminator.cpp optimiser/UnusedAssignEliminator.cpp
optimiser/RedundantAssignEliminator.h optimiser/UnusedAssignEliminator.h
optimiser/RedundantStoreBase.cpp optimiser/UnusedStoreBase.cpp
optimiser/RedundantStoreBase.h optimiser/UnusedStoreBase.h
optimiser/Rematerialiser.cpp optimiser/Rematerialiser.cpp
optimiser/Rematerialiser.h optimiser/Rematerialiser.h
optimiser/SMTSolver.cpp optimiser/SMTSolver.cpp

View File

@ -70,7 +70,7 @@ class NameDispenser;
* variable references can use the SSA variable. The only exception to this rule are * variable references can use the SSA variable. The only exception to this rule are
* for loop conditions, as we cannot insert a variable declaration there. * for loop conditions, as we cannot insert a variable declaration there.
* *
* After this stage, redundantAssignmentRemover is recommended to remove the unnecessary * After this stage, UnusedAssignmentEliminator is recommended to remove the unnecessary
* intermediate assignments. * intermediate assignments.
* *
* This stage provides best results if CSE is run right before it, because * This stage provides best results if CSE is run right before it, because

View File

@ -55,7 +55,7 @@
#include <libyul/optimiser/StackLimitEvader.h> #include <libyul/optimiser/StackLimitEvader.h>
#include <libyul/optimiser/StructuralSimplifier.h> #include <libyul/optimiser/StructuralSimplifier.h>
#include <libyul/optimiser/SyntacticalEquality.h> #include <libyul/optimiser/SyntacticalEquality.h>
#include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/UnusedAssignEliminator.h>
#include <libyul/optimiser/VarNameCleaner.h> #include <libyul/optimiser/VarNameCleaner.h>
#include <libyul/optimiser/LoadResolver.h> #include <libyul/optimiser/LoadResolver.h>
#include <libyul/optimiser/LoopInvariantCodeMotion.h> #include <libyul/optimiser/LoopInvariantCodeMotion.h>
@ -219,7 +219,7 @@ map<string, unique_ptr<OptimiserStep>> const& OptimiserSuite::allSteps()
LiteralRematerialiser, LiteralRematerialiser,
LoadResolver, LoadResolver,
LoopInvariantCodeMotion, LoopInvariantCodeMotion,
RedundantAssignEliminator, UnusedAssignEliminator,
ReasoningBasedSimplifier, ReasoningBasedSimplifier,
Rematerialiser, Rematerialiser,
SSAReverser, SSAReverser,
@ -260,7 +260,7 @@ map<string, char> const& OptimiserSuite::stepNameToAbbreviationMap()
{LoadResolver::name, 'L'}, {LoadResolver::name, 'L'},
{LoopInvariantCodeMotion::name, 'M'}, {LoopInvariantCodeMotion::name, 'M'},
{ReasoningBasedSimplifier::name, 'R'}, {ReasoningBasedSimplifier::name, 'R'},
{RedundantAssignEliminator::name, 'r'}, {UnusedAssignEliminator::name, 'r'},
{Rematerialiser::name, 'm'}, {Rematerialiser::name, 'm'},
{SSAReverser::name, 'V'}, {SSAReverser::name, 'V'},
{SSATransform::name, 'a'}, {SSATransform::name, 'a'},

View File

@ -20,7 +20,7 @@
* until they go out of scope or are re-assigned. * until they go out of scope or are re-assigned.
*/ */
#include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/UnusedAssignEliminator.h>
#include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/Semantics.h>
#include <libyul/AST.h> #include <libyul/AST.h>
@ -33,36 +33,36 @@ using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::yul; using namespace solidity::yul;
void RedundantAssignEliminator::run(OptimiserStepContext& _context, Block& _ast) void UnusedAssignEliminator::run(OptimiserStepContext& _context, Block& _ast)
{ {
RedundantAssignEliminator rae{_context.dialect}; UnusedAssignEliminator rae{_context.dialect};
rae(_ast); rae(_ast);
StatementRemover remover{rae.m_pendingRemovals}; StatementRemover remover{rae.m_pendingRemovals};
remover(_ast); remover(_ast);
} }
void RedundantAssignEliminator::operator()(Identifier const& _identifier) void UnusedAssignEliminator::operator()(Identifier const& _identifier)
{ {
changeUndecidedTo(_identifier.name, State::Used); changeUndecidedTo(_identifier.name, State::Used);
} }
void RedundantAssignEliminator::operator()(VariableDeclaration const& _variableDeclaration) void UnusedAssignEliminator::operator()(VariableDeclaration const& _variableDeclaration)
{ {
RedundantStoreBase::operator()(_variableDeclaration); UnusedStoreBase::operator()(_variableDeclaration);
for (auto const& var: _variableDeclaration.variables) for (auto const& var: _variableDeclaration.variables)
m_declaredVariables.emplace(var.name); m_declaredVariables.emplace(var.name);
} }
void RedundantAssignEliminator::operator()(Assignment const& _assignment) void UnusedAssignEliminator::operator()(Assignment const& _assignment)
{ {
visit(*_assignment.value); visit(*_assignment.value);
for (auto const& var: _assignment.variableNames) for (auto const& var: _assignment.variableNames)
changeUndecidedTo(var.name, State::Unused); changeUndecidedTo(var.name, State::Unused);
} }
void RedundantAssignEliminator::operator()(FunctionDefinition const& _functionDefinition) void UnusedAssignEliminator::operator()(FunctionDefinition const& _functionDefinition)
{ {
ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {}); ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {});
ScopedSaveAndRestore outerReturnVariables(m_returnVariables, {}); ScopedSaveAndRestore outerReturnVariables(m_returnVariables, {});
@ -70,28 +70,28 @@ void RedundantAssignEliminator::operator()(FunctionDefinition const& _functionDe
for (auto const& retParam: _functionDefinition.returnVariables) for (auto const& retParam: _functionDefinition.returnVariables)
m_returnVariables.insert(retParam.name); m_returnVariables.insert(retParam.name);
RedundantStoreBase::operator()(_functionDefinition); UnusedStoreBase::operator()(_functionDefinition);
} }
void RedundantAssignEliminator::operator()(Leave const&) void UnusedAssignEliminator::operator()(Leave const&)
{ {
for (YulString name: m_returnVariables) for (YulString name: m_returnVariables)
changeUndecidedTo(name, State::Used); changeUndecidedTo(name, State::Used);
} }
void RedundantAssignEliminator::operator()(Block const& _block) void UnusedAssignEliminator::operator()(Block const& _block)
{ {
ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {}); ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {});
RedundantStoreBase::operator()(_block); UnusedStoreBase::operator()(_block);
for (auto const& var: m_declaredVariables) for (auto const& var: m_declaredVariables)
finalize(var, State::Unused); finalize(var, State::Unused);
} }
void RedundantAssignEliminator::visit(Statement const& _statement) void UnusedAssignEliminator::visit(Statement const& _statement)
{ {
RedundantStoreBase::visit(_statement); UnusedStoreBase::visit(_statement);
if (auto const* assignment = get_if<Assignment>(&_statement)) if (auto const* assignment = get_if<Assignment>(&_statement))
if (assignment->variableNames.size() == 1) if (assignment->variableNames.size() == 1)
@ -99,7 +99,7 @@ void RedundantAssignEliminator::visit(Statement const& _statement)
m_stores[assignment->variableNames.front().name][&_statement]; m_stores[assignment->variableNames.front().name][&_statement];
} }
void RedundantAssignEliminator::shortcutNestedLoop(TrackedStores const& _zeroRuns) void UnusedAssignEliminator::shortcutNestedLoop(TrackedStores const& _zeroRuns)
{ {
// Shortcut to avoid horrible runtime: // Shortcut to avoid horrible runtime:
// Change all assignments that were newly introduced in the for loop to "used". // Change all assignments that were newly introduced in the for loop to "used".
@ -116,7 +116,7 @@ void RedundantAssignEliminator::shortcutNestedLoop(TrackedStores const& _zeroRun
} }
} }
void RedundantAssignEliminator::finalizeFunctionDefinition(FunctionDefinition const& _functionDefinition) void UnusedAssignEliminator::finalizeFunctionDefinition(FunctionDefinition const& _functionDefinition)
{ {
for (auto const& param: _functionDefinition.parameters) for (auto const& param: _functionDefinition.parameters)
finalize(param.name, State::Unused); finalize(param.name, State::Unused);
@ -124,14 +124,14 @@ void RedundantAssignEliminator::finalizeFunctionDefinition(FunctionDefinition co
finalize(retParam.name, State::Used); finalize(retParam.name, State::Used);
} }
void RedundantAssignEliminator::changeUndecidedTo(YulString _variable, RedundantAssignEliminator::State _newState) void UnusedAssignEliminator::changeUndecidedTo(YulString _variable, UnusedAssignEliminator::State _newState)
{ {
for (auto& assignment: m_stores[_variable]) for (auto& assignment: m_stores[_variable])
if (assignment.second == State::Undecided) if (assignment.second == State::Undecided)
assignment.second = _newState; assignment.second = _newState;
} }
void RedundantAssignEliminator::finalize(YulString _variable, RedundantAssignEliminator::State _finalState) void UnusedAssignEliminator::finalize(YulString _variable, UnusedAssignEliminator::State _finalState)
{ {
std::map<Statement const*, State> stores = std::move(m_stores[_variable]); std::map<Statement const*, State> stores = std::move(m_stores[_variable]);
m_stores.erase(_variable); m_stores.erase(_variable);

View File

@ -25,7 +25,7 @@
#include <libyul/ASTForward.h> #include <libyul/ASTForward.h>
#include <libyul/optimiser/ASTWalker.h> #include <libyul/optimiser/ASTWalker.h>
#include <libyul/optimiser/OptimiserStep.h> #include <libyul/optimiser/OptimiserStep.h>
#include <libyul/optimiser/RedundantStoreBase.h> #include <libyul/optimiser/UnusedStoreBase.h>
#include <map> #include <map>
#include <vector> #include <vector>
@ -107,13 +107,13 @@ struct Dialect;
* *
* Prerequisite: Disambiguator, ForLoopInitRewriter. * Prerequisite: Disambiguator, ForLoopInitRewriter.
*/ */
class RedundantAssignEliminator: public RedundantStoreBase class UnusedAssignEliminator: public UnusedStoreBase
{ {
public: public:
static constexpr char const* name{"RedundantAssignEliminator"}; static constexpr char const* name{"UnusedAssignEliminator"};
static void run(OptimiserStepContext&, Block& _ast); static void run(OptimiserStepContext&, Block& _ast);
explicit RedundantAssignEliminator(Dialect const& _dialect): RedundantStoreBase(_dialect) {} explicit UnusedAssignEliminator(Dialect const& _dialect): UnusedStoreBase(_dialect) {}
void operator()(Identifier const& _identifier) override; void operator()(Identifier const& _identifier) override;
void operator()(VariableDeclaration const& _variableDeclaration) override; void operator()(VariableDeclaration const& _variableDeclaration) override;
@ -122,7 +122,7 @@ public:
void operator()(Leave const&) override; void operator()(Leave const&) override;
void operator()(Block const& _block) override; void operator()(Block const& _block) override;
using RedundantStoreBase::visit; using UnusedStoreBase::visit;
void visit(Statement const& _statement) override; void visit(Statement const& _statement) override;
private: private:

View File

@ -16,10 +16,10 @@
*/ */
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
/** /**
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator. * Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
*/ */
#include <libyul/optimiser/RedundantStoreBase.h> #include <libyul/optimiser/UnusedStoreBase.h>
#include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/Semantics.h>
#include <libyul/optimiser/OptimiserStep.h> #include <libyul/optimiser/OptimiserStep.h>
@ -33,7 +33,7 @@ using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::yul; using namespace solidity::yul;
void RedundantStoreBase::operator()(If const& _if) void UnusedStoreBase::operator()(If const& _if)
{ {
visit(*_if.condition); visit(*_if.condition);
@ -43,7 +43,7 @@ void RedundantStoreBase::operator()(If const& _if)
merge(m_stores, move(skipBranch)); merge(m_stores, move(skipBranch));
} }
void RedundantStoreBase::operator()(Switch const& _switch) void UnusedStoreBase::operator()(Switch const& _switch)
{ {
visit(*_switch.expression); visit(*_switch.expression);
@ -69,7 +69,7 @@ void RedundantStoreBase::operator()(Switch const& _switch)
merge(m_stores, move(branch)); merge(m_stores, move(branch));
} }
void RedundantStoreBase::operator()(FunctionDefinition const& _functionDefinition) void UnusedStoreBase::operator()(FunctionDefinition const& _functionDefinition)
{ {
ScopedSaveAndRestore outerAssignments(m_stores, {}); ScopedSaveAndRestore outerAssignments(m_stores, {});
ScopedSaveAndRestore forLoopInfo(m_forLoopInfo, {}); ScopedSaveAndRestore forLoopInfo(m_forLoopInfo, {});
@ -79,7 +79,7 @@ void RedundantStoreBase::operator()(FunctionDefinition const& _functionDefinitio
finalizeFunctionDefinition(_functionDefinition); finalizeFunctionDefinition(_functionDefinition);
} }
void RedundantStoreBase::operator()(ForLoop const& _forLoop) void UnusedStoreBase::operator()(ForLoop const& _forLoop)
{ {
ScopedSaveAndRestore outerForLoopInfo(m_forLoopInfo, {}); ScopedSaveAndRestore outerForLoopInfo(m_forLoopInfo, {});
ScopedSaveAndRestore forLoopNestingDepth(m_forLoopNestingDepth, m_forLoopNestingDepth + 1); ScopedSaveAndRestore forLoopNestingDepth(m_forLoopNestingDepth, m_forLoopNestingDepth + 1);
@ -127,19 +127,19 @@ void RedundantStoreBase::operator()(ForLoop const& _forLoop)
m_forLoopInfo.pendingBreakStmts.clear(); m_forLoopInfo.pendingBreakStmts.clear();
} }
void RedundantStoreBase::operator()(Break const&) void UnusedStoreBase::operator()(Break const&)
{ {
m_forLoopInfo.pendingBreakStmts.emplace_back(move(m_stores)); m_forLoopInfo.pendingBreakStmts.emplace_back(move(m_stores));
m_stores.clear(); m_stores.clear();
} }
void RedundantStoreBase::operator()(Continue const&) void UnusedStoreBase::operator()(Continue const&)
{ {
m_forLoopInfo.pendingContinueStmts.emplace_back(move(m_stores)); m_forLoopInfo.pendingContinueStmts.emplace_back(move(m_stores));
m_stores.clear(); m_stores.clear();
} }
void RedundantStoreBase::merge(TrackedStores& _target, TrackedStores&& _other) void UnusedStoreBase::merge(TrackedStores& _target, TrackedStores&& _other)
{ {
util::joinMap(_target, move(_other), []( util::joinMap(_target, move(_other), [](
map<Statement const*, State>& _assignmentHere, map<Statement const*, State>& _assignmentHere,
@ -150,7 +150,7 @@ void RedundantStoreBase::merge(TrackedStores& _target, TrackedStores&& _other)
}); });
} }
void RedundantStoreBase::merge(TrackedStores& _target, vector<TrackedStores>&& _source) void UnusedStoreBase::merge(TrackedStores& _target, vector<TrackedStores>&& _source)
{ {
for (TrackedStores& ts: _source) for (TrackedStores& ts: _source)
merge(_target, move(ts)); merge(_target, move(ts));

View File

@ -16,7 +16,7 @@
*/ */
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
/** /**
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator. * Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
*/ */
#pragma once #pragma once
@ -34,14 +34,14 @@ namespace solidity::yul
struct Dialect; struct Dialect;
/** /**
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator. * Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
* *
* Prerequisite: Disambiguator, ForLoopInitRewriter. * Prerequisite: Disambiguator, ForLoopInitRewriter.
*/ */
class RedundantStoreBase: public ASTWalker class UnusedStoreBase: public ASTWalker
{ {
public: public:
explicit RedundantStoreBase(Dialect const& _dialect): m_dialect(_dialect) {} explicit UnusedStoreBase(Dialect const& _dialect): m_dialect(_dialect) {}
using ASTWalker::operator(); using ASTWalker::operator();
void operator()(If const& _if) override; void operator()(If const& _if) override;

View File

@ -52,7 +52,7 @@
#include <libyul/optimiser/SSAReverser.h> #include <libyul/optimiser/SSAReverser.h>
#include <libyul/optimiser/SSATransform.h> #include <libyul/optimiser/SSATransform.h>
#include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/Semantics.h>
#include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/UnusedAssignEliminator.h>
#include <libyul/optimiser/StructuralSimplifier.h> #include <libyul/optimiser/StructuralSimplifier.h>
#include <libyul/optimiser/StackCompressor.h> #include <libyul/optimiser/StackCompressor.h>
#include <libyul/optimiser/Suite.h> #include <libyul/optimiser/Suite.h>
@ -231,16 +231,16 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
ForLoopInitRewriter::run(*m_context, *m_ast); ForLoopInitRewriter::run(*m_context, *m_ast);
SSATransform::run(*m_context, *m_ast); SSATransform::run(*m_context, *m_ast);
}}, }},
{"redundantAssignEliminator", [&]() { {"unusedAssignEliminator", [&]() {
disambiguate(); disambiguate();
ForLoopInitRewriter::run(*m_context, *m_ast); ForLoopInitRewriter::run(*m_context, *m_ast);
RedundantAssignEliminator::run(*m_context, *m_ast); UnusedAssignEliminator::run(*m_context, *m_ast);
}}, }},
{"ssaPlusCleanup", [&]() { {"ssaPlusCleanup", [&]() {
disambiguate(); disambiguate();
ForLoopInitRewriter::run(*m_context, *m_ast); ForLoopInitRewriter::run(*m_context, *m_ast);
SSATransform::run(*m_context, *m_ast); SSATransform::run(*m_context, *m_ast);
RedundantAssignEliminator::run(*m_context, *m_ast); UnusedAssignEliminator::run(*m_context, *m_ast);
}}, }},
{"loadResolver", [&]() { {"loadResolver", [&]() {
disambiguate(); disambiguate();
@ -293,7 +293,7 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
ForLoopInitRewriter::run(*m_context, *m_ast); ForLoopInitRewriter::run(*m_context, *m_ast);
// apply SSA // apply SSA
SSATransform::run(*m_context, *m_ast); SSATransform::run(*m_context, *m_ast);
RedundantAssignEliminator::run(*m_context, *m_ast); UnusedAssignEliminator::run(*m_context, *m_ast);
// reverse SSA // reverse SSA
SSAReverser::run(*m_context, *m_ast); SSAReverser::run(*m_context, *m_ast);
FunctionHoister::run(*m_context, *m_ast); FunctionHoister::run(*m_context, *m_ast);

View File

@ -30,7 +30,7 @@
#include <libyul/optimiser/ForLoopInitRewriter.h> #include <libyul/optimiser/ForLoopInitRewriter.h>
#include <libyul/optimiser/FunctionHoister.h> #include <libyul/optimiser/FunctionHoister.h>
#include <libyul/optimiser/LoopInvariantCodeMotion.h> #include <libyul/optimiser/LoopInvariantCodeMotion.h>
#include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/UnusedAssignEliminator.h>
#include <libyul/optimiser/Rematerialiser.h> #include <libyul/optimiser/Rematerialiser.h>
#include <libyul/optimiser/Suite.h> #include <libyul/optimiser/Suite.h>
#include <libyul/optimiser/StructuralSimplifier.h> #include <libyul/optimiser/StructuralSimplifier.h>
@ -50,7 +50,7 @@ namespace solidity::phaser::test
vector<string> const ChrOmOsoMeSteps{ vector<string> const ChrOmOsoMeSteps{
ConditionalSimplifier::name, ConditionalSimplifier::name,
FunctionHoister::name, FunctionHoister::name,
RedundantAssignEliminator::name, UnusedAssignEliminator::name,
ForLoopConditionOutOfBody::name, ForLoopConditionOutOfBody::name,
Rematerialiser::name, Rematerialiser::name,
ForLoopConditionOutOfBody::name, ForLoopConditionOutOfBody::name,