Skip to content

Commit 5ff0811

Browse files
authored
Merge pull request #11717 from jaa2/develop
Handle --optimize-runs option in assembly mode
2 parents 62727f3 + c627e6a commit 5ff0811

File tree

12 files changed

+88
-5
lines changed

12 files changed

+88
-5
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Bugfixes:
2222
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
2323
* Yul Code Generator: Fix source location references for calls to builtin functions.
2424
* Yul Parser: Fix source location references for ``if`` statements.
25+
* Commandline Interface: Apply ``--optimizer-runs`` option in assembly / yul mode.
2526

2627

2728
### 0.8.6 (2021-06-22)

docs/internals/optimizer.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ differences, for example, functions may be inlined, combined, or rewritten to el
4949
redundancies, etc. (compare the output between the flags ``--ir`` and
5050
``--optimize --ir-optimized``).
5151

52+
.. _optimizer-parameter-runs:
53+
5254
Optimizer Parameter Runs
5355
========================
5456

docs/yul.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,11 +1177,13 @@ intermediate states. This allows for easy debugging and verification of the opti
11771177
Please refer to the general :ref:`optimizer documentation <optimizer>`
11781178
for more details about the different optimization stages and how to use the optimizer.
11791179

1180-
If you want to use Solidity in stand-alone Yul mode, you activate the optimizer using ``--optimize``:
1180+
If you want to use Solidity in stand-alone Yul mode, you activate the optimizer using ``--optimize``
1181+
and optionally specify the :ref:`expected number of contract executions <optimizer-parameter-runs>` with
1182+
``--optimize-runs``:
11811183

11821184
.. code-block:: sh
11831185
1184-
solc --strict-assembly --optimize
1186+
solc --strict-assembly --optimize --optimize-runs 200
11851187
11861188
In Solidity mode, the Yul optimizer is activated together with the regular optimizer.
11871189

solc/CommandLineInterface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ bool CommandLineInterface::processInput()
555555
m_options.assembly.inputLanguage,
556556
m_options.assembly.targetMachine,
557557
m_options.optimizer.enabled,
558+
m_options.optimizer.expectedExecutionsPerDeployment,
558559
m_options.optimizer.yulSteps
559560
);
560561
}
@@ -595,7 +596,8 @@ bool CommandLineInterface::compile()
595596
m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm);
596597

597598
OptimiserSettings settings = m_options.optimizer.enabled ? OptimiserSettings::standard() : OptimiserSettings::minimal();
598-
settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment;
599+
if (m_options.optimizer.expectedExecutionsPerDeployment.has_value())
600+
settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment.value();
599601
if (m_options.optimizer.noOptimizeYul)
600602
settings.runYulOptimiser = false;
601603

@@ -941,6 +943,7 @@ bool CommandLineInterface::assemble(
941943
yul::AssemblyStack::Language _language,
942944
yul::AssemblyStack::Machine _targetMachine,
943945
bool _optimize,
946+
optional<unsigned int> _expectedExecutionsPerDeployment,
944947
optional<string> _yulOptimiserSteps
945948
)
946949
{
@@ -951,6 +954,8 @@ bool CommandLineInterface::assemble(
951954
for (auto const& src: m_fileReader.sourceCodes())
952955
{
953956
OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal();
957+
if (_expectedExecutionsPerDeployment.has_value())
958+
settings.expectedExecutionsPerDeployment = _expectedExecutionsPerDeployment.value();
954959
if (_yulOptimiserSteps.has_value())
955960
settings.yulOptimiserSteps = _yulOptimiserSteps.value();
956961

solc/CommandLineInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CommandLineInterface
7878
yul::AssemblyStack::Language _language,
7979
yul::AssemblyStack::Machine _targetMachine,
8080
bool _optimize,
81+
std::optional<unsigned int> _expectedExecutionsPerDeployment = std::nullopt,
8182
std::optional<std::string> _yulOptimiserSteps = std::nullopt
8283
);
8384

solc/CommandLineParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,8 @@ General Information)").c_str(),
967967
m_options.optimizer.enabled = (m_args.count(g_strOptimize) > 0);
968968
m_options.optimizer.noOptimizeYul = (m_args.count(g_strNoOptimizeYul) > 0);
969969

970+
m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as<unsigned>();
971+
970972
if (m_args.count(g_strYulOptimizations))
971973
{
972974
if (!m_options.optimizer.enabled)

solc/CommandLineParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct CommandLineOptions
159159
struct
160160
{
161161
bool enabled = false;
162-
unsigned expectedExecutionsPerDeployment = 0;
162+
std::optional<unsigned> expectedExecutionsPerDeployment;
163163
bool noOptimizeYul = false;
164164
std::optional<std::string> yulSteps;
165165
} optimizer;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--yul --yul-dialect evm --optimize --ir-optimized --optimize-runs 10000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warning: Yul is still experimental. Please use the output with care.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object "RunsTest1" {
2+
code {
3+
// Deploy the contract
4+
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
5+
return(0, datasize("Runtime"))
6+
}
7+
object "Runtime" {
8+
code {
9+
let funcSel := shl(224, 0xabc12345)
10+
mstore(0, funcSel)
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)