diff options
Diffstat (limited to 'libevmasm')
-rw-r--r-- | libevmasm/Assembly.cpp | 2 | ||||
-rw-r--r-- | libevmasm/PeepholeOptimiser.cpp | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index df691e7d..37c4fb22 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -407,7 +407,7 @@ map<u256, u256> Assembly::optimiseInternal( if (_settings.runPeephole) { PeepholeOptimiser peepOpt(m_items); - while (peepOpt.optimise()) + while (peepOpt.optimise() && count < 0xffffff) count++; } diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 31fdd317..168d1109 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -249,6 +249,11 @@ void applyMethods(OptimiserState& _state, Method, OtherMethods... _other) applyMethods(_state, _other...); } +size_t numberOfPops(AssemblyItems const& _items) +{ + return std::count(_items.begin(), _items.end(), Instruction::POP); +} + } bool PeepholeOptimiser::optimise() @@ -257,8 +262,10 @@ bool PeepholeOptimiser::optimise() while (state.i < m_items.size()) applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); if (m_optimisedItems.size() < m_items.size() || ( - m_optimisedItems.size() == m_items.size() && - eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) + m_optimisedItems.size() == m_items.size() && ( + eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) || + numberOfPops(m_optimisedItems) > numberOfPops(m_items) + ) )) { m_items = std::move(m_optimisedItems); |