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:
@@ -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(
|
||||
_ast.statements.size() > 0 && _ast.statements.at(0).type() == typeid(Block),
|
||||
"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);
|
||||
if (stackSurplus.empty())
|
||||
|
||||
@@ -41,7 +41,12 @@ class StackCompressor
|
||||
public:
|
||||
/// Try to remove local variables until the AST is compilable.
|
||||
/// @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);
|
||||
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
||||
|
||||
// This is a tuning parameter, but actually just prevents infinite loops.
|
||||
size_t stackCompressorMaxIterations = 16;
|
||||
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);
|
||||
|
||||
VarNameCleaner{ast, *_dialect, reservedIdentifiers}(ast);
|
||||
|
||||
Reference in New Issue
Block a user