Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Should I mark my short functions as "inline"?

jlperla
Beginner
332 Views
With Intel 11.1 on windows, I haven't been marking my functions as "inline" when I would guess they probably should be. I hear that compilers often ignore the directive and choose on their own when it makes sense. Is this safe to assume here?
0 Kudos
2 Replies
TimP
Honored Contributor III
332 Views
By default, the compiler looks for the most attractive opportunities for inter-procedural optimization, including in-lining. If, as I do, you prefer to disable the whole program link-time optimization (/Qipo), setting /Qip makes it more aggressive for in-lining among functions in a single source file. There are other options in the help file to control in-lining thresholds. If you know that a function should be in-lined, it may be helpful to so mark it.
0 Kudos
JenniferJ
Moderator
332 Views

As Tim says, it's depending on what options you used.

1. /Ob0: no inlining at all. "inline" keyword does not matter

2. /Ob1: "inline" will help, and some C++ inlining (default constructs etc.)

3. /Ob2: more than /Ob1; and compiler will do more aggressive inlining as well for small fundtions without "inline" if the small functions are in the same file (compiling unit)

4. /Qipo: more than /Ob2, for small functions that are even in other files.

There is a default setting for "small" functions. But it's controlable as well using the following options:

/Qinline-min-size: set size limit for inlining small routines

/Qinline-min-size- no size limit for inlining small routines

/Qinline-max-size: set size limit for inlining large routines

/Qinline-max-size- no size limit for inlining large routines

/Qinline-max-total-size:maximum increase in size for inline function expansion

/Qinline-max-total-size- no size limit for inline function expansion

/Qinline-max-per-routine: maximum number of inline instances in any function

/Qinline-max-per-routine- no maximum number of inline instances in any function

/Qinline-max-per-compile: maximum number of inline instances in the current compilation

/Qinline-max-per-compile- no maximum number of inline instances in the current compilation

/Qinline-factor: set inlining upper limits by n percentage

/Qinline-factor- do not set set inlining upper limits

/Qinline-forceinline treat inline routines as forceinline

/Qinline-dllimport allow(DEFAULT)/disallow functions declared __declspec(dllimport) tobe inlined

/Qinline-calloc directs the compiler to inline calloc() calls as malloc()/memset()

Note: those fine tune optimization optionsare only available in the 11.x professional edition of the Intel C++ Compiler.

Jennifer

0 Kudos
Reply