2017-07-17 11:12:00 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2017-07-17 11:12:00 +00:00
|
|
|
/**
|
|
|
|
* @author Alex Beregszaszi
|
|
|
|
* @date 2017
|
|
|
|
* Helper class for optimiser settings.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
2020-04-24 12:19:36 +00:00
|
|
|
#include <string>
|
2017-07-17 11:12:00 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2017-07-17 11:12:00 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct OptimiserSettings
|
|
|
|
{
|
2020-04-24 12:19:36 +00:00
|
|
|
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
|
|
|
|
|
2017-07-17 11:12:00 +00:00
|
|
|
/// No optimisations at all - not recommended.
|
|
|
|
static OptimiserSettings none()
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
/// Minimal optimisations: Peephole and jumpdest remover
|
|
|
|
static OptimiserSettings minimal()
|
|
|
|
{
|
|
|
|
OptimiserSettings s = none();
|
|
|
|
s.runJumpdestRemover = true;
|
|
|
|
s.runPeephole = true;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
/// Standard optimisations.
|
2019-03-20 15:15:07 +00:00
|
|
|
static OptimiserSettings standard()
|
2017-07-17 11:12:00 +00:00
|
|
|
{
|
|
|
|
OptimiserSettings s;
|
|
|
|
s.runOrderLiterals = true;
|
|
|
|
s.runJumpdestRemover = true;
|
|
|
|
s.runPeephole = true;
|
|
|
|
s.runDeduplicate = true;
|
|
|
|
s.runCSE = true;
|
|
|
|
s.runConstantOptimiser = true;
|
2019-11-26 15:41:58 +00:00
|
|
|
s.runYulOptimiser = true;
|
|
|
|
s.optimizeStackAllocation = true;
|
2017-07-17 11:12:00 +00:00
|
|
|
s.expectedExecutionsPerDeployment = 200;
|
|
|
|
return s;
|
|
|
|
}
|
2019-11-26 15:41:58 +00:00
|
|
|
/// Full optimisations. Currently an alias for standard optimisations.
|
2017-07-17 11:12:00 +00:00
|
|
|
static OptimiserSettings full()
|
|
|
|
{
|
2019-11-26 15:41:58 +00:00
|
|
|
return standard();
|
2017-07-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(OptimiserSettings const& _other) const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
runOrderLiterals == _other.runOrderLiterals &&
|
|
|
|
runJumpdestRemover == _other.runJumpdestRemover &&
|
|
|
|
runPeephole == _other.runPeephole &&
|
|
|
|
runDeduplicate == _other.runDeduplicate &&
|
|
|
|
runCSE == _other.runCSE &&
|
|
|
|
runConstantOptimiser == _other.runConstantOptimiser &&
|
2019-02-26 18:55:13 +00:00
|
|
|
optimizeStackAllocation == _other.optimizeStackAllocation &&
|
2017-07-17 11:12:00 +00:00
|
|
|
runYulOptimiser == _other.runYulOptimiser &&
|
2020-04-24 12:19:36 +00:00
|
|
|
yulOptimiserSteps == _other.yulOptimiserSteps &&
|
2017-07-17 11:12:00 +00:00
|
|
|
expectedExecutionsPerDeployment == _other.expectedExecutionsPerDeployment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Move literals to the right of commutative binary operators during code generation.
|
|
|
|
/// This helps exploiting associativity.
|
|
|
|
bool runOrderLiterals = false;
|
|
|
|
/// Non-referenced jump destination remover.
|
|
|
|
bool runJumpdestRemover = false;
|
|
|
|
/// Peephole optimizer
|
|
|
|
bool runPeephole = false;
|
|
|
|
/// Assembly block deduplicator
|
|
|
|
bool runDeduplicate = false;
|
|
|
|
/// Common subexpression eliminator based on assembly items.
|
|
|
|
bool runCSE = false;
|
|
|
|
/// Constant optimizer, which tries to find better representations that satisfy the given
|
|
|
|
/// size/cost-trade-off.
|
|
|
|
bool runConstantOptimiser = false;
|
2019-02-26 18:55:13 +00:00
|
|
|
/// Perform more efficient stack allocation for variables during code generation from Yul to bytecode.
|
|
|
|
bool optimizeStackAllocation = false;
|
2017-07-17 11:12:00 +00:00
|
|
|
/// Yul optimiser with default settings. Will only run on certain parts of the code for now.
|
|
|
|
bool runYulOptimiser = false;
|
2020-04-24 12:19:36 +00:00
|
|
|
/// 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;
|
2017-07-17 11:12:00 +00:00
|
|
|
/// 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|