mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Chromosome: Add a constructor that reads steps from an abbreviation string
This commit is contained in:
parent
38f79a1761
commit
d22c59aa0e
@ -21,8 +21,18 @@
|
|||||||
#include <tools/yulPhaser/SimulationRNG.h>
|
#include <tools/yulPhaser/SimulationRNG.h>
|
||||||
|
|
||||||
#include <libyul/optimiser/BlockFlattener.h>
|
#include <libyul/optimiser/BlockFlattener.h>
|
||||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
#include <libyul/optimiser/ConditionalSimplifier.h>
|
||||||
|
#include <libyul/optimiser/ExpressionInliner.h>
|
||||||
|
#include <libyul/optimiser/ExpressionSimplifier.h>
|
||||||
|
#include <libyul/optimiser/ForLoopConditionOutOfBody.h>
|
||||||
|
#include <libyul/optimiser/ForLoopConditionOutOfBody.h>
|
||||||
|
#include <libyul/optimiser/ForLoopInitRewriter.h>
|
||||||
|
#include <libyul/optimiser/FunctionHoister.h>
|
||||||
|
#include <libyul/optimiser/LoopInvariantCodeMotion.h>
|
||||||
|
#include <libyul/optimiser/RedundantAssignEliminator.h>
|
||||||
|
#include <libyul/optimiser/Rematerialiser.h>
|
||||||
#include <libyul/optimiser/Suite.h>
|
#include <libyul/optimiser/Suite.h>
|
||||||
|
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||||
#include <libyul/optimiser/UnusedPruner.h>
|
#include <libyul/optimiser/UnusedPruner.h>
|
||||||
|
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
@ -39,6 +49,24 @@ namespace solidity::phaser::test
|
|||||||
BOOST_AUTO_TEST_SUITE(Phaser)
|
BOOST_AUTO_TEST_SUITE(Phaser)
|
||||||
BOOST_AUTO_TEST_SUITE(ChromosomeTest)
|
BOOST_AUTO_TEST_SUITE(ChromosomeTest)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(constructor_should_convert_from_string_to_optimisation_steps)
|
||||||
|
{
|
||||||
|
vector<string> expectedSteps{
|
||||||
|
ConditionalSimplifier::name,
|
||||||
|
FunctionHoister::name,
|
||||||
|
RedundantAssignEliminator::name,
|
||||||
|
ForLoopConditionOutOfBody::name,
|
||||||
|
Rematerialiser::name,
|
||||||
|
ForLoopConditionOutOfBody::name,
|
||||||
|
ExpressionSimplifier::name,
|
||||||
|
ForLoopInitRewriter::name,
|
||||||
|
LoopInvariantCodeMotion::name,
|
||||||
|
ExpressionInliner::name
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_TEST(Chromosome("ChrOmOsoMe").optimisationSteps() == expectedSteps);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(makeRandom_should_create_chromosome_with_random_optimisation_steps)
|
BOOST_AUTO_TEST_CASE(makeRandom_should_create_chromosome_with_random_optimisation_steps)
|
||||||
{
|
{
|
||||||
constexpr uint32_t numSteps = 1000;
|
constexpr uint32_t numSteps = 1000;
|
||||||
|
@ -142,11 +142,11 @@ BOOST_AUTO_TEST_CASE(run_should_not_make_fitness_of_top_chromosomes_worse)
|
|||||||
stringstream output;
|
stringstream output;
|
||||||
CharStream sourceStream(sampleSourceCode, current_test_case().p_name);
|
CharStream sourceStream(sampleSourceCode, current_test_case().p_name);
|
||||||
vector<Chromosome> chromosomes = {
|
vector<Chromosome> chromosomes = {
|
||||||
Chromosome({StructuralSimplifier::name}),
|
Chromosome(vector<string>{StructuralSimplifier::name}),
|
||||||
Chromosome({BlockFlattener::name}),
|
Chromosome(vector<string>{BlockFlattener::name}),
|
||||||
Chromosome({SSAReverser::name}),
|
Chromosome(vector<string>{SSAReverser::name}),
|
||||||
Chromosome({UnusedPruner::name}),
|
Chromosome(vector<string>{UnusedPruner::name}),
|
||||||
Chromosome({StructuralSimplifier::name, BlockFlattener::name}),
|
Chromosome(vector<string>{StructuralSimplifier::name, BlockFlattener::name}),
|
||||||
};
|
};
|
||||||
auto program = Program::load(sourceStream);
|
auto program = Program::load(sourceStream);
|
||||||
Population population(program, chromosomes);
|
Population population(program, chromosomes);
|
||||||
|
@ -36,6 +36,12 @@ ostream& operator<<(ostream& _stream, Chromosome const& _chromosome);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Chromosome::Chromosome(string const& _optimisationSteps)
|
||||||
|
{
|
||||||
|
for (char abbreviation: _optimisationSteps)
|
||||||
|
m_optimisationSteps.push_back(OptimiserSuite::stepAbbreviationToNameMap().at(abbreviation));
|
||||||
|
}
|
||||||
|
|
||||||
Chromosome Chromosome::makeRandom(size_t _length)
|
Chromosome Chromosome::makeRandom(size_t _length)
|
||||||
{
|
{
|
||||||
vector<string> steps;
|
vector<string> steps;
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
Chromosome() = default;
|
Chromosome() = default;
|
||||||
explicit Chromosome(std::vector<std::string> _optimisationSteps):
|
explicit Chromosome(std::vector<std::string> _optimisationSteps):
|
||||||
m_optimisationSteps(std::move(_optimisationSteps)) {}
|
m_optimisationSteps(std::move(_optimisationSteps)) {}
|
||||||
|
explicit Chromosome(std::string const& _optimisationSteps);
|
||||||
static Chromosome makeRandom(size_t _length);
|
static Chromosome makeRandom(size_t _length);
|
||||||
|
|
||||||
size_t length() const { return m_optimisationSteps.size(); }
|
size_t length() const { return m_optimisationSteps.size(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user