Inlining Support
From Open64 Wiki
What is Inline Expansion?
Inlining is a very useful compiler optimization that replaces a function call site with the body of the callee. This optimization may improve time and space usage at runtime, at the possible cost of increasing the size of the final program. However, this doesn't always work out in favour of the program. On one hand, it can remove the cost of function 'call and return' instructions and allow the compiler to provide further optimizations while on the other, it may make the generated code slower (by maybe decreasing locality of reference), the increased code size may cause a small, critical section of code to no longer fit in the cache, causing cache misses and slowdown, may result in the inlined procedure consuming additional registers (increasing register pressure) or lead to creating programs that cannot run (given RAM constraints) or cause thrashing. Hence, we cannot have a static policy of implementing these decisions and must base our choice on intelligent heuristics. Open64 intends to implement the use of supervised machine learning techniques to automatically construct such good inlining heuristics.
Inlining Support in Open64
The inlining source code in open64 can be found at:
$INSTALL_DIR/open64/osprey/ipa/inline/
AUTHOR: marcel
COMMIT DATE: 10/2005 (Original Version)
CONTENTS:
- inline.(h,cxx): Standalone (intra-file) inliner.
- inline_driver.cxx: Main driver- command line processing and file name manipulation for the IPA Summary Phase
- inline_split_common.(h,cxx): Implementation of the utilities necessary to split common arrays
- inline_stub.cxx: Stub to compile the real version in libwopt
- inline_summarize.h: Auxilliary data structures used by the inliner version of summary phase.
- inline_utils.(h,cxx): Standalone (intra-file) inliner (copied from ld/process.c)
- timelib.(h,cxx): Contains the interface information for the timer library.
Inlining Options in Open64
The following are the IPA inline expansion options available in Open64 as mentioned in the Open64 User Guide:
- -fimplicit-inline-templates (C++ Only) : Instructs the compiler to emit code for implicit instantiations of inline templates.
- -fno-implicit-inline-templates (C++ Only) : Instructs the compiler to never emit code for implicit instantiations of inline templates. [DEFAULT]
- -fimplicit-templates (C++ Only): Instructs the compiler to emit code for non-inline templates which are instantiated implicitly.
- -fno-implicit-templates (C++ Only): Instructs the compiler to never emit code for non-inline templates which are instantiated implicitly (i.e. by use); it will only emit code for explicit instantiations.
- -finline, -inline, -INLINE : Instruct the compiler to perform inline processing (i.e. expansion of inline functions). If optimizations are not being performed then function inlining is suppressed.
- -noinline, -fno-inline: They disable inlining and don’t pay attention to the inline keyword.
Note when performing inter-procedural analysis (IPA) then ‘-IPA:inline=OFF’ must be specified when disabling inlining
- -finline-functions (C/C++ Only): Automatically integrates simple functions (i.e. the callees) into the callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way. If all calls to a given function are integrated, and the function is declared static, then normally assembler code is not generated for the function.
- -fno-inline-functions (C/C++ Only): This will disable the automatic integration of simple functions.
Note this option is enabled at optimization level 3, ‘-O3’. (DEFAULT)
- -fkeep-inline-functions (C/C++ Only): Instructs the compiler to generate code for functions even if they are fully inlined. In C, emit code for static functions that are declared inline into the object file, even if the function has been inlined into all of its callers. This switch does not affect functions using the extern inline extension in C. In C++, emit any and all inline functions into the object file.
- -INLINE:question=answer: This option group transforms function calls by use of inlining. If inlining directives are inserted in the source code then the ‘-INLINE’ option must be specified in order for those directives to be recognized. Note when specifying the ‘-INLINE’ option the program may not always compile successfully, with the exception of ‘-INLINE:=OFF’ which suppresses the invocation of the lightweight inliner.
- -INLINE:all: Instructs the compiler to perform all possible inlining.
Note since inlining increases the code size, this option should be specified with some discretion (e.g., use only if program is small).
- -INLINE:aggressive=ON|OFF: Instructs the compiler to be very aggressive when performing inlining. (DEFAULT is OFF)
- -INLINE:list=ON|OFF: Instructs the compiler to emit a list of inlining transformations as they occur to ‘stderr’. The emitted comments outline which functions are inlined, which functions are not inlined, and why. (DEFAULT IS OFF)
- -INLINE:must=name1[,name2,...], -INLINE:never=name1[,name2,...]: Functions can be tagged for inlining by specifying the function name when using the ‘-INLINE:must’ option or suppressed by using the option ‘-INLINE:never’.
Note when using this option in C++, use the C++ mangled name for the function.
- -INLINE:none: Disables automatic inlining specified by the interprocedural analysis group option (‘-IPA:’). (DEFAULT IS ON).
Note inlining specified by a commandline option or implied by the language are still performed.
- -INLINE:preempt=ON|OFF: Inline functions labeled preemptible in the lightweight inliner. Preempt inlining prevents alternate definitions of a function, in another dynamic shared object (DSO), from preempting the definition of the function being inlined.(DEFAULT is OFF).