mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1434 from ethereum/addpop
optimizing ADD; POP and similar
This commit is contained in:
commit
a077a3a5ec
@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @file Assembly.h
|
||||
/** @file AssemblyItem.h
|
||||
* @author Gav Wood <i@gavwood.com>
|
||||
* @date 2014
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file PeepholeOptimiser.h
|
||||
* @file PeepholeOptimiser.cpp
|
||||
* Performs local optimising code changes to assembly.
|
||||
*/
|
||||
|
||||
@ -57,6 +57,32 @@ struct PushPop
|
||||
}
|
||||
};
|
||||
|
||||
struct AddPop
|
||||
{
|
||||
static size_t windowSize() { return 2; }
|
||||
static bool apply(AssemblyItems::const_iterator _in, std::back_insert_iterator<AssemblyItems> _out)
|
||||
{
|
||||
if (_in[1] == Instruction::POP &&
|
||||
_in[0].type() == Operation
|
||||
)
|
||||
{
|
||||
Instruction i0 = _in[0].instruction();
|
||||
if (instructionInfo(i0).ret == 1 &&
|
||||
!SemanticInformation::invalidatesMemory(i0) &&
|
||||
!SemanticInformation::invalidatesStorage(i0) &&
|
||||
!SemanticInformation::altersControlFlow(i0) &&
|
||||
!instructionInfo(i0).sideEffects
|
||||
)
|
||||
{
|
||||
for (int j = 0; j < instructionInfo(i0).args; j++)
|
||||
*_out = Instruction::POP;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct DoubleSwap
|
||||
{
|
||||
static size_t windowSize() { return 2; }
|
||||
@ -136,7 +162,7 @@ bool PeepholeOptimiser::optimise()
|
||||
{
|
||||
OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)};
|
||||
while (state.i < m_items.size())
|
||||
applyMethods(state, PushPop(), DoubleSwap(), JumpToNext(), TagConjunctions(), Identity());
|
||||
applyMethods(state, PushPop(), AddPop(), DoubleSwap(), JumpToNext(), TagConjunctions(), Identity());
|
||||
if (m_optimisedItems.size() < m_items.size())
|
||||
{
|
||||
m_items = std::move(m_optimisedItems);
|
||||
|
Loading…
Reference in New Issue
Block a user