mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move the default optimisation steps from OptimiserSuite to OptimiserSettings
- Now it's a mandatory parameter in OptimiserSuite::run()
This commit is contained in:
parent
69b79f848b
commit
c41a832f65
@ -502,6 +502,7 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _
|
|||||||
&meter,
|
&meter,
|
||||||
_object,
|
_object,
|
||||||
_optimiserSettings.optimizeStackAllocation,
|
_optimiserSettings.optimizeStackAllocation,
|
||||||
|
_optimiserSettings.yulOptimiserSteps,
|
||||||
_externalIdentifiers
|
_externalIdentifiers
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -23,12 +23,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace solidity::frontend
|
namespace solidity::frontend
|
||||||
{
|
{
|
||||||
|
|
||||||
struct OptimiserSettings
|
struct OptimiserSettings
|
||||||
{
|
{
|
||||||
|
static char constexpr DefaultYulOptimiserSteps[] =
|
||||||
|
"dhfoDgvulfnTUtnIf" // None of these can make stack problems worse
|
||||||
|
"["
|
||||||
|
"xarrscLM" // Turn into SSA and simplify
|
||||||
|
"cCTUtTOntnfDIul" // Perform structural simplification
|
||||||
|
"Lcul" // Simplify again
|
||||||
|
"Vcul jj" // Reverse SSA
|
||||||
|
|
||||||
|
// should have good "compilability" property here.
|
||||||
|
|
||||||
|
"eul" // Run functional expression inliner
|
||||||
|
"xarulrul" // Prune a bit more in SSA
|
||||||
|
"xarrcL" // Turn into SSA again and simplify
|
||||||
|
"gvif" // Run full inliner
|
||||||
|
"CTUcarrLsTOtfDncarrIulc" // SSA plus simplify
|
||||||
|
"]"
|
||||||
|
"jmuljuljul VcTOcul jmul"; // Make source short and pretty
|
||||||
|
|
||||||
/// No optimisations at all - not recommended.
|
/// No optimisations at all - not recommended.
|
||||||
static OptimiserSettings none()
|
static OptimiserSettings none()
|
||||||
{
|
{
|
||||||
@ -74,6 +93,7 @@ struct OptimiserSettings
|
|||||||
runConstantOptimiser == _other.runConstantOptimiser &&
|
runConstantOptimiser == _other.runConstantOptimiser &&
|
||||||
optimizeStackAllocation == _other.optimizeStackAllocation &&
|
optimizeStackAllocation == _other.optimizeStackAllocation &&
|
||||||
runYulOptimiser == _other.runYulOptimiser &&
|
runYulOptimiser == _other.runYulOptimiser &&
|
||||||
|
yulOptimiserSteps == _other.yulOptimiserSteps &&
|
||||||
expectedExecutionsPerDeployment == _other.expectedExecutionsPerDeployment;
|
expectedExecutionsPerDeployment == _other.expectedExecutionsPerDeployment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +115,11 @@ struct OptimiserSettings
|
|||||||
bool optimizeStackAllocation = false;
|
bool optimizeStackAllocation = false;
|
||||||
/// Yul optimiser with default settings. Will only run on certain parts of the code for now.
|
/// Yul optimiser with default settings. Will only run on certain parts of the code for now.
|
||||||
bool runYulOptimiser = false;
|
bool runYulOptimiser = false;
|
||||||
|
/// Sequence of optimisation steps to be performed by Yul optimiser.
|
||||||
|
/// Note that there are some hard-coded steps in the optimiser and you cannot disable
|
||||||
|
/// them just by setting this to an empty string. Set @a runYulOptimiser to false if you want
|
||||||
|
/// no optimisations.
|
||||||
|
std::string yulOptimiserSteps = DefaultYulOptimiserSteps;
|
||||||
/// This specifies an estimate on how often each opcode in this assembly will be executed,
|
/// This specifies an estimate on how often each opcode in this assembly will be executed,
|
||||||
/// i.e. use a small value to optimise for size and a large value to optimise for runtime gas usage.
|
/// i.e. use a small value to optimise for size and a large value to optimise for runtime gas usage.
|
||||||
size_t expectedExecutionsPerDeployment = 200;
|
size_t expectedExecutionsPerDeployment = 200;
|
||||||
|
@ -183,7 +183,8 @@ void AssemblyStack::optimize(Object& _object, bool _isCreation)
|
|||||||
dialect,
|
dialect,
|
||||||
meter.get(),
|
meter.get(),
|
||||||
_object,
|
_object,
|
||||||
m_optimiserSettings.optimizeStackAllocation
|
m_optimiserSettings.optimizeStackAllocation,
|
||||||
|
m_optimiserSettings.yulOptimiserSteps
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ void OptimiserSuite::run(
|
|||||||
GasMeter const* _meter,
|
GasMeter const* _meter,
|
||||||
Object& _object,
|
Object& _object,
|
||||||
bool _optimizeStackAllocation,
|
bool _optimizeStackAllocation,
|
||||||
|
string const& _optimisationSequence,
|
||||||
set<YulString> const& _externallyUsedIdentifiers
|
set<YulString> const& _externallyUsedIdentifiers
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -94,25 +95,12 @@ void OptimiserSuite::run(
|
|||||||
|
|
||||||
OptimiserSuite suite(_dialect, reservedIdentifiers, Debug::None, ast);
|
OptimiserSuite suite(_dialect, reservedIdentifiers, Debug::None, ast);
|
||||||
|
|
||||||
suite.runSequence(
|
// Some steps depend on properties ensured by FunctionHoister, FunctionGrouper and
|
||||||
"dhfoDgvulfnTUtnIf" // None of these can make stack problems worse
|
// ForLoopInitRewriter. Run them first to be able to run arbitrary sequences safely.
|
||||||
"["
|
suite.runSequence("fgo", ast);
|
||||||
"xarrscLM" // Turn into SSA and simplify
|
|
||||||
"cCTUtTOntnfDIul" // Perform structural simplification
|
|
||||||
"Lcul" // Simplify again
|
|
||||||
"Vcul jj" // Reverse SSA
|
|
||||||
|
|
||||||
// should have good "compilability" property here.
|
// Now the user-supplied part
|
||||||
|
suite.runSequence(_optimisationSequence, ast);
|
||||||
"eul" // Run functional expression inliner
|
|
||||||
"xarulrul" // Prune a bit more in SSA
|
|
||||||
"xarrcL" // Turn into SSA again and simplify
|
|
||||||
"gvif" // Run full inliner
|
|
||||||
"CTUcarrLsTOtfDncarrIulc" // SSA plus simplify
|
|
||||||
"]"
|
|
||||||
"jmuljuljul VcTOcul jmul", // Make source short and pretty
|
|
||||||
ast
|
|
||||||
);
|
|
||||||
|
|
||||||
// This is a tuning parameter, but actually just prevents infinite loops.
|
// This is a tuning parameter, but actually just prevents infinite loops.
|
||||||
size_t stackCompressorMaxIterations = 16;
|
size_t stackCompressorMaxIterations = 16;
|
||||||
|
@ -62,6 +62,7 @@ public:
|
|||||||
GasMeter const* _meter,
|
GasMeter const* _meter,
|
||||||
Object& _object,
|
Object& _object,
|
||||||
bool _optimizeStackAllocation,
|
bool _optimizeStackAllocation,
|
||||||
|
std::string const& _optimisationSequence,
|
||||||
std::set<YulString> const& _externallyUsedIdentifiers = {}
|
std::set<YulString> const& _externallyUsedIdentifiers = {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -74,6 +74,8 @@
|
|||||||
|
|
||||||
#include <libsolutil/AnsiColorized.h>
|
#include <libsolutil/AnsiColorized.h>
|
||||||
|
|
||||||
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
@ -342,7 +344,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
|||||||
yul::Object obj;
|
yul::Object obj;
|
||||||
obj.code = m_ast;
|
obj.code = m_ast;
|
||||||
obj.analysisInfo = m_analysisInfo;
|
obj.analysisInfo = m_analysisInfo;
|
||||||
OptimiserSuite::run(*m_dialect, &meter, obj, true);
|
OptimiserSuite::run(*m_dialect, &meter, obj, true, solidity::frontend::OptimiserSettings::DefaultYulOptimiserSteps);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user