mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Optimizer context has parameter expectedExecutionsPerDeployment
This commit is contained in:
		
							parent
							
								
									074f22f22c
								
							
						
					
					
						commit
						1f5b874eaf
					
				| @ -548,6 +548,7 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _ | |||||||
| 		_object, | 		_object, | ||||||
| 		_optimiserSettings.optimizeStackAllocation, | 		_optimiserSettings.optimizeStackAllocation, | ||||||
| 		_optimiserSettings.yulOptimiserSteps, | 		_optimiserSettings.yulOptimiserSteps, | ||||||
|  | 		isCreation? nullopt : make_optional(_optimiserSettings.expectedExecutionsPerDeployment), | ||||||
| 		_externalIdentifiers | 		_externalIdentifiers | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -44,6 +44,7 @@ | |||||||
| 
 | 
 | ||||||
| #include <libevmasm/Assembly.h> | #include <libevmasm/Assembly.h> | ||||||
| #include <liblangutil/Scanner.h> | #include <liblangutil/Scanner.h> | ||||||
|  | #include <optional> | ||||||
| 
 | 
 | ||||||
| using namespace std; | using namespace std; | ||||||
| using namespace solidity; | using namespace solidity; | ||||||
| @ -185,7 +186,9 @@ void AssemblyStack::optimize(Object& _object, bool _isCreation) | |||||||
| 		meter.get(), | 		meter.get(), | ||||||
| 		_object, | 		_object, | ||||||
| 		m_optimiserSettings.optimizeStackAllocation, | 		m_optimiserSettings.optimizeStackAllocation, | ||||||
| 		m_optimiserSettings.yulOptimiserSteps | 		m_optimiserSettings.yulOptimiserSteps, | ||||||
|  | 		_isCreation ? nullopt : make_optional(m_optimiserSettings.expectedExecutionsPerDeployment), | ||||||
|  | 		{} | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -42,6 +42,8 @@ | |||||||
| #include <liblangutil/Scanner.h> | #include <liblangutil/Scanner.h> | ||||||
| #include <liblangutil/SourceReferenceFormatter.h> | #include <liblangutil/SourceReferenceFormatter.h> | ||||||
| 
 | 
 | ||||||
|  | #include <libsolidity/interface/OptimiserSettings.h> | ||||||
|  | 
 | ||||||
| // The following headers are generated from the
 | // The following headers are generated from the
 | ||||||
| // yul files placed in libyul/backends/wasm/polyfill.
 | // yul files placed in libyul/backends/wasm/polyfill.
 | ||||||
| 
 | 
 | ||||||
| @ -68,7 +70,13 @@ Object EVMToEwasmTranslator::run(Object const& _object) | |||||||
| 	Block ast = std::get<Block>(Disambiguator(m_dialect, *_object.analysisInfo)(*_object.code)); | 	Block ast = std::get<Block>(Disambiguator(m_dialect, *_object.analysisInfo)(*_object.code)); | ||||||
| 	set<YulString> reservedIdentifiers; | 	set<YulString> reservedIdentifiers; | ||||||
| 	NameDispenser nameDispenser{m_dialect, ast, reservedIdentifiers}; | 	NameDispenser nameDispenser{m_dialect, ast, reservedIdentifiers}; | ||||||
| 	OptimiserStepContext context{m_dialect, nameDispenser, reservedIdentifiers}; | 	// expectedExecutionsPerDeployment is currently unused.
 | ||||||
|  | 	OptimiserStepContext context{ | ||||||
|  | 		m_dialect, | ||||||
|  | 		nameDispenser, | ||||||
|  | 		reservedIdentifiers, | ||||||
|  | 		frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||||
|  | 	}; | ||||||
| 
 | 
 | ||||||
| 	FunctionHoister::run(context, ast); | 	FunctionHoister::run(context, ast); | ||||||
| 	FunctionGrouper::run(context, ast); | 	FunctionGrouper::run(context, ast); | ||||||
|  | |||||||
| @ -37,6 +37,8 @@ struct OptimiserStepContext | |||||||
| 	Dialect const& dialect; | 	Dialect const& dialect; | ||||||
| 	NameDispenser& dispenser; | 	NameDispenser& dispenser; | ||||||
| 	std::set<YulString> const& reservedIdentifiers; | 	std::set<YulString> const& reservedIdentifiers; | ||||||
|  | 	/// The value nullopt represents creation code
 | ||||||
