mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not inline recursive functions.
This commit is contained in:
parent
f06582f97f
commit
1e3878121a
@ -14,6 +14,7 @@ Compiler Features:
|
||||
* Metadata: Add IPFS hashes of source files.
|
||||
* Assembler: Encode the compiler version in the deployed bytecode.
|
||||
* Yul Optimizer: Simplify single-run ``for`` loops to ``if`` statements.
|
||||
* Yul Optimizer: Do not inline recursive functions.
|
||||
* Optimizer: Add rules for multiplication and division by left-shifted one.
|
||||
|
||||
|
||||
|
@ -79,16 +79,6 @@ void FullInliner::run()
|
||||
}
|
||||
}
|
||||
|
||||
void FullInliner::updateCodeSize(FunctionDefinition const& _fun)
|
||||
{
|
||||
m_functionSizes[_fun.name] = CodeSize::codeSize(_fun.body);
|
||||
}
|
||||
|
||||
void FullInliner::handleBlock(YulString _currentFunctionName, Block& _block)
|
||||
{
|
||||
InlineModifier{*this, m_nameDispenser, _currentFunctionName}(_block);
|
||||
}
|
||||
|
||||
bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
|
||||
{
|
||||
// No recursive inlining
|
||||
@ -99,6 +89,9 @@ bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
|
||||
if (!calledFunction)
|
||||
return false;
|
||||
|
||||
if (recursive(*calledFunction))
|
||||
return false;
|
||||
|
||||
// Inline really, really tiny functions
|
||||
size_t size = m_functionSizes.at(calledFunction->name);
|
||||
if (size <= 1)
|
||||
@ -131,6 +124,21 @@ void FullInliner::tentativelyUpdateCodeSize(YulString _function, YulString _call
|
||||
m_functionSizes.at(_callSite) += m_functionSizes.at(_function);
|
||||
}
|
||||
|
||||
void FullInliner::updateCodeSize(FunctionDefinition const& _fun)
|
||||
{
|
||||
m_functionSizes[_fun.name] = CodeSize::codeSize(_fun.body);
|
||||
}
|
||||
|
||||
void FullInliner::handleBlock(YulString _currentFunctionName, Block& _block)
|
||||
{
|
||||
InlineModifier{*this, m_nameDispenser, _currentFunctionName}(_block);
|
||||
}
|
||||
|
||||
bool FullInliner::recursive(FunctionDefinition const& _fun) const
|
||||
{
|
||||
map<YulString, size_t> references = ReferencesCounter::countReferences(_fun);
|
||||
return references[_fun.name] > 0;
|
||||
}
|
||||
|
||||
void InlineModifier::operator()(Block& _block)
|
||||
{
|
||||
|
@ -93,6 +93,7 @@ public:
|
||||
private:
|
||||
void updateCodeSize(FunctionDefinition const& _fun);
|
||||
void handleBlock(YulString _currentFunctionName, Block& _block);
|
||||
bool recursive(FunctionDefinition const& _fun) const;
|
||||
|
||||
/// The AST to be modified. The root block itself will not be modified, because
|
||||
/// we store pointers to functions.
|
||||
|
@ -39,12 +39,7 @@
|
||||
// let t_20 := 0
|
||||
// t_20 := 2
|
||||
// mstore(7, t_20)
|
||||
// let x_1_21 := 10
|
||||
// let x_14_23 := 1
|
||||
// mstore(0, x_14_23)
|
||||
// mstore(7, h())
|
||||
// g(10)
|
||||
// mstore(1, x_14_23)
|
||||
// mstore(1, x)
|
||||
// }
|
||||
// function g(x_1)
|
||||
|
@ -8,10 +8,7 @@
|
||||
// step: fullInliner
|
||||
// ----
|
||||
// {
|
||||
// {
|
||||
// let a_4 := mload(0)
|
||||
// f(1)
|
||||
// }
|
||||
// { f(mload(0)) }
|
||||
// function f(a)
|
||||
// { f(1) }
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user