aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-17 04:11:45 +0800
committerGitHub <noreply@github.com>2017-10-17 04:11:45 +0800
commit7989fc4c356929de47e2d696ef5478c398941508 (patch)
tree35cfd7db3b44364243b295c3e6f19d05beb1a996 /libevmasm
parent18a72dbe4668e23aaf38404183b978fbbb1824d1 (diff)
parentf5e91e4a94b01daf2bbde637abef1796f063c348 (diff)
downloaddexon-solidity-7989fc4c356929de47e2d696ef5478c398941508.tar.gz
dexon-solidity-7989fc4c356929de47e2d696ef5478c398941508.tar.zst
dexon-solidity-7989fc4c356929de47e2d696ef5478c398941508.zip
Merge pull request #3077 from ethereum/optimze_pops
Assume peephole optimizer was successful if number of pops increased.
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/Assembly.cpp3
-rw-r--r--libevmasm/PeepholeOptimiser.cpp11
2 files changed, 12 insertions, 2 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index df691e7d..5fab24e1 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -408,7 +408,10 @@ map<u256, u256> Assembly::optimiseInternal(
{
PeepholeOptimiser peepOpt(m_items);
while (peepOpt.optimise())
+ {
count++;
+ assertThrow(count < 64000, OptimizerException, "Peephole optimizer seems to be stuck.");
+ }
}
// This only modifies PushTags, we have to run again to actually remove code.
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);