|  | 	std::optional<size_t> expectedExecutionsPerDeployment; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -88,6 +88,7 @@ void OptimiserSuite::run( | |||||||
| 	Object& _object, | 	Object& _object, | ||||||
| 	bool _optimizeStackAllocation, | 	bool _optimizeStackAllocation, | ||||||
| 	string const& _optimisationSequence, | 	string const& _optimisationSequence, | ||||||
|  | 	optional<size_t> _expectedExecutionsPerDeployment, | ||||||
| 	set<YulString> const& _externallyUsedIdentifiers | 	set<YulString> const& _externallyUsedIdentifiers | ||||||
| ) | ) | ||||||
| { | { | ||||||
| @ -101,7 +102,7 @@ void OptimiserSuite::run( | |||||||
| 	)(*_object.code)); | 	)(*_object.code)); | ||||||
| 	Block& ast = *_object.code; | 	Block& ast = *_object.code; | ||||||
| 
 | 
 | ||||||
| 	OptimiserSuite suite(_dialect, reservedIdentifiers, Debug::None, ast); | 	OptimiserSuite suite(_dialect, reservedIdentifiers, Debug::None, ast, _expectedExecutionsPerDeployment); | ||||||
| 
 | 
 | ||||||
| 	// Some steps depend on properties ensured by FunctionHoister, BlockFlattener, FunctionGrouper and
 | 	// Some steps depend on properties ensured by FunctionHoister, BlockFlattener, FunctionGrouper and
 | ||||||
| 	// ForLoopInitRewriter. Run them first to be able to run arbitrary sequences safely.
 | 	// ForLoopInitRewriter. Run them first to be able to run arbitrary sequences safely.
 | ||||||
|  | |||||||
| @ -58,12 +58,14 @@ public: | |||||||
| 		PrintStep, | 		PrintStep, | ||||||
| 		PrintChanges | 		PrintChanges | ||||||
| 	}; | 	}; | ||||||
|  | 	/// The value nullopt for `_expectedExecutionsPerDeployment` represents creation code.
 | ||||||
| 	static void run( | 	static void run( | ||||||
| 		Dialect const& _dialect, | 		Dialect const& _dialect, | ||||||
| 		GasMeter const* _meter, | 		GasMeter const* _meter, | ||||||
| 		Object& _object, | 		Object& _object, | ||||||
| 		bool _optimizeStackAllocation, | 		bool _optimizeStackAllocation, | ||||||
| 		std::string const& _optimisationSequence, | 		std::string const& _optimisationSequence, | ||||||
|  | 		std::optional<size_t> _expectedExecutionsPerDeployment, | ||||||
| 		std::set<YulString> const& _externallyUsedIdentifiers = {} | 		std::set<YulString> const& _externallyUsedIdentifiers = {} | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| @ -88,10 +90,11 @@ private: | |||||||
| 		Dialect const& _dialect, | 		Dialect const& _dialect, | ||||||
| 		std::set<YulString> const& _externallyUsedIdentifiers, | 		std::set<YulString> const& _externallyUsedIdentifiers, | ||||||
| 		Debug _debug, | 		Debug _debug, | ||||||
| 		Block& _ast | 		Block& _ast, | ||||||
|  | 		std::optional<size_t> expectedExecutionsPerDeployment | ||||||
| 	): | 	): | ||||||
| 		m_dispenser{_dialect, _ast, _externallyUsedIdentifiers}, | 		m_dispenser{_dialect, _ast, _externallyUsedIdentifiers}, | ||||||
| 		m_context{_dialect, m_dispenser, _externallyUsedIdentifiers}, | 		m_context{_dialect, m_dispenser, _externallyUsedIdentifiers, expectedExecutionsPerDeployment}, | ||||||
| 		m_debug(_debug) | 		m_debug(_debug) | ||||||
| 	{} | 	{} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -317,7 +317,14 @@ YulOptimizerTestCommon::YulOptimizerTestCommon( | |||||||
| 		}}, | 		}}, | ||||||
| 		{"fullSuite", [&]() { | 		{"fullSuite", [&]() { | ||||||
| 			GasMeter meter(dynamic_cast<EVMDialect const&>(*m_dialect), false, 200); | 			GasMeter meter(dynamic_cast<EVMDialect const&>(*m_dialect), false, 200); | ||||||
| 			OptimiserSuite::run(*m_dialect, &meter, *m_object, true, solidity::frontend::OptimiserSettings::DefaultYulOptimiserSteps); | 			OptimiserSuite::run( | ||||||
|  | 				*m_dialect, | ||||||
|  | 				&meter, | ||||||
|  | 				*m_object, | ||||||
|  | 				true, | ||||||
|  | 				frontend::OptimiserSettings::DefaultYulOptimiserSteps, | ||||||
|  | 				frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||||
|  | 			); | ||||||
| 		}}, | 		}}, | ||||||
| 		{"stackLimitEvader", [&]() { | 		{"stackLimitEvader", [&]() { | ||||||
| 			disambiguate(); | 			disambiguate(); | ||||||
| @ -434,6 +441,7 @@ void YulOptimizerTestCommon::updateContext() | |||||||
| 	m_context = make_unique<OptimiserStepContext>(OptimiserStepContext{ | 	m_context = make_unique<OptimiserStepContext>(OptimiserStepContext{ | ||||||
| 		*m_dialect, | 		*m_dialect, | ||||||
| 		*m_nameDispenser, | 		*m_nameDispenser, | ||||||
| 		m_reservedIdentifiers | 		m_reservedIdentifiers, | ||||||
|  | 		frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||||
| 	}); | 	}); | ||||||
| } | } | ||||||
|  | |||||||
| @ -43,6 +43,8 @@ | |||||||
| 
 | 
 | ||||||
| #include <libsolutil/JSON.h> | #include <libsolutil/JSON.h> | ||||||
| 
 | 
 | ||||||
|  | #include <libsolidity/interface/OptimiserSettings.h> | ||||||
|  | 
 | ||||||
| #include <boost/algorithm/string/predicate.hpp> | #include <boost/algorithm/string/predicate.hpp> | ||||||
| #include <boost/algorithm/string/join.hpp> | #include <boost/algorithm/string/join.hpp> | ||||||
| #include <boost/program_options.hpp> | #include <boost/program_options.hpp> | ||||||
| @ -191,7 +193,12 @@ public: | |||||||
| 			char option = static_cast<char>(readStandardInputChar()); | 			char option = static_cast<char>(readStandardInputChar()); | ||||||
| 			cout << ' ' << option << endl; | 			cout << ' ' << option << endl; | ||||||
| 
 | 
 | ||||||
| 			OptimiserStepContext context{m_dialect, *m_nameDispenser, reservedIdentifiers}; | 			OptimiserStepContext context{ | ||||||
|  | 				m_dialect, | ||||||
|  | 				*m_nameDispenser, | ||||||
|  | 				reservedIdentifiers, | ||||||
|  | 				solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||||
|  | 			}; | ||||||
| 
 | 
 | ||||||
| 			auto abbreviationAndName = abbreviationMap.find(option); | 			auto abbreviationAndName = abbreviationMap.find(option); | ||||||
| 			if (abbreviationAndName != abbreviationMap.end()) | 			if (abbreviationAndName != abbreviationMap.end()) | ||||||
|  | |||||||
| @ -41,6 +41,8 @@ | |||||||
| 
 | 
 | ||||||
| #include <libsolutil/JSON.h> | #include <libsolutil/JSON.h> | ||||||
| 
 | 
 | ||||||
|  | #include <libsolidity/interface/OptimiserSettings.h> | ||||||
|  | 
 | ||||||
| #include <cassert> | #include <cassert> | ||||||
| #include <memory> | #include <memory> | ||||||
| 
 | 
 | ||||||
| @ -201,7 +203,12 @@ unique_ptr<Block> Program::applyOptimisationSteps( | |||||||
| 	// An empty set of reserved identifiers. It could be a constructor parameter but I don't
 | 	// An empty set of reserved identifiers. It could be a constructor parameter but I don't
 | ||||||
| 	// think it would be useful in this tool. Other tools (like yulopti) have it empty too.
 | 	// think it would be useful in this tool. Other tools (like yulopti) have it empty too.
 | ||||||
| 	set<YulString> const externallyUsedIdentifiers = {}; | 	set<YulString> const externallyUsedIdentifiers = {}; | ||||||
| 	OptimiserStepContext context{_dialect, _nameDispenser, externallyUsedIdentifiers}; | 	OptimiserStepContext context{ | ||||||
|  | 		_dialect, | ||||||
|  | 		_nameDispenser, | ||||||
|  | 		externallyUsedIdentifiers, | ||||||
|  | 		frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||||
|  | 	}; | ||||||
| 
 | 
 | ||||||
| 	for (string const& step: _optimisationSteps) | 	for (string const& step: _optimisationSteps) | ||||||
| 		OptimiserSuite::allSteps().at(step)->run(context, *_ast); | 		OptimiserSuite::allSteps().at(step)->run(context, *_ast); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user