diff options
author | chriseth <chris@ethereum.org> | 2018-12-12 07:49:36 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-12-13 01:06:28 +0800 |
commit | 9557dd7e74a801ebafaf4777d60a591b0c484779 (patch) | |
tree | b55af218e8debaeb4a79670f932e1e66afb736b6 /libyul | |
parent | 5e0c312dad2daaae155486397bfbd26d6d172718 (diff) | |
download | dexon-solidity-9557dd7e74a801ebafaf4777d60a591b0c484779.tar.gz dexon-solidity-9557dd7e74a801ebafaf4777d60a591b0c484779.tar.zst dexon-solidity-9557dd7e74a801ebafaf4777d60a591b0c484779.zip |
Support unassigned variables in the SSA value tracker and the data flow analyzer.
Diffstat (limited to 'libyul')
-rw-r--r-- | libyul/optimiser/DataFlowAnalyzer.cpp | 9 | ||||
-rw-r--r-- | libyul/optimiser/DataFlowAnalyzer.h | 2 | ||||
-rw-r--r-- | libyul/optimiser/SSAValueTracker.cpp | 9 | ||||
-rw-r--r-- | libyul/optimiser/SSAValueTracker.h | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/libyul/optimiser/DataFlowAnalyzer.cpp b/libyul/optimiser/DataFlowAnalyzer.cpp index 64c67b38..7bff2c89 100644 --- a/libyul/optimiser/DataFlowAnalyzer.cpp +++ b/libyul/optimiser/DataFlowAnalyzer.cpp @@ -136,17 +136,22 @@ void DataFlowAnalyzer::operator()(Block& _block) void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expression* _value) { + static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; clearValues(_variables); MovableChecker movableChecker; if (_value) movableChecker.visit(*_value); - if (_variables.size() == 1) + else + for (auto const& var: _variables) + m_value[var] = &zero; + + if (_value && _variables.size() == 1) { YulString name = *_variables.begin(); // Expression has to be movable and cannot contain a reference // to the variable that will be assigned to. - if (_value && movableChecker.movable() && !movableChecker.referencedVariables().count(name)) + if (movableChecker.movable() && !movableChecker.referencedVariables().count(name)) m_value[name] = _value; } diff --git a/libyul/optimiser/DataFlowAnalyzer.h b/libyul/optimiser/DataFlowAnalyzer.h index cd134d48..4f12ff6a 100644 --- a/libyul/optimiser/DataFlowAnalyzer.h +++ b/libyul/optimiser/DataFlowAnalyzer.h @@ -36,6 +36,8 @@ namespace yul * Tracks assignments and is used as base class for both Rematerialiser and * Common Subexpression Eliminator. * + * A special zero constant expression is used for the default value of variables. + * * Prerequisite: Disambiguator */ class DataFlowAnalyzer: public ASTModifier diff --git a/libyul/optimiser/SSAValueTracker.cpp b/libyul/optimiser/SSAValueTracker.cpp index ef96c379..a0e44b2b 100644 --- a/libyul/optimiser/SSAValueTracker.cpp +++ b/libyul/optimiser/SSAValueTracker.cpp @@ -35,11 +35,12 @@ void SSAValueTracker::operator()(Assignment const& _assignment) void SSAValueTracker::operator()(VariableDeclaration const& _varDecl) { - if (_varDecl.variables.size() == 1) - setValue(_varDecl.variables.front().name, _varDecl.value.get()); - else if (!_varDecl.value) + static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; + if (!_varDecl.value) for (auto const& var: _varDecl.variables) - setValue(var.name, nullptr); + setValue(var.name, &zero); + else if (_varDecl.variables.size() == 1) + setValue(_varDecl.variables.front().name, _varDecl.value.get()); } void SSAValueTracker::setValue(YulString _name, Expression const* _value) diff --git a/libyul/optimiser/SSAValueTracker.h b/libyul/optimiser/SSAValueTracker.h index efec2200..0a6cde80 100644 --- a/libyul/optimiser/SSAValueTracker.h +++ b/libyul/optimiser/SSAValueTracker.h @@ -33,7 +33,7 @@ namespace yul * Class that walks the AST and stores the initial value of each variable * that is never assigned to. * - * Default value is represented as nullptr. + * A special zero constant expression is used for the default value of variables. * * Prerequisite: Disambiguator */ |