From 96be94fa5edfe970f700957335c43d664eb00794 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 14 Dec 2022 18:20:45 +0100 Subject: [PATCH] Per-function deduplication. --- libevmasm/Assembly.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 1cfc04ce6..36571adc8 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -408,31 +408,31 @@ map const& Assembly::optimiseInternal( } // This only modifies PushTags, we have to run again to actually remove code. - // TODO: investigate options for EOF. - if (_settings.runDeduplicate && !m_eofVersion.has_value()) - { - BlockDeduplicator deduplicator{m_codeSections.front().items}; - if (deduplicator.deduplicate()) + if (_settings.runDeduplicate) + for (auto& section: m_codeSections) { - for (auto const& replacement: deduplicator.replacedTags()) + BlockDeduplicator deduplicator{section.items}; + if (deduplicator.deduplicate()) { - assertThrow( - replacement.first <= numeric_limits::max() && replacement.second <= numeric_limits::max(), - OptimizerException, - "Invalid tag replacement." - ); - assertThrow( - !tagReplacements.count(replacement.first), - OptimizerException, - "Replacement already known." - ); - tagReplacements[replacement.first] = replacement.second; - if (_tagsReferencedFromOutside.erase(static_cast(replacement.first))) - _tagsReferencedFromOutside.insert(static_cast(replacement.second)); + for (auto const& replacement: deduplicator.replacedTags()) + { + assertThrow( + replacement.first <= numeric_limits::max() && replacement.second <= numeric_limits::max(), + OptimizerException, + "Invalid tag replacement." + ); + assertThrow( + !tagReplacements.count(replacement.first), + OptimizerException, + "Replacement already known." + ); + tagReplacements[replacement.first] = replacement.second; + if (_tagsReferencedFromOutside.erase(static_cast(replacement.first))) + _tagsReferencedFromOutside.insert(static_cast(replacement.second)); + } + count++; } - count++; } - } // TODO: investigate for EOF if (_settings.runCSE && !m_eofVersion.has_value())