From 03ff14122304c1abaf93e91e2a7859fb76cdc515 Mon Sep 17 00:00:00 2001 From: jaa2 <43010335+jaa2@users.noreply.github.com> Date: Wed, 28 Jul 2021 10:32:19 -0500 Subject: [PATCH] CommandLineParser: Handle --optimize-runs option in assembly mode Fixes #11708. --- docs/yul.rst | 6 ++++-- solc/CommandLineInterface.cpp | 3 +++ solc/CommandLineInterface.h | 1 + solc/CommandLineParser.cpp | 5 +++++ test/solc/CommandLineParser.cpp | 3 ++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/yul.rst b/docs/yul.rst index b8557475fbdf..2eac722cddd0 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -1177,11 +1177,13 @@ intermediate states. This allows for easy debugging and verification of the opti Please refer to the general :ref:`optimizer documentation ` 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 runs ` with +``--optimize-runs``: .. 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. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 32224ac6e5c6..cc8e7dc6eec2 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -555,6 +555,7 @@ bool CommandLineInterface::processInput() m_options.assembly.inputLanguage, m_options.assembly.targetMachine, m_options.optimizer.enabled, + m_options.optimizer.expectedExecutionsPerDeployment, m_options.optimizer.yulSteps ); } @@ -941,6 +942,7 @@ bool CommandLineInterface::assemble( yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine, bool _optimize, + unsigned int _expectedExecutionsPerDeployment, optional _yulOptimiserSteps ) { @@ -951,6 +953,7 @@ bool CommandLineInterface::assemble( for (auto const& src: m_fileReader.sourceCodes()) { OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal(); + settings.expectedExecutionsPerDeployment = _expectedExecutionsPerDeployment; if (_yulOptimiserSteps.has_value()) settings.yulOptimiserSteps = _yulOptimiserSteps.value(); diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 8e17489a7b00..f35f74f1e6a6 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -78,6 +78,7 @@ class CommandLineInterface yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine, bool _optimize, + unsigned int _expectedExecutionsPerDeployment, std::optional _yulOptimiserSteps = std::nullopt ); diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 5a1daed1e9c8..655f154e98fc 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -966,6 +966,11 @@ General Information)").c_str(), m_options.assembly.inputLanguage = m_args.count(g_strYul) ? Input::Yul : (m_args.count(g_strStrictAssembly) ? Input::StrictAssembly : Input::Assembly); m_options.optimizer.enabled = (m_args.count(g_strOptimize) > 0); m_options.optimizer.noOptimizeYul = (m_args.count(g_strNoOptimizeYul) > 0); + + if (m_args.count(g_strOptimizeRuns)) + { + m_options.optimizer.expectedExecutionsPerDeployment = m_args[g_strOptimizeRuns].as(); + } if (m_args.count(g_strYulOptimizations)) { diff --git a/test/solc/CommandLineParser.cpp b/test/solc/CommandLineParser.cpp index 21ef808944e5..3ad504f3c2a6 100644 --- a/test/solc/CommandLineParser.cpp +++ b/test/solc/CommandLineParser.cpp @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options) if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm) commandLine += vector{ "--optimize", - "--optimize-runs=1000", // Ignored in assembly mode + "--optimize-runs=1000", "--yul-optimizations=agf", }; @@ -332,6 +332,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options) { expectedOptions.optimizer.enabled = true; expectedOptions.optimizer.yulSteps = "agf"; + expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000; } stringstream sout, serr;