diff options
author | chriseth <c@ethdev.com> | 2016-11-22 21:55:09 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-11-22 21:58:24 +0800 |
commit | 7fb7d5ae39a4bd5e0852db1fe5d21fdd4a0fd80f (patch) | |
tree | 2bf77027e3090c6bb969e8c0aa9d079ddcfc054b /libevmasm/Assembly.cpp | |
parent | aa48008cc72c6f44db2cbd30a1bee522be67ecd8 (diff) | |
download | dexon-solidity-7fb7d5ae39a4bd5e0852db1fe5d21fdd4a0fd80f.tar.gz dexon-solidity-7fb7d5ae39a4bd5e0852db1fe5d21fdd4a0fd80f.tar.zst dexon-solidity-7fb7d5ae39a4bd5e0852db1fe5d21fdd4a0fd80f.zip |
Optimizer: Clear state for JUMPDESTs.
Diffstat (limited to 'libevmasm/Assembly.cpp')
-rw-r--r-- | libevmasm/Assembly.cpp | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index a3037456..c394afa2 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -360,46 +360,35 @@ map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_ auto iter = m_items.begin(); while (iter != m_items.end()) { - auto end = iter; - while (end != m_items.end()) - if (SemanticInformation::altersControlFlow(*end++)) - break; - KnownState emptyState; CommonSubexpressionEliminator eliminator(emptyState); - auto blockIter = iter; - auto const blockEnd = end; - while (blockIter < blockEnd) + auto orig = iter; + iter = eliminator.feedItems(iter, m_items.end()); + bool shouldReplace = false; + AssemblyItems optimisedChunk; + try + { + optimisedChunk = eliminator.getOptimizedItems(); + shouldReplace = (optimisedChunk.size() < size_t(iter - orig)); + } + catch (StackTooDeepException const&) + { + // This might happen if the opcode reconstruction is not as efficient + // as the hand-crafted code. + } + catch (ItemNotAvailableException const&) { - auto orig = blockIter; - blockIter = eliminator.feedItems(blockIter, blockEnd); - bool shouldReplace = false; - AssemblyItems optimisedChunk; - try - { - optimisedChunk = eliminator.getOptimizedItems(); - shouldReplace = (optimisedChunk.size() < size_t(blockIter - orig)); - } - catch (StackTooDeepException const&) - { - // This might happen if the opcode reconstruction is not as efficient - // as the hand-crafted code. - } - catch (ItemNotAvailableException const&) - { - // This might happen if e.g. associativity and commutativity rules - // reorganise the expression tree, but not all leaves are available. - } - - if (shouldReplace) - { - count++; - optimisedItems += optimisedChunk; - } - else - copy(orig, blockIter, back_inserter(optimisedItems)); + // This might happen if e.g. associativity and commutativity rules + // reorganise the expression tree, but not all leaves are available. } - iter = end; + + if (shouldReplace) + { + count++; + optimisedItems += optimisedChunk; + } + else + copy(orig, iter, back_inserter(optimisedItems)); } if (optimisedItems.size() < m_items.size()) { |