For a routine to be considered for inlining, it has to meet certain minimum criteria. There are criteria to be met by the call-site, the caller, and the callee. The call-site is the site of the call to the function that might be inlined. The caller is the function that contains the call-site. The callee is the function being called that might be inlined.
Minimum call-site criteria:
The number of actual arguments must match the number of formal arguments of the callee.
The number of return values must match the number of return values of the callee.
The data types of the actual and formal arguments must be compatible.
No multilingual inlining is permitted. Caller and callee must be written in the same source language.
Minimum criteria for the caller:
At most 2000 intermediate statements will be inlined into the caller from all the call-sites being inlined into the caller. You can change this value by specifying the option
-Qoptionf,-ip_inline_max_total_stats=new value
The function must be called if it is declared as static. Otherwise, it will be deleted.
Minimum criteria for the callee:
Does not have variable argument list.
Is not considered infrequent due to the name. Routines which contain the following substrings in their names are not inlined: abort, alloca, denied, err, exit, fail, fatal, fault, halt, init, interrupt, invalid, quit, rare, stop, timeout, trace, trap, and warn.
Is not considered unsafe for other reasons.
Once these criteria are met, the compiler picks the routines whose in-line expansions will provide the greatest benefit to program performance. This is done using the following default heuristics. When you use profile-guided optimizations, a number of other heuristics are used (see Profile-Guided Optimization (PGO) for more information on profile-guided optimization).
The default heuristic focuses on call-sites in loops or calls to functions containing loops.
When profile information is available, the focus changes to the most frequently executed call-sites.
Also, the default in-line heuristic does not permit
the inlining of functions with more than 230 intermediate statements,
or the number specified by the option
-Qoptionf,-ip_inline_max_stats. The default
inline heuristic will stop inlining when direct recursion is detected.
The default heuristic will always inline very small functions that meet the minimum inline criteria. By default, functions with 10 or fewer intermediate statements will be inlined.