aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-11-25 03:46:40 +0800
committerGitHub <noreply@github.com>2016-11-25 03:46:40 +0800
commita077a3a5ec58c36a0e1ced3eaf8dacd8c761a209 (patch)
treed42f2f8ebeea6318e174511216c542da346a9630
parent19c9e85a20f296a66be07cac1573f28000ac5f44 (diff)
parentb6ffb6c8b7a581e1c3d0e7882be0d1606cc37509 (diff)
downloaddexon-solidity-a077a3a5ec58c36a0e1ced3eaf8dacd8c761a209.tar.gz
dexon-solidity-a077a3a5ec58c36a0e1ced3eaf8dacd8c761a209.tar.zst
dexon-solidity-a077a3a5ec58c36a0e1ced3eaf8dacd8c761a209.zip
Merge pull request #1434 from ethereum/addpop
optimizing ADD; POP and similar
-rw-r--r--libevmasm/AssemblyItem.h2
-rw-r--r--libevmasm/PeepholeOptimiser.cpp30
2 files changed, 29 insertions, 3 deletions
diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h
index 2bc28dbd..b5bd3ed8 100644
--- a/libevmasm/AssemblyItem.h
+++ b/libevmasm/AssemblyItem.h
@@ -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
*/
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp
index e93db9ac..901e310e 100644
--- a/libevmasm/PeepholeOptimiser.cpp
+++ b/libevmasm/PeepholeOptimiser.cpp
@@ -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);