aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-14 00:59:04 +0800
committerchriseth <chris@ethereum.org>2017-10-14 01:00:56 +0800
commit7c94e5462abb327016520b896178de41bea473c2 (patch)
treea3c44ae1b221c6bf1a288e43b4956d511cfe874a /libevmasm
parentd9bb4b44a4409db607ee74739f9a5ce1bd557067 (diff)
downloaddexon-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.cpp2
-rw-r--r--libevmasm/PeepholeOptimiser.cpp11
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);