mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add tests for ForLoopConditionIntoBody
This commit is contained in:
parent
a86b00e8d0
commit
4ab377eb00
@ -33,6 +33,7 @@
|
||||
#include <libyul/optimiser/FunctionHoister.h>
|
||||
#include <libyul/optimiser/ExpressionInliner.h>
|
||||
#include <libyul/optimiser/FullInliner.h>
|
||||
#include <libyul/optimiser/ForLoopConditionIntoBody.h>
|
||||
#include <libyul/optimiser/ForLoopInitRewriter.h>
|
||||
#include <libyul/optimiser/MainFunction.h>
|
||||
#include <libyul/optimiser/Rematerialiser.h>
|
||||
@ -121,6 +122,11 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
||||
VarDeclInitializer{}(*m_ast);
|
||||
else if (m_optimizerStep == "varNameCleaner")
|
||||
VarNameCleaner{*m_ast, *m_dialect}(*m_ast);
|
||||
else if (m_optimizerStep == "forLoopConditionIntoBody")
|
||||
{
|
||||
disambiguate();
|
||||
ForLoopConditionIntoBody{}(*m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "forLoopInitRewriter")
|
||||
{
|
||||
disambiguate();
|
||||
|
@ -0,0 +1,26 @@
|
||||
{
|
||||
let a := 1
|
||||
for { } 42 { } { }
|
||||
for { } "hello" { } { }
|
||||
for { } 0 { } { }
|
||||
for { } a { } { }
|
||||
for { } add(a, a) { } { }
|
||||
}
|
||||
// ====
|
||||
// step: forLoopConditionIntoBody
|
||||
// ----
|
||||
// {
|
||||
// let a := 1
|
||||
// for { } 42 { }
|
||||
// { }
|
||||
// for { } "hello" { }
|
||||
// { }
|
||||
// for { } 0 { }
|
||||
// { }
|
||||
// for { } 1 { }
|
||||
// { if iszero(a) { break } }
|
||||
// for { } 1 { }
|
||||
// {
|
||||
// if iszero(add(a, a)) { break }
|
||||
// }
|
||||
// }
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
for { let a := 1 } iszero(eq(a, 10)) { a := add(a, 1) } { }
|
||||
}
|
||||
// ====
|
||||
// step: forLoopConditionIntoBody
|
||||
// ----
|
||||
// {
|
||||
// for { let a := 1 } 1 { a := add(a, 1) }
|
||||
// {
|
||||
// if iszero(iszero(eq(a, 10))) { break }
|
||||
// }
|
||||
// }
|
@ -0,0 +1,41 @@
|
||||
{
|
||||
let random := 42
|
||||
for {
|
||||
for { let a := 1} iszero(eq(a,10)) {} {
|
||||
a := add(a, 1)
|
||||
}
|
||||
let b := 1
|
||||
} iszero(eq(b, 10)) {
|
||||
for { let c := 1 } iszero(eq(c,2)) { c := add(c, 1) } {
|
||||
b := add(b, 1)
|
||||
}
|
||||
} {
|
||||
mstore(b,b)
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: forLoopConditionIntoBody
|
||||
// ----
|
||||
// {
|
||||
// let random := 42
|
||||
// for {
|
||||
// for { let a := 1 } 1 { }
|
||||
// {
|
||||
// if iszero(iszero(eq(a, 10))) { break }
|
||||
// a := add(a, 1)
|
||||
// }
|
||||
// let b := 1
|
||||
// }
|
||||
// 1
|
||||
// {
|
||||
// for { let c := 1 } 1 { c := add(c, 1) }
|
||||
// {
|
||||
// if iszero(iszero(eq(c, 2))) { break }
|
||||
// b := add(b, 1)
|
||||
// }
|
||||
// }
|
||||
// {
|
||||
// if iszero(iszero(eq(b, 10))) { break }
|
||||
// mstore(b, b)
|
||||
// }
|
||||
// }
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
let random := 42
|
||||
for { let a := 1 } iszero(eq(a, 10)) { a := add(a, 1) } {
|
||||
a := add(a, 1)
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: forLoopConditionIntoBody
|
||||
// ----
|
||||
// {
|
||||
// let random := 42
|
||||
// for { let a := 1 } 1 { a := add(a, 1) }
|
||||
// {
|
||||
// if iszero(iszero(eq(a, 10))) { break }
|
||||
// a := add(a, 1)
|
||||
// }
|
||||
// }
|
@ -40,6 +40,7 @@
|
||||
#include <libyul/optimiser/FunctionHoister.h>
|
||||
#include <libyul/optimiser/ExpressionInliner.h>
|
||||
#include <libyul/optimiser/FullInliner.h>
|
||||
#include <libyul/optimiser/ForLoopConditionIntoBody.h>
|
||||
#include <libyul/optimiser/ForLoopInitRewriter.h>
|
||||
#include <libyul/optimiser/MainFunction.h>
|
||||
#include <libyul/optimiser/Rematerialiser.h>
|
||||
@ -129,7 +130,7 @@ public:
|
||||
}
|
||||
cout << "(q)quit/(f)flatten/(c)se/initialize var(d)ecls/(x)plit/(j)oin/(g)rouper/(h)oister/" << endl;
|
||||
cout << " (e)xpr inline/(i)nline/(s)implify/varname c(l)eaner/(u)nusedprune/ss(a) transform/" << endl;
|
||||
cout << " (r)edundant assign elim./re(m)aterializer/f(o)r-loop-pre-rewriter/" << endl;
|
||||
cout << " (r)edundant assign elim./re(m)aterializer/f(o)r-loop-init-rewriter/f(O)r-loop-condition-into-body/" << endl;
|
||||
cout << " s(t)ructural simplifier/equi(v)alent function combiner/ssa re(V)erser/? " << endl;
|
||||
cout << " co(n)trol flow simplifier/stack com(p)ressor/(D)ead code eliminator/? " << endl;
|
||||
cout.flush();
|
||||
@ -145,6 +146,9 @@ public:
|
||||
case 'o':
|
||||
ForLoopInitRewriter{}(*m_ast);
|
||||
break;
|
||||
case 'O':
|
||||
ForLoopConditionIntoBody{}(*m_ast);
|
||||
break;
|
||||
case 'c':
|
||||
(CommonSubexpressionEliminator{m_dialect})(*m_ast);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user