diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index 5b1ae2550..ca8f94239 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -55,6 +55,30 @@ OptionalStatements replaceConstArgSwitch(Switch& _switchStmt, u256 const& _const return optional<vector<Statement>>{vector<Statement>{}}; } +optional<u256> hasLiteralValue(Expression const& _expression) +{ + if (holds_alternative<Literal>(_expression)) + return valueOfLiteral(std::get<Literal>(_expression)); + else + return std::optional<u256>(); +} + +bool expressionAlwaysTrue(Expression const& _expression) +{ + if (std::optional<u256> value = hasLiteralValue(_expression)) + return *value != 0; + else + return false; +} + +bool expressionAlwaysFalse(Expression const& _expression) +{ + if (std::optional<u256> value = hasLiteralValue(_expression)) + return *value == 0; + else + return false; +} + } void StructuralSimplifier::run(OptimiserStepContext&, Block& _ast) @@ -103,27 +127,3 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements) } ); } - -bool StructuralSimplifier::expressionAlwaysTrue(Expression const& _expression) -{ - if (std::optional<u256> value = hasLiteralValue(_expression)) - return *value != 0; - else - return false; -} - -bool StructuralSimplifier::expressionAlwaysFalse(Expression const& _expression) -{ - if (std::optional<u256> value = hasLiteralValue(_expression)) - return *value == 0; - else - return false; -} - -std::optional<u256> StructuralSimplifier::hasLiteralValue(Expression const& _expression) const -{ - if (holds_alternative<Literal>(_expression)) - return valueOfLiteral(std::get<Literal>(_expression)); - else - return std::optional<u256>(); -} diff --git a/libyul/optimiser/StructuralSimplifier.h b/libyul/optimiser/StructuralSimplifier.h index 3fd59efde..734b2e53a 100644 --- a/libyul/optimiser/StructuralSimplifier.h +++ b/libyul/optimiser/StructuralSimplifier.h @@ -18,7 +18,6 @@ #pragma once #include <libyul/optimiser/ASTWalker.h> -#include <libyul/optimiser/DataFlowAnalyzer.h> #include <libyul/optimiser/OptimiserStep.h> #include <libsolutil/Common.h> @@ -50,9 +49,6 @@ private: StructuralSimplifier() = default; void simplify(std::vector<Statement>& _statements); - bool expressionAlwaysTrue(Expression const& _expression); - bool expressionAlwaysFalse(Expression const& _expression); - std::optional<u256> hasLiteralValue(Expression const& _expression) const; }; } diff --git a/test/libyul/KnowledgeBaseTest.cpp b/test/libyul/KnowledgeBaseTest.cpp index 03cc4cd8d..ac48f962f 100644 --- a/test/libyul/KnowledgeBaseTest.cpp +++ b/test/libyul/KnowledgeBaseTest.cpp @@ -25,7 +25,6 @@ #include <libyul/Object.h> #include <libyul/optimiser/KnowledgeBase.h> #include <libyul/optimiser/SSAValueTracker.h> -#include <libyul/optimiser/DataFlowAnalyzer.h> #include <libyul/optimiser/NameDispenser.h> #include <libyul/optimiser/CommonSubexpressionEliminator.h> #include <libyul/backends/evm/EVMDialect.h>