annotate gcc/doc/optinfo.texi @ 158:494b0b89df80 default tip

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