mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] ProgramSize: Add an option to repeat the optimisation sequence several times
This commit is contained in:
parent
751caf0ed3
commit
930a9918a6
@ -72,6 +72,39 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_size_of_the_optimised_program, F
|
||||
BOOST_TEST(ProgramSize(m_program).evaluate(chromosome) == optimisedProgram.codeSize());
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_repeat_the_optimisation_specified_number_of_times, FitnessMetricFixture)
|
||||
{
|
||||
Chromosome chromosome(vector<string>{UnusedPruner::name, EquivalentFunctionCombiner::name});
|
||||
|
||||
Program programOptimisedOnce = m_program;
|
||||
programOptimisedOnce.optimise(chromosome.optimisationSteps());
|
||||
Program programOptimisedTwice = programOptimisedOnce;
|
||||
programOptimisedTwice.optimise(chromosome.optimisationSteps());
|
||||
assert(m_program.codeSize() != programOptimisedOnce.codeSize());
|
||||
assert(m_program.codeSize() != programOptimisedTwice.codeSize());
|
||||
assert(programOptimisedOnce.codeSize() != programOptimisedTwice.codeSize());
|
||||
|
||||
ProgramSize metric(m_program, 2);
|
||||
|
||||
BOOST_TEST(metric.evaluate(chromosome) != m_program.codeSize());
|
||||
BOOST_TEST(metric.evaluate(chromosome) != programOptimisedOnce.codeSize());
|
||||
BOOST_TEST(metric.evaluate(chromosome) == programOptimisedTwice.codeSize());
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_not_optimise_if_number_of_repetitions_is_zero, FitnessMetricFixture)
|
||||
{
|
||||
Chromosome chromosome(vector<string>{UnusedPruner::name, EquivalentFunctionCombiner::name});
|
||||
|
||||
Program optimisedProgram = m_program;
|
||||
optimisedProgram.optimise(chromosome.optimisationSteps());
|
||||
assert(m_program.codeSize() != optimisedProgram.codeSize());
|
||||
|
||||
ProgramSize metric(m_program, 0);
|
||||
|
||||
BOOST_TEST(metric.evaluate(chromosome) == m_program.codeSize());
|
||||
BOOST_TEST(metric.evaluate(chromosome) != optimisedProgram.codeSize());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -23,6 +23,8 @@ using namespace solidity::phaser;
|
||||
size_t ProgramSize::evaluate(Chromosome const& _chromosome) const
|
||||
{
|
||||
Program programCopy = m_program;
|
||||
programCopy.optimise(_chromosome.optimisationSteps());
|
||||
for (size_t i = 0; i < m_repetitionCount; ++i)
|
||||
programCopy.optimise(_chromosome.optimisationSteps());
|
||||
|
||||
return programCopy.codeSize();
|
||||
}
|
||||
|
@ -53,12 +53,15 @@ public:
|
||||
class ProgramSize: public FitnessMetric
|
||||
{
|
||||
public:
|
||||
ProgramSize(Program _program): m_program(std::move(_program)) {}
|
||||
explicit ProgramSize(Program _program, size_t _repetitionCount = 1):
|
||||
m_program(std::move(_program)),
|
||||
m_repetitionCount(_repetitionCount) {}
|
||||
|
||||
size_t evaluate(Chromosome const& _chromosome) const override;
|
||||
|
||||
private:
|
||||
Program m_program;
|
||||
size_t m_repetitionCount;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user