From 847e30e6ffb2e0b82a0888609184fd7db9f208a4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Oct 2020 16:44:26 +0000 Subject: [PATCH] Optimise libevmasm in yul --- Changelog.md | 1 + libyul/AssemblyStack.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 949e6fc05..6fab20f5e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Language 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: 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). diff --git a/libyul/AssemblyStack.cpp b/libyul/AssemblyStack.cpp index 121bc48e4..32318edb8 100644 --- a/libyul/AssemblyStack.cpp +++ b/libyul/AssemblyStack.cpp @@ -36,8 +36,6 @@ #include #include -#include - #include #include #include @@ -65,6 +63,28 @@ Dialect const& languageToDialect(AssemblyStack::Language _language, EVMVersion _ 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 _deployName) const EthAssemblyAdapter adapter(assembly); compileEVM(adapter, m_optimiserSettings.optimizeStackAllocation); + assembly.optimise(translateOptimiserSettings(m_optimiserSettings, m_evmVersion)); + optional subIndex; // Pick matching assembly if name was given