aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/libjulia/Simplifier.cpp178
-rw-r--r--test/libjulia/YulOptimizerTest.cpp6
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/constant_propagation.yul6
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/constants.yul6
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_complex.yul6
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_negative.yul6
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_simple.yul10
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/including_function_calls.yul12
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/inside_for.yul16
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/invariant.yul10
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_1.yul8
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_2.yul8
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_arguments.yul12
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_names.yul16
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_equality_not_movable.yul13
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_removes_non_constant_and_not_movable.yul10
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/reversed.yul8
-rw-r--r--test/libjulia/yulOptimizerTests/expressionSimplifier/smoke.yul5
18 files changed, 158 insertions, 178 deletions
diff --git a/test/libjulia/Simplifier.cpp b/test/libjulia/Simplifier.cpp
deleted file mode 100644
index 3cc95b7a..00000000
--- a/test/libjulia/Simplifier.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- This file is part of solidity.
-
- solidity is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- solidity is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with solidity. If not, see <http://www.gnu.org/licenses/>.
-*/
-/**
- * @date 2017
- * Unit tests for the expression simplifier optimizer stage.
- */
-
-#include <test/libjulia/Common.h>
-
-#include <libjulia/optimiser/ExpressionSimplifier.h>
-
-#include <libsolidity/inlineasm/AsmPrinter.h>
-
-#include <boost/test/unit_test.hpp>
-
-#include <boost/range/adaptors.hpp>
-#include <boost/algorithm/string/join.hpp>
-
-using namespace std;
-using namespace dev;
-using namespace dev::julia;
-using namespace dev::julia::test;
-using namespace dev::solidity;
-
-
-#define CHECK(_original, _expectation)\
-do\
-{\
- assembly::AsmPrinter p;\
- Block b = *(parse(_original, false).first);\
- (ExpressionSimplifier{})(b);\
- string result = p(b);\
- BOOST_CHECK_EQUAL(result, format(_expectation, false));\
-}\
-while(false)
-
-BOOST_AUTO_TEST_SUITE(YulSimplifier)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- CHECK("{ }", "{ }");
-}
-
-BOOST_AUTO_TEST_CASE(constants)
-{
- CHECK(
- "{ let a := add(1, mul(3, 4)) }",
- "{ let a := 13 }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(invariant)
-{
- CHECK(
- "{ let a := mload(sub(7, 7)) let b := sub(a, 0) }",
- "{ let a := mload(0) let b := a }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(reversed)
-{
- CHECK(
- "{ let a := add(0, mload(0)) }",
- "{ let a := mload(0) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(constant_propagation)
-{
- CHECK(
- "{ let a := add(7, sub(mload(0), 7)) }",
- "{ let a := mload(0) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(identity_rules_simple)
-{
- CHECK(
- "{ let a := mload(0) let b := sub(a, a) }",
- "{ let a := mload(0) let b := 0 }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(identity_rules_complex)
-{
- CHECK(
- "{ let a := sub(calldataload(0), calldataload(0)) }",
- "{ let a := 0 }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(identity_rules_negative)
-{
- CHECK(
- "{ let a := sub(calldataload(1), calldataload(0)) }",
- "{ let a := sub(calldataload(1), calldataload(0)) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(including_function_calls)
-{
- CHECK(
- "{ function f() -> a {} let b := add(7, sub(f(), 7)) }",
- "{ function f() -> a {} let b := f() }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(inside_for)
-{
- CHECK(
- "{ for { let a := 10 } iszero(eq(a, 0)) { a := add(a, 1) } {} }",
- "{ for { let a := 10 } iszero(iszero(a)) { a := add(a, 1) } {} }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(mod_and)
-{
- CHECK(
- "{ mstore(0, mod(calldataload(0), exp(2, 8))) }",
- "{ mstore(0, and(calldataload(0), 255)) }"
- );
- CHECK(
- "{ mstore(0, mod(calldataload(0), exp(2, 255))) }",
- "{ mstore(0, and(calldataload(0), 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(not_applied_removes_non_constant_and_not_movable)
-{
- CHECK(
- // The first argument of div is not constant.
- // keccak256 is not movable.
- "{ let a := div(keccak256(0, 0), 0) }",
- "{ let a := div(keccak256(0, 0), 0) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(not_applied_function_call_different_names)
-{
- CHECK(
- "{ function f1() -> a { } function f2() -> b {} let c := sub(f1(), f2()) }",
- "{ function f1() -> a { } function f2() -> b {} let c := sub(f1(), f2()) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(not_applied_function_call_different_arguments)
-{
- CHECK(
- "{ function f(a) -> b { } let c := sub(f(0), f(1)) }",
- "{ function f(a) -> b { } let c := sub(f(0), f(1)) }"
- );
-}
-
-BOOST_AUTO_TEST_CASE(not_applied_function_call_equality_not_movable)
-{
- CHECK(
- // Even if the functions pass the equality check, they are not movable.
- "{ function f() -> a { } let b := sub(f(), f()) }",
- "{ function f() -> a { } let b := sub(f(), f()) }"
- );
-}
-
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libjulia/YulOptimizerTest.cpp b/test/libjulia/YulOptimizerTest.cpp
index 4cd063a8..2d79674b 100644
--- a/test/libjulia/YulOptimizerTest.cpp
+++ b/test/libjulia/YulOptimizerTest.cpp
@@ -31,6 +31,7 @@
#include <libjulia/optimiser/FullInliner.h>
#include <libjulia/optimiser/MainFunction.h>
#include <libjulia/optimiser/Rematerialiser.h>
+#include <libjulia/optimiser/ExpressionSimplifier.h>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/inlineasm/AsmPrinter.h>
@@ -134,6 +135,11 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
disambiguate();
(Rematerialiser{})(*m_ast);
}
+ else if (m_optimizerStep == "expressionSimplifier")
+ {
+ disambiguate();
+ (ExpressionSimplifier{})(*m_ast);
+ }
else
{
FormattedScope(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl;
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/constant_propagation.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/constant_propagation.yul
new file mode 100644
index 00000000..0b55adc5
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/constant_propagation.yul
@@ -0,0 +1,6 @@
+{ let a := add(7, sub(mload(0), 7)) }
+// ----
+// expressionSimplifier
+// {
+// let a := mload(0)
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/constants.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/constants.yul
new file mode 100644
index 00000000..bd1a5a53
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/constants.yul
@@ -0,0 +1,6 @@
+{ let a := add(1, mul(3, 4)) }
+// ----
+// expressionSimplifier
+// {
+// let a := 13
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_complex.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_complex.yul
new file mode 100644
index 00000000..f6190622
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_complex.yul
@@ -0,0 +1,6 @@
+{ let a := sub(calldataload(0), calldataload(0)) }
+// ----
+// expressionSimplifier
+// {
+// let a := 0
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_negative.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_negative.yul
new file mode 100644
index 00000000..e91403cd
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_negative.yul
@@ -0,0 +1,6 @@
+{ let a := sub(calldataload(1), calldataload(0)) }
+// ----
+// expressionSimplifier
+// {
+// let a := sub(calldataload(1), calldataload(0))
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_simple.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_simple.yul
new file mode 100644
index 00000000..d35686cd
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/identity_rules_simple.yul
@@ -0,0 +1,10 @@
+{
+ let a := mload(0)
+ let b := sub(a, a)
+}
+// ----
+// expressionSimplifier
+// {
+// let a := mload(0)
+// let b := 0
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/including_function_calls.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/including_function_calls.yul
new file mode 100644
index 00000000..c2ca504a
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/including_function_calls.yul
@@ -0,0 +1,12 @@
+{
+ function f() -> a {}
+ let b := add(7, sub(f(), 7))
+}
+// ----
+// expressionSimplifier
+// {
+// function f() -> a
+// {
+// }
+// let b := f()
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/inside_for.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/inside_for.yul
new file mode 100644
index 00000000..42c37826
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/inside_for.yul
@@ -0,0 +1,16 @@
+{
+ for { let a := 10 } iszero(eq(a, 0)) { a := add(a, 1) } {}
+}
+// ----
+// expressionSimplifier
+// {
+// for {
+// let a := 10
+// }
+// iszero(iszero(a))
+// {
+// a := add(a, 1)
+// }
+// {
+// }
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/invariant.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/invariant.yul
new file mode 100644
index 00000000..e6d84552
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/invariant.yul
@@ -0,0 +1,10 @@
+{
+ let a := mload(sub(7, 7))
+ let b := sub(a, 0)
+}
+// ----
+// expressionSimplifier
+// {
+// let a := mload(0)
+// let b := a
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_1.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_1.yul
new file mode 100644
index 00000000..88714ce0
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_1.yul
@@ -0,0 +1,8 @@
+{
+ mstore(0, mod(calldataload(0), exp(2, 8)))
+}
+// ----
+// expressionSimplifier
+// {
+// mstore(0, and(calldataload(0), 255))
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_2.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_2.yul
new file mode 100644
index 00000000..4d52abe8
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/mod_and_2.yul
@@ -0,0 +1,8 @@
+{
+ mstore(0, mod(calldataload(0), exp(2, 255)))
+}
+// ----
+// expressionSimplifier
+// {
+// mstore(0, and(calldataload(0), 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff))
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_arguments.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_arguments.yul
new file mode 100644
index 00000000..53270b72
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_arguments.yul
@@ -0,0 +1,12 @@
+{
+ function f(a) -> b { }
+ let c := sub(f(0), f(1))
+}
+// ----
+// expressionSimplifier
+// {
+// function f(a) -> b
+// {
+// }
+// let c := sub(f(0), f(1))
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_names.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_names.yul
new file mode 100644
index 00000000..6ab65d29
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_different_names.yul
@@ -0,0 +1,16 @@
+{
+ function f1() -> a { }
+ function f2() -> b { }
+ let c := sub(f1(), f2())
+}
+// ----
+// expressionSimplifier
+// {
+// function f1() -> a
+// {
+// }
+// function f2() -> b
+// {
+// }
+// let c := sub(f1(), f2())
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_equality_not_movable.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_equality_not_movable.yul
new file mode 100644
index 00000000..ab1bd128
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_function_call_equality_not_movable.yul
@@ -0,0 +1,13 @@
+// Even if the functions pass the equality check, they are not movable.
+{
+ function f() -> a { }
+ let b := sub(f(), f())
+}
+// ----
+// expressionSimplifier
+// {
+// function f() -> a
+// {
+// }
+// let b := sub(f(), f())
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_removes_non_constant_and_not_movable.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_removes_non_constant_and_not_movable.yul
new file mode 100644
index 00000000..fc61c3df
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/not_applied_removes_non_constant_and_not_movable.yul
@@ -0,0 +1,10 @@
+// The first argument of div is not constant.
+// keccak256 is not movable.
+{
+ let a := div(keccak256(0, 0), 0)
+}
+// ----
+// expressionSimplifier
+// {
+// let a := div(keccak256(0, 0), 0)
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/reversed.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/reversed.yul
new file mode 100644
index 00000000..6353cda9
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/reversed.yul
@@ -0,0 +1,8 @@
+{
+ let a := add(0, mload(0))
+}
+// ----
+// expressionSimplifier
+// {
+// let a := mload(0)
+// }
diff --git a/test/libjulia/yulOptimizerTests/expressionSimplifier/smoke.yul b/test/libjulia/yulOptimizerTests/expressionSimplifier/smoke.yul
new file mode 100644
index 00000000..88420e92
--- /dev/null
+++ b/test/libjulia/yulOptimizerTests/expressionSimplifier/smoke.yul
@@ -0,0 +1,5 @@
+{ }
+// ----
+// expressionSimplifier
+// {
+// }