Reputation: 9331
With IBM's XL compiler family it is possible to supply two options (-qreport
and -qlist
) to generate reports for each source file that include information on which optimizations were applied, or which parts of the code could not be optimized (and why).
Is it possible to get a similar reporting for GNU's g++ - and if yes, how to do it?
Upvotes: 23
Views: 5356
Reputation: 3993
From https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Optimize-Options.html#Optimize-Options:
You can invoke GCC with -Q --help=optimizers
to find out the exact set of optimizations that are enabled at each level.
Example: (count number of optimization options enabled) A file is not necessary.
$ g++ -std=c++17 -O2 -Q --help=optimizers 2>&1 |grep enabled |wc -l
135
Note that many optimizations enabled by -O1/2/3 have no individual flags (see also: c++ - g++ O1 is not equal to O0 with all related optimization flags - Stack Overflow)
Upvotes: 3
Reputation: 1316
Have a look at the -fdump-tree-[switch]
flags. You can use -fdump-tree-all
to get loads of information.
Also in trunk gcc -fopt-info-[options]
will give you access higher level optimization information e.g. when particular optimizations were applied, missed etc e.g.
-fopt-info-inline-optimized-missed
Prints all successful and missed inlining optimizations (to stderr
in this case). This is obviously pretty new functionality so I'm not sure how well supported it is yet.
In earlier releases they had -ftree-vectorizer-verbose=n
which is now being deprecated in favor of opt-info.
All these options are listed here https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html though it can be a bit tricky to pick out the useful ones.
Upvotes: 17
Reputation: 7009
Use -S -fverbose-asm
to list every silently applied option (including optimization ones) in assembler output header.
Upvotes: 7