mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Pass "optimize stack allocation" flag down to the stack compressor.
This commit is contained in:
parent
556d11dae0
commit
38cbf8d230
@ -428,6 +428,7 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
yul::EVMDialect::strictAssemblyForEVM(m_evmVersion),
|
yul::EVMDialect::strictAssemblyForEVM(m_evmVersion),
|
||||||
*parserResult,
|
*parserResult,
|
||||||
analysisInfo,
|
analysisInfo,
|
||||||
|
_optimiserSettings.optimizeStackAllocation,
|
||||||
externallyUsedIdentifiers
|
externallyUsedIdentifiers
|
||||||
);
|
);
|
||||||
analysisInfo = yul::AsmAnalysisInfo{};
|
analysisInfo = yul::AsmAnalysisInfo{};
|
||||||
|
@ -135,7 +135,10 @@ void AssemblyStack::optimize(Object& _object)
|
|||||||
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);
|
optimize(*subObject);
|
||||||
OptimiserSuite::run(languageToDialect(m_language, m_evmVersion), *_object.code, *_object.analysisInfo);
|
// TODO: Store this as setting - it should be the same as the flag passed to
|
||||||
|
// ::assemble(...)
|
||||||
|
bool optimizeStackAllocation = false;
|
||||||
|
OptimiserSuite::run(languageToDialect(m_language, m_evmVersion), *_object.code, *_object.analysisInfo, optimizeStackAllocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineAssemblyObject AssemblyStack::assemble(Machine _machine, bool _optimize) const
|
MachineAssemblyObject AssemblyStack::assemble(Machine _machine, bool _optimize) const
|
||||||
|
@ -33,7 +33,11 @@ using namespace yul;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
std::map<YulString, int> CompilabilityChecker::run(std::shared_ptr<Dialect> _dialect, Block const& _ast)
|
map<YulString, int> CompilabilityChecker::run(
|
||||||
|
shared_ptr<Dialect> _dialect,
|
||||||
|
Block const& _ast,
|
||||||
|
bool _optimizeStackAllocation
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_dialect->flavour == AsmFlavour::Yul)
|
if (_dialect->flavour == AsmFlavour::Yul)
|
||||||
return {};
|
return {};
|
||||||
@ -43,12 +47,11 @@ std::map<YulString, int> CompilabilityChecker::run(std::shared_ptr<Dialect> _dia
|
|||||||
solAssert(dynamic_cast<EVMDialect const*>(_dialect.get()), "");
|
solAssert(dynamic_cast<EVMDialect const*>(_dialect.get()), "");
|
||||||
shared_ptr<NoOutputEVMDialect> noOutputDialect = make_shared<NoOutputEVMDialect>(dynamic_pointer_cast<EVMDialect>(_dialect));
|
shared_ptr<NoOutputEVMDialect> noOutputDialect = make_shared<NoOutputEVMDialect>(dynamic_pointer_cast<EVMDialect>(_dialect));
|
||||||
|
|
||||||
bool optimize = true;
|
|
||||||
yul::AsmAnalysisInfo analysisInfo =
|
yul::AsmAnalysisInfo analysisInfo =
|
||||||
yul::AsmAnalyzer::analyzeStrictAssertCorrect(noOutputDialect, _ast);
|
yul::AsmAnalyzer::analyzeStrictAssertCorrect(noOutputDialect, _ast);
|
||||||
|
|
||||||
NoOutputAssembly assembly;
|
NoOutputAssembly assembly;
|
||||||
CodeTransform transform(assembly, analysisInfo, _ast, *noOutputDialect, optimize);
|
CodeTransform transform(assembly, analysisInfo, _ast, *noOutputDialect, _optimizeStackAllocation);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transform(_ast);
|
transform(_ast);
|
||||||
|
@ -39,7 +39,11 @@ namespace yul
|
|||||||
class CompilabilityChecker
|
class CompilabilityChecker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::map<YulString, int> run(std::shared_ptr<Dialect> _dialect, Block const& _ast);
|
static std::map<YulString, int> run(
|
||||||
|
std::shared_ptr<Dialect> _dialect,
|
||||||
|
Block const& _ast,
|
||||||
|
bool _optimizeStackAllocation
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,15 +74,15 @@ void eliminateVariables(shared_ptr<Dialect> const& _dialect, ASTNode& _node, siz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StackCompressor::run(shared_ptr<Dialect> const& _dialect, Block& _ast)
|
bool StackCompressor::run(shared_ptr<Dialect> const& _dialect, Block& _ast, bool _optimizeStackAllocation)
|
||||||
{
|
{
|
||||||
yulAssert(
|
yulAssert(
|
||||||
_ast.statements.size() > 0 && _ast.statements.at(0).type() == typeid(Block),
|
_ast.statements.size() > 0 && _ast.statements.at(0).type() == typeid(Block),
|
||||||
"Need to run the function grouper before the stack compressor."
|
"Need to run the function grouper before the stack compressor."
|
||||||
);
|
);
|
||||||
for (size_t iterations = 0; iterations < 4; iterations++)
|
for (size_t iterations = 0; iterations < 6; iterations++)
|
||||||
{
|
{
|
||||||
map<YulString, int> stackSurplus = CompilabilityChecker::run(_dialect, _ast);
|
map<YulString, int> stackSurplus = CompilabilityChecker::run(_dialect, _ast, _optimizeStackAllocation);
|
||||||
if (stackSurplus.empty())
|
if (stackSurplus.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class StackCompressor
|
|||||||
public:
|
public:
|
||||||
/// Try to remove local variables until the AST is compilable.
|
/// Try to remove local variables until the AST is compilable.
|
||||||
/// @returns true if it was successful.
|
/// @returns true if it was successful.
|
||||||
static bool run(std::shared_ptr<Dialect> const& _dialect, Block& _ast);
|
static bool run(std::shared_ptr<Dialect> const& _dialect, Block& _ast, bool _optimizeStackAllocation);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ void OptimiserSuite::run(
|
|||||||
shared_ptr<Dialect> const& _dialect,
|
shared_ptr<Dialect> const& _dialect,
|
||||||
Block& _ast,
|
Block& _ast,
|
||||||
AsmAnalysisInfo const& _analysisInfo,
|
AsmAnalysisInfo const& _analysisInfo,
|
||||||
|
bool _optimizeStackAllocation,
|
||||||
set<YulString> const& _externallyUsedIdentifiers
|
set<YulString> const& _externallyUsedIdentifiers
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -185,7 +186,7 @@ void OptimiserSuite::run(
|
|||||||
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
||||||
|
|
||||||
FunctionGrouper{}(ast);
|
FunctionGrouper{}(ast);
|
||||||
StackCompressor::run(_dialect, ast);
|
solAssert(StackCompressor::run(_dialect, ast, _optimizeStackAllocation), "");
|
||||||
BlockFlattener{}(ast);
|
BlockFlattener{}(ast);
|
||||||
|
|
||||||
VarNameCleaner{ast, *_dialect, reservedIdentifiers}(ast);
|
VarNameCleaner{ast, *_dialect, reservedIdentifiers}(ast);
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
std::shared_ptr<Dialect> const& _dialect,
|
std::shared_ptr<Dialect> const& _dialect,
|
||||||
Block& _ast,
|
Block& _ast,
|
||||||
AsmAnalysisInfo const& _analysisInfo,
|
AsmAnalysisInfo const& _analysisInfo,
|
||||||
|
bool _optimizeStackAllocation,
|
||||||
std::set<YulString> const& _externallyUsedIdentifiers = {}
|
std::set<YulString> const& _externallyUsedIdentifiers = {}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -39,7 +39,7 @@ string check(string const& _input)
|
|||||||
{
|
{
|
||||||
shared_ptr<Block> ast = yul::test::parse(_input, false).first;
|
shared_ptr<Block> ast = yul::test::parse(_input, false).first;
|
||||||
BOOST_REQUIRE(ast);
|
BOOST_REQUIRE(ast);
|
||||||
map<YulString, int> functions = CompilabilityChecker::run(EVMDialect::strictAssemblyForEVM(dev::test::Options::get().evmVersion()), *ast);
|
map<YulString, int> functions = CompilabilityChecker::run(EVMDialect::strictAssemblyForEVM(dev::test::Options::get().evmVersion()), *ast, true);
|
||||||
string out;
|
string out;
|
||||||
for (auto const& function: functions)
|
for (auto const& function: functions)
|
||||||
out += function.first.str() + ": " + to_string(function.second) + " ";
|
out += function.first.str() + ": " + to_string(function.second) + " ";
|
||||||
|
@ -247,11 +247,11 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
|||||||
{
|
{
|
||||||
disambiguate();
|
disambiguate();
|
||||||
(FunctionGrouper{})(*m_ast);
|
(FunctionGrouper{})(*m_ast);
|
||||||
StackCompressor::run(m_dialect, *m_ast);
|
StackCompressor::run(m_dialect, *m_ast, true);
|
||||||
(BlockFlattener{})(*m_ast);
|
(BlockFlattener{})(*m_ast);
|
||||||
}
|
}
|
||||||
else if (m_optimizerStep == "fullSuite")
|
else if (m_optimizerStep == "fullSuite")
|
||||||
OptimiserSuite::run(m_dialect, *m_ast, *m_analysisInfo);
|
OptimiserSuite::run(m_dialect, *m_ast, *m_analysisInfo, true);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl;
|
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl;
|
||||||
|
@ -198,7 +198,7 @@ public:
|
|||||||
SSAReverser::run(*m_ast);
|
SSAReverser::run(*m_ast);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
StackCompressor::run(m_dialect, *m_ast);
|
StackCompressor::run(m_dialect, *m_ast, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Unknown option." << endl;
|
cout << "Unknown option." << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user