mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Assume peephole optimizer was successful if number of pops increased.
This commit is contained in:
parent
d9bb4b44a4
commit
7c94e5462a
@ -13,6 +13,7 @@ Features:
|
|||||||
* Type Checker: Require ``storage`` or ``memory`` keyword for local variables as experimental 0.5.0 feature.
|
* Type Checker: Require ``storage`` or ``memory`` keyword for local variables as experimental 0.5.0 feature.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Optimizer: Remove unused stack computation results.
|
||||||
* Parser: Fix source location of VariableDeclarationStatement.
|
* Parser: Fix source location of VariableDeclarationStatement.
|
||||||
* Type Checker: Properly check array length and don't rely on an assertion in code generation.
|
* Type Checker: Properly check array length and don't rely on an assertion in code generation.
|
||||||
* Type Checker: Properly support overwriting members inherited from ``address`` in a contract
|
* Type Checker: Properly support overwriting members inherited from ``address`` in a contract
|
||||||
|
@ -407,7 +407,7 @@ map<u256, u256> Assembly::optimiseInternal(
|
|||||||
if (_settings.runPeephole)
|
if (_settings.runPeephole)
|
||||||
{
|
{
|
||||||
PeepholeOptimiser peepOpt(m_items);
|
PeepholeOptimiser peepOpt(m_items);
|
||||||
while (peepOpt.optimise())
|
while (peepOpt.optimise() && count < 0xffffff)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,11 @@ void applyMethods(OptimiserState& _state, Method, OtherMethods... _other)
|
|||||||
applyMethods(_state, _other...);
|
applyMethods(_state, _other...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t numberOfPops(AssemblyItems const& _items)
|
||||||
|
{
|
||||||
|
return std::count(_items.begin(), _items.end(), Instruction::POP);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeepholeOptimiser::optimise()
|
bool PeepholeOptimiser::optimise()
|
||||||
@ -257,8 +262,10 @@ bool PeepholeOptimiser::optimise()
|
|||||||
while (state.i < m_items.size())
|
while (state.i < m_items.size())
|
||||||
applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
|
applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
|
||||||
if (m_optimisedItems.size() < m_items.size() || (
|
if (m_optimisedItems.size() < m_items.size() || (
|
||||||
m_optimisedItems.size() == m_items.size() &&
|
m_optimisedItems.size() == m_items.size() && (
|
||||||
eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3)
|
eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) ||
|
||||||
|
numberOfPops(m_optimisedItems) > numberOfPops(m_items)
|
||||||
|
)
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
m_items = std::move(m_optimisedItems);
|
m_items = std::move(m_optimisedItems);
|
||||||
|
@ -841,6 +841,20 @@ BOOST_AUTO_TEST_CASE(peephole_double_push)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
|
||||||
|
{
|
||||||
|
AssemblyItems items{
|
||||||
|
u256(4),
|
||||||
|
Instruction::CALLDATASIZE,
|
||||||
|
Instruction::LT,
|
||||||
|
Instruction::POP
|
||||||
|
};
|
||||||
|
PeepholeOptimiser peepOpt(items);
|
||||||
|
for (size_t i = 0; i < 3; i++)
|
||||||
|
BOOST_CHECK(peepOpt.optimise());
|
||||||
|
BOOST_CHECK(items.empty());
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(jumpdest_removal)
|
BOOST_AUTO_TEST_CASE(jumpdest_removal)
|
||||||
{
|
{
|
||||||
AssemblyItems items{
|
AssemblyItems items{
|
||||||
|
Loading…
Reference in New Issue
Block a user