diff options
Diffstat (limited to 'libyul/optimiser')
-rw-r--r-- | libyul/optimiser/DataFlowAnalyzer.cpp | 3 | ||||
-rw-r--r-- | libyul/optimiser/SSAValueTracker.cpp | 13 | ||||
-rw-r--r-- | libyul/optimiser/SSAValueTracker.h | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index 7bff2c89..c8d236dc 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -96,7 +96,10 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun) for (auto const& parameter: _fun.parameters) m_variableScopes.back().variables.emplace(parameter.name); for (auto const& var: _fun.returnVariables) + { m_variableScopes.back().variables.emplace(var.name); + handleAssignment({var.name}, nullptr); + } ASTModifier::operator()(_fun); popScope(); diff --git a/libyul/optimiser/SSAValueTracker.cpp b/libyul/optimiser/SSAValueTracker.cpp index a0e44b2b..23eb9ec2 100644 --- a/libyul/optimiser/SSAValueTracker.cpp +++ b/libyul/optimiser/SSAValueTracker.cpp @@ -33,12 +33,18 @@ void SSAValueTracker::operator()(Assignment const& _assignment) m_values.erase(var.name); } +void SSAValueTracker::operator()(FunctionDefinition const& _funDef) +{ + for (auto const& var: _funDef.returnVariables) + setValue(var.name, nullptr); + ASTWalker::operator()(_funDef); +} + void SSAValueTracker::operator()(VariableDeclaration const& _varDecl) { - static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; if (!_varDecl.value) for (auto const& var: _varDecl.variables) - setValue(var.name, &zero); + setValue(var.name, nullptr); else if (_varDecl.variables.size() == 1) setValue(_varDecl.variables.front().name, _varDecl.value.get()); } @@ -50,5 +56,8 @@ void SSAValueTracker::setValue(YulString _name, Expression const* _value) OptimizerException, "Source needs to be disambiguated." ); + static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; + if (!_value) + _value = &zero; m_values[_name] = _value; } diff --git a/libyul/optimiser/SSAValueTracker.h b/libyul/optimiser/SSAValueTracker.h index 0a6cde80..0680485f 100644 --- a/libyul/optimiser/SSAValueTracker.h +++ b/libyul/optimiser/SSAValueTracker.h @@ -41,6 +41,7 @@ class SSAValueTracker: public ASTWalker { public: using ASTWalker::operator(); + void operator()(FunctionDefinition const& _funDef) override; void operator()(VariableDeclaration const& _varDecl) override; void operator()(Assignment const& _assignment) override; |