% Understanding and controlling gcc's inlining decisions % Michael Stone % October 7, 2012 Here are two cute tricks for understanding and controlling GCC's inlining decisions that I learned recently while preparing to help mentor for MIT's [Performance Engineering][6.172] class ([2010 OCW lectures]). 1. GCC has a [debugging option][GCC Debugging Options] called `-fdump-ipa-inline`. When given, GCC will output a log file that describes, on a call-site-by-call-site basis, what inlining decision it made and why. (As a result, with this flag set, one can write unit tests to check the outcome of critical inlining decisions!) 2. If you've found an inlining decision that makes you unhappy and your normal `static inline ...` declaration isn't cutting the mustard, then GCC's `always_inline` and `noinline` [function attributes][GCC Function Attributes] might be what you're looking for! Other tricks: 1. Per [Auto-vectorization in GCC] and SO, something like `-ftree-vectorize-verbose=7` (`-vec-report3` with ICC) or `-fdump-tree-vect` will give you lots of information Other links: 1. [Agner Fog's Software Optimization Resources] [6.172]: http://stellar.mit.edu/S/course/6/fa12/6.172/index.html [GCC Function Attributes]: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html [GCC Debugging Options]: http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging-Options [Auto-vectorization in GCC]: http://gcc.gnu.org/projects/tree-ssa/vectorization.html [2010 OCW lectures]: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-172-performance-engineering-of-software-systems-fall-2010/ [Agner Fog's Software Optimization Resources]: http://agner.org/optimize/