diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-01 05:10:55 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-27 19:40:28 +0800 |
commit | f9d5f7e4973d68500adec10d29e13c0151d8fedb (patch) | |
tree | f8abb75d104b60697de8b8209ed10ac6f10b9b2b /libevmasm/Assembly.cpp | |
parent | 89fadd6935bd1dda4c8a4846c8fa43ce71cc85cc (diff) | |
download | dexon-solidity-f9d5f7e4973d68500adec10d29e13c0151d8fedb.tar.gz dexon-solidity-f9d5f7e4973d68500adec10d29e13c0151d8fedb.tar.zst dexon-solidity-f9d5f7e4973d68500adec10d29e13c0151d8fedb.zip |
Introduce fine-grained optimiser settings in libevmasm
Diffstat (limited to 'libevmasm/Assembly.cpp')
-rw-r--r-- | libevmasm/Assembly.cpp | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 597fdae1..42b923df 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -350,38 +350,65 @@ void Assembly::injectStart(AssemblyItem const& _i) Assembly& Assembly::optimise(bool _enable, bool _isCreation, size_t _runs) { - optimiseInternal(_enable, _isCreation, _runs); + OptimiserSettings settings; + settings.isCreation = _isCreation; + settings.runPeephole = true; + if (_enable) + { + settings.runDeduplicate = true; + settings.runCSE = true; + settings.runConstantOptimiser = true; + } + settings.expectedExecutionsPerDeployment = _runs; + optimiseInternal(settings); return *this; } -map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_t _runs) + +Assembly& Assembly::optimise(OptimiserSettings _settings) { + optimiseInternal(_settings); + return *this; +} + +map<u256, u256> Assembly::optimiseInternal(OptimiserSettings _settings) +{ + // Run optimisation for sub-assemblies. for (size_t subId = 0; subId < m_subs.size(); ++subId) { - map<u256, u256> subTagReplacements = m_subs[subId]->optimiseInternal(_enable, false, _runs); + OptimiserSettings settings = _settings; + // Disable creation mode for sub-assemblies. + settings.isCreation = false; + map<u256, u256> subTagReplacements = m_subs[subId]->optimiseInternal(settings); + // Apply the replacements (can be empty). BlockDeduplicator::applyTagReplacement(m_items, subTagReplacements, subId); } map<u256, u256> tagReplacements; + // Iterate until no new optimisation possibilities are found. for (unsigned count = 1; count > 0;) { count = 0; - PeepholeOptimiser peepOpt(m_items); - while (peepOpt.optimise()) - count++; - - if (!_enable) - continue; + if (_settings.runPeephole) + { + PeepholeOptimiser peepOpt(m_items); + while (peepOpt.optimise()) + count++; + } // This only modifies PushTags, we have to run again to actually remove code. - BlockDeduplicator dedup(m_items); - if (dedup.deduplicate()) + if (_settings.runDeduplicate) { - tagReplacements.insert(dedup.replacedTags().begin(), dedup.replacedTags().end()); - count++; + BlockDeduplicator dedup(m_items); + if (dedup.deduplicate()) + { + tagReplacements.insert(dedup.replacedTags().begin(), dedup.replacedTags().end()); + count++; + } } + if (_settings.runCSE) { // Control flow graph optimization has been here before but is disabled because it // assumes we only jump to tags that are pushed. This is not the case anymore with @@ -429,10 +456,10 @@ map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_ } } - if (_enable) + if (_settings.runConstantOptimiser) ConstantOptimisationMethod::optimiseConstants( - _isCreation, - _isCreation ? 1 : _runs, + _settings.isCreation, + _settings.isCreation ? 1 : _settings.expectedExecutionsPerDeployment, *this, m_items ); |