Optimise libevmasm in yul

This commit is contained in:
Alex Beregszaszi 2020-10-29 16:44:26 +00:00 committed by Kamil Śliwak
parent f6cb933f24
commit 847e30e6ff
2 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,7 @@ Language Features:
Compiler Features: Compiler Features:
* AssemblyStack: Also run opcode-based optimizer when compiling Yul code.
* Yul EVM Code Transform: Do not reuse stack slots that immediately become unreachable. * Yul EVM Code Transform: Do not reuse stack slots that immediately become unreachable.
* Yul EVM Code Transform: Also pop unused argument slots for functions without return variables (under the same restrictions as for functions with return variables). * Yul EVM Code Transform: Also pop unused argument slots for functions without return variables (under the same restrictions as for functions with return variables).
* Yul Optimizer: Move function arguments and return variables to memory with the experimental Stack Limit Evader (which is not enabled by default). * Yul Optimizer: Move function arguments and return variables to memory with the experimental Stack Limit Evader (which is not enabled by default).

View File

@ -36,8 +36,6 @@
#include <libyul/ObjectParser.h> #include <libyul/ObjectParser.h>
#include <libyul/optimiser/Suite.h> #include <libyul/optimiser/Suite.h>
#include <libsolidity/interface/OptimiserSettings.h>
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>
#include <optional> #include <optional>
@ -65,6 +63,28 @@ Dialect const& languageToDialect(AssemblyStack::Language _language, EVMVersion _
return Dialect::yulDeprecated(); return Dialect::yulDeprecated();
} }
// Duplicated from libsolidity/codegen/CompilerContext.cpp
// TODO: refactor and remove duplication
evmasm::Assembly::OptimiserSettings translateOptimiserSettings(
frontend::OptimiserSettings const& _settings,
langutil::EVMVersion _evmVersion
)
{
// Constructing it this way so that we notice changes in the fields.
evmasm::Assembly::OptimiserSettings asmSettings{false, false, false, false, false, false, false, _evmVersion, 0};
asmSettings.isCreation = true;
asmSettings.runInliner = _settings.runInliner;
asmSettings.runJumpdestRemover = _settings.runJumpdestRemover;
asmSettings.runPeephole = _settings.runPeephole;
asmSettings.runDeduplicate = _settings.runDeduplicate;
asmSettings.runCSE = _settings.runCSE;
asmSettings.runConstantOptimiser = _settings.runConstantOptimiser;
asmSettings.expectedExecutionsPerDeployment = _settings.expectedExecutionsPerDeployment;
asmSettings.evmVersion = _evmVersion;
return asmSettings;
}
} }
@ -261,6 +281,8 @@ AssemblyStack::assembleEVMWithDeployed(optional<string_view> _deployName) const
EthAssemblyAdapter adapter(assembly); EthAssemblyAdapter adapter(assembly);
compileEVM(adapter, m_optimiserSettings.optimizeStackAllocation); compileEVM(adapter, m_optimiserSettings.optimizeStackAllocation);
assembly.optimise(translateOptimiserSettings(m_optimiserSettings, m_evmVersion));
optional<size_t> subIndex; optional<size_t> subIndex;
// Pick matching assembly if name was given // Pick matching assembly if name was given