mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6963 from ethereum/runOptimizerOnAllDialects
[Yul] Run optimizer on all dialects.
This commit is contained in:
commit
53f26d9719
@ -422,9 +422,10 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
if (_optimiserSettings.runYulOptimiser && _localVariables.empty())
|
if (_optimiserSettings.runYulOptimiser && _localVariables.empty())
|
||||||
{
|
{
|
||||||
bool const isCreation = m_runtimeContext != nullptr;
|
bool const isCreation = m_runtimeContext != nullptr;
|
||||||
|
yul::GasMeter meter(dialect, isCreation, _optimiserSettings.expectedExecutionsPerDeployment);
|
||||||
yul::OptimiserSuite::run(
|
yul::OptimiserSuite::run(
|
||||||
dialect,
|
dialect,
|
||||||
yul::GasMeter(dialect, isCreation, _optimiserSettings.expectedExecutionsPerDeployment),
|
&meter,
|
||||||
*parserResult,
|
*parserResult,
|
||||||
analysisInfo,
|
analysisInfo,
|
||||||
_optimiserSettings.optimizeStackAllocation,
|
_optimiserSettings.optimizeStackAllocation,
|
||||||
|
@ -94,8 +94,6 @@ void AssemblyStack::optimize()
|
|||||||
if (!m_optimiserSettings.runYulOptimiser)
|
if (!m_optimiserSettings.runYulOptimiser)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_language != Language::StrictAssembly)
|
|
||||||
solUnimplemented("Optimizer for both loose assembly and Yul is not yet implemented");
|
|
||||||
solAssert(m_analysisSuccessful, "Analysis was not successful.");
|
solAssert(m_analysisSuccessful, "Analysis was not successful.");
|
||||||
|
|
||||||
m_analysisSuccessful = false;
|
m_analysisSuccessful = false;
|
||||||
@ -147,17 +145,18 @@ void AssemblyStack::optimize(Object& _object, bool _isCreation)
|
|||||||
for (auto& subNode: _object.subObjects)
|
for (auto& subNode: _object.subObjects)
|
||||||
if (auto subObject = dynamic_cast<Object*>(subNode.get()))
|
if (auto subObject = dynamic_cast<Object*>(subNode.get()))
|
||||||
optimize(*subObject, false);
|
optimize(*subObject, false);
|
||||||
if (EVMDialect const* dialect = dynamic_cast<EVMDialect const*>(&languageToDialect(m_language, m_evmVersion)))
|
|
||||||
{
|
Dialect const& dialect = languageToDialect(m_language, m_evmVersion);
|
||||||
GasMeter meter(*dialect, _isCreation, m_optimiserSettings.expectedExecutionsPerDeployment);
|
unique_ptr<GasMeter> meter;
|
||||||
OptimiserSuite::run(
|
if (EVMDialect const* evmDialect = dynamic_cast<EVMDialect const*>(&dialect))
|
||||||
*dialect,
|
meter = make_unique<GasMeter>(*evmDialect, _isCreation, m_optimiserSettings.expectedExecutionsPerDeployment);
|
||||||
meter,
|
OptimiserSuite::run(
|
||||||
*_object.code,
|
dialect,
|
||||||
*_object.analysisInfo,
|
meter.get(),
|
||||||
m_optimiserSettings.optimizeStackAllocation
|
*_object.code,
|
||||||
);
|
*_object.analysisInfo,
|
||||||
}
|
m_optimiserSettings.optimizeStackAllocation
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace yul
|
namespace yul
|
||||||
{
|
{
|
||||||
@ -69,6 +70,8 @@ struct Dialect: boost::noncopyable
|
|||||||
virtual BuiltinFunction const* discardFunction() const { return nullptr; }
|
virtual BuiltinFunction const* discardFunction() const { return nullptr; }
|
||||||
virtual BuiltinFunction const* equalityFunction() const { return nullptr; }
|
virtual BuiltinFunction const* equalityFunction() const { return nullptr; }
|
||||||
|
|
||||||
|
virtual std::set<YulString> fixedFunctionNames() const { return {}; }
|
||||||
|
|
||||||
Dialect(AsmFlavour _flavour): flavour(_flavour) {}
|
Dialect(AsmFlavour _flavour): flavour(_flavour) {}
|
||||||
virtual ~Dialect() = default;
|
virtual ~Dialect() = default;
|
||||||
|
|
||||||
|
@ -115,9 +115,9 @@ wasm::Expression EWasmCodeTransform::operator()(Label const&)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const&)
|
wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const& _f)
|
||||||
{
|
{
|
||||||
yulAssert(false, "");
|
yulAssert(false, "EVM instruction in ewasm code: " + eth::instructionInfo(_f.instruction).name);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ struct WasmDialect: public Dialect
|
|||||||
BuiltinFunction const* discardFunction() const override { return builtin("drop"_yulstring); }
|
BuiltinFunction const* discardFunction() const override { return builtin("drop"_yulstring); }
|
||||||
BuiltinFunction const* equalityFunction() const override { return builtin("i64.eq"_yulstring); }
|
BuiltinFunction const* equalityFunction() const override { return builtin("i64.eq"_yulstring); }
|
||||||
|
|
||||||
|
std::set<YulString> fixedFunctionNames() const override { return {"main"_yulstring}; }
|
||||||
|
|
||||||
static WasmDialect const& instance();
|
static WasmDialect const& instance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -60,7 +60,7 @@ using namespace yul;
|
|||||||
|
|
||||||
void OptimiserSuite::run(
|
void OptimiserSuite::run(
|
||||||
Dialect const& _dialect,
|
Dialect const& _dialect,
|
||||||
GasMeter const& _meter,
|
GasMeter const* _meter,
|
||||||
Block& _ast,
|
Block& _ast,
|
||||||
AsmAnalysisInfo const& _analysisInfo,
|
AsmAnalysisInfo const& _analysisInfo,
|
||||||
bool _optimizeStackAllocation,
|
bool _optimizeStackAllocation,
|
||||||
@ -68,6 +68,7 @@ void OptimiserSuite::run(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
set<YulString> reservedIdentifiers = _externallyUsedIdentifiers;
|
set<YulString> reservedIdentifiers = _externallyUsedIdentifiers;
|
||||||
|
reservedIdentifiers += _dialect.fixedFunctionNames();
|
||||||
|
|
||||||
Block ast = boost::get<Block>(Disambiguator(_dialect, _analysisInfo, reservedIdentifiers)(_ast));
|
Block ast = boost::get<Block>(Disambiguator(_dialect, _analysisInfo, reservedIdentifiers)(_ast));
|
||||||
|
|
||||||
@ -210,7 +211,10 @@ void OptimiserSuite::run(
|
|||||||
FunctionGrouper{}(ast);
|
FunctionGrouper{}(ast);
|
||||||
|
|
||||||
if (EVMDialect const* dialect = dynamic_cast<EVMDialect const*>(&_dialect))
|
if (EVMDialect const* dialect = dynamic_cast<EVMDialect const*>(&_dialect))
|
||||||
ConstantOptimiser{*dialect, _meter}(ast);
|
{
|
||||||
|
yulAssert(_meter, "");
|
||||||
|
ConstantOptimiser{*dialect, *_meter}(ast);
|
||||||
|
}
|
||||||
VarNameCleaner{ast, _dialect, reservedIdentifiers}(ast);
|
VarNameCleaner{ast, _dialect, reservedIdentifiers}(ast);
|
||||||
yul::AsmAnalyzer::analyzeStrictAssertCorrect(_dialect, ast);
|
yul::AsmAnalyzer::analyzeStrictAssertCorrect(_dialect, ast);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class OptimiserSuite
|
|||||||
public:
|
public:
|
||||||
static void run(
|
static void run(
|
||||||
Dialect const& _dialect,
|
Dialect const& _dialect,
|
||||||
GasMeter const& _meter,
|
GasMeter const* _meter,
|
||||||
Block& _ast,
|
Block& _ast,
|
||||||
AsmAnalysisInfo const& _analysisInfo,
|
AsmAnalysisInfo const& _analysisInfo,
|
||||||
bool _optimizeStackAllocation,
|
bool _optimizeStackAllocation,
|
||||||
|
@ -292,7 +292,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
|||||||
else if (m_optimizerStep == "fullSuite")
|
else if (m_optimizerStep == "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_ast, *m_analysisInfo, true);
|
OptimiserSuite::run(*m_dialect, &meter, *m_ast, *m_analysisInfo, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user