Page MenuHomePhabricator

[InlineCost] Check if caller formulates indirect recursion.
Needs ReviewPublic

Authored by twoh on Apr 29 2019, 2:35 PM.



If a function uses stack heavily, the function shouldn't be inlined if the
caller can be recursively invoked, because it may lead stack size explosion.
Current inliner implemention only checks for self-recursion, but indirectely
recursive function has the same risk, and that actually happens with MySQL5.6+LTO.

To overcome this limitation, this diff adds a knob that can control the
"degree" of indirect recursion that the inliner attempts to detect. The default
value is 1 which means that it only checks for self-recursion, and wouldn't
change the current behavior.. MySQL issue can be addressed by setting the flag
to 2.

Event Timeline

twoh created this revision.Apr 29 2019, 2:35 PM
lebedev.ri added inline comments.

Can you also add a test to show what happens if @large_stack_callee is not called?
It should then be inlined?
Or is the intention to completely prohibit inlining of recursive calls?

twoh marked an inline comment as done.Apr 29 2019, 3:54 PM
twoh added inline comments.

No is the only place where IsCallerRecursive is effective, so it only matters when AllocatedSize > InlineConstants::TotalAllocaSizeRecursiveCaller.