1@c Copyright (C) 2013-2018 Free Software Foundation, Inc. 2@c This is part of the GCC manual. 3@c For copying conditions, see the file gcc.texi. 4 5@cindex optimization dumps 6 7This section is describes dump infrastructure which is common to both 8pass dumps as well as optimization dumps. The goal for this 9infrastructure is to provide both gcc developers and users detailed 10information about various compiler transformations and optimizations. 11 12@menu 13* Dump setup:: Setup of optimization dumps. 14* Optimization groups:: Groups made up of optimization passes. 15* Dump files and streams:: Dump output file names and streams. 16* Dump output verbosity:: How much information to dump. 17* Dump types:: Various types of dump functions. 18* Dump examples:: Sample usage. 19@end menu 20 21@node Dump setup 22@subsection Dump setup 23@cindex dump setup 24 25A dump_manager class is defined in @file{dumpfile.h}. Various passes 26register dumping pass-specific information via @code{dump_register} in 27@file{passes.c}. During the registration, an optimization pass can 28select its optimization group (@pxref{Optimization groups}). After 29that optimization information corresponding to the entire group 30(presumably from multiple passes) can be output via command-line 31switches. Note that if a pass does not fit into any of the pre-defined 32groups, it can select @code{OPTGROUP_NONE}. 33 34Note that in general, a pass need not know its dump output file name, 35whether certain flags are enabled, etc. However, for legacy reasons, 36passes could also call @code{dump_begin} which returns a stream in 37case the particular pass has optimization dumps enabled. A pass could 38call @code{dump_end} when the dump has ended. These methods should go 39away once all the passes are converted to use the new dump 40infrastructure. 41 42The recommended way to setup the dump output is via @code{dump_start} 43and @code{dump_end}. 44 45@node Optimization groups 46@subsection Optimization groups 47@cindex optimization groups 48The optimization passes are grouped into several categories. Currently 49defined categories in @file{dumpfile.h} are 50 51@ftable @code 52 53@item OPTGROUP_IPA 54IPA optimization passes. Enabled by @option{-ipa} 55 56@item OPTGROUP_LOOP 57Loop optimization passes. Enabled by @option{-loop}. 58 59@item OPTGROUP_INLINE 60Inlining passes. Enabled by @option{-inline}. 61 62@item OPTGROUP_OMP 63OMP (Offloading and Multi Processing) passes. Enabled by 64@option{-omp}. 65 66@item OPTGROUP_VEC 67Vectorization passes. Enabled by @option{-vec}. 68 69@item OPTGROUP_OTHER 70All other optimization passes which do not fall into one of the above. 71 72@item OPTGROUP_ALL 73All optimization passes. Enabled by @option{-optall}. 74 75@end ftable 76 77By using groups a user could selectively enable optimization 78information only for a group of passes. By default, the optimization 79information for all the passes is dumped. 80 81@node Dump files and streams 82@subsection Dump files and streams 83@cindex optimization info file names 84 85There are two separate output streams available for outputting 86optimization information from passes. Note that both these streams 87accept @code{stderr} and @code{stdout} as valid streams and thus it is 88possible to dump output to standard output or error. This is specially 89handy for outputting all available information in a single file by 90redirecting @code{stderr}. 91 92@table @code 93@item @code{pstream} 94This stream is for pass-specific dump output. For example, 95@option{-fdump-tree-vect=foo.v} dumps tree vectorization pass output 96into the given file name @file{foo.v}. If the file name is not provided, 97the default file name is based on the source file and pass number. Note 98that one could also use special file names @code{stdout} and 99@code{stderr} for dumping to standard output and standard error 100respectively. 101 102@item @code{alt_stream} 103This steam is used for printing optimization specific output in 104response to the @option{-fopt-info}. Again a file name can be given. If 105the file name is not given, it defaults to @code{stderr}. 106@end table 107 108@node Dump output verbosity 109@subsection Dump output verbosity 110@cindex dump verbosity 111 112The dump verbosity has the following options 113 114@table @samp 115@item optimized 116Print information when an optimization is successfully applied. It is 117up to a pass to decide which information is relevant. For example, the 118vectorizer passes print the source location of loops which got 119successfully vectorized. 120 121@item missed 122Print information about missed optimizations. Individual passes 123control which information to include in the output. For example, 124 125@smallexample 126gcc -O2 -ftree-vectorize -fopt-info-vec-missed 127@end smallexample 128 129will print information about missed optimization opportunities from 130vectorization passes on stderr. 131 132@item note 133Print verbose information about optimizations, such as certain 134transformations, more detailed messages about decisions etc. 135 136@item all 137Print detailed optimization information. This includes 138@var{optimized}, @var{missed}, and @var{note}. 139@end table 140 141@node Dump types 142@subsection Dump types 143@cindex dump types 144 145@ftable @code 146 147@item dump_printf 148 149This is a generic method for doing formatted output. It takes an 150additional argument @code{dump_kind} which signifies the type of 151dump. This method outputs information only when the dumps are enabled 152for this particular @code{dump_kind}. Note that the caller doesn't 153need to know if the particular dump is enabled or not, or even the 154file name. The caller only needs to decide which dump output 155information is relevant, and under what conditions. This determines 156the associated flags. 157 158Consider the following example from @file{loop-unroll.c} where an 159informative message about a loop (along with its location) is printed 160when any of the following flags is enabled 161@itemize @minus 162 163@item optimization messages 164@item RTL dumps 165@item detailed dumps 166 167@end itemize 168 169@example 170int report_flags = MSG_OPTIMIZED_LOCATIONS | TDF_RTL | TDF_DETAILS; 171dump_printf_loc (report_flags, locus, 172 "loop turned into non-loop; it never loops.\n"); 173@end example 174 175@item dump_basic_block 176Output basic block. 177@item dump_generic_expr 178Output generic expression. 179@item dump_gimple_stmt 180Output gimple statement. 181 182Note that the above methods also have variants prefixed with 183@code{_loc}, such as @code{dump_printf_loc}, which are similar except 184they also output the source location information. 185 186@end ftable 187 188@node Dump examples 189@subsection Dump examples 190@cindex dump examples 191 192@smallexample 193gcc -O3 -fopt-info-missed=missed.all 194@end smallexample 195 196outputs missed optimization report from all the passes into 197@file{missed.all}. 198 199As another example, 200@smallexample 201gcc -O3 -fopt-info-inline-optimized-missed=inline.txt 202@end smallexample 203 204will output information about missed optimizations as well as 205optimized locations from all the inlining passes into 206@file{inline.txt}. 207 208If the @var{filename} is provided, then the dumps from all the 209applicable optimizations are concatenated into the @file{filename}. 210Otherwise the dump is output onto @file{stderr}. If @var{options} is 211omitted, it defaults to @option{optimized-optall}, which means dump 212all information about successful optimizations from all the passes. 213In the following example, the optimization information is output on 214to @file{stderr}. 215 216@smallexample 217gcc -O3 -fopt-info 218@end smallexample 219 220Note that @option{-fopt-info-vec-missed} behaves the same as 221@option{-fopt-info-missed-vec}. The order of the optimization group 222names and message types listed after @option{-fopt-info} does not matter. 223 224As another example, consider 225 226@smallexample 227gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt 228@end smallexample 229 230Here the two output file names @file{vec.miss} and @file{loop.opt} are 231in conflict since only one output file is allowed. In this case, only 232the first option takes effect and the subsequent options are 233ignored. Thus only the @file{vec.miss} is produced which containts 234dumps from the vectorizer about missed opportunities. 235