mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
OptimiserSuite: Extract the code for repeating a sequence into runSequenceUntilStable()
- Define a constant for the maximum number of repeats of the optimisation string
This commit is contained in:
parent
10879bcae6
commit
1b4e06605d
@ -113,150 +113,105 @@ void OptimiserSuite::run(
|
|||||||
|
|
||||||
// None of the above can make stack problems worse.
|
// None of the above can make stack problems worse.
|
||||||
|
|
||||||
size_t codeSize = 0;
|
suite.runSequenceUntilStable({
|
||||||
for (size_t rounds = 0; rounds < 12; ++rounds)
|
// Turn into SSA and simplify
|
||||||
{
|
ExpressionSplitter::name,
|
||||||
{
|
SSATransform::name,
|
||||||
size_t newSize = CodeSize::codeSizeIncludingFunctions(ast);
|
RedundantAssignEliminator::name,
|
||||||
if (newSize == codeSize)
|
RedundantAssignEliminator::name,
|
||||||
break;
|
ExpressionSimplifier::name,
|
||||||
codeSize = newSize;
|
CommonSubexpressionEliminator::name,
|
||||||
}
|
LoadResolver::name,
|
||||||
|
LoopInvariantCodeMotion::name,
|
||||||
|
|
||||||
{
|
// perform structural simplification
|
||||||
// Turn into SSA and simplify
|
CommonSubexpressionEliminator::name,
|
||||||
suite.runSequence({
|
ConditionalSimplifier::name,
|
||||||
ExpressionSplitter::name,
|
LiteralRematerialiser::name,
|
||||||
SSATransform::name,
|
ConditionalUnsimplifier::name,
|
||||||
RedundantAssignEliminator::name,
|
StructuralSimplifier::name,
|
||||||
RedundantAssignEliminator::name,
|
LiteralRematerialiser::name,
|
||||||
ExpressionSimplifier::name,
|
ForLoopConditionOutOfBody::name,
|
||||||
CommonSubexpressionEliminator::name,
|
ControlFlowSimplifier::name,
|
||||||
LoadResolver::name,
|
StructuralSimplifier::name,
|
||||||
LoopInvariantCodeMotion::name
|
ControlFlowSimplifier::name,
|
||||||
}, ast);
|
BlockFlattener::name,
|
||||||
}
|
DeadCodeEliminator::name,
|
||||||
|
ForLoopConditionIntoBody::name,
|
||||||
|
UnusedPruner::name,
|
||||||
|
CircularReferencesPruner::name,
|
||||||
|
|
||||||
{
|
// simplify again
|
||||||
// perform structural simplification
|
LoadResolver::name,
|
||||||
suite.runSequence({
|
CommonSubexpressionEliminator::name,
|
||||||
CommonSubexpressionEliminator::name,
|
UnusedPruner::name,
|
||||||
ConditionalSimplifier::name,
|
CircularReferencesPruner::name,
|
||||||
LiteralRematerialiser::name,
|
|
||||||
ConditionalUnsimplifier::name,
|
|
||||||
StructuralSimplifier::name,
|
|
||||||
LiteralRematerialiser::name,
|
|
||||||
ForLoopConditionOutOfBody::name,
|
|
||||||
ControlFlowSimplifier::name,
|
|
||||||
StructuralSimplifier::name,
|
|
||||||
ControlFlowSimplifier::name,
|
|
||||||
BlockFlattener::name,
|
|
||||||
DeadCodeEliminator::name,
|
|
||||||
ForLoopConditionIntoBody::name,
|
|
||||||
UnusedPruner::name,
|
|
||||||
CircularReferencesPruner::name
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
// reverse SSA
|
||||||
// simplify again
|
SSAReverser::name,
|
||||||
suite.runSequence({
|
CommonSubexpressionEliminator::name,
|
||||||
LoadResolver::name,
|
UnusedPruner::name,
|
||||||
CommonSubexpressionEliminator::name,
|
CircularReferencesPruner::name,
|
||||||
UnusedPruner::name,
|
|
||||||
CircularReferencesPruner::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
ExpressionJoiner::name,
|
||||||
// reverse SSA
|
ExpressionJoiner::name,
|
||||||
suite.runSequence({
|
|
||||||
SSAReverser::name,
|
|
||||||
CommonSubexpressionEliminator::name,
|
|
||||||
UnusedPruner::name,
|
|
||||||
CircularReferencesPruner::name,
|
|
||||||
|
|
||||||
ExpressionJoiner::name,
|
|
||||||
ExpressionJoiner::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
// should have good "compilability" property here.
|
// should have good "compilability" property here.
|
||||||
|
|
||||||
{
|
// run functional expression inliner
|
||||||
// run functional expression inliner
|
ExpressionInliner::name,
|
||||||
suite.runSequence({
|
UnusedPruner::name,
|
||||||
ExpressionInliner::name,
|
CircularReferencesPruner::name,
|
||||||
UnusedPruner::name,
|
|
||||||
CircularReferencesPruner::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
// Prune a bit more in SSA
|
||||||
// Prune a bit more in SSA
|
ExpressionSplitter::name,
|
||||||
suite.runSequence({
|
SSATransform::name,
|
||||||
ExpressionSplitter::name,
|
RedundantAssignEliminator::name,
|
||||||
SSATransform::name,
|
UnusedPruner::name,
|
||||||
RedundantAssignEliminator::name,
|
CircularReferencesPruner::name,
|
||||||
UnusedPruner::name,
|
RedundantAssignEliminator::name,
|
||||||
CircularReferencesPruner::name,
|
UnusedPruner::name,
|
||||||
RedundantAssignEliminator::name,
|
CircularReferencesPruner::name,
|
||||||
UnusedPruner::name,
|
|
||||||
CircularReferencesPruner::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
// Turn into SSA again and simplify
|
||||||
// Turn into SSA again and simplify
|
ExpressionSplitter::name,
|
||||||
suite.runSequence({
|
SSATransform::name,
|
||||||
ExpressionSplitter::name,
|
RedundantAssignEliminator::name,
|
||||||
SSATransform::name,
|
RedundantAssignEliminator::name,
|
||||||
RedundantAssignEliminator::name,
|
CommonSubexpressionEliminator::name,
|
||||||
RedundantAssignEliminator::name,
|
LoadResolver::name,
|
||||||
CommonSubexpressionEliminator::name,
|
|
||||||
LoadResolver::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
// run full inliner
|
||||||
// run full inliner
|
FunctionGrouper::name,
|
||||||
suite.runSequence({
|
EquivalentFunctionCombiner::name,
|
||||||
FunctionGrouper::name,
|
FullInliner::name,
|
||||||
EquivalentFunctionCombiner::name,
|
BlockFlattener::name,
|
||||||
FullInliner::name,
|
|
||||||
BlockFlattener::name
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
// SSA plus simplify
|
||||||
// SSA plus simplify
|
ConditionalSimplifier::name,
|
||||||
suite.runSequence({
|
LiteralRematerialiser::name,
|
||||||
ConditionalSimplifier::name,
|
ConditionalUnsimplifier::name,
|
||||||
LiteralRematerialiser::name,
|
CommonSubexpressionEliminator::name,
|
||||||
ConditionalUnsimplifier::name,
|
SSATransform::name,
|
||||||
CommonSubexpressionEliminator::name,
|
RedundantAssignEliminator::name,
|
||||||
SSATransform::name,
|
RedundantAssignEliminator::name,
|
||||||
RedundantAssignEliminator::name,
|
LoadResolver::name,
|
||||||
RedundantAssignEliminator::name,
|
ExpressionSimplifier::name,
|
||||||
LoadResolver::name,
|
LiteralRematerialiser::name,
|
||||||
ExpressionSimplifier::name,
|
ForLoopConditionOutOfBody::name,
|
||||||
LiteralRematerialiser::name,
|
StructuralSimplifier::name,
|
||||||
ForLoopConditionOutOfBody::name,
|
BlockFlattener::name,
|
||||||
StructuralSimplifier::name,
|
DeadCodeEliminator::name,
|
||||||
BlockFlattener::name,
|
ControlFlowSimplifier::name,
|
||||||
DeadCodeEliminator::name,
|
CommonSubexpressionEliminator::name,
|
||||||
ControlFlowSimplifier::name,
|
SSATransform::name,
|
||||||
CommonSubexpressionEliminator::name,
|
RedundantAssignEliminator::name,
|
||||||
SSATransform::name,
|
RedundantAssignEliminator::name,
|
||||||
RedundantAssignEliminator::name,
|
ForLoopConditionIntoBody::name,
|
||||||
RedundantAssignEliminator::name,
|
UnusedPruner::name,
|
||||||
ForLoopConditionIntoBody::name,
|
CircularReferencesPruner::name,
|
||||||
UnusedPruner::name,
|
CommonSubexpressionEliminator::name,
|
||||||
CircularReferencesPruner::name,
|
}, ast);
|
||||||
CommonSubexpressionEliminator::name,
|
|
||||||
}, ast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make source short and pretty.
|
// Make source short and pretty.
|
||||||
|
|
||||||
@ -453,3 +408,21 @@ void OptimiserSuite::runSequence(std::vector<string> const& _steps, Block& _ast)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptimiserSuite::runSequenceUntilStable(
|
||||||
|
std::vector<string> const& _steps,
|
||||||
|
Block& _ast,
|
||||||
|
size_t maxRounds
|
||||||
|
)
|
||||||
|
{
|
||||||
|
size_t codeSize = 0;
|
||||||
|
for (size_t rounds = 0; rounds < maxRounds; ++rounds)
|
||||||
|
{
|
||||||
|
size_t newSize = CodeSize::codeSizeIncludingFunctions(_ast);
|
||||||
|
if (newSize == codeSize)
|
||||||
|
break;
|
||||||
|
codeSize = newSize;
|
||||||
|
|
||||||
|
runSequence(_steps, _ast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -45,6 +45,8 @@ struct Object;
|
|||||||
class OptimiserSuite
|
class OptimiserSuite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr size_t MaxRounds = 12;
|
||||||
|
|
||||||
enum class Debug
|
enum class Debug
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
@ -60,6 +62,11 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
void runSequence(std::vector<std::string> const& _steps, Block& _ast);
|
void runSequence(std::vector<std::string> const& _steps, Block& _ast);
|
||||||
|
void runSequenceUntilStable(
|
||||||
|
std::vector<std::string> const& _steps,
|
||||||
|
Block& _ast,
|
||||||
|
size_t maxRounds = MaxRounds
|
||||||
|
);
|
||||||
|
|
||||||
static std::map<std::string, std::unique_ptr<OptimiserStep>> const& allSteps();
|
static std::map<std::string, std::unique_ptr<OptimiserStep>> const& allSteps();
|
||||||
static std::map<std::string, char> const& stepNameToAbbreviationMap();
|
static std::map<std::string, char> const& stepNameToAbbreviationMap();
|
||||||
|
Loading…
Reference in New Issue
Block a user