Merge pull request #8267 from ghallak/prune-unnecessary-funcs

[Yul] Prune functions that call each other but are otherwise unreferenced
This commit is contained in:
chriseth
2020-02-12 11:09:27 +01:00
committed by GitHub
11 changed files with 204 additions and 2 deletions
+8
View File
@@ -28,6 +28,7 @@
#include <libyul/optimiser/DeadCodeEliminator.h>
#include <libyul/optimiser/Disambiguator.h>
#include <libyul/optimiser/CallGraphGenerator.h>
#include <libyul/optimiser/CircularReferencesPruner.h>
#include <libyul/optimiser/ConditionalUnsimplifier.h>
#include <libyul/optimiser/ConditionalSimplifier.h>
#include <libyul/optimiser/CommonSubexpressionEliminator.h>
@@ -250,6 +251,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
CommonSubexpressionEliminator::run(*m_context, *m_ast);
ExpressionSimplifier::run(*m_context, *m_ast);
UnusedPruner::run(*m_context, *m_ast);
CircularReferencesPruner::run(*m_context, *m_ast);
DeadCodeEliminator::run(*m_context, *m_ast);
ExpressionJoiner::run(*m_context, *m_ast);
ExpressionJoiner::run(*m_context, *m_ast);
@@ -259,6 +261,12 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
disambiguate();
UnusedPruner::run(*m_context, *m_ast);
}
else if (m_optimizerStep == "circularReferencesPruner")
{
disambiguate();
FunctionHoister::run(*m_context, *m_ast);
CircularReferencesPruner::run(*m_context, *m_ast);
}
else if (m_optimizerStep == "deadCodeEliminator")
{
disambiguate();
@@ -0,0 +1,20 @@
{
let a
function f() -> x { x := g() }
function g() -> y { y := f() }
function h() -> z { z := g() }
a := h()
}
// ====
// step: circularReferencesPruner
// ----
// {
// let a
// a := h()
// function f() -> x
// { x := g() }
// function g() -> y
// { y := f() }
// function h() -> z
// { z := g() }
// }
@@ -0,0 +1,14 @@
{
{
function a() -> x { x := b() }
function b() -> y { y := a() }
}
{
function c() -> z { z := d() }
function d() -> w { w := c() }
}
}
// ====
// step: circularReferencesPruner
// ----
// { }
@@ -0,0 +1,14 @@
{
{
function z() -> x { x := y() }
function y() -> x { x := z() }
}
{
function z() -> x { x := y() }
function y() -> x { x := z() }
}
}
// ====
// step: circularReferencesPruner
// ----
// { }
@@ -0,0 +1,8 @@
{
function f() -> x { x := g() }
function g() -> x { x := f() }
}
// ====
// step: circularReferencesPruner
// ----
// { }
+1 -1
View File
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_strin
BOOST_TEST(chromosome.length() == allSteps.size());
BOOST_TEST(chromosome.optimisationSteps() == allSteps);
BOOST_TEST(toString(chromosome) == "fcCUnDvejsxIOoighTLMrmVatud");
BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighTLMrmVatud");
}
BOOST_AUTO_TEST_SUITE_END()