mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Provide max iterations for stack compressor as parameter.
This commit is contained in:
parent
9ac117e5b9
commit
8514c0bc60
@ -132,13 +132,18 @@ void eliminateVariables(shared_ptr<Dialect> const& _dialect, ASTNode& _node, siz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StackCompressor::run(shared_ptr<Dialect> const& _dialect, Block& _ast, bool _optimizeStackAllocation)
|
bool StackCompressor::run(
|
||||||
|
shared_ptr<Dialect> const& _dialect,
|
||||||
|
Block& _ast,
|
||||||
|
bool _optimizeStackAllocation,
|
||||||
|
size_t _maxIterations
|
||||||
|
)
|
||||||
{
|
{
|
||||||
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 < 6; iterations++)
|
for (size_t iterations = 0; iterations < _maxIterations; iterations++)
|
||||||
{
|
{
|
||||||
map<YulString, int> stackSurplus = CompilabilityChecker::run(_dialect, _ast, _optimizeStackAllocation);
|
map<YulString, int> stackSurplus = CompilabilityChecker::run(_dialect, _ast, _optimizeStackAllocation);
|
||||||
if (stackSurplus.empty())
|
if (stackSurplus.empty())
|
||||||
|
@ -41,7 +41,12 @@ 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, bool _optimizeStackAllocation);
|
static bool run(
|
||||||
|
std::shared_ptr<Dialect> const& _dialect,
|
||||||
|
Block& _ast,
|
||||||
|
bool _optimizeStackAllocation,
|
||||||
|
size_t _maxIterations
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,12 @@ void OptimiserSuite::run(
|
|||||||
Rematerialiser::run(*_dialect, ast);
|
Rematerialiser::run(*_dialect, ast);
|
||||||
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
||||||
|
|
||||||
|
// This is a tuning parameter, but actually just prevents infinite loops.
|
||||||
|
size_t stackCompressorMaxIterations = 16;
|
||||||
FunctionGrouper{}(ast);
|
FunctionGrouper{}(ast);
|
||||||
solAssert(StackCompressor::run(_dialect, ast, _optimizeStackAllocation), "");
|
// We ignore the return value because we will get a much better error
|
||||||
|
// message once we perform code generation.
|
||||||
|
StackCompressor::run(_dialect, ast, _optimizeStackAllocation, stackCompressorMaxIterations);
|
||||||
BlockFlattener{}(ast);
|
BlockFlattener{}(ast);
|
||||||
|
|
||||||
VarNameCleaner{ast, *_dialect, reservedIdentifiers}(ast);
|
VarNameCleaner{ast, *_dialect, reservedIdentifiers}(ast);
|
||||||
|
@ -247,7 +247,8 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
|||||||
{
|
{
|
||||||
disambiguate();
|
disambiguate();
|
||||||
(FunctionGrouper{})(*m_ast);
|
(FunctionGrouper{})(*m_ast);
|
||||||
StackCompressor::run(m_dialect, *m_ast, true);
|
size_t maxIterations = 16;
|
||||||
|
StackCompressor::run(m_dialect, *m_ast, true, maxIterations);
|
||||||
(BlockFlattener{})(*m_ast);
|
(BlockFlattener{})(*m_ast);
|
||||||
}
|
}
|
||||||
else if (m_optimizerStep == "fullSuite")
|
else if (m_optimizerStep == "fullSuite")
|
||||||
|
@ -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, true);
|
StackCompressor::run(m_dialect, *m_ast, true, 16);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Unknown option." << endl;
|
cout << "Unknown option." << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user