Make hardcoded parts of the optimizer sequence configurable

This commit is contained in:
Nikola Matic
2022-09-12 10:57:36 +02:00
parent f808855329
commit f6f0d6a360
55 changed files with 461 additions and 6 deletions
@@ -59,6 +59,8 @@ struct OptimiserSettings
"]"
"jmul[jul] VcTOcul jmul"; // Make source short and pretty
static char constexpr DefaultYulOptimiserCleanupSteps[] = "fDnTOc";
/// No optimisations at all - not recommended.
static OptimiserSettings none()
{
@@ -146,6 +148,11 @@ struct OptimiserSettings
/// them just by setting this to an empty string. Set @a runYulOptimiser to false if you want
/// no optimisations.
std::string yulOptimiserSteps = DefaultYulOptimiserSteps;
/// Sequence of clean up optimisation steps after the above (default or user supplied) set of
/// optimisation steps is completed. Note that if the string is left empty, there will still
/// be hard-coded optimisation steps that will run regardless. Set @a runYulOptimiser to false
/// if you want no optimisations.
std::string yulOptimiserCleanupSteps = DefaultYulOptimiserCleanupSteps;
/// 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.
size_t expectedExecutionsPerDeployment = 200;
+8 -3
View File
@@ -472,7 +472,7 @@ std::optional<Json::Value> checkOptimizerDetail(Json::Value const& _details, std
return {};
}
std::optional<Json::Value> checkOptimizerDetailSteps(Json::Value const& _details, std::string const& _name, string& _setting)
std::optional<Json::Value> checkOptimizerDetailSteps(Json::Value const& _details, std::string const& _name, string& _optimiserSetting, string& _cleanupSetting)
{
if (_details.isMember(_name))
{
@@ -490,7 +490,12 @@ std::optional<Json::Value> checkOptimizerDetailSteps(Json::Value const& _details
);
}
_setting = _details[_name].asString();
std::string const fullSequence = _details[_name].asString();
auto const delimiterPos = fullSequence.find(":");
_optimiserSetting = fullSequence.substr(0, delimiterPos);
if (delimiterPos != string::npos)
_cleanupSetting = fullSequence.substr(delimiterPos + 1);
}
else
return formatFatalError("JSONError", "\"settings.optimizer.details." + _name + "\" must be a string");
@@ -616,7 +621,7 @@ std::variant<OptimiserSettings, Json::Value> parseOptimizerSettings(Json::Value
return *result;
if (auto error = checkOptimizerDetail(details["yulDetails"], "stackAllocation", settings.optimizeStackAllocation))
return *error;
if (auto error = checkOptimizerDetailSteps(details["yulDetails"], "optimizerSteps", settings.yulOptimiserSteps))
if (auto error = checkOptimizerDetailSteps(details["yulDetails"], "optimizerSteps", settings.yulOptimiserSteps, settings.yulOptimiserCleanupSteps))
return *error;
}
}