mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
CommandLineParser: Handle --optimize-runs option in assembly mode
Fixes #11708.
This commit is contained in:
parent
1794e1c837
commit
c627e6af10
@ -22,6 +22,7 @@ Bugfixes:
|
|||||||
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
|
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
|
||||||
* Yul Code Generator: Fix source location references for calls to builtin functions.
|
* Yul Code Generator: Fix source location references for calls to builtin functions.
|
||||||
* Yul Parser: Fix source location references for ``if`` statements.
|
* Yul Parser: Fix source location references for ``if`` statements.
|
||||||
|
* Commandline Interface: Apply ``--optimizer-runs`` option in assembly / yul mode.
|
||||||
|
|
||||||
|
|
||||||
### 0.8.6 (2021-06-22)
|
### 0.8.6 (2021-06-22)
|
||||||
|
@ -49,6 +49,8 @@ differences, for example, functions may be inlined, combined, or rewritten to el
|
|||||||
redundancies, etc. (compare the output between the flags ``--ir`` and
|
redundancies, etc. (compare the output between the flags ``--ir`` and
|
||||||
``--optimize --ir-optimized``).
|
``--optimize --ir-optimized``).
|
||||||
|
|
||||||
|
.. _optimizer-parameter-runs:
|
||||||
|
|
||||||
Optimizer Parameter Runs
|
Optimizer Parameter Runs
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
@ -1177,11 +1177,13 @@ intermediate states. This allows for easy debugging and verification of the opti
|
|||||||
Please refer to the general :ref:`optimizer documentation <optimizer>`
|
Please refer to the general :ref:`optimizer documentation <optimizer>`
|
||||||
for more details about the different optimization stages and how to use the optimizer.
|
for more details about the different optimization stages and how to use the optimizer.
|
||||||
|
|
||||||
If you want to use Solidity in stand-alone Yul mode, you activate the optimizer using ``--optimize``:
|
If you want to use Solidity in stand-alone Yul mode, you activate the optimizer using ``--optimize``
|
||||||
|
and optionally specify the :ref:`expected number of contract executions <optimizer-parameter-runs>` with
|
||||||
|
``--optimize-runs``:
|
||||||
|
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
solc --strict-assembly --optimize
|
solc --strict-assembly --optimize --optimize-runs 200
|
||||||
|
|
||||||
In Solidity mode, the Yul optimizer is activated together with the regular optimizer.
|
In Solidity mode, the Yul optimizer is activated together with the regular optimizer.
|
||||||
|
|
||||||
|
@ -555,6 +555,7 @@ bool CommandLineInterface::processInput()
|
|||||||
m_options.assembly.inputLanguage,
|
m_options.assembly.inputLanguage,
|
||||||
m_options.assembly.targetMachine,
|
m_options.assembly.targetMachine,
|
||||||
m_options.optimizer.enabled,
|
m_options.optimizer.enabled,
|
||||||
|
m_options.optimizer.expectedExecutionsPerDeployment,
|
||||||
m_options.optimizer.yulSteps
|
m_options.optimizer.yulSteps
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -595,7 +596,8 @@ bool CommandLineInterface::compile()
|
|||||||
m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm);
|
m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm);
|
||||||
|
|
||||||
OptimiserSettings settings = m_options.optimizer.enabled ? OptimiserSettings::standard() : OptimiserSettings::minimal();
|
OptimiserSettings settings = m_options.optimizer.enabled ? OptimiserSettings::standard() : OptimiserSettings::minimal();
|
||||||
settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment;
|
if (m_options.optimizer.expectedExecutionsPerDeployment.has_value())
|
||||||
|
settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment.value();
|
||||||
if (m_options.optimizer.noOptimizeYul)
|
if (m_options.optimizer.noOptimizeYul)
|
||||||
settings.runYulOptimiser = false;
|
settings.runYulOptimiser = false;
|
||||||
|
|
||||||
@ -941,6 +943,7 @@ bool CommandLineInterface::assemble(
|
|||||||
yul::AssemblyStack::Language _language,
|
yul::AssemblyStack::Language _language,
|
||||||
yul::AssemblyStack::Machine _targetMachine,
|
yul::AssemblyStack::Machine _targetMachine,
|
||||||
bool _optimize,
|
bool _optimize,
|
||||||
|
optional<unsigned int> _expectedExecutionsPerDeployment,
|
||||||
optional<string> _yulOptimiserSteps
|
optional<string> _yulOptimiserSteps
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -951,6 +954,8 @@ bool CommandLineInterface::assemble(
|
|||||||
for (auto const& src: m_fileReader.sourceCodes())
|
for (auto const& src: m_fileReader.sourceCodes())
|
||||||
{
|
{
|
||||||
OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal();
|
OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal();
|
||||||
|
if (_expectedExecutionsPerDeployment.has_value())
|
||||||
|
settings.expectedExecutionsPerDeployment = _expectedExecutionsPerDeployment.value();
|
||||||
if (_yulOptimiserSteps.has_value())
|
if (_yulOptimiserSteps.has_value())
|
||||||
settings.yulOptimiserSteps = _yulOptimiserSteps.value();
|
settings.yulOptimiserSteps = _yulOptimiserSteps.value();
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ private:
|
|||||||
yul::AssemblyStack::Language _language,
|
yul::AssemblyStack::Language _language,
|
||||||
yul::AssemblyStack::Machine _targetMachine,
|
yul::AssemblyStack::Machine _targetMachine,
|
||||||
bool _optimize,
|
bool _optimize,
|
||||||
|
std::optional<unsigned int> _expectedExecutionsPerDeployment = std::nullopt,
|
||||||
std::optional<std::string> _yulOptimiserSteps = std::nullopt
|
std::optional<std::string> _yulOptimiserSteps = std::nullopt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -967,6 +967,8 @@ General Information)").c_str(),
|
|||||||
m_options.optimizer.enabled = (m_args.count(g_strOptimize) > 0);
|
m_options.optimizer.enabled = (m_args.count(g_strOptimize) > 0);
|
||||||
m_options.optimizer.noOptimizeYul = (m_args.count(g_strNoOptimizeYul) > 0);
|
m_options.optimizer.noOptimizeYul = (m_args.count(g_strNoOptimizeYul) > 0);
|
||||||
|
|
||||||
|
m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as<unsigned>();
|
||||||
|
|
||||||
if (m_args.count(g_strYulOptimizations))
|
if (m_args.count(g_strYulOptimizations))
|
||||||
{
|
{
|
||||||
if (!m_options.optimizer.enabled)
|
if (!m_options.optimizer.enabled)
|
||||||
|
@ -159,7 +159,7 @@ struct CommandLineOptions
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
unsigned expectedExecutionsPerDeployment = 0;
|
std::optional<unsigned> expectedExecutionsPerDeployment;
|
||||||
bool noOptimizeYul = false;
|
bool noOptimizeYul = false;
|
||||||
std::optional<std::string> yulSteps;
|
std::optional<std::string> yulSteps;
|
||||||
} optimizer;
|
} optimizer;
|
||||||
|
1
test/cmdlineTests/yul_optimize_runs/args
Normal file
1
test/cmdlineTests/yul_optimize_runs/args
Normal file
@ -0,0 +1 @@
|
|||||||
|
--yul --yul-dialect evm --optimize --ir-optimized --optimize-runs 10000
|
1
test/cmdlineTests/yul_optimize_runs/err
Normal file
1
test/cmdlineTests/yul_optimize_runs/err
Normal file
@ -0,0 +1 @@
|
|||||||
|
Warning: Yul is still experimental. Please use the output with care.
|
13
test/cmdlineTests/yul_optimize_runs/input.yul
Normal file
13
test/cmdlineTests/yul_optimize_runs/input.yul
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
object "RunsTest1" {
|
||||||
|
code {
|
||||||
|
// Deploy the contract
|
||||||
|
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
|
||||||
|
return(0, datasize("Runtime"))
|
||||||
|
}
|
||||||
|
object "Runtime" {
|
||||||
|
code {
|
||||||
|
let funcSel := shl(224, 0xabc12345)
|
||||||
|
mstore(0, funcSel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
test/cmdlineTests/yul_optimize_runs/output
Normal file
52
test/cmdlineTests/yul_optimize_runs/output
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
======= yul_optimize_runs/input.yul (EVM) =======
|
||||||
|
|
||||||
|
Pretty printed source:
|
||||||
|
object "RunsTest1" {
|
||||||
|
code {
|
||||||
|
{
|
||||||
|
let _1 := datasize("Runtime")
|
||||||
|
datacopy(0, dataoffset("Runtime"), _1)
|
||||||
|
return(0, _1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
object "Runtime" {
|
||||||
|
code {
|
||||||
|
{
|
||||||
|
mstore(0, 0xabc1234500000000000000000000000000000000000000000000000000000000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Binary representation:
|
||||||
|
602480600d600039806000f3fe7fabc1234500000000000000000000000000000000000000000000000000000000600052
|
||||||
|
|
||||||
|
Text representation:
|
||||||
|
/* "yul_optimize_runs/input.yul":106:125 */
|
||||||
|
dataSize(sub_0)
|
||||||
|
dup1
|
||||||
|
/* "yul_optimize_runs/input.yul":83:104 */
|
||||||
|
dataOffset(sub_0)
|
||||||
|
/* "yul_optimize_runs/input.yul":80:81 */
|
||||||
|
0x00
|
||||||
|
/* "yul_optimize_runs/input.yul":71:126 */
|
||||||
|
codecopy
|
||||||
|
/* "yul_optimize_runs/input.yul":145:164 */
|
||||||
|
dup1
|
||||||
|
/* "yul_optimize_runs/input.yul":80:81 */
|
||||||
|
0x00
|
||||||
|
/* "yul_optimize_runs/input.yul":135:165 */
|
||||||
|
return
|
||||||
|
stop
|
||||||
|
|
||||||
|
sub_0: assembly {
|
||||||
|
/* "yul_optimize_runs/input.yul":237:257 */
|
||||||
|
0xabc1234500000000000000000000000000000000000000000000000000000000
|
||||||
|
/* "yul_optimize_runs/input.yul":277:278 */
|
||||||
|
0x00
|
||||||
|
/* "yul_optimize_runs/input.yul":270:288 */
|
||||||
|
mstore
|
||||||
|
}
|
||||||
|
|
@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
|||||||
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
||||||
commandLine += vector<string>{
|
commandLine += vector<string>{
|
||||||
"--optimize",
|
"--optimize",
|
||||||
"--optimize-runs=1000", // Ignored in assembly mode
|
"--optimize-runs=1000",
|
||||||
"--yul-optimizations=agf",
|
"--yul-optimizations=agf",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -332,7 +332,10 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
|||||||
{
|
{
|
||||||
expectedOptions.optimizer.enabled = true;
|
expectedOptions.optimizer.enabled = true;
|
||||||
expectedOptions.optimizer.yulSteps = "agf";
|
expectedOptions.optimizer.yulSteps = "agf";
|
||||||
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
|
|
||||||
stringstream sout, serr;
|
stringstream sout, serr;
|
||||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||||
|
Loading…
Reference in New Issue
Block a user