-finline-functions (-qinline)
Category
Pragma equivalent
None.
Purpose
Attempts to inline functions instead of generating calls to those functions, for improved performance.
Syntax
>>--- -finline-functions---------------------------------------><
.- -qnoinline------------------------------. >>-+- -qinline-+----------------------------+-+---------------->< | .-:--------------------. | | V | | +-=---+-auto-------------+-+-+ | +-noauto-----------+ | | '-level--=--number-' | | .-:-------------. | | V | | '-+- + +----function_name-+--' '- - '
Defaults
- -qnoinline at the -O0 or -qnoopt optimization level
- -qinline=noauto:level=5 at the -O2 optimization level
- -qinline=auto:level=5 at the -O2 -qipa, -O3 or higher optimization level
If -qinline is specified without any suboptions, the default option is -qinline=auto:level=5.
Parameters
- auto | noauto
- Enables or disables automatic inlining. When option -qinline=auto is
in effect, all functions are considered for inlining by the compiler.
When option -qinline=noauto is in effect, only
the following types of functions are considered for inlining:
- Functions that are defined with the inline specifier
- Small functions that are identified by the compiler
- level=number
- Indicates the relative degree of inlining. The values for number must be integers in the range 0 - 10 inclusive. The default value for number is 5. The greater the value of number, the more aggressive inlining the compiler conducts.
- function_name
- If function_name is specified after the -qinline+ option, the named function must be inlined. If function_name is specified after the -qinline- option, the named function must not be inlined. The function_name must be the mangled name of the function. You can find the mangled function name in the listing file.
Usage
You can specify -qinline or specify -qinline with any optimization level of -O, -O2, -O3, -O4, or -O5 to enable inlining of functions, including those functions that are declared with the inline specifier or that are defined within a class declaration.
When -qinline is in effect, the compiler determines whether inlining a specific function can improve performance. That is, whether a function is appropriate for inlining is subject to two factors: limits on the number of inlined calls and the amount of code size increase as a result. Therefore, enabling inlining a function does not guarantee that function will be inlined.
Because inlining does not always improve runtime performance, you need to test the effects of this option on your code. Do not attempt to inline recursive or mutually recursive functions.
You can use the -qinline+<function_name> or -qinline-<function_name> option to specify the functions that must be inlined or must not be inlined.
The -qinline-<function_name> option takes higher precedence than the always_inline or __always_inline__ attribute. When you specify both the always_inline or __always_inline__ attribute and the -qinline-<function_name> option to a function, that function is not inlined.
- Functions that are specified with the always_inline or __always_inline__ attribute
- Functions that are specified with the -qinline+<function_name> option
If you specify the -g option to generate debugging information, the inlining effect of -qinline might be suppressed.
If you specify the -qcompact option to avoid optimizations that increase code size, the inlining effect of -qinline might be suppressed.
Predefined macros
None.
Examples
Example 1
To compile myprogram.c so that no functions are inlined, use the following command:
xlc myprogram.c -O2 -qnoinline
However, if some functions in myprogram.c are specified with the always_inline or __always_inline__ attribute, the -qnoinline option has no effect on these functions and they are still inlined.
If you want to enable automatic inlining, you use the auto suboption:
-O2 -qinline=auto
You can specify an inlining level 6 - 10 to achieve more aggressive automatic inlining. For example:
-O2 -qinline=auto:level=7
If automatic inlining is already enabled by default and you want to specify an inlining level of 7, you enter:
-O2 -qinline=level=7
Example 2
Assuming myprogram.c contains the salary, taxes, expenses, and benefits functions, you can use the following command to compile myprogram.c to inline these functions:
xlc myprogram.c -O2 -qinline+salary:taxes:expenses:benefits
If you do not want the functions salary, taxes, expenses, and benefits to be inlined, use the following command to compile myprogram.c:
xlc myprogram.c -O2 -qinline-salary:taxes:expenses:benefits
You can also disable automatic inlining and specify certain functions to be inlined with the -qinline+ option. Consider the following example:
-O2 -qinline=noauto -qinline+salary:taxes:benefits
In this case, the functions salary, taxes, and benefits are inlined. Functions that are specified with the always_inline or __always_inline__ attribute or declared with the inline specifier are also inlined. No other functions are inlined.
-qinline+increase-decrease // Invalid
-qinline=level=5+increase // Invalid
However, you
can use multiple -qinline options separately. See
the following example:-qinline+increase -qinline-decrease -qinline=noauto:level=5
In C++, you can use the -qinline+ and -qinline- options in the same way as in example 2; however, you must specify the mangled function names instead of the actual function names after these options.