aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm/Assembly.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-11 21:11:07 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:19 +0800
commit0335ed4cb476ece63224a96c8ab660116ff08c3a (patch)
tree6579706bb8da1e8b84e05dc95775bfca5076cc7c /libevmasm/Assembly.cpp
parent22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3 (diff)
downloaddexon-solidity-0335ed4cb476ece63224a96c8ab660116ff08c3a.tar.gz
dexon-solidity-0335ed4cb476ece63224a96c8ab660116ff08c3a.tar.zst
dexon-solidity-0335ed4cb476ece63224a96c8ab660116ff08c3a.zip
Simple peephole optimizer that is activated even if not requested.
Diffstat (limited to 'libevmasm/Assembly.cpp')
-rw-r--r--libevmasm/Assembly.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index 0ee3f421..a813a3a7 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -20,13 +20,17 @@
*/
#include "Assembly.h"
-#include <fstream>
+
#include <libevmasm/CommonSubexpressionEliminator.h>
#include <libevmasm/ControlFlowGraph.h>
+#include <libevmasm/PeepholeOptimiser.h>
#include <libevmasm/BlockDeduplicator.h>
#include <libevmasm/ConstantOptimiser.h>
#include <libevmasm/GasMeter.h>
+
+#include <fstream>
#include <json/json.h>
+
using namespace std;
using namespace dev;
using namespace dev::eth;
@@ -314,16 +318,15 @@ void Assembly::injectStart(AssemblyItem const& _i)
Assembly& Assembly::optimise(bool _enable, bool _isCreation, size_t _runs)
{
- if (_enable)
- optimiseInternal(_isCreation, _runs);
+ optimiseInternal(_enable, _isCreation, _runs);
return *this;
}
-map<u256, u256> Assembly::optimiseInternal(bool _isCreation, size_t _runs)
+map<u256, u256> Assembly::optimiseInternal(bool _enable, bool _isCreation, size_t _runs)
{
for (size_t subId = 0; subId < m_subs.size(); ++subId)
{
- map<u256, u256> subTagReplacements = m_subs[subId]->optimiseInternal(false, _runs);
+ map<u256, u256> subTagReplacements = m_subs[subId]->optimiseInternal(_enable, false, _runs);
BlockDeduplicator::applyTagReplacement(m_items, subTagReplacements, subId);
}
@@ -333,6 +336,13 @@ map<u256, u256> Assembly::optimiseInternal(bool _isCreation, size_t _runs)
{
count = 0;
+ PeepholeOptimiser peepOpt(m_items);
+ if (peepOpt.optimise())
+ count++;
+
+ if (!_enable)
+ continue;
+
// This only modifies PushTags, we have to run again to actually remove code.
BlockDeduplicator dedup(m_items);
if (dedup.deduplicate())
@@ -399,12 +409,13 @@ map<u256, u256> Assembly::optimiseInternal(bool _isCreation, size_t _runs)
}
}
- total += ConstantOptimisationMethod::optimiseConstants(
- _isCreation,
- _isCreation ? 1 : _runs,
- *this,
- m_items
- );
+ if (_enable)
+ total += ConstantOptimisationMethod::optimiseConstants(
+ _isCreation,
+ _isCreation ? 1 : _runs,
+ *this,
+ m_items
+ );
return tagReplacements;
}