Inlining
Inline expansion, or inlining, uses a variety of language keywords or compiler optimisations to directly include the instructions of a function where it is called to avoid the overhead of a function call.
Prerequisite knowledge
In order to get started with inlining, you should first be familiar with how to install and run your program, including knowing how to update compilation flags for compiled languages. You should also be familiar with the programming language used in your program.
Overview
There might be a significant overhead related to function calls, especially in situations where functions are called multiple times within a loop. One way to overcome those issues is to place the code of the function into the calling routine. This can be automatically done by the compiler, however this is not guaranteed for all cases. Code developers can use some techniques to suggest inlining:
- In C/C++, placing the code in the same file as the calling routine might help in inlining the code.
- In C99/C++, the
inline
keyword can be used in the declaration of a function. - In Fortran, placing the code in the same file or module as the calling routine might help in inlining the code.
Compiler options
Table 1 summarises some compiler options that might be used to direct the compiler to integrate "simple enough" functions into the callers.
Table 1. Compiler options
Compiler | Inlining |
---|---|
Cray Fortran |
|
Cray C/C++ | -finline-functions, -finline-aggressive |
AOCC | -finline-functions, -finline-aggressive |
GNU |
|
Intel |
|
PGI |
|