diff options
author | chriseth <chris@ethereum.org> | 2017-10-14 00:59:04 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-10-14 01:00:56 +0800 |
commit | 7c94e5462abb327016520b896178de41bea473c2 (patch) | |
tree | a3c44ae1b221c6bf1a288e43b4956d511cfe874a /libevmasm | |
parent | d9bb4b44a4409db607ee74739f9a5ce1bd557067 (diff) | |
download | dexon-solidity-7c94e5462abb327016520b896178de41bea473c2.tar.gz dexon-solidity-7c94e5462abb327016520b896178de41bea473c2.tar.zst dexon-solidity-7c94e5462abb327016520b896178de41bea473c2.zip |
Assume peephole optimizer was successful if number of pops increased.
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); |