mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename RedundantAssignEliminator to UnusedAssignEliminator.
This commit is contained in:
parent
defc74c8a2
commit
bd321b9f1f
@ -173,10 +173,10 @@ add_library(yul
|
||||
optimiser/OptimizerUtilities.h
|
||||
optimiser/ReasoningBasedSimplifier.cpp
|
||||
optimiser/ReasoningBasedSimplifier.h
|
||||
optimiser/RedundantAssignEliminator.cpp
|
||||
optimiser/RedundantAssignEliminator.h
|
||||
optimiser/RedundantStoreBase.cpp
|
||||
optimiser/RedundantStoreBase.h
|
||||
optimiser/UnusedAssignEliminator.cpp
|
||||
optimiser/UnusedAssignEliminator.h
|
||||
optimiser/UnusedStoreBase.cpp
|
||||
optimiser/UnusedStoreBase.h
|
||||
optimiser/Rematerialiser.cpp
|
||||
optimiser/Rematerialiser.h
|
||||
optimiser/SMTSolver.cpp
|
||||
|
@ -70,7 +70,7 @@ class NameDispenser;
|
||||
* 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.
|
||||
*
|
||||
* After this stage, redundantAssignmentRemover is recommended to remove the unnecessary
|
||||
* After this stage, UnusedAssignmentEliminator is recommended to remove the unnecessary
|
||||
* intermediate assignments.
|
||||
*
|
||||
* This stage provides best results if CSE is run right before it, because
|
||||
|
@ -55,7 +55,7 @@
|
||||
#include <libyul/optimiser/StackLimitEvader.h>
|
||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||
#include <libyul/optimiser/SyntacticalEquality.h>
|
||||
#include <libyul/optimiser/RedundantAssignEliminator.h>
|
||||
#include <libyul/optimiser/UnusedAssignEliminator.h>
|
||||
#include <libyul/optimiser/VarNameCleaner.h>
|
||||
#include <libyul/optimiser/LoadResolver.h>
|
||||
#include <libyul/optimiser/LoopInvariantCodeMotion.h>
|
||||
@ -219,7 +219,7 @@ map<string, unique_ptr<OptimiserStep>> const& OptimiserSuite::allSteps()
|
||||
LiteralRematerialiser,
|
||||
LoadResolver,
|
||||
LoopInvariantCodeMotion,
|
||||
RedundantAssignEliminator,
|
||||
UnusedAssignEliminator,
|
||||
ReasoningBasedSimplifier,
|
||||
Rematerialiser,
|
||||
SSAReverser,
|
||||
@ -260,7 +260,7 @@ map<string, char> const& OptimiserSuite::stepNameToAbbreviationMap()
|
||||
{LoadResolver::name, 'L'},
|
||||
{LoopInvariantCodeMotion::name, 'M'},
|
||||
{ReasoningBasedSimplifier::name, 'R'},
|
||||
{RedundantAssignEliminator::name, 'r'},
|
||||
{UnusedAssignEliminator::name, 'r'},
|
||||
{Rematerialiser::name, 'm'},
|
||||
{SSAReverser::name, 'V'},
|
||||
{SSATransform::name, 'a'},
|
||||
|
@ -20,7 +20,7 @@
|
||||
* 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/AST.h>
|
||||
@ -33,36 +33,36 @@ using namespace std;
|
||||
using namespace solidity;
|
||||
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);
|
||||
|
||||
StatementRemover remover{rae.m_pendingRemovals};
|
||||
remover(_ast);
|
||||
}
|
||||
|
||||
void RedundantAssignEliminator::operator()(Identifier const& _identifier)
|
||||
void UnusedAssignEliminator::operator()(Identifier const& _identifier)
|
||||
{
|
||||
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)
|
||||
m_declaredVariables.emplace(var.name);
|
||||
}
|
||||
|
||||
void RedundantAssignEliminator::operator()(Assignment const& _assignment)
|
||||
void UnusedAssignEliminator::operator()(Assignment const& _assignment)
|
||||
{
|
||||
visit(*_assignment.value);
|
||||
for (auto const& var: _assignment.variableNames)
|
||||
changeUndecidedTo(var.name, State::Unused);
|
||||
}
|
||||
|
||||
void RedundantAssignEliminator::operator()(FunctionDefinition const& _functionDefinition)
|
||||
void UnusedAssignEliminator::operator()(FunctionDefinition const& _functionDefinition)
|
||||
{
|
||||
ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {});
|
||||
ScopedSaveAndRestore outerReturnVariables(m_returnVariables, {});
|
||||
@ -70,28 +70,28 @@ void RedundantAssignEliminator::operator()(FunctionDefinition const& _functionDe
|
||||
for (auto const& retParam: _functionDefinition.returnVariables)
|
||||
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)
|
||||
changeUndecidedTo(name, State::Used);
|
||||
}
|
||||
|
||||
void RedundantAssignEliminator::operator()(Block const& _block)
|
||||
void UnusedAssignEliminator::operator()(Block const& _block)
|
||||
{
|
||||
ScopedSaveAndRestore outerDeclaredVariables(m_declaredVariables, {});
|
||||
|
||||
RedundantStoreBase::operator()(_block);
|
||||
UnusedStoreBase::operator()(_block);
|
||||
|
||||
for (auto const& var: m_declaredVariables)
|
||||
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 (assignment->variableNames.size() == 1)
|
||||
@ -99,7 +99,7 @@ void RedundantAssignEliminator::visit(Statement const& _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:
|
||||
// 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)
|
||||
finalize(param.name, State::Unused);
|
||||
@ -124,14 +124,14 @@ void RedundantAssignEliminator::finalizeFunctionDefinition(FunctionDefinition co
|
||||
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])
|
||||
if (assignment.second == State::Undecided)
|
||||
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]);
|
||||
m_stores.erase(_variable);
|
@ -25,7 +25,7 @@
|
||||
#include <libyul/ASTForward.h>
|
||||
#include <libyul/optimiser/ASTWalker.h>
|
||||
#include <libyul/optimiser/OptimiserStep.h>
|
||||
#include <libyul/optimiser/RedundantStoreBase.h>
|
||||
#include <libyul/optimiser/UnusedStoreBase.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -107,13 +107,13 @@ struct Dialect;
|
||||
*
|
||||
* Prerequisite: Disambiguator, ForLoopInitRewriter.
|
||||
*/
|
||||
class RedundantAssignEliminator: public RedundantStoreBase
|
||||
class UnusedAssignEliminator: public UnusedStoreBase
|
||||
{
|
||||
public:
|
||||
static constexpr char const* name{"RedundantAssignEliminator"};
|
||||
static constexpr char const* name{"UnusedAssignEliminator"};
|
||||
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()(VariableDeclaration const& _variableDeclaration) override;
|
||||
@ -122,7 +122,7 @@ public:
|
||||
void operator()(Leave const&) override;
|
||||
void operator()(Block const& _block) override;
|
||||
|
||||
using RedundantStoreBase::visit;
|
||||
using UnusedStoreBase::visit;
|
||||
void visit(Statement const& _statement) override;
|
||||
|
||||
private:
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
// 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/OptimiserStep.h>
|
||||
@ -33,7 +33,7 @@ using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::yul;
|
||||
|
||||
void RedundantStoreBase::operator()(If const& _if)
|
||||
void UnusedStoreBase::operator()(If const& _if)
|
||||
{
|
||||
visit(*_if.condition);
|
||||
|
||||
@ -43,7 +43,7 @@ void RedundantStoreBase::operator()(If const& _if)
|
||||
merge(m_stores, move(skipBranch));
|
||||
}
|
||||
|
||||
void RedundantStoreBase::operator()(Switch const& _switch)
|
||||
void UnusedStoreBase::operator()(Switch const& _switch)
|
||||
{
|
||||
visit(*_switch.expression);
|
||||
|
||||
@ -69,7 +69,7 @@ void RedundantStoreBase::operator()(Switch const& _switch)
|
||||
merge(m_stores, move(branch));
|
||||
}
|
||||
|
||||
void RedundantStoreBase::operator()(FunctionDefinition const& _functionDefinition)
|
||||
void UnusedStoreBase::operator()(FunctionDefinition const& _functionDefinition)
|
||||
{
|
||||
ScopedSaveAndRestore outerAssignments(m_stores, {});
|
||||
ScopedSaveAndRestore forLoopInfo(m_forLoopInfo, {});
|
||||
@ -79,7 +79,7 @@ void RedundantStoreBase::operator()(FunctionDefinition const& _functionDefinitio
|
||||
finalizeFunctionDefinition(_functionDefinition);
|
||||
}
|
||||
|
||||
void RedundantStoreBase::operator()(ForLoop const& _forLoop)
|
||||
void UnusedStoreBase::operator()(ForLoop const& _forLoop)
|
||||
{
|
||||
ScopedSaveAndRestore outerForLoopInfo(m_forLoopInfo, {});
|
||||
ScopedSaveAndRestore forLoopNestingDepth(m_forLoopNestingDepth, m_forLoopNestingDepth + 1);
|
||||
@ -127,19 +127,19 @@ void RedundantStoreBase::operator()(ForLoop const& _forLoop)
|
||||
m_forLoopInfo.pendingBreakStmts.clear();
|
||||
}
|
||||
|
||||
void RedundantStoreBase::operator()(Break const&)
|
||||
void UnusedStoreBase::operator()(Break const&)
|
||||
{
|
||||
m_forLoopInfo.pendingBreakStmts.emplace_back(move(m_stores));
|
||||
m_stores.clear();
|
||||
}
|
||||
|
||||
void RedundantStoreBase::operator()(Continue const&)
|
||||
void UnusedStoreBase::operator()(Continue const&)
|
||||
{
|
||||
m_forLoopInfo.pendingContinueStmts.emplace_back(move(m_stores));
|
||||
m_stores.clear();
|
||||
}
|
||||
|
||||
void RedundantStoreBase::merge(TrackedStores& _target, TrackedStores&& _other)
|
||||
void UnusedStoreBase::merge(TrackedStores& _target, TrackedStores&& _other)
|
||||
{
|
||||
util::joinMap(_target, move(_other), [](
|
||||
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)
|
||||
merge(_target, move(ts));
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
/**
|
||||
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator.
|
||||
* Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@ -34,14 +34,14 @@ namespace solidity::yul
|
||||
struct Dialect;
|
||||
|
||||
/**
|
||||
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator.
|
||||
* Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
|
||||
*
|
||||
* Prerequisite: Disambiguator, ForLoopInitRewriter.
|
||||
*/
|
||||
class RedundantStoreBase: public ASTWalker
|
||||
class UnusedStoreBase: public ASTWalker
|
||||
{
|
||||
public:
|
||||
explicit RedundantStoreBase(Dialect const& _dialect): m_dialect(_dialect) {}
|
||||
explicit UnusedStoreBase(Dialect const& _dialect): m_dialect(_dialect) {}
|
||||
|
||||
using ASTWalker::operator();
|
||||
void operator()(If const& _if) override;
|
@ -52,7 +52,7 @@
|
||||
#include <libyul/optimiser/SSAReverser.h>
|
||||
#include <libyul/optimiser/SSATransform.h>
|
||||
#include <libyul/optimiser/Semantics.h>
|
||||
#include <libyul/optimiser/RedundantAssignEliminator.h>
|
||||
#include <libyul/optimiser/UnusedAssignEliminator.h>
|
||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||
#include <libyul/optimiser/StackCompressor.h>
|
||||
#include <libyul/optimiser/Suite.h>
|
||||
@ -231,16 +231,16 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
|
||||
ForLoopInitRewriter::run(*m_context, *m_ast);
|
||||
SSATransform::run(*m_context, *m_ast);
|
||||
}},
|
||||
{"redundantAssignEliminator", [&]() {
|
||||
{"unusedAssignEliminator", [&]() {
|
||||
disambiguate();
|
||||
ForLoopInitRewriter::run(*m_context, *m_ast);
|
||||
RedundantAssignEliminator::run(*m_context, *m_ast);
|
||||
UnusedAssignEliminator::run(*m_context, *m_ast);
|
||||
}},
|
||||
{"ssaPlusCleanup", [&]() {
|
||||
disambiguate();
|
||||
ForLoopInitRewriter::run(*m_context, *m_ast);
|
||||
SSATransform::run(*m_context, *m_ast);
|
||||
RedundantAssignEliminator::run(*m_context, *m_ast);
|
||||
UnusedAssignEliminator::run(*m_context, *m_ast);
|
||||
}},
|
||||
{"loadResolver", [&]() {
|
||||
disambiguate();
|
||||
@ -293,7 +293,7 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
|
||||
ForLoopInitRewriter::run(*m_context, *m_ast);
|
||||
// apply SSA
|
||||
SSATransform::run(*m_context, *m_ast);
|
||||
RedundantAssignEliminator::run(*m_context, *m_ast);
|
||||
UnusedAssignEliminator::run(*m_context, *m_ast);
|
||||
// reverse SSA
|
||||
SSAReverser::run(*m_context, *m_ast);
|
||||
FunctionHoister::run(*m_context, *m_ast);
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <libyul/optimiser/ForLoopInitRewriter.h>
|
||||
#include <libyul/optimiser/FunctionHoister.h>
|
||||
#include <libyul/optimiser/LoopInvariantCodeMotion.h>
|
||||
#include <libyul/optimiser/RedundantAssignEliminator.h>
|
||||
#include <libyul/optimiser/UnusedAssignEliminator.h>
|
||||
#include <libyul/optimiser/Rematerialiser.h>
|
||||
#include <libyul/optimiser/Suite.h>
|
||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||
@ -50,7 +50,7 @@ namespace solidity::phaser::test
|
||||
vector<string> const ChrOmOsoMeSteps{
|
||||
ConditionalSimplifier::name,
|
||||
FunctionHoister::name,
|
||||
RedundantAssignEliminator::name,
|
||||
UnusedAssignEliminator::name,
|
||||
ForLoopConditionOutOfBody::name,
|
||||
Rematerialiser::name,
|
||||
ForLoopConditionOutOfBody::name,
|
||||
|
Loading…
Reference in New Issue
Block a user