]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/optinfo.texi
Daily bump.
[thirdparty/gcc.git] / gcc / doc / optinfo.texi
CommitLineData
23a5b65a 1@c Copyright (C) 2013-2014 Free Software Foundation, Inc.
b1055be0
SS
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.
b1055be0 15* Dump files and streams:: Dump output file names and streams.
69479ebd 16* Dump output verbosity:: How much information to dump.
b1055be0
SS
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_VEC
63Vectorization passes. Enabled by @option{-vec}.
64
65@item OPTGROUP_OTHER
66All other optimization passes which do not fall into one of the above.
67
68@item OPTGROUP_ALL
69All optimization passes. Enabled by @option{-all}.
70
71@end ftable
72
73By using groups a user could selectively enable optimization
74information only for a group of passes. By default, the optimization
75information for all the passes is dumped.
76
77@node Dump files and streams
78@subsection Dump files and streams
79@cindex optimization info file names
80
81There are two separate output streams available for outputting
82optimization information from passes. Note that both these streams
83accept @code{stderr} and @code{stdout} as valid streams and thus it is
84possible to dump output to standard output or error. This is specially
85handy for outputting all available information in a single file by
86redirecting @code{stderr}.
87
88@table @code
89@item @code{pstream}
90This stream is for pass-specific dump output. For example,
91@option{-fdump-tree-vect=foo.v} dumps tree vectorization pass output
92into the given file name @file{foo.v}. If the file name is not provided,
93the default file name is based on the source file and pass number. Note
94that one could also use special file names @code{stdout} and
95@code{stderr} for dumping to standard output and standard error
96respectively.
97
98@item @code{alt_stream}
99This steam is used for printing optimization specific output in
100response to the @option{-fopt-info}. Again a file name can be given. If
101the file name is not given, it defaults to @code{stderr}.
102@end table
103
104@node Dump output verbosity
105@subsection Dump output verbosity
106@cindex dump verbosity
107
108The dump verbosity has the following options
109
110@table @samp
111@item optimized
112Print information when an optimization is successfully applied. It is
113up to a pass to decide which information is relevant. For example, the
114vectorizer passes print the source location of loops which got
115successfully vectorized.
116
117@item missed
118Print information about missed optimizations. Individual passes
119control which information to include in the output. For example,
120
121@smallexample
122gcc -O2 -ftree-vectorize -fopt-info-vec-missed
123@end smallexample
124
125will print information about missed optimization opportunities from
126vectorization passes on stderr.
127
128@item note
129Print verbose information about optimizations, such as certain
130transformations, more detailed messages about decisions etc.
131
132@item all
133Print detailed optimization information. This includes
134@var{optimized}, @var{missed}, and @var{note}.
135@end table
136
137@node Dump types
138@subsection Dump types
139@cindex dump types
140
141@ftable @code
142
143@item dump_printf
144
145This is a generic method for doing formatted output. It takes an
146additional argument @code{dump_kind} which signifies the type of
147dump. This method outputs information only when the dumps are enabled
148for this particular @code{dump_kind}. Note that the caller doesn't
149need to know if the particular dump is enabled or not, or even the
150file name. The caller only needs to decide which dump output
151information is relevant, and under what conditions. This determines
152the associated flags.
153
154Consider the following example from @file{loop-unroll.c} where an
155informative message about a loop (along with its location) is printed
156when any of the following flags is enabled
157@itemize @minus
158
159@item optimization messages
160@item RTL dumps
161@item detailed dumps
162
163@end itemize
164
165@example
166int report_flags = MSG_OPTIMIZED_LOCATIONS | TDF_RTL | TDF_DETAILS;
167dump_printf_loc (report_flags, locus,
168 "loop turned into non-loop; it never loops.\n");
169@end example
170
171@item dump_basic_block
172Output basic block.
173@item dump_generic_expr
174Output generic expression.
175@item dump_gimple_stmt
176Output gimple statement.
177
178Note that the above methods also have variants prefixed with
179@code{_loc}, such as @code{dump_printf_loc}, which are similar except
180they also output the source location information.
181
182@end ftable
183
184@node Dump examples
185@subsection Dump examples
186@cindex dump examples
187
188@smallexample
189gcc -O3 -fopt-info-missed=missed.all
190@end smallexample
191
192outputs missed optimization report from all the passes into
193@file{missed.all}.
194
195As another example,
196@smallexample
197gcc -O3 -fopt-info-inline-optimized-missed=inline.txt
198@end smallexample
199
200will output information about missed optimizations as well as
201optimized locations from all the inlining passes into
202@file{inline.txt}.
203
204If the @var{filename} is provided, then the dumps from all the
205applicable optimizations are concatenated into the @file{filename}.
206Otherwise the dump is output onto @file{stderr}. If @var{options} is
207omitted, it defaults to @option{all-all}, which means dump all
208available optimization info from all the passes. In the following
209example, all optimization info is output on to @file{stderr}.
210
211@smallexample
212gcc -O3 -fopt-info
213@end smallexample
214
215Note that @option{-fopt-info-vec-missed} behaves the same as
216@option{-fopt-info-missed-vec}.
217
218As another example, consider
219
220@smallexample
221gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt
222@end smallexample
223
224Here the two output file names @file{vec.miss} and @file{loop.opt} are
225in conflict since only one output file is allowed. In this case, only
226the first option takes effect and the subsequent options are
227ignored. Thus only the @file{vec.miss} is produced which containts
228dumps from the vectorizer about missed opportunities.