mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not hard-code the default 'runs' value as 200 in code that fills out optimizer settings
This commit is contained in:
parent
6d8ef71277
commit
6ad6fa2382
@ -30,6 +30,8 @@
|
|||||||
#include <libsolutil/Assertions.h>
|
#include <libsolutil/Assertions.h>
|
||||||
#include <libsolutil/Keccak256.h>
|
#include <libsolutil/Keccak256.h>
|
||||||
|
|
||||||
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -124,7 +126,7 @@ public:
|
|||||||
langutil::EVMVersion evmVersion;
|
langutil::EVMVersion evmVersion;
|
||||||
/// This specifies an estimate on how often each opcode in this assembly will be executed,
|
/// This specifies an estimate on how often each opcode in this assembly will be executed,
|
||||||
/// i.e. use a small value to optimise for size and a large value to optimise for runtime gas usage.
|
/// i.e. use a small value to optimise for size and a large value to optimise for runtime gas usage.
|
||||||
size_t expectedExecutionsPerDeployment = 200;
|
size_t expectedExecutionsPerDeployment = frontend::OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Modify and return the current assembly such that creation and execution gas usage
|
/// Modify and return the current assembly such that creation and execution gas usage
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libsolutil/Common.h>
|
#include <libsolutil/Common.h>
|
||||||
|
#include <libevmasm/Assembly.h>
|
||||||
#include <libevmasm/AssemblyItem.h>
|
#include <libevmasm/AssemblyItem.h>
|
||||||
#include <liblangutil/EVMVersion.h>
|
#include <liblangutil/EVMVersion.h>
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ private:
|
|||||||
|
|
||||||
AssemblyItems& m_items;
|
AssemblyItems& m_items;
|
||||||
std::set<size_t> const& m_tagsReferencedFromOutside;
|
std::set<size_t> const& m_tagsReferencedFromOutside;
|
||||||
size_t const m_runs = 200;
|
size_t const m_runs = Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
bool const m_isCreation = false;
|
bool const m_isCreation = false;
|
||||||
langutil::EVMVersion const m_evmVersion;
|
langutil::EVMVersion const m_evmVersion;
|
||||||
};
|
};
|
||||||
|
@ -146,7 +146,7 @@ public:
|
|||||||
|
|
||||||
/// Changes the optimiser settings.
|
/// Changes the optimiser settings.
|
||||||
/// Must be set before parsing.
|
/// Must be set before parsing.
|
||||||
void setOptimiserSettings(bool _optimize, size_t _runs = 200);
|
void setOptimiserSettings(bool _optimize, size_t _runs = OptimiserSettings{}.expectedExecutionsPerDeployment);
|
||||||
|
|
||||||
/// Changes the optimiser settings.
|
/// Changes the optimiser settings.
|
||||||
/// Must be set before parsing.
|
/// Must be set before parsing.
|
||||||
|
@ -85,7 +85,6 @@ struct OptimiserSettings
|
|||||||
s.runConstantOptimiser = true;
|
s.runConstantOptimiser = true;
|
||||||
s.runYulOptimiser = true;
|
s.runYulOptimiser = true;
|
||||||
s.optimizeStackAllocation = true;
|
s.optimizeStackAllocation = true;
|
||||||
s.expectedExecutionsPerDeployment = 200;
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
/// Full optimisations. Currently an alias for standard optimisations.
|
/// Full optimisations. Currently an alias for standard optimisations.
|
||||||
|
@ -1037,7 +1037,9 @@ General Information)").c_str(),
|
|||||||
)
|
)
|
||||||
(
|
(
|
||||||
g_argOptimizeRuns.c_str(),
|
g_argOptimizeRuns.c_str(),
|
||||||
po::value<unsigned>()->value_name("n")->default_value(200),
|
// TODO: The type in OptimiserSettings is size_t but we only accept values up to 2**32-1
|
||||||
|
// on the CLI and in Standard JSON. We should just switch to uint32_t everywhere.
|
||||||
|
po::value<unsigned>()->value_name("n")->default_value(static_cast<unsigned>(OptimiserSettings{}.expectedExecutionsPerDeployment)),
|
||||||
"Set for how many contract runs to optimize. "
|
"Set for how many contract runs to optimize. "
|
||||||
"Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage."
|
"Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage."
|
||||||
)
|
)
|
||||||
|
@ -1286,7 +1286,8 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
|
|||||||
settings.runCSE = true;
|
settings.runCSE = true;
|
||||||
settings.runConstantOptimiser = true;
|
settings.runConstantOptimiser = true;
|
||||||
settings.evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
settings.evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
||||||
settings.expectedExecutionsPerDeployment = 200;
|
settings.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
|
;
|
||||||
main.optimise(settings);
|
main.optimise(settings);
|
||||||
|
|
||||||
AssemblyItems expectationMain{
|
AssemblyItems expectationMain{
|
||||||
@ -1679,7 +1680,7 @@ BOOST_AUTO_TEST_CASE(inliner)
|
|||||||
Instruction::SWAP1,
|
Instruction::SWAP1,
|
||||||
jumpOutOf,
|
jumpOutOf,
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1701,7 +1702,7 @@ BOOST_AUTO_TEST_CASE(inliner_no_inline_type)
|
|||||||
Instruction::SWAP1,
|
Instruction::SWAP1,
|
||||||
Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
items.begin(), items.end()
|
items.begin(), items.end()
|
||||||
@ -1726,7 +1727,7 @@ BOOST_AUTO_TEST_CASE(inliner_no_inline)
|
|||||||
Instruction::JUMPI,
|
Instruction::JUMPI,
|
||||||
Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1757,7 +1758,7 @@ BOOST_AUTO_TEST_CASE(inliner_single_jump)
|
|||||||
AssemblyItem(Tag, 2),
|
AssemblyItem(Tag, 2),
|
||||||
jumpOutOf,
|
jumpOutOf,
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1777,7 +1778,7 @@ BOOST_AUTO_TEST_CASE(inliner_end_of_bytecode)
|
|||||||
Instruction::STOP,
|
Instruction::STOP,
|
||||||
AssemblyItem(Tag, 2),
|
AssemblyItem(Tag, 2),
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
items.begin(), items.end()
|
items.begin(), items.end()
|
||||||
@ -1802,7 +1803,7 @@ BOOST_AUTO_TEST_CASE(inliner_cse_break)
|
|||||||
Instruction::STOP, // CSE breaking instruction
|
Instruction::STOP, // CSE breaking instruction
|
||||||
jumpOutOf
|
jumpOutOf
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
items.begin(), items.end()
|
items.begin(), items.end()
|
||||||
@ -1822,7 +1823,7 @@ BOOST_AUTO_TEST_CASE(inliner_stop)
|
|||||||
AssemblyItem(Tag, 1),
|
AssemblyItem(Tag, 1),
|
||||||
Instruction::STOP
|
Instruction::STOP
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1840,7 +1841,7 @@ BOOST_AUTO_TEST_CASE(inliner_stop_jumpi)
|
|||||||
Instruction::STOP
|
Instruction::STOP
|
||||||
};
|
};
|
||||||
AssemblyItems expectation = items;
|
AssemblyItems expectation = items;
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1867,7 +1868,7 @@ BOOST_AUTO_TEST_CASE(inliner_revert)
|
|||||||
Instruction::REVERT
|
Instruction::REVERT
|
||||||
};
|
};
|
||||||
|
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1887,7 +1888,7 @@ BOOST_AUTO_TEST_CASE(inliner_revert_increased_datagas)
|
|||||||
};
|
};
|
||||||
|
|
||||||
AssemblyItems expectation = items;
|
AssemblyItems expectation = items;
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
@ -1908,7 +1909,7 @@ BOOST_AUTO_TEST_CASE(inliner_invalid)
|
|||||||
AssemblyItem(Tag, 1),
|
AssemblyItem(Tag, 1),
|
||||||
Instruction::INVALID
|
Instruction::INVALID
|
||||||
};
|
};
|
||||||
Inliner{items, {}, 200, false, {}}.optimise();
|
Inliner{items, {}, Assembly::OptimiserSettings{}.expectedExecutionsPerDeployment, false, {}}.optimise();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||||
items.begin(), items.end(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
|
@ -34,7 +34,6 @@ using namespace solidity::frontend;
|
|||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
|
||||||
GasTest::GasTest(string const& _filename):
|
GasTest::GasTest(string const& _filename):
|
||||||
@ -43,7 +42,7 @@ GasTest::GasTest(string const& _filename):
|
|||||||
m_source = m_reader.source();
|
m_source = m_reader.source();
|
||||||
m_optimise = m_reader.boolSetting("optimize", false);
|
m_optimise = m_reader.boolSetting("optimize", false);
|
||||||
m_optimiseYul = m_reader.boolSetting("optimize-yul", false);
|
m_optimiseYul = m_reader.boolSetting("optimize-yul", false);
|
||||||
m_optimiseRuns = m_reader.sizetSetting("optimize-runs", 200);
|
m_optimiseRuns = m_reader.sizetSetting("optimize-runs", OptimiserSettings{}.expectedExecutionsPerDeployment);
|
||||||
parseExpectations(m_reader.stream());
|
parseExpectations(m_reader.stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <test/TestCase.h>
|
#include <test/TestCase.h>
|
||||||
#include <liblangutil/Exceptions.h>
|
#include <liblangutil/Exceptions.h>
|
||||||
|
|
||||||
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -47,7 +49,7 @@ private:
|
|||||||
|
|
||||||
bool m_optimise = false;
|
bool m_optimise = false;
|
||||||
bool m_optimiseYul = false;
|
bool m_optimiseYul = false;
|
||||||
size_t m_optimiseRuns = 200;
|
size_t m_optimiseRuns = OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
std::map<std::string, std::map<std::string, std::string>> m_expectations;
|
std::map<std::string, std::map<std::string, std::string>> m_expectations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "libsolidity/formal/ModelCheckerSettings.h"
|
#include "libsolidity/formal/ModelCheckerSettings.h"
|
||||||
#include <test/tools/fuzzer_common.h>
|
#include <test/tools/fuzzer_common.h>
|
||||||
|
|
||||||
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
#include <libsolidity/interface/CompilerStack.h>
|
#include <libsolidity/interface/CompilerStack.h>
|
||||||
|
|
||||||
#include <libsolutil/JSON.h>
|
#include <libsolutil/JSON.h>
|
||||||
@ -34,9 +35,10 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
using namespace solidity::util;
|
||||||
|
|
||||||
static vector<EVMVersion> s_evmVersions = {
|
static vector<EVMVersion> s_evmVersions = {
|
||||||
EVMVersion::homestead(),
|
EVMVersion::homestead(),
|
||||||
@ -62,7 +64,7 @@ void FuzzerUtil::testCompilerJsonInterface(string const& _input, bool _optimize,
|
|||||||
config["settings"] = Json::objectValue;
|
config["settings"] = Json::objectValue;
|
||||||
config["settings"]["optimizer"] = Json::objectValue;
|
config["settings"]["optimizer"] = Json::objectValue;
|
||||||
config["settings"]["optimizer"]["enabled"] = _optimize;
|
config["settings"]["optimizer"]["enabled"] = _optimize;
|
||||||
config["settings"]["optimizer"]["runs"] = 200;
|
config["settings"]["optimizer"]["runs"] = static_cast<int>(OptimiserSettings{}.expectedExecutionsPerDeployment);
|
||||||
config["settings"]["evmVersion"] = "berlin";
|
config["settings"]["evmVersion"] = "berlin";
|
||||||
|
|
||||||
// Enable all SourceUnit-level outputs.
|
// Enable all SourceUnit-level outputs.
|
||||||
|
Loading…
Reference in New Issue
Block a user