Search code examples
c++compiler-optimization

Can I get a log of optimizations applied by the compiler?


When compiling a C++ application or library with optimizations turned on, like -O3 for gcc, is there a way to get the applied optimizations listed? I mean, without comparing the actual byte code. This would be interesting to learn.


Solution

  • From

    http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html

    the -fopt-info family of switches causes the optimizer to dump out information to stderr (or a file if you prefer). In particular, -fopt-info-missed can be useful to see why an optimisation could not be applied.

    There are quite a few different combinations available. From the linked page:

    For example,

              gcc -O3 -fopt-info-missed=missed.all
    

    outputs missed optimization report from all the passes into missed.all.

    As another example,

      gcc -O3 -fopt-info-inline-optimized-missed=inline.txt
    

    will output information about missed optimizations as well as optimized locations from all the inlining passes into inline.txt.