For a call to be considered for inlining, it has to meet certain minimum criteria. There are three main components of a call:
Call-site is the site of the call to the function that might be inlined.
Caller is the function that contains the call-site.
Callee is the function being called that might be inlined.
The following table details the minimum criteria for each component:
Component |
Minimum criteria |
---|---|
Call-site |
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. |
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: -Qoption,f,-ip_ninl_max_total_stats=n /Qoption,f,-ip_ninl_max_total_stats=n where n is a new value. The function must be called if it is declared as static. Otherwise, it will be deleted. |
Callee |
Does not have variable argument list. Is not considered unsafe for other reasons. 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. |
If the minimum criteria identified are met, the compiler picks the routines whose inline expansions will provide the greatest benefit to program performance. This is done using the default heuristics. The inlining heuristics used by the compiler differ based on whether you use profile-guided optimizations, -prof-use (Linux*) or /Qprof-use (Windows*), or not.
When you use profile-guided optimizations with -ip or -ipo (Linux) or /Qip or /Qipo (Windows), the compiler uses the following heuristics:
The default heuristic focuses on the most frequently executed call sites, based on the profile information gathered for the program.
The default inline heuristic will stop inlining when direct recursion is detected.
The default heuristic always inlines very small functions that meet the minimum inline criteria.
By default, the compiler does not inline functions with more than 230 intermediate statements. You can change this value by specifying the following:
Platform |
Command |
---|---|
Linux |
-Qoption,f,-ip_ninl_max_stats=n |
Windows |
/Qoption,f,-ip_ninl_max_stats=n |
where n is a new value.
See Using Qoption Specifiers and Profile-Guided Optimization Overview.
When you do not use profile-guided optimizations with -ip or -ipo (Linux) or /Qip or /Qipo (Windows), the compiler uses less aggressive inlining heuristics: it inlines a function if the inline expansion does not increase the size of the final program.
Preemption of a function means that the code, which implements that function at run-time, is replaced by different code. When a function is preempted, the new version of this function is executed rather than the old version. Preemption can be used to replace an erroneous or inferior version of a function with a correct or improved version.
The compiler assumes that when -ip is on, any externally visible function might be preempted and therefore cannot be inlined. Currently, this means that all Fortran subprograms, except for internal procedures, are not inlinable when -ip is on. However, if you use -ipo on a file-by-file basis, the functions can be inlined.