[yulopti] Replace hard-coded step list with OptimiserSuite's maps

This commit is contained in:
cameel 2020-01-24 23:51:35 +01:00
parent 4e7c1c7876
commit 4129c27495

View File

@ -30,40 +30,11 @@
#include <libyul/Object.h> #include <libyul/Object.h>
#include <liblangutil/SourceReferenceFormatter.h> #include <liblangutil/SourceReferenceFormatter.h>
#include <libyul/optimiser/BlockFlattener.h>
#include <libyul/optimiser/Disambiguator.h> #include <libyul/optimiser/Disambiguator.h>
#include <libyul/optimiser/CallGraphGenerator.h>
#include <libyul/optimiser/CommonSubexpressionEliminator.h>
#include <libyul/optimiser/ConditionalSimplifier.h>
#include <libyul/optimiser/ConditionalUnsimplifier.h>
#include <libyul/optimiser/ControlFlowSimplifier.h>
#include <libyul/optimiser/NameCollector.h>
#include <libyul/optimiser/EquivalentFunctionCombiner.h>
#include <libyul/optimiser/ExpressionSplitter.h>
#include <libyul/optimiser/FunctionGrouper.h>
#include <libyul/optimiser/FunctionHoister.h>
#include <libyul/optimiser/ExpressionInliner.h>
#include <libyul/optimiser/FullInliner.h>
#include <libyul/optimiser/ForLoopConditionIntoBody.h>
#include <libyul/optimiser/ForLoopConditionOutOfBody.h>
#include <libyul/optimiser/ForLoopInitRewriter.h>
#include <libyul/optimiser/MainFunction.h>
#include <libyul/optimiser/Rematerialiser.h>
#include <libyul/optimiser/ExpressionSimplifier.h>
#include <libyul/optimiser/UnusedPruner.h>
#include <libyul/optimiser/DeadCodeEliminator.h>
#include <libyul/optimiser/ExpressionJoiner.h>
#include <libyul/optimiser/OptimiserStep.h> #include <libyul/optimiser/OptimiserStep.h>
#include <libyul/optimiser/RedundantAssignEliminator.h>
#include <libyul/optimiser/SSAReverser.h>
#include <libyul/optimiser/SSATransform.h>
#include <libyul/optimiser/StackCompressor.h> #include <libyul/optimiser/StackCompressor.h>
#include <libyul/optimiser/StructuralSimplifier.h>
#include <libyul/optimiser/Semantics.h>
#include <libyul/optimiser/VarDeclInitializer.h>
#include <libyul/optimiser/VarNameCleaner.h> #include <libyul/optimiser/VarNameCleaner.h>
#include <libyul/optimiser/LoadResolver.h> #include <libyul/optimiser/Suite.h>
#include <libyul/optimiser/LoopInvariantCodeMotion.h>
#include <libyul/backends/evm/EVMDialect.h> #include <libyul/backends/evm/EVMDialect.h>
@ -71,6 +42,7 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <cassert>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
@ -150,90 +122,26 @@ public:
cout << ' ' << char(option) << endl; cout << ' ' << char(option) << endl;
OptimiserStepContext context{m_dialect, *m_nameDispenser, reservedIdentifiers}; OptimiserStepContext context{m_dialect, *m_nameDispenser, reservedIdentifiers};
switch (option)
map<char, string> const& abbreviationMap = OptimiserSuite::stepAbbreviationToNameMap();
assert(abbreviationMap.count('q') == 0 && "We have chosen 'q' for quit");
assert(abbreviationMap.count('p') == 0 && "We have chosen 'p' for StackCompressor");
auto abbreviationAndName = abbreviationMap.find(option);
if (abbreviationAndName != abbreviationMap.end())
{
OptimiserStep const& step = *OptimiserSuite::allSteps().at(abbreviationAndName->second);
step.run(context, *m_ast);
}
else switch (option)
{ {
case 'q': case 'q':
return; return;
case 'f':
BlockFlattener::run(context, *m_ast);
break;
case 'o':
ForLoopInitRewriter::run(context, *m_ast);
break;
case 'O':
ForLoopConditionOutOfBody::run(context, *m_ast);
break;
case 'I':
ForLoopConditionIntoBody::run(context, *m_ast);
break;
case 'c':
CommonSubexpressionEliminator::run(context, *m_ast);
break;
case 'C':
ConditionalSimplifier::run(context, *m_ast);
break;
case 'U':
ConditionalUnsimplifier::run(context, *m_ast);
break;
case 'd':
VarDeclInitializer::run(context, *m_ast);
break;
case 'l': case 'l':
VarNameCleaner::run(context, *m_ast); VarNameCleaner::run(context, *m_ast);
// VarNameCleaner destroys the unique names guarantee of the disambiguator. // VarNameCleaner destroys the unique names guarantee of the disambiguator.
disambiguated = false; disambiguated = false;
break; break;
case 'x':
ExpressionSplitter::run(context, *m_ast);
break;
case 'j':
ExpressionJoiner::run(context, *m_ast);
break;
case 'g':
FunctionGrouper::run(context, *m_ast);
break;
case 'h':
FunctionHoister::run(context, *m_ast);
break;
case 'e':
ExpressionInliner::run(context, *m_ast);
break;
case 'i':
FullInliner::run(context, *m_ast);
break;
case 's':
ExpressionSimplifier::run(context, *m_ast);
break;
case 't':
StructuralSimplifier::run(context, *m_ast);
break;
case 'T':
LiteralRematerialiser::run(context, *m_ast);
break;
case 'n':
ControlFlowSimplifier::run(context, *m_ast);
break;
case 'u':
UnusedPruner::run(context, *m_ast);
break;
case 'D':
DeadCodeEliminator::run(context, *m_ast);
break;
case 'a':
SSATransform::run(context, *m_ast);
break;
case 'r':
RedundantAssignEliminator::run(context, *m_ast);
break;
case 'm':
Rematerialiser::run(context, *m_ast);
break;
case 'v':
EquivalentFunctionCombiner::run(context, *m_ast);
break;
case 'V':
SSAReverser::run(context, *m_ast);
break;
case 'p': case 'p':
{ {
Object obj; Object obj;
@ -241,12 +149,6 @@ public:
StackCompressor::run(m_dialect, obj, true, 16); StackCompressor::run(m_dialect, obj, true, 16);
break; break;
} }
case 'L':
LoadResolver::run(context, *m_ast);
break;
case 'M':
LoopInvariantCodeMotion::run(context, *m_ast);
break;
default: default:
cout << "Unknown option." << endl; cout << "Unknown option." << endl;
} }