aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-25 04:08:30 +0800
committerchriseth <c@ethdev.com>2016-11-25 23:10:57 +0800
commitf5216249527a82834162d66f93f15a50346e38d4 (patch)
treefe87c1b8b6bf3453b056181ab8b896701aaadc2f /libevmasm
parent8a78b1951600a936fadae6ea1644a49e491366f0 (diff)
downloaddexon-solidity-f5216249527a82834162d66f93f15a50346e38d4.tar.gz
dexon-solidity-f5216249527a82834162d66f93f15a50346e38d4.tar.zst
dexon-solidity-f5216249527a82834162d66f93f15a50346e38d4.zip
Integrate AddPop.
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/Assembly.cpp2
-rw-r--r--libevmasm/PeepholeOptimiser.cpp27
2 files changed, 13 insertions, 16 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index 96306750..edbb9828 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -337,7 +337,7 @@ map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_
count = 0;
PeepholeOptimiser peepOpt(m_items);
- if (peepOpt.optimise())
+ while (peepOpt.optimise())
count++;
if (!_enable)
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp
index c8a28afc..b96b0295 100644
--- a/libevmasm/PeepholeOptimiser.cpp
+++ b/libevmasm/PeepholeOptimiser.cpp
@@ -95,7 +95,7 @@ struct Identity: SimplePeepholeOptimizerMethod<Identity, 1>
struct PushPop: SimplePeepholeOptimizerMethod<PushPop, 2>
{
- static size_t applySimple(AssemblyItem const& _push, AssemblyItem const& _pop, std::back_insert_iterator<AssemblyItems>)
+ static bool applySimple(AssemblyItem const& _push, AssemblyItem const& _pop, std::back_insert_iterator<AssemblyItems>)
{
auto t = _push.type();
return _pop == Instruction::POP && (
@@ -106,23 +106,20 @@ struct PushPop: SimplePeepholeOptimizerMethod<PushPop, 2>
}
};
-struct AddPop: SimplePeepholeOptimizerMethod<AddPop, 2>
+struct OpPop: SimplePeepholeOptimizerMethod<OpPop, 2>
{
- static bool apply(AssemblyItems::const_iterator _in, std::back_insert_iterator<AssemblyItems> _out)
+ static bool applySimple(
+ AssemblyItem const& _op,
+ AssemblyItem const& _pop,
+ std::back_insert_iterator<AssemblyItems> _out
+ )
{
- if (_in[1] == Instruction::POP &&
- _in[0].type() == Operation
- )
+ if (_pop == Instruction::POP && _op.type() == Operation)
{
- Instruction i0 = _in[0].instruction();
- if (instructionInfo(i0).ret == 1 &&
- !SemanticInformation::invalidatesMemory(i0) &&
- !SemanticInformation::invalidatesStorage(i0) &&
- !SemanticInformation::altersControlFlow(i0) &&
- !instructionInfo(i0).sideEffects
- )
+ Instruction instr = _op.instruction();
+ if (instructionInfo(instr).ret == 1 && !instructionInfo(instr).sideEffects)
{
- for (int j = 0; j < instructionInfo(i0).args; j++)
+ for (int j = 0; j < instructionInfo(instr).args; j++)
*_out = Instruction::POP;
return true;
}
@@ -236,7 +233,7 @@ bool PeepholeOptimiser::optimise()
{
OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)};
while (state.i < m_items.size())
- applyMethods(state, PushPop(), AddPop(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
+ applyMethods(state, PushPop(), OpPop(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
if (m_optimisedItems.size() < m_items.size())
{
m_items = std::move(m_optimisedItems);