Removing scope rules for pre block in 'For Loops'

This commit is contained in:
fnatic
2019-04-17 05:58:40 +05:30
parent 94053c9a52
commit 5b6ed7a97c
24 changed files with 60 additions and 111 deletions
@@ -32,7 +32,7 @@ struct Dialect;
* Optimisation stage that replaces expressions known to be the current value of a variable
* in scope by a reference to that variable.
*
* Prerequisite: Disambiguator
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class CommonSubexpressionEliminator: public DataFlowAnalyzer
{
+3 -6
View File
@@ -112,10 +112,9 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
void DataFlowAnalyzer::operator()(ForLoop& _for)
{
// Special scope handling of the pre block.
pushScope(false);
for (auto& statement: _for.pre.statements)
visit(statement);
// If the pre block was not empty,
// we would have to deal with more complicated scoping rules.
assertThrow(_for.pre.statements.empty(), OptimizerException, "");
AssignmentsSinceContinue assignmentsSinceCont;
assignmentsSinceCont(_for.body);
@@ -130,8 +129,6 @@ void DataFlowAnalyzer::operator()(ForLoop& _for)
clearValues(assignmentsSinceCont.names());
(*this)(_for.post);
clearValues(assignments.names());
popScope();
}
void DataFlowAnalyzer::operator()(Block& _block)
+1 -1
View File
@@ -39,7 +39,7 @@ struct Dialect;
*
* A special zero constant expression is used for the default value of variables.
*
* Prerequisite: Disambiguator
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class DataFlowAnalyzer: public ASTModifier
{
+1 -1
View File
@@ -36,7 +36,7 @@ struct Dialect;
* It tracks the current values of variables using the DataFlowAnalyzer
* and takes them into account for replacements.
*
* Prerequisite: Disambiguator.
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class ExpressionSimplifier: public DataFlowAnalyzer
{
+3 -10
View File
@@ -118,12 +118,9 @@ void RedundantAssignEliminator::operator()(ForLoop const& _forLoop)
ForLoopInfo outerForLoopInfo;
swap(outerForLoopInfo, m_forLoopInfo);
set<YulString> outerDeclaredVariables;
swap(m_declaredVariables, outerDeclaredVariables);
// We need to visit the statements directly because of the
// scoping rules.
walkVector(_forLoop.pre.statements);
// If the pre block was not empty,
// we would have to deal with more complicated scoping rules.
assertThrow(_forLoop.pre.statements.empty(), OptimizerException, "");
// We just run the loop twice to account for the
// back edge.
@@ -156,10 +153,6 @@ void RedundantAssignEliminator::operator()(ForLoop const& _forLoop)
merge(m_assignments, move(m_forLoopInfo.pendingBreakStmts));
m_forLoopInfo.pendingBreakStmts.clear();
for (auto const& var: m_declaredVariables)
finalize(var, State::Unused);
swap(m_declaredVariables, outerDeclaredVariables);
// Restore potential outer for-loop states.
swap(m_forLoopInfo, outerForLoopInfo);
}
+1 -1
View File
@@ -95,7 +95,7 @@ struct Dialect;
* This step is usually run right after the SSA transform to complete
* the generation of the pseudo-SSA.
*
* Prerequisite: Disambiguator.
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class RedundantAssignEliminator: public ASTWalker
{
+1 -1
View File
@@ -33,7 +33,7 @@ namespace yul
* - the variable is referenced at most 5 times and the value is rather cheap
* ("cost" of at most 1 like a constant up to 0xff)
*
* Prerequisite: Disambiguator
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class Rematerialiser: public DataFlowAnalyzer
{
+1 -1
View File
@@ -36,7 +36,7 @@ namespace yul
* - replace switch with const expr with matching case body
* - replace for with false condition by its initialization part
*
* Prerequisites: Disambiguator
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*
* Important: Can only be used on EVM code.
*/