mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Inline tiny functions first.
This commit is contained in:
@@ -42,7 +42,9 @@ using namespace solidity::yul;
|
||||
|
||||
void FullInliner::run(OptimiserStepContext& _context, Block& _ast)
|
||||
{
|
||||
FullInliner{_ast, _context.dispenser, _context.dialect}.run();
|
||||
FullInliner inliner{_ast, _context.dispenser, _context.dialect};
|
||||
inliner.run(Pass::InlineTiny);
|
||||
inliner.run(Pass::InlineRest);
|
||||
}
|
||||
|
||||
FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect):
|
||||
@@ -73,8 +75,10 @@ FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const&
|
||||
}
|
||||
}
|
||||
|
||||
void FullInliner::run()
|
||||
void FullInliner::run(Pass _pass)
|
||||
{
|
||||
m_pass = _pass;
|
||||
|
||||
// Note that the order of inlining can result in very different code.
|
||||
// Since AST IDs and thus function names depend on whether or not a contract
|
||||
// is compiled together with other source files, a change in AST IDs
|
||||
@@ -171,6 +175,10 @@ bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
|
||||
if (size <= 1)
|
||||
return true;
|
||||
|
||||
// In the first pass, only inline tiny functions.
|
||||
if (m_pass == Pass::InlineTiny)
|
||||
return false;
|
||||
|
||||
// Do not inline into already big functions.
|
||||
if (m_functionSizes.at(_callSite) > 45)
|
||||
return false;
|
||||
|
||||
@@ -91,8 +91,10 @@ public:
|
||||
void tentativelyUpdateCodeSize(YulString _function, YulString _callSite);
|
||||
|
||||
private:
|
||||
enum Pass { InlineTiny, InlineRest };
|
||||
|
||||
FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect);
|
||||
void run();
|
||||
void run(Pass _pass);
|
||||
|
||||
/// @returns a map containing the maximum depths of a call chain starting at each
|
||||
/// function. For recursive functions, the value is one larger than for all others.
|
||||
@@ -102,6 +104,7 @@ private:
|
||||
void handleBlock(YulString _currentFunctionName, Block& _block);
|
||||
bool recursive(FunctionDefinition const& _fun) const;
|
||||
|
||||
Pass m_pass;
|
||||
/// The AST to be modified. The root block itself will not be modified, because
|
||||
/// we store pointers to functions.
|
||||
Block& m_ast;
|
||||
|
||||
Reference in New Issue
Block a user