diff options
author | chriseth <c@ethdev.com> | 2015-05-12 22:16:44 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-05-12 22:27:43 +0800 |
commit | ca73a4017054ed33d125b0ee661f8b5682c9538b (patch) | |
tree | 42565c9765fdc3a4df5934e30fd0e016c2d78424 /libsolidity | |
parent | b6bd56bccd836a1f97afe18468029504e525bba6 (diff) | |
download | dexon-solidity-ca73a4017054ed33d125b0ee661f8b5682c9538b.tar.gz dexon-solidity-ca73a4017054ed33d125b0ee661f8b5682c9538b.tar.zst dexon-solidity-ca73a4017054ed33d125b0ee661f8b5682c9538b.zip |
Unify blocks with shared code.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/SolidityOptimizer.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index e50469dd..efc9316b 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -29,6 +29,7 @@ #include <libevmasm/CommonSubexpressionEliminator.h> #include <libevmasm/ControlFlowGraph.h> #include <libevmasm/Assembly.h> +#include <libevmasm/BlockDeduplicator.h> using namespace std; using namespace dev::eth; @@ -125,7 +126,7 @@ public: BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } - void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation) + AssemblyItems getCFG(AssemblyItems const& _input) { AssemblyItems output = _input; // Running it four times should be enough for these tests. @@ -138,6 +139,12 @@ public: back_inserter(optItems)); output = move(optItems); } + return output; + } + + void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation) + { + AssemblyItems output = getCFG(_input); BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } @@ -925,6 +932,35 @@ BOOST_AUTO_TEST_CASE(control_flow_graph_do_not_remove_returned_to) checkCFG(input, {u256(2)}); } +BOOST_AUTO_TEST_CASE(block_deduplicator) +{ + AssemblyItems input{ + AssemblyItem(PushTag, 2), + AssemblyItem(PushTag, 1), + AssemblyItem(PushTag, 3), + u256(6), + eth::Instruction::SWAP3, + eth::Instruction::JUMP, + AssemblyItem(Tag, 1), + u256(6), + eth::Instruction::SWAP3, + eth::Instruction::JUMP, + AssemblyItem(Tag, 2), + u256(6), + eth::Instruction::SWAP3, + eth::Instruction::JUMP, + AssemblyItem(Tag, 3) + }; + BlockDeduplicator dedup(input); + dedup.deduplicate(); + + set<u256> pushTags; + for (AssemblyItem const& item: input) + if (item.type() == PushTag) + pushTags.insert(item.data()); + BOOST_CHECK_EQUAL(pushTags.size(), 2); +} + BOOST_AUTO_TEST_SUITE_END() } |