New simplifier via broken expressions.

This commit is contained in:
chriseth
2018-10-16 16:18:39 +02:00
parent 76db0d69cf
commit a320eec7d3
5 changed files with 74 additions and 16 deletions
+13 -1
View File
@@ -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);
}