When function inlining is enabled, the compiler uses a complex
decision tree to decide if a function is to be inlined.
The following simplified algorithm is used:
If the function is qualified with __forceinline,
the function is inlined if it is possible to do so.
If the function is qualified with __inline and
the option --forceinline is selected, the function
is inlined if it is possible to do so.
If the function is qualified with __inline and
the option --forceinline is not selected, the function
is inlined if it is practical to do so.
If the optimization level is -O2 or
higher, or --autoinline is specified, the compiler automatically
inlines functions if it is practical to do so, even if you do not
explicitly give a hint that function inlining is wanted.
When deciding if it is practical to inline a function, the
compiler takes into account several other criteria, such as:
the size of the
function, and how many times it is called
the current optimization level
whether it is optimizing for speed (-Otime)
or size (-Ospace)
whether the function has external or static linkage
how many parameters the function has
whether the return value of the function is used.
Ultimately, the compiler can decide not to inline a function,
even if the function is qualified with __forceinline.
As a general rule:
smaller functions
stand a better chance of being inlined
compiling with -Otime increases
the likelihood that a function is inlined
large functions are not normally inlined because
this can adversely affect code density and performance.
A recursive function is inlined into itself only once, even
if __forceinline is used.
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.