From f5216249527a82834162d66f93f15a50346e38d4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 24 Nov 2016 21:08:30 +0100 Subject: Integrate AddPop. --- libevmasm/PeepholeOptimiser.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'libevmasm/PeepholeOptimiser.cpp') 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 struct PushPop: SimplePeepholeOptimizerMethod { - static size_t applySimple(AssemblyItem const& _push, AssemblyItem const& _pop, std::back_insert_iterator) + static bool applySimple(AssemblyItem const& _push, AssemblyItem const& _pop, std::back_insert_iterator) { auto t = _push.type(); return _pop == Instruction::POP && ( @@ -106,23 +106,20 @@ struct PushPop: SimplePeepholeOptimizerMethod } }; -struct AddPop: SimplePeepholeOptimizerMethod +struct OpPop: SimplePeepholeOptimizerMethod { - static bool apply(AssemblyItems::const_iterator _in, std::back_insert_iterator _out) + static bool applySimple( + AssemblyItem const& _op, + AssemblyItem const& _pop, + std::back_insert_iterator _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); -- cgit