Require for loop init rewriter for SSA.

Co-authored-by: Harikrishnan Mulackal <webmail.hari@gmail.com>
This commit is contained in:
chriseth 2020-07-02 17:02:26 +02:00 committed by Daniel Kirchner
parent c0ee566049
commit 711ed588d7
8 changed files with 49 additions and 28 deletions

View File

@ -194,7 +194,7 @@ void IntroduceControlFlowSSA::operator()(FunctionDefinition& _function)
void IntroduceControlFlowSSA::operator()(ForLoop& _for)
{
(*this)(_for.pre);
yulAssert(_for.pre.statements.empty(), "For loop init rewriter not run.");
Assignments assignments;
assignments(_for.body);
@ -357,11 +357,7 @@ void PropagateValues::operator()(Assignment& _assignment)
void PropagateValues::operator()(ForLoop& _for)
{
// This will clear the current value in case of a reassignment inside the
// init part, although the new variable would still be in scope inside the whole loop.
// This small inefficiency is fine if we move the pre part of all for loops out
// of the for loop.
(*this)(_for.pre);
yulAssert(_for.pre.statements.empty(), "For loop init rewriter not run.");
Assignments assignments;
assignments(_for.body);

View File

@ -85,7 +85,7 @@ class NameDispenser;
*
* TODO Which transforms are required to keep this idempotent?
*
* Prerequisite: Disambiguator.
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class SSATransform: public ASTModifier
{

View File

@ -255,6 +255,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
else if (m_optimizerStep == "ssaTransform")
{
disambiguate();
ForLoopInitRewriter::run(*m_context, *m_ast);
SSATransform::run(*m_context, *m_ast);
}
else if (m_optimizerStep == "redundantAssignEliminator")

View File

@ -0,0 +1,33 @@
{
for { let x := 0 } 1 { x := 2 } {
for { let y := 0 } 1 { y := 6 } {
}
}
}
// ----
// step: ssaTransform
//
// {
// let x_1 := 0
// let x := x_1
// for { }
// 1
// {
// let x_7 := x
// let x_2 := 2
// x := x_2
// }
// {
// let x_5 := x
// let y_3 := 0
// let y := y_3
// for { }
// 1
// {
// let y_6 := y
// let y_4 := 6
// y := y_4
// }
// { }
// }
// }

View File

@ -12,7 +12,8 @@
// {
// let a_1 := mload(0)
// let a := a_1
// for { mstore(0, a_1) }
// mstore(0, a_1)
// for { }
// a
// {
// let a_4 := a

View File

@ -12,19 +12,9 @@
// {
// let a_1 := mload(0)
// let a := a_1
// for {
// let a_2 := add(a_1, 3)
// a := a_2
// }
// a
// {
// let a_4 := a
// mstore(0, a_4)
// }
// {
// let a_3 := a
// mstore(0, a_3)
// }
// let a_5 := a
// mstore(0, a_5)
// let a_2 := add(a_1, 3)
// a := a_2
// for { } a_2 { mstore(0, a_2) }
// { mstore(0, a_2) }
// mstore(0, a_2)
// }

View File

@ -12,7 +12,8 @@
// {
// let a_1 := mload(0)
// let a := a_1
// for { mstore(0, a_1) }
// mstore(0, a_1)
// for { }
// a
// {
// let a_4 := a

View File

@ -32,10 +32,9 @@
// a := a_4
// }
// let a_10 := a
// for {
// let a_5 := add(a_10, 3)
// a := a_5
// }
// let a_5 := add(a_10, 3)
// a := a_5
// for { }
// a
// {
// let a_12 := a