Merge pull request #12310 from ethereum/renameRedundant

Rename RedundantAssignEliminator to UnusedAssignEliminator.
This commit is contained in:
chriseth 2021-11-23 15:47:24 +01:00 committed by GitHub
commit 18d6792966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 87 additions and 82 deletions

View File

@ -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

View File

@ -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

View File

@ -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'},

View File

@ -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);

View File

@ -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:

View File

@ -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));

View File

@ -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,19 @@ namespace solidity::yul
struct Dialect;
/**
* Base class for both RedundantAssignEliminator and RedundantStoreEliminator.
* Base class for both UnusedAssignEliminator and UnusedStoreEliminator.
*
* The class tracks the state of abstract "stores" (assignments or mstore/sstore
* statements) across the control-flow. It is the job of the derived class to create
* the stores and track references, but the base class adjusts their "used state" at
* control-flow splits and joins.
*
* 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;

View File

@ -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);

View File

@ -8,7 +8,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let a := 2

View File

@ -14,7 +14,7 @@
mstore(x, 0)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -13,7 +13,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -16,7 +16,7 @@
x := 3
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -13,7 +13,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -12,7 +12,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -19,7 +19,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x := 1

View File

@ -26,7 +26,7 @@
x := 13
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x := 1

View File

@ -19,7 +19,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// for { } 1 { }

View File

@ -35,7 +35,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x := 1

View File

@ -32,7 +32,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x := 1

View File

@ -11,7 +11,7 @@
x := 3
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -23,7 +23,7 @@
mstore(x, 0x42)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x := 1

View File

@ -12,7 +12,7 @@
r := 2
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let r

View File

@ -10,7 +10,7 @@
mstore(0, d)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let c

View File

@ -11,7 +11,7 @@
mstore(0, d)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let c

View File

@ -11,7 +11,7 @@
mstore(0, d)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let c

View File

@ -21,7 +21,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// function f(a, b) -> x

View File

@ -9,7 +9,7 @@
y := 4
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// function f() -> a, b

View File

@ -6,7 +6,7 @@
a := b
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let a := 2

View File

@ -4,7 +4,7 @@
a := mload(0)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let a

View File

@ -12,7 +12,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let i := 0

View File

@ -13,7 +13,7 @@
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let i := 0

View File

@ -7,7 +7,7 @@
}
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let a

View File

@ -4,6 +4,6 @@
a := 2
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// { let a }

View File

@ -8,7 +8,7 @@
mstore(x, 0)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -7,7 +7,7 @@
mstore(x, 0)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -8,7 +8,7 @@
mstore(x, 0)
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -6,7 +6,7 @@
case 0 { mstore(0, 1) }
}
// ----
// step: redundantAssignEliminator
// step: unusedAssignEliminator
//
// {
// let x

View File

@ -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,
@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_strin
BOOST_TEST(chromosome.length() == allSteps.size());
BOOST_TEST(chromosome.optimisationSteps() == allSteps);
BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighFTLMRrmVatpud");
BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighFTLMRmVatrpud");
}
BOOST_AUTO_TEST_CASE(optimisationSteps_should_translate_chromosomes_genes_to_optimisation_step_names)