mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Additional peephole optimizer rules for removing side-effect free instructions before simple terminations.
This commit is contained in:
parent
936b07a979
commit
54ab09fee8
@ -4,6 +4,7 @@ Language Features:
|
|||||||
|
|
||||||
|
|
||||||
Compiler Features:
|
Compiler Features:
|
||||||
|
* Peephole Optimizer: Remove operations without side effects before simple terminations.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -146,6 +146,35 @@ struct OpStop: SimplePeepholeOptimizerMethod<OpStop>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct OpReturnRevert: SimplePeepholeOptimizerMethod<OpReturnRevert>
|
||||||
|
{
|
||||||
|
static bool applySimple(
|
||||||
|
AssemblyItem const& _op,
|
||||||
|
AssemblyItem const& _push,
|
||||||
|
AssemblyItem const& _pushOrDup,
|
||||||
|
AssemblyItem const& _returnRevert,
|
||||||
|
std::back_insert_iterator<AssemblyItems> _out
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
(_returnRevert == Instruction::RETURN || _returnRevert == Instruction::REVERT) &&
|
||||||
|
_push.type() == Push &&
|
||||||
|
(_pushOrDup.type() == Push || _pushOrDup == dupInstruction(1))
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
(_op.type() == Operation && !instructionInfo(_op.instruction()).sideEffects) ||
|
||||||
|
_op.type() == Push
|
||||||
|
)
|
||||||
|
{
|
||||||
|
*_out = _push;
|
||||||
|
*_out = _pushOrDup;
|
||||||
|
*_out = _returnRevert;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct DoubleSwap: SimplePeepholeOptimizerMethod<DoubleSwap>
|
struct DoubleSwap: SimplePeepholeOptimizerMethod<DoubleSwap>
|
||||||
{
|
{
|
||||||
static size_t applySimple(AssemblyItem const& _s1, AssemblyItem const& _s2, std::back_insert_iterator<AssemblyItems>)
|
static size_t applySimple(AssemblyItem const& _s1, AssemblyItem const& _s2, std::back_insert_iterator<AssemblyItems>)
|
||||||
@ -459,7 +488,7 @@ bool PeepholeOptimiser::optimise()
|
|||||||
while (state.i < m_items.size())
|
while (state.i < m_items.size())
|
||||||
applyMethods(
|
applyMethods(
|
||||||
state,
|
state,
|
||||||
PushPop(), OpPop(), OpStop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(),
|
PushPop(), OpPop(), OpStop(), OpReturnRevert(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(),
|
||||||
DupSwap(), IsZeroIsZeroJumpI(), EqIsZeroJumpI(), DoubleJump(), JumpToNext(), UnreachableCode(),
|
DupSwap(), IsZeroIsZeroJumpI(), EqIsZeroJumpI(), DoubleJump(), JumpToNext(), UnreachableCode(),
|
||||||
TagConjunctions(), TruthyAnd(), Identity()
|
TagConjunctions(), TruthyAnd(), Identity()
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user