aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/optimiser
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-13 23:46:48 +0800
committerGitHub <noreply@github.com>2018-12-13 23:46:48 +0800
commit633dd44576e267f4728b86ec69a9cc56517a1f89 (patch)
tree9384c8d7a4cccdc7e2db2176481978779bc17baf /libyul/optimiser
parent996bfb2a83bf1d99192575fa05ba43e4bc05ef0c (diff)
parentb11d413720763e5d4a95260846293a15af7d3b54 (diff)
downloaddexon-solidity-633dd44576e267f4728b86ec69a9cc56517a1f89.tar.gz
dexon-solidity-633dd44576e267f4728b86ec69a9cc56517a1f89.tar.zst
dexon-solidity-633dd44576e267f4728b86ec69a9cc56517a1f89.zip
Merge pull request #5649 from ethereum/returnsAreZero
[Yul] Consider return variables to be zero initially.
Diffstat (limited to 'libyul/optimiser')
-rw-r--r--libyul/optimiser/DataFlowAnalyzer.cpp3
-rw-r--r--libyul/optimiser/SSAValueTracker.cpp13
-rw-r--r--libyul/optimiser/SSAValueTracker.h1
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;