Introduce side-effect-free as relaxed version of movable.

This commit is contained in:
chriseth
2019-05-16 12:30:05 +02:00
parent d172b9bf11
commit e8a88b13e4
8 changed files with 56 additions and 11 deletions
+17 -8
View File
@@ -51,21 +51,30 @@ void MovableChecker::operator()(Identifier const& _identifier)
void MovableChecker::operator()(FunctionalInstruction const& _instr)
{
ASTWalker::operator()(_instr);
if (!eth::SemanticInformation::movable(_instr.instruction))
m_movable = false;
else
ASTWalker::operator()(_instr);
if (!eth::SemanticInformation::sideEffectFree(_instr.instruction))
m_sideEffectFree = false;
}
void MovableChecker::operator()(FunctionCall const& _functionCall)
{
ASTWalker::operator()(_functionCall);
if (BuiltinFunction const* f = m_dialect.builtin(_functionCall.functionName.name))
if (f->movable)
{
ASTWalker::operator()(_functionCall);
return;
}
m_movable = false;
{
if (!f->movable)
m_movable = false;
if (!f->sideEffectFree)
m_sideEffectFree = false;
}
else
{
m_movable = false;
m_sideEffectFree = false;
}
}
void MovableChecker::visit(Statement const&)
+5
View File
@@ -46,6 +46,8 @@ public:
using ASTWalker::visit;
bool movable() const { return m_movable; }
bool sideEffectFree() const { return m_sideEffectFree; }
std::set<YulString> const& referencedVariables() const { return m_variableReferences; }
private:
@@ -54,6 +56,9 @@ private:
std::set<YulString> m_variableReferences;
/// Is the current expression movable or not.
bool m_movable = true;
/// Is the current expression side-effect free, i.e. can be removed
/// without changing the semantics.
bool m_sideEffectFree = true;
};
/**