diff options
author | chriseth <chris@ethereum.org> | 2018-10-03 00:07:50 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-10-16 22:18:39 +0800 |
commit | a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf (patch) | |
tree | 8978c38d55a7781aae5ad44901e422c666edfa91 /libyul/optimiser/ExpressionSimplifier.cpp | |
parent | 76db0d69cfba634bdc5f6da41dc30c2abdb66bc2 (diff) | |
download | dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar.gz dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar.bz2 dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar.lz dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar.xz dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.tar.zst dexon-solidity-a320eec7d38f98a1fbb9f6267e5e30cfae5c59cf.zip |
New simplifier via broken expressions.
Diffstat (limited to 'libyul/optimiser/ExpressionSimplifier.cpp')
-rw-r--r-- | libyul/optimiser/ExpressionSimplifier.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libyul/optimiser/ExpressionSimplifier.cpp b/libyul/optimiser/ExpressionSimplifier.cpp index c95fb3d5..64e9d7e7 100644 --- a/libyul/optimiser/ExpressionSimplifier.cpp +++ b/libyul/optimiser/ExpressionSimplifier.cpp @@ -22,6 +22,7 @@ #include <libyul/optimiser/SimplificationRules.h> #include <libyul/optimiser/Semantics.h> +#include <libyul/optimiser/SSAValueTracker.h> #include <libsolidity/inlineasm/AsmData.h> @@ -36,13 +37,24 @@ using namespace dev::solidity; void ExpressionSimplifier::visit(Expression& _expression) { ASTModifier::visit(_expression); - while (auto match = SimplificationRules::findFirstMatch(_expression)) + while (auto match = SimplificationRules::findFirstMatch(_expression, m_ssaValues)) { // Do not apply the rule if it removes non-constant parts of the expression. // TODO: The check could actually be less strict than "movable". // We only require "Does not cause side-effects". + // Note: References to variables that are only assigned once are always movable, + // so if the value of the variable is not movable, the expression that references + // the variable still is. + if (match->removesNonConstants && !MovableChecker(_expression).movable()) return; _expression = match->action().toExpression(locationOf(_expression)); } } + +void ExpressionSimplifier::run(Block& _ast) +{ + SSAValueTracker ssaValues; + ssaValues(_ast); + ExpressionSimplifier{ssaValues.values()}(_ast); +} |