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, | ||||
| 		_optimiserSettings.optimizeStackAllocation, | ||||
| 		_optimiserSettings.yulOptimiserSteps, | ||||
| 		isCreation? nullopt : make_optional(_optimiserSettings.expectedExecutionsPerDeployment), | ||||
| 		_externalIdentifiers | ||||
| 	); | ||||
| 
 | ||||
|  | ||||
| @ -44,6 +44,7 @@ | ||||
| 
 | ||||
| #include <libevmasm/Assembly.h> | ||||
| #include <liblangutil/Scanner.h> | ||||
| #include <optional> | ||||
| 
 | ||||
| using namespace std; | ||||
| using namespace solidity; | ||||
| @ -185,7 +186,9 @@ void AssemblyStack::optimize(Object& _object, bool _isCreation) | ||||
| 		meter.get(), | ||||
| 		_object, | ||||
| 		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/SourceReferenceFormatter.h> | ||||
| 
 | ||||
| #include <libsolidity/interface/OptimiserSettings.h> | ||||
| 
 | ||||
| // The following headers are generated from the
 | ||||
| // 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)); | ||||
| 	set<YulString> 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); | ||||
| 	FunctionGrouper::run(context, ast); | ||||
|  | ||||
| @ -37,6 +37,8 @@ struct OptimiserStepContext | ||||
| 	Dialect const& dialect; | ||||
| 	NameDispenser& dispenser; | ||||
| 	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, | ||||
| 	bool _optimizeStackAllocation, | ||||
| 	string const& _optimisationSequence, | ||||
| 	optional<size_t> _expectedExecutionsPerDeployment, | ||||
| 	set<YulString> const& _externallyUsedIdentifiers | ||||
| ) | ||||
| { | ||||
| @ -101,7 +102,7 @@ void OptimiserSuite::run( | ||||
| 	)(*_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
 | ||||
| 	// ForLoopInitRewriter. Run them first to be able to run arbitrary sequences safely.
 | ||||
|  | ||||
| @ -58,12 +58,14 @@ public: | ||||
| 		PrintStep, | ||||
| 		PrintChanges | ||||
| 	}; | ||||
| 	/// The value nullopt for `_expectedExecutionsPerDeployment` represents creation code.
 | ||||
| 	static void run( | ||||
| 		Dialect const& _dialect, | ||||
| 		GasMeter const* _meter, | ||||
| 		Object& _object, | ||||
| 		bool _optimizeStackAllocation, | ||||
| 		std::string const& _optimisationSequence, | ||||
| 		std::optional<size_t> _expectedExecutionsPerDeployment, | ||||
| 		std::set<YulString> const& _externallyUsedIdentifiers = {} | ||||
| 	); | ||||
| 
 | ||||
| @ -88,10 +90,11 @@ private: | ||||
| 		Dialect const& _dialect, | ||||
| 		std::set<YulString> const& _externallyUsedIdentifiers, | ||||
| 		Debug _debug, | ||||
| 		Block& _ast | ||||
| 		Block& _ast, | ||||
| 		std::optional<size_t> expectedExecutionsPerDeployment | ||||
| 	): | ||||
| 		m_dispenser{_dialect, _ast, _externallyUsedIdentifiers}, | ||||
| 		m_context{_dialect, m_dispenser, _externallyUsedIdentifiers}, | ||||
| 		m_context{_dialect, m_dispenser, _externallyUsedIdentifiers, expectedExecutionsPerDeployment}, | ||||
| 		m_debug(_debug) | ||||
| 	{} | ||||
| 
 | ||||
|  | ||||
| @ -317,7 +317,14 @@ YulOptimizerTestCommon::YulOptimizerTestCommon( | ||||
| 		}}, | ||||
| 		{"fullSuite", [&]() { | ||||
| 			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", [&]() { | ||||
| 			disambiguate(); | ||||
| @ -434,6 +441,7 @@ void YulOptimizerTestCommon::updateContext() | ||||
| 	m_context = make_unique<OptimiserStepContext>(OptimiserStepContext{ | ||||
| 		*m_dialect, | ||||
| 		*m_nameDispenser, | ||||
| 		m_reservedIdentifiers | ||||
| 		m_reservedIdentifiers, | ||||
| 		frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| @ -43,6 +43,8 @@ | ||||
| 
 | ||||
| #include <libsolutil/JSON.h> | ||||
| 
 | ||||
| #include <libsolidity/interface/OptimiserSettings.h> | ||||
| 
 | ||||
| #include <boost/algorithm/string/predicate.hpp> | ||||
| #include <boost/algorithm/string/join.hpp> | ||||
| #include <boost/program_options.hpp> | ||||
| @ -191,7 +193,12 @@ public: | ||||
| 			char option = static_cast<char>(readStandardInputChar()); | ||||
| 			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); | ||||
| 			if (abbreviationAndName != abbreviationMap.end()) | ||||
|  | ||||
| @ -41,6 +41,8 @@ | ||||
| 
 | ||||
| #include <libsolutil/JSON.h> | ||||
| 
 | ||||
| #include <libsolidity/interface/OptimiserSettings.h> | ||||
| 
 | ||||
| #include <cassert> | ||||
| #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
 | ||||
| 	// think it would be useful in this tool. Other tools (like yulopti) have it empty too.
 | ||||
| 	set<YulString> const externallyUsedIdentifiers = {}; | ||||
| 	OptimiserStepContext context{_dialect, _nameDispenser, externallyUsedIdentifiers}; | ||||
| 	OptimiserStepContext context{ | ||||
| 		_dialect, | ||||
| 		_nameDispenser, | ||||
| 		externallyUsedIdentifiers, | ||||
| 		frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment | ||||
| 	}; | ||||
| 
 | ||||
| 	for (string const& step: _optimisationSteps) | ||||
| 		OptimiserSuite::allSteps().at(step)->run(context, *_ast); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user