When a compiler inlines a function, it replaces the function call with the actual code for the function.
Benefits of Inlining
Inlining generally improves program performance in the
following ways:
The best candidates for inlining are small functions that are called often from a few places. Here are some more ways to improve performance with inlining:
Drawbacks of Inlining
An expected result of inlining is a larger executable module,
because the code for the function is included at each call site.
However, the difference in size may be less than the size of the
function multiplied by the number of calls due to extra
optimizations that can be performed.
In some cases, inlining may slow program performance, especially if you build with the build options that allow automatic inlining. Automatic inlining does not always select the best candidates for inlining. It is more effective to nominate specific functions to be inlined by including the following qualifiers in the function declarations:
_Inline
inline.
When you use inlining, you need more stack space. When a function is called, its local storage is allocated at the time of the call and freed when it returns to the calling function. If that same function is inlined, its storage is allocated when the function that calls it is entered, and is not freed until that calling function ends.
You should turn off inlining if you plan to debug your executable module. Inlining can make debugging difficult; for example, if you set an entry breakpoint for a function call but the function is inlined, the breakpoint will not work.
Build Options that Affect Inlining
Build with opt(inline, yes) to
enable the inlining of functions that are qualified with the
keyword _Inline in C source code or with the keyword inline in
C++ source code. Build with opt(inline, no) to prevent this
inlining.
Build with opt(autoInline, yes) to enable the automatic inlining of C functions that are not qualified with _Inline or C++ functions that are not qualified with inline. In automatic inlining, the compiler decides which functions to inline. Build with opt(autoInline, no) to prevent this inlining.
To gain some control over automatic inlining, you can use the following options:
opt(autoInlineLimit, number) on AIX platforms
opt(autoInlineThreshold, number) on OS/2 and Windows NT platforms
By default, inlining is not performed unless you are optimizing. To optimize, build with opt(level, level) and specify a value greater than zero for level. Building with opt(level,0) implicitly sets opt(inline, no) and opt(autoInline, no). Building with any other optimization level implicitly sets opt(inline, yes) and opt(autoInline, yes).
![]()
Incremental C++ Build
C Compilation
![]()
Optimize your
Program
![]()
Set Build Options
Build
Nominate Inline Functions
![]()
Optimization Options
![]()
Optimization Options
