Skip to content

Commit

Permalink
CommandLineParser: Handle --optimize-runs option in assembly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jaa2 committed Jul 28, 2021
1 parent 1794e1c commit 03ff141
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/yul.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
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 <optimizer-parameter-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.

Expand Down
3 changes: 3 additions & 0 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down Expand Up @@ -941,6 +942,7 @@ bool CommandLineInterface::assemble(
yul::AssemblyStack::Language _language,
yul::AssemblyStack::Machine _targetMachine,
bool _optimize,
unsigned int _expectedExecutionsPerDeployment,
optional<string> _yulOptimiserSteps
)
{
Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions solc/CommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CommandLineInterface
yul::AssemblyStack::Language _language,
yul::AssemblyStack::Machine _targetMachine,
bool _optimize,
unsigned int _expectedExecutionsPerDeployment,
std::optional<std::string> _yulOptimiserSteps = std::nullopt
);

Expand Down
5 changes: 5 additions & 0 deletions solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>();
}

if (m_args.count(g_strYulOptimizations))
{
Expand Down
3 changes: 2 additions & 1 deletion test/solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
commandLine += vector<string>{
"--optimize",
"--optimize-runs=1000", // Ignored in assembly mode
"--optimize-runs=1000",
"--yul-optimizations=agf",
};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 03ff141

Please sign in to comment.