mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Integrate AddPop.
This commit is contained in:
parent
8a78b19516
commit
f521624952
@ -337,7 +337,7 @@ map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_
|
|||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
PeepholeOptimiser peepOpt(m_items);
|
PeepholeOptimiser peepOpt(m_items);
|
||||||
if (peepOpt.optimise())
|
while (peepOpt.optimise())
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (!_enable)
|
if (!_enable)
|
||||||
|
@ -95,7 +95,7 @@ struct Identity: SimplePeepholeOptimizerMethod<Identity, 1>
|
|||||||
|
|
||||||
struct PushPop: SimplePeepholeOptimizerMethod<PushPop, 2>
|
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();
|
auto t = _push.type();
|
||||||
return _pop == Instruction::POP && (
|
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 &&
|
if (_pop == Instruction::POP && _op.type() == Operation)
|
||||||
_in[0].type() == Operation
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
Instruction i0 = _in[0].instruction();
|
Instruction instr = _op.instruction();
|
||||||
if (instructionInfo(i0).ret == 1 &&
|
if (instructionInfo(instr).ret == 1 && !instructionInfo(instr).sideEffects)
|
||||||
!SemanticInformation::invalidatesMemory(i0) &&
|
|
||||||
!SemanticInformation::invalidatesStorage(i0) &&
|
|
||||||
!SemanticInformation::altersControlFlow(i0) &&
|
|
||||||
!instructionInfo(i0).sideEffects
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < instructionInfo(i0).args; j++)
|
for (int j = 0; j < instructionInfo(instr).args; j++)
|
||||||
*_out = Instruction::POP;
|
*_out = Instruction::POP;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -236,7 +233,7 @@ bool PeepholeOptimiser::optimise()
|
|||||||
{
|
{
|
||||||
OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)};
|
OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)};
|
||||||
while (state.i < m_items.size())
|
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())
|
if (m_optimisedItems.size() < m_items.size())
|
||||||
{
|
{
|
||||||
m_items = std::move(m_optimisedItems);
|
m_items = std::move(m_optimisedItems);
|
||||||
|
Loading…
Reference in New Issue
Block a user