annotate gcc/dumpfile.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* Dump infrastructure for optimizations and intermediate representation.
kono
parents:
diff changeset
2 Copyright (C) 2012-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "options.h"
kono
parents:
diff changeset
24 #include "tree.h"
kono
parents:
diff changeset
25 #include "gimple-pretty-print.h"
kono
parents:
diff changeset
26 #include "diagnostic-core.h"
kono
parents:
diff changeset
27 #include "dumpfile.h"
kono
parents:
diff changeset
28 #include "context.h"
kono
parents:
diff changeset
29 #include "profile-count.h"
kono
parents:
diff changeset
30 #include "tree-cfg.h"
kono
parents:
diff changeset
31 #include "langhooks.h"
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 /* If non-NULL, return one past-the-end of the matching SUBPART of
kono
parents:
diff changeset
34 the WHOLE string. */
kono
parents:
diff changeset
35 #define skip_leading_substring(whole, part) \
kono
parents:
diff changeset
36 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 static dump_flags_t pflags; /* current dump_flags */
kono
parents:
diff changeset
39 static dump_flags_t alt_flags; /* current opt_info flags */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 static void dump_loc (dump_flags_t, FILE *, source_location);
kono
parents:
diff changeset
42 static FILE *dump_open_alternate_stream (struct dump_file_info *);
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* These are currently used for communicating between passes.
kono
parents:
diff changeset
45 However, instead of accessing them directly, the passes can use
kono
parents:
diff changeset
46 dump_printf () for dumps. */
kono
parents:
diff changeset
47 FILE *dump_file = NULL;
kono
parents:
diff changeset
48 FILE *alt_dump_file = NULL;
kono
parents:
diff changeset
49 const char *dump_file_name;
kono
parents:
diff changeset
50 dump_flags_t dump_flags;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 #define DUMP_FILE_INFO(suffix, swtch, dkind, num) \
kono
parents:
diff changeset
53 {suffix, swtch, NULL, NULL, NULL, NULL, NULL, dkind, 0, 0, 0, 0, 0, num, \
kono
parents:
diff changeset
54 false, false}
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* Table of tree dump switches. This must be consistent with the
kono
parents:
diff changeset
57 TREE_DUMP_INDEX enumeration in dumpfile.h. */
kono
parents:
diff changeset
58 static struct dump_file_info dump_files[TDI_end] =
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 DUMP_FILE_INFO (NULL, NULL, DK_none, 0),
kono
parents:
diff changeset
61 DUMP_FILE_INFO (".cgraph", "ipa-cgraph", DK_ipa, 0),
kono
parents:
diff changeset
62 DUMP_FILE_INFO (".type-inheritance", "ipa-type-inheritance", DK_ipa, 0),
kono
parents:
diff changeset
63 DUMP_FILE_INFO (".ipa-clones", "ipa-clones", DK_ipa, 0),
kono
parents:
diff changeset
64 DUMP_FILE_INFO (".original", "tree-original", DK_tree, 0),
kono
parents:
diff changeset
65 DUMP_FILE_INFO (".gimple", "tree-gimple", DK_tree, 0),
kono
parents:
diff changeset
66 DUMP_FILE_INFO (".nested", "tree-nested", DK_tree, 0),
kono
parents:
diff changeset
67 #define FIRST_AUTO_NUMBERED_DUMP 1
kono
parents:
diff changeset
68 #define FIRST_ME_AUTO_NUMBERED_DUMP 3
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 DUMP_FILE_INFO (NULL, "lang-all", DK_lang, 0),
kono
parents:
diff changeset
71 DUMP_FILE_INFO (NULL, "tree-all", DK_tree, 0),
kono
parents:
diff changeset
72 DUMP_FILE_INFO (NULL, "rtl-all", DK_rtl, 0),
kono
parents:
diff changeset
73 DUMP_FILE_INFO (NULL, "ipa-all", DK_ipa, 0),
kono
parents:
diff changeset
74 };
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 /* Define a name->number mapping for a dump flag value. */
kono
parents:
diff changeset
77 struct dump_option_value_info
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 const char *const name; /* the name of the value */
kono
parents:
diff changeset
80 const dump_flags_t value; /* the value of the name */
kono
parents:
diff changeset
81 };
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* Table of dump options. This must be consistent with the TDF_* flags
kono
parents:
diff changeset
84 in dumpfile.h and opt_info_options below. */
kono
parents:
diff changeset
85 static const struct dump_option_value_info dump_options[] =
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 {"address", TDF_ADDRESS},
kono
parents:
diff changeset
88 {"asmname", TDF_ASMNAME},
kono
parents:
diff changeset
89 {"slim", TDF_SLIM},
kono
parents:
diff changeset
90 {"raw", TDF_RAW},
kono
parents:
diff changeset
91 {"graph", TDF_GRAPH},
kono
parents:
diff changeset
92 {"details", (TDF_DETAILS | MSG_OPTIMIZED_LOCATIONS
kono
parents:
diff changeset
93 | MSG_MISSED_OPTIMIZATION
kono
parents:
diff changeset
94 | MSG_NOTE)},
kono
parents:
diff changeset
95 {"cselib", TDF_CSELIB},
kono
parents:
diff changeset
96 {"stats", TDF_STATS},
kono
parents:
diff changeset
97 {"blocks", TDF_BLOCKS},
kono
parents:
diff changeset
98 {"vops", TDF_VOPS},
kono
parents:
diff changeset
99 {"lineno", TDF_LINENO},
kono
parents:
diff changeset
100 {"uid", TDF_UID},
kono
parents:
diff changeset
101 {"stmtaddr", TDF_STMTADDR},
kono
parents:
diff changeset
102 {"memsyms", TDF_MEMSYMS},
kono
parents:
diff changeset
103 {"eh", TDF_EH},
kono
parents:
diff changeset
104 {"alias", TDF_ALIAS},
kono
parents:
diff changeset
105 {"nouid", TDF_NOUID},
kono
parents:
diff changeset
106 {"enumerate_locals", TDF_ENUMERATE_LOCALS},
kono
parents:
diff changeset
107 {"scev", TDF_SCEV},
kono
parents:
diff changeset
108 {"gimple", TDF_GIMPLE},
kono
parents:
diff changeset
109 {"folding", TDF_FOLDING},
kono
parents:
diff changeset
110 {"optimized", MSG_OPTIMIZED_LOCATIONS},
kono
parents:
diff changeset
111 {"missed", MSG_MISSED_OPTIMIZATION},
kono
parents:
diff changeset
112 {"note", MSG_NOTE},
kono
parents:
diff changeset
113 {"optall", MSG_ALL},
kono
parents:
diff changeset
114 {"all", dump_flags_t (~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_GRAPH
kono
parents:
diff changeset
115 | TDF_STMTADDR | TDF_RHS_ONLY | TDF_NOUID
kono
parents:
diff changeset
116 | TDF_ENUMERATE_LOCALS | TDF_SCEV | TDF_GIMPLE))},
kono
parents:
diff changeset
117 {NULL, 0}
kono
parents:
diff changeset
118 };
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 /* A subset of the dump_options table which is used for -fopt-info
kono
parents:
diff changeset
121 types. This must be consistent with the MSG_* flags in dumpfile.h.
kono
parents:
diff changeset
122 */
kono
parents:
diff changeset
123 static const struct dump_option_value_info optinfo_verbosity_options[] =
kono
parents:
diff changeset
124 {
kono
parents:
diff changeset
125 {"optimized", MSG_OPTIMIZED_LOCATIONS},
kono
parents:
diff changeset
126 {"missed", MSG_MISSED_OPTIMIZATION},
kono
parents:
diff changeset
127 {"note", MSG_NOTE},
kono
parents:
diff changeset
128 {"all", MSG_ALL},
kono
parents:
diff changeset
129 {NULL, 0}
kono
parents:
diff changeset
130 };
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /* Flags used for -fopt-info groups. */
kono
parents:
diff changeset
133 static const struct dump_option_value_info optgroup_options[] =
kono
parents:
diff changeset
134 {
kono
parents:
diff changeset
135 {"ipa", OPTGROUP_IPA},
kono
parents:
diff changeset
136 {"loop", OPTGROUP_LOOP},
kono
parents:
diff changeset
137 {"inline", OPTGROUP_INLINE},
kono
parents:
diff changeset
138 {"omp", OPTGROUP_OMP},
kono
parents:
diff changeset
139 {"vec", OPTGROUP_VEC},
kono
parents:
diff changeset
140 {"optall", OPTGROUP_ALL},
kono
parents:
diff changeset
141 {NULL, 0}
kono
parents:
diff changeset
142 };
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 gcc::dump_manager::dump_manager ():
kono
parents:
diff changeset
145 m_next_dump (FIRST_AUTO_NUMBERED_DUMP),
kono
parents:
diff changeset
146 m_extra_dump_files (NULL),
kono
parents:
diff changeset
147 m_extra_dump_files_in_use (0),
kono
parents:
diff changeset
148 m_extra_dump_files_alloced (0)
kono
parents:
diff changeset
149 {
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 gcc::dump_manager::~dump_manager ()
kono
parents:
diff changeset
153 {
kono
parents:
diff changeset
154 for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 dump_file_info *dfi = &m_extra_dump_files[i];
kono
parents:
diff changeset
157 /* suffix, swtch, glob are statically allocated for the entries
kono
parents:
diff changeset
158 in dump_files, and for statistics, but are dynamically allocated
kono
parents:
diff changeset
159 for those for passes. */
kono
parents:
diff changeset
160 if (dfi->owns_strings)
kono
parents:
diff changeset
161 {
kono
parents:
diff changeset
162 XDELETEVEC (const_cast <char *> (dfi->suffix));
kono
parents:
diff changeset
163 XDELETEVEC (const_cast <char *> (dfi->swtch));
kono
parents:
diff changeset
164 XDELETEVEC (const_cast <char *> (dfi->glob));
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166 /* These, if non-NULL, are always dynamically allocated. */
kono
parents:
diff changeset
167 XDELETEVEC (const_cast <char *> (dfi->pfilename));
kono
parents:
diff changeset
168 XDELETEVEC (const_cast <char *> (dfi->alt_filename));
kono
parents:
diff changeset
169 }
kono
parents:
diff changeset
170 XDELETEVEC (m_extra_dump_files);
kono
parents:
diff changeset
171 }
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 unsigned int
kono
parents:
diff changeset
174 gcc::dump_manager::
kono
parents:
diff changeset
175 dump_register (const char *suffix, const char *swtch, const char *glob,
kono
parents:
diff changeset
176 dump_kind dkind, int optgroup_flags, bool take_ownership)
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 int num = m_next_dump++;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 size_t count = m_extra_dump_files_in_use++;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 if (count >= m_extra_dump_files_alloced)
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 if (m_extra_dump_files_alloced == 0)
kono
parents:
diff changeset
185 m_extra_dump_files_alloced = 512;
kono
parents:
diff changeset
186 else
kono
parents:
diff changeset
187 m_extra_dump_files_alloced *= 2;
kono
parents:
diff changeset
188 m_extra_dump_files = XRESIZEVEC (struct dump_file_info,
kono
parents:
diff changeset
189 m_extra_dump_files,
kono
parents:
diff changeset
190 m_extra_dump_files_alloced);
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 /* Construct a new object in the space allocated above. */
kono
parents:
diff changeset
193 new (m_extra_dump_files + count) dump_file_info ();
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195 else
kono
parents:
diff changeset
196 {
kono
parents:
diff changeset
197 /* Zero out the already constructed object. */
kono
parents:
diff changeset
198 m_extra_dump_files[count] = dump_file_info ();
kono
parents:
diff changeset
199 }
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 m_extra_dump_files[count].suffix = suffix;
kono
parents:
diff changeset
202 m_extra_dump_files[count].swtch = swtch;
kono
parents:
diff changeset
203 m_extra_dump_files[count].glob = glob;
kono
parents:
diff changeset
204 m_extra_dump_files[count].dkind = dkind;
kono
parents:
diff changeset
205 m_extra_dump_files[count].optgroup_flags = optgroup_flags;
kono
parents:
diff changeset
206 m_extra_dump_files[count].num = num;
kono
parents:
diff changeset
207 m_extra_dump_files[count].owns_strings = take_ownership;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 return count + TDI_end;
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 /* Allow languages and middle-end to register their dumps before the
kono
parents:
diff changeset
214 optimization passes. */
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 void
kono
parents:
diff changeset
217 gcc::dump_manager::
kono
parents:
diff changeset
218 register_dumps ()
kono
parents:
diff changeset
219 {
kono
parents:
diff changeset
220 lang_hooks.register_dumps (this);
kono
parents:
diff changeset
221 /* If this assert fails, some FE registered more than
kono
parents:
diff changeset
222 FIRST_ME_AUTO_NUMBERED_DUMP - FIRST_AUTO_NUMBERED_DUMP
kono
parents:
diff changeset
223 dump files. Bump FIRST_ME_AUTO_NUMBERED_DUMP accordingly. */
kono
parents:
diff changeset
224 gcc_assert (m_next_dump <= FIRST_ME_AUTO_NUMBERED_DUMP);
kono
parents:
diff changeset
225 m_next_dump = FIRST_ME_AUTO_NUMBERED_DUMP;
kono
parents:
diff changeset
226 dump_files[TDI_original].num = m_next_dump++;
kono
parents:
diff changeset
227 dump_files[TDI_gimple].num = m_next_dump++;
kono
parents:
diff changeset
228 dump_files[TDI_nested].num = m_next_dump++;
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 /* Return the dump_file_info for the given phase. */
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 struct dump_file_info *
kono
parents:
diff changeset
235 gcc::dump_manager::
kono
parents:
diff changeset
236 get_dump_file_info (int phase) const
kono
parents:
diff changeset
237 {
kono
parents:
diff changeset
238 if (phase < TDI_end)
kono
parents:
diff changeset
239 return &dump_files[phase];
kono
parents:
diff changeset
240 else if ((size_t) (phase - TDI_end) >= m_extra_dump_files_in_use)
kono
parents:
diff changeset
241 return NULL;
kono
parents:
diff changeset
242 else
kono
parents:
diff changeset
243 return m_extra_dump_files + (phase - TDI_end);
kono
parents:
diff changeset
244 }
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 /* Locate the dump_file_info with swtch equal to SWTCH,
kono
parents:
diff changeset
247 or return NULL if no such dump_file_info exists. */
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 struct dump_file_info *
kono
parents:
diff changeset
250 gcc::dump_manager::
kono
parents:
diff changeset
251 get_dump_file_info_by_switch (const char *swtch) const
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 for (unsigned i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
254 if (0 == strcmp (m_extra_dump_files[i].swtch, swtch))
kono
parents:
diff changeset
255 return &m_extra_dump_files[i];
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 /* Not found. */
kono
parents:
diff changeset
258 return NULL;
kono
parents:
diff changeset
259 }
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /* Return the name of the dump file for the given phase.
kono
parents:
diff changeset
263 The caller is responsible for calling free on the returned
kono
parents:
diff changeset
264 buffer.
kono
parents:
diff changeset
265 If the dump is not enabled, returns NULL. */
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 char *
kono
parents:
diff changeset
268 gcc::dump_manager::
kono
parents:
diff changeset
269 get_dump_file_name (int phase) const
kono
parents:
diff changeset
270 {
kono
parents:
diff changeset
271 struct dump_file_info *dfi;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 if (phase == TDI_none)
kono
parents:
diff changeset
274 return NULL;
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 return get_dump_file_name (dfi);
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 /* Return the name of the dump file for the given dump_file_info.
kono
parents:
diff changeset
282 The caller is responsible for calling free on the returned
kono
parents:
diff changeset
283 buffer.
kono
parents:
diff changeset
284 If the dump is not enabled, returns NULL. */
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 char *
kono
parents:
diff changeset
287 gcc::dump_manager::
kono
parents:
diff changeset
288 get_dump_file_name (struct dump_file_info *dfi) const
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 char dump_id[10];
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 gcc_assert (dfi);
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 if (dfi->pstate == 0)
kono
parents:
diff changeset
295 return NULL;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 /* If available, use the command line dump filename. */
kono
parents:
diff changeset
298 if (dfi->pfilename)
kono
parents:
diff changeset
299 return xstrdup (dfi->pfilename);
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 if (dfi->num < 0)
kono
parents:
diff changeset
302 dump_id[0] = '\0';
kono
parents:
diff changeset
303 else
kono
parents:
diff changeset
304 {
kono
parents:
diff changeset
305 /* (null), LANG, TREE, RTL, IPA. */
kono
parents:
diff changeset
306 char suffix = " ltri"[dfi->dkind];
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 if (snprintf (dump_id, sizeof (dump_id), ".%03d%c", dfi->num, suffix) < 0)
kono
parents:
diff changeset
309 dump_id[0] = '\0';
kono
parents:
diff changeset
310 }
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 return concat (dump_base_name, dump_id, dfi->suffix, NULL);
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* For a given DFI, open an alternate dump filename (which could also
kono
parents:
diff changeset
316 be a standard stream such as stdout/stderr). If the alternate dump
kono
parents:
diff changeset
317 file cannot be opened, return NULL. */
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 static FILE *
kono
parents:
diff changeset
320 dump_open_alternate_stream (struct dump_file_info *dfi)
kono
parents:
diff changeset
321 {
kono
parents:
diff changeset
322 FILE *stream ;
kono
parents:
diff changeset
323 if (!dfi->alt_filename)
kono
parents:
diff changeset
324 return NULL;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 if (dfi->alt_stream)
kono
parents:
diff changeset
327 return dfi->alt_stream;
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 stream = strcmp ("stderr", dfi->alt_filename) == 0
kono
parents:
diff changeset
330 ? stderr
kono
parents:
diff changeset
331 : strcmp ("stdout", dfi->alt_filename) == 0
kono
parents:
diff changeset
332 ? stdout
kono
parents:
diff changeset
333 : fopen (dfi->alt_filename, dfi->alt_state < 0 ? "w" : "a");
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 if (!stream)
kono
parents:
diff changeset
336 error ("could not open dump file %qs: %m", dfi->alt_filename);
kono
parents:
diff changeset
337 else
kono
parents:
diff changeset
338 dfi->alt_state = 1;
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 return stream;
kono
parents:
diff changeset
341 }
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 /* Print source location on DFILE if enabled. */
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 void
kono
parents:
diff changeset
346 dump_loc (dump_flags_t dump_kind, FILE *dfile, source_location loc)
kono
parents:
diff changeset
347 {
kono
parents:
diff changeset
348 if (dump_kind)
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 if (LOCATION_LOCUS (loc) > BUILTINS_LOCATION)
kono
parents:
diff changeset
351 fprintf (dfile, "%s:%d:%d: note: ", LOCATION_FILE (loc),
kono
parents:
diff changeset
352 LOCATION_LINE (loc), LOCATION_COLUMN (loc));
kono
parents:
diff changeset
353 else if (current_function_decl)
kono
parents:
diff changeset
354 fprintf (dfile, "%s:%d:%d: note: ",
kono
parents:
diff changeset
355 DECL_SOURCE_FILE (current_function_decl),
kono
parents:
diff changeset
356 DECL_SOURCE_LINE (current_function_decl),
kono
parents:
diff changeset
357 DECL_SOURCE_COLUMN (current_function_decl));
kono
parents:
diff changeset
358 }
kono
parents:
diff changeset
359 }
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 /* Dump gimple statement GS with SPC indentation spaces and
kono
parents:
diff changeset
362 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 void
kono
parents:
diff changeset
365 dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
kono
parents:
diff changeset
366 gimple *gs, int spc)
kono
parents:
diff changeset
367 {
kono
parents:
diff changeset
368 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
369 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
372 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
373 }
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 /* Similar to dump_gimple_stmt, except additionally print source location. */
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 void
kono
parents:
diff changeset
378 dump_gimple_stmt_loc (dump_flags_t dump_kind, source_location loc,
kono
parents:
diff changeset
379 dump_flags_t extra_dump_flags, gimple *gs, int spc)
kono
parents:
diff changeset
380 {
kono
parents:
diff changeset
381 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
382 {
kono
parents:
diff changeset
383 dump_loc (dump_kind, dump_file, loc);
kono
parents:
diff changeset
384 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
385 }
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
388 {
kono
parents:
diff changeset
389 dump_loc (dump_kind, alt_dump_file, loc);
kono
parents:
diff changeset
390 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
391 }
kono
parents:
diff changeset
392 }
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
kono
parents:
diff changeset
395 DUMP_KIND is enabled. */
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 void
kono
parents:
diff changeset
398 dump_generic_expr (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
kono
parents:
diff changeset
399 tree t)
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
402 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
405 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
406 }
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 /* Similar to dump_generic_expr, except additionally print the source
kono
parents:
diff changeset
410 location. */
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 void
kono
parents:
diff changeset
413 dump_generic_expr_loc (int dump_kind, source_location loc,
kono
parents:
diff changeset
414 dump_flags_t extra_dump_flags, tree t)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
417 {
kono
parents:
diff changeset
418 dump_loc (dump_kind, dump_file, loc);
kono
parents:
diff changeset
419 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
420 }
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 dump_loc (dump_kind, alt_dump_file, loc);
kono
parents:
diff changeset
425 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427 }
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 /* Output a formatted message using FORMAT on appropriate dump streams. */
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 void
kono
parents:
diff changeset
432 dump_printf (dump_flags_t dump_kind, const char *format, ...)
kono
parents:
diff changeset
433 {
kono
parents:
diff changeset
434 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
435 {
kono
parents:
diff changeset
436 va_list ap;
kono
parents:
diff changeset
437 va_start (ap, format);
kono
parents:
diff changeset
438 vfprintf (dump_file, format, ap);
kono
parents:
diff changeset
439 va_end (ap);
kono
parents:
diff changeset
440 }
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
443 {
kono
parents:
diff changeset
444 va_list ap;
kono
parents:
diff changeset
445 va_start (ap, format);
kono
parents:
diff changeset
446 vfprintf (alt_dump_file, format, ap);
kono
parents:
diff changeset
447 va_end (ap);
kono
parents:
diff changeset
448 }
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 /* Similar to dump_printf, except source location is also printed. */
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 void
kono
parents:
diff changeset
454 dump_printf_loc (dump_flags_t dump_kind, source_location loc,
kono
parents:
diff changeset
455 const char *format, ...)
kono
parents:
diff changeset
456 {
kono
parents:
diff changeset
457 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
458 {
kono
parents:
diff changeset
459 va_list ap;
kono
parents:
diff changeset
460 dump_loc (dump_kind, dump_file, loc);
kono
parents:
diff changeset
461 va_start (ap, format);
kono
parents:
diff changeset
462 vfprintf (dump_file, format, ap);
kono
parents:
diff changeset
463 va_end (ap);
kono
parents:
diff changeset
464 }
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
467 {
kono
parents:
diff changeset
468 va_list ap;
kono
parents:
diff changeset
469 dump_loc (dump_kind, alt_dump_file, loc);
kono
parents:
diff changeset
470 va_start (ap, format);
kono
parents:
diff changeset
471 vfprintf (alt_dump_file, format, ap);
kono
parents:
diff changeset
472 va_end (ap);
kono
parents:
diff changeset
473 }
kono
parents:
diff changeset
474 }
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 /* Start a dump for PHASE. Store user-supplied dump flags in
kono
parents:
diff changeset
477 *FLAG_PTR. Return the number of streams opened. Set globals
kono
parents:
diff changeset
478 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
kono
parents:
diff changeset
479 set dump_flags appropriately for both pass dump stream and
kono
parents:
diff changeset
480 -fopt-info stream. */
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 int
kono
parents:
diff changeset
483 gcc::dump_manager::
kono
parents:
diff changeset
484 dump_start (int phase, dump_flags_t *flag_ptr)
kono
parents:
diff changeset
485 {
kono
parents:
diff changeset
486 int count = 0;
kono
parents:
diff changeset
487 char *name;
kono
parents:
diff changeset
488 struct dump_file_info *dfi;
kono
parents:
diff changeset
489 FILE *stream;
kono
parents:
diff changeset
490 if (phase == TDI_none || !dump_phase_enabled_p (phase))
kono
parents:
diff changeset
491 return 0;
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
494 name = get_dump_file_name (phase);
kono
parents:
diff changeset
495 if (name)
kono
parents:
diff changeset
496 {
kono
parents:
diff changeset
497 stream = strcmp ("stderr", name) == 0
kono
parents:
diff changeset
498 ? stderr
kono
parents:
diff changeset
499 : strcmp ("stdout", name) == 0
kono
parents:
diff changeset
500 ? stdout
kono
parents:
diff changeset
501 : fopen (name, dfi->pstate < 0 ? "w" : "a");
kono
parents:
diff changeset
502 if (!stream)
kono
parents:
diff changeset
503 error ("could not open dump file %qs: %m", name);
kono
parents:
diff changeset
504 else
kono
parents:
diff changeset
505 {
kono
parents:
diff changeset
506 dfi->pstate = 1;
kono
parents:
diff changeset
507 count++;
kono
parents:
diff changeset
508 }
kono
parents:
diff changeset
509 free (name);
kono
parents:
diff changeset
510 dfi->pstream = stream;
kono
parents:
diff changeset
511 dump_file = dfi->pstream;
kono
parents:
diff changeset
512 /* Initialize current dump flags. */
kono
parents:
diff changeset
513 pflags = dfi->pflags;
kono
parents:
diff changeset
514 }
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 stream = dump_open_alternate_stream (dfi);
kono
parents:
diff changeset
517 if (stream)
kono
parents:
diff changeset
518 {
kono
parents:
diff changeset
519 dfi->alt_stream = stream;
kono
parents:
diff changeset
520 count++;
kono
parents:
diff changeset
521 alt_dump_file = dfi->alt_stream;
kono
parents:
diff changeset
522 /* Initialize current -fopt-info flags. */
kono
parents:
diff changeset
523 alt_flags = dfi->alt_flags;
kono
parents:
diff changeset
524 }
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 if (flag_ptr)
kono
parents:
diff changeset
527 *flag_ptr = dfi->pflags;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 return count;
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 /* Finish a tree dump for PHASE and close associated dump streams. Also
kono
parents:
diff changeset
533 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 void
kono
parents:
diff changeset
536 gcc::dump_manager::
kono
parents:
diff changeset
537 dump_finish (int phase)
kono
parents:
diff changeset
538 {
kono
parents:
diff changeset
539 struct dump_file_info *dfi;
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 if (phase < 0)
kono
parents:
diff changeset
542 return;
kono
parents:
diff changeset
543 dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
544 if (dfi->pstream && (!dfi->pfilename
kono
parents:
diff changeset
545 || (strcmp ("stderr", dfi->pfilename) != 0
kono
parents:
diff changeset
546 && strcmp ("stdout", dfi->pfilename) != 0)))
kono
parents:
diff changeset
547 fclose (dfi->pstream);
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 if (dfi->alt_stream && strcmp ("stderr", dfi->alt_filename) != 0
kono
parents:
diff changeset
550 && strcmp ("stdout", dfi->alt_filename) != 0)
kono
parents:
diff changeset
551 fclose (dfi->alt_stream);
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 dfi->alt_stream = NULL;
kono
parents:
diff changeset
554 dfi->pstream = NULL;
kono
parents:
diff changeset
555 dump_file = NULL;
kono
parents:
diff changeset
556 alt_dump_file = NULL;
kono
parents:
diff changeset
557 dump_flags = TDI_none;
kono
parents:
diff changeset
558 alt_flags = 0;
kono
parents:
diff changeset
559 pflags = 0;
kono
parents:
diff changeset
560 }
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 /* Begin a tree dump for PHASE. Stores any user supplied flag in
kono
parents:
diff changeset
563 *FLAG_PTR and returns a stream to write to. If the dump is not
kono
parents:
diff changeset
564 enabled, returns NULL.
kono
parents:
diff changeset
565 Multiple calls will reopen and append to the dump file. */
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 FILE *
kono
parents:
diff changeset
568 dump_begin (int phase, dump_flags_t *flag_ptr)
kono
parents:
diff changeset
569 {
kono
parents:
diff changeset
570 return g->get_dumps ()->dump_begin (phase, flag_ptr);
kono
parents:
diff changeset
571 }
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 FILE *
kono
parents:
diff changeset
574 gcc::dump_manager::
kono
parents:
diff changeset
575 dump_begin (int phase, dump_flags_t *flag_ptr)
kono
parents:
diff changeset
576 {
kono
parents:
diff changeset
577 char *name;
kono
parents:
diff changeset
578 struct dump_file_info *dfi;
kono
parents:
diff changeset
579 FILE *stream;
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 if (phase == TDI_none || !dump_phase_enabled_p (phase))
kono
parents:
diff changeset
582 return NULL;
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 name = get_dump_file_name (phase);
kono
parents:
diff changeset
585 if (!name)
kono
parents:
diff changeset
586 return NULL;
kono
parents:
diff changeset
587 dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 stream = strcmp ("stderr", name) == 0
kono
parents:
diff changeset
590 ? stderr
kono
parents:
diff changeset
591 : strcmp ("stdout", name) == 0
kono
parents:
diff changeset
592 ? stdout
kono
parents:
diff changeset
593 : fopen (name, dfi->pstate < 0 ? "w" : "a");
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 if (!stream)
kono
parents:
diff changeset
596 error ("could not open dump file %qs: %m", name);
kono
parents:
diff changeset
597 else
kono
parents:
diff changeset
598 dfi->pstate = 1;
kono
parents:
diff changeset
599 free (name);
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 if (flag_ptr)
kono
parents:
diff changeset
602 *flag_ptr = dfi->pflags;
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 /* Initialize current flags */
kono
parents:
diff changeset
605 pflags = dfi->pflags;
kono
parents:
diff changeset
606 return stream;
kono
parents:
diff changeset
607 }
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 /* Returns nonzero if dump PHASE is enabled for at least one stream.
kono
parents:
diff changeset
610 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
kono
parents:
diff changeset
611 any phase. */
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 int
kono
parents:
diff changeset
614 gcc::dump_manager::
kono
parents:
diff changeset
615 dump_phase_enabled_p (int phase) const
kono
parents:
diff changeset
616 {
kono
parents:
diff changeset
617 if (phase == TDI_tree_all)
kono
parents:
diff changeset
618 {
kono
parents:
diff changeset
619 size_t i;
kono
parents:
diff changeset
620 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
kono
parents:
diff changeset
621 if (dump_files[i].pstate || dump_files[i].alt_state)
kono
parents:
diff changeset
622 return 1;
kono
parents:
diff changeset
623 for (i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
624 if (m_extra_dump_files[i].pstate || m_extra_dump_files[i].alt_state)
kono
parents:
diff changeset
625 return 1;
kono
parents:
diff changeset
626 return 0;
kono
parents:
diff changeset
627 }
kono
parents:
diff changeset
628 else
kono
parents:
diff changeset
629 {
kono
parents:
diff changeset
630 struct dump_file_info *dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
631 return dfi->pstate || dfi->alt_state;
kono
parents:
diff changeset
632 }
kono
parents:
diff changeset
633 }
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 /* Returns nonzero if tree dump PHASE has been initialized. */
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 int
kono
parents:
diff changeset
638 gcc::dump_manager::
kono
parents:
diff changeset
639 dump_initialized_p (int phase) const
kono
parents:
diff changeset
640 {
kono
parents:
diff changeset
641 struct dump_file_info *dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
642 return dfi->pstate > 0 || dfi->alt_state > 0;
kono
parents:
diff changeset
643 }
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 /* Returns the switch name of PHASE. */
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 const char *
kono
parents:
diff changeset
648 dump_flag_name (int phase)
kono
parents:
diff changeset
649 {
kono
parents:
diff changeset
650 return g->get_dumps ()->dump_flag_name (phase);
kono
parents:
diff changeset
651 }
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 const char *
kono
parents:
diff changeset
654 gcc::dump_manager::
kono
parents:
diff changeset
655 dump_flag_name (int phase) const
kono
parents:
diff changeset
656 {
kono
parents:
diff changeset
657 struct dump_file_info *dfi = get_dump_file_info (phase);
kono
parents:
diff changeset
658 return dfi->swtch;
kono
parents:
diff changeset
659 }
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 /* Finish a tree dump for PHASE. STREAM is the stream created by
kono
parents:
diff changeset
662 dump_begin. */
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 void
kono
parents:
diff changeset
665 dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream)
kono
parents:
diff changeset
666 {
kono
parents:
diff changeset
667 if (stream != stderr && stream != stdout)
kono
parents:
diff changeset
668 fclose (stream);
kono
parents:
diff changeset
669 }
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
kono
parents:
diff changeset
672 enabled tree dumps. */
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 int
kono
parents:
diff changeset
675 gcc::dump_manager::
kono
parents:
diff changeset
676 dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename)
kono
parents:
diff changeset
677 {
kono
parents:
diff changeset
678 int n = 0;
kono
parents:
diff changeset
679 size_t i;
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
kono
parents:
diff changeset
682 {
kono
parents:
diff changeset
683 if ((dump_files[i].dkind == dkind))
kono
parents:
diff changeset
684 {
kono
parents:
diff changeset
685 const char *old_filename = dump_files[i].pfilename;
kono
parents:
diff changeset
686 dump_files[i].pstate = -1;
kono
parents:
diff changeset
687 dump_files[i].pflags |= flags;
kono
parents:
diff changeset
688 n++;
kono
parents:
diff changeset
689 /* Override the existing filename. */
kono
parents:
diff changeset
690 if (filename)
kono
parents:
diff changeset
691 {
kono
parents:
diff changeset
692 dump_files[i].pfilename = xstrdup (filename);
kono
parents:
diff changeset
693 /* Since it is a command-line provided file, which is
kono
parents:
diff changeset
694 common to all the phases, use it in append mode. */
kono
parents:
diff changeset
695 dump_files[i].pstate = 1;
kono
parents:
diff changeset
696 }
kono
parents:
diff changeset
697 if (old_filename && filename != old_filename)
kono
parents:
diff changeset
698 free (CONST_CAST (char *, old_filename));
kono
parents:
diff changeset
699 }
kono
parents:
diff changeset
700 }
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 for (i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
703 {
kono
parents:
diff changeset
704 if ((m_extra_dump_files[i].dkind == dkind))
kono
parents:
diff changeset
705 {
kono
parents:
diff changeset
706 const char *old_filename = m_extra_dump_files[i].pfilename;
kono
parents:
diff changeset
707 m_extra_dump_files[i].pstate = -1;
kono
parents:
diff changeset
708 m_extra_dump_files[i].pflags |= flags;
kono
parents:
diff changeset
709 n++;
kono
parents:
diff changeset
710 /* Override the existing filename. */
kono
parents:
diff changeset
711 if (filename)
kono
parents:
diff changeset
712 {
kono
parents:
diff changeset
713 m_extra_dump_files[i].pfilename = xstrdup (filename);
kono
parents:
diff changeset
714 /* Since it is a command-line provided file, which is
kono
parents:
diff changeset
715 common to all the phases, use it in append mode. */
kono
parents:
diff changeset
716 m_extra_dump_files[i].pstate = 1;
kono
parents:
diff changeset
717 }
kono
parents:
diff changeset
718 if (old_filename && filename != old_filename)
kono
parents:
diff changeset
719 free (CONST_CAST (char *, old_filename));
kono
parents:
diff changeset
720 }
kono
parents:
diff changeset
721 }
kono
parents:
diff changeset
722
kono
parents:
diff changeset
723 return n;
kono
parents:
diff changeset
724 }
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
kono
parents:
diff changeset
727 Enable dumps with FLAGS on FILENAME. Return the number of enabled
kono
parents:
diff changeset
728 dumps. */
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 int
kono
parents:
diff changeset
731 gcc::dump_manager::
kono
parents:
diff changeset
732 opt_info_enable_passes (int optgroup_flags, dump_flags_t flags,
kono
parents:
diff changeset
733 const char *filename)
kono
parents:
diff changeset
734 {
kono
parents:
diff changeset
735 int n = 0;
kono
parents:
diff changeset
736 size_t i;
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
kono
parents:
diff changeset
739 {
kono
parents:
diff changeset
740 if ((dump_files[i].optgroup_flags & optgroup_flags))
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 const char *old_filename = dump_files[i].alt_filename;
kono
parents:
diff changeset
743 /* Since this file is shared among different passes, it
kono
parents:
diff changeset
744 should be opened in append mode. */
kono
parents:
diff changeset
745 dump_files[i].alt_state = 1;
kono
parents:
diff changeset
746 dump_files[i].alt_flags |= flags;
kono
parents:
diff changeset
747 n++;
kono
parents:
diff changeset
748 /* Override the existing filename. */
kono
parents:
diff changeset
749 if (filename)
kono
parents:
diff changeset
750 dump_files[i].alt_filename = xstrdup (filename);
kono
parents:
diff changeset
751 if (old_filename && filename != old_filename)
kono
parents:
diff changeset
752 free (CONST_CAST (char *, old_filename));
kono
parents:
diff changeset
753 }
kono
parents:
diff changeset
754 }
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 for (i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
757 {
kono
parents:
diff changeset
758 if ((m_extra_dump_files[i].optgroup_flags & optgroup_flags))
kono
parents:
diff changeset
759 {
kono
parents:
diff changeset
760 const char *old_filename = m_extra_dump_files[i].alt_filename;
kono
parents:
diff changeset
761 /* Since this file is shared among different passes, it
kono
parents:
diff changeset
762 should be opened in append mode. */
kono
parents:
diff changeset
763 m_extra_dump_files[i].alt_state = 1;
kono
parents:
diff changeset
764 m_extra_dump_files[i].alt_flags |= flags;
kono
parents:
diff changeset
765 n++;
kono
parents:
diff changeset
766 /* Override the existing filename. */
kono
parents:
diff changeset
767 if (filename)
kono
parents:
diff changeset
768 m_extra_dump_files[i].alt_filename = xstrdup (filename);
kono
parents:
diff changeset
769 if (old_filename && filename != old_filename)
kono
parents:
diff changeset
770 free (CONST_CAST (char *, old_filename));
kono
parents:
diff changeset
771 }
kono
parents:
diff changeset
772 }
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 return n;
kono
parents:
diff changeset
775 }
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
kono
parents:
diff changeset
778 relevant details in the dump_files array. */
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 int
kono
parents:
diff changeset
781 gcc::dump_manager::
kono
parents:
diff changeset
782 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
kono
parents:
diff changeset
783 {
kono
parents:
diff changeset
784 const char *option_value;
kono
parents:
diff changeset
785 const char *ptr;
kono
parents:
diff changeset
786 dump_flags_t flags;
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 if (doglob && !dfi->glob)
kono
parents:
diff changeset
789 return 0;
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
kono
parents:
diff changeset
792 if (!option_value)
kono
parents:
diff changeset
793 return 0;
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 if (*option_value && *option_value != '-' && *option_value != '=')
kono
parents:
diff changeset
796 return 0;
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 ptr = option_value;
kono
parents:
diff changeset
799 flags = 0;
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 while (*ptr)
kono
parents:
diff changeset
802 {
kono
parents:
diff changeset
803 const struct dump_option_value_info *option_ptr;
kono
parents:
diff changeset
804 const char *end_ptr;
kono
parents:
diff changeset
805 const char *eq_ptr;
kono
parents:
diff changeset
806 unsigned length;
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 while (*ptr == '-')
kono
parents:
diff changeset
809 ptr++;
kono
parents:
diff changeset
810 end_ptr = strchr (ptr, '-');
kono
parents:
diff changeset
811 eq_ptr = strchr (ptr, '=');
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 if (eq_ptr && !end_ptr)
kono
parents:
diff changeset
814 end_ptr = eq_ptr;
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 if (!end_ptr)
kono
parents:
diff changeset
817 end_ptr = ptr + strlen (ptr);
kono
parents:
diff changeset
818 length = end_ptr - ptr;
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 for (option_ptr = dump_options; option_ptr->name; option_ptr++)
kono
parents:
diff changeset
821 if (strlen (option_ptr->name) == length
kono
parents:
diff changeset
822 && !memcmp (option_ptr->name, ptr, length))
kono
parents:
diff changeset
823 {
kono
parents:
diff changeset
824 flags |= option_ptr->value;
kono
parents:
diff changeset
825 goto found;
kono
parents:
diff changeset
826 }
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 if (*ptr == '=')
kono
parents:
diff changeset
829 {
kono
parents:
diff changeset
830 /* Interpret rest of the argument as a dump filename. This
kono
parents:
diff changeset
831 filename overrides other command line filenames. */
kono
parents:
diff changeset
832 if (dfi->pfilename)
kono
parents:
diff changeset
833 free (CONST_CAST (char *, dfi->pfilename));
kono
parents:
diff changeset
834 dfi->pfilename = xstrdup (ptr + 1);
kono
parents:
diff changeset
835 break;
kono
parents:
diff changeset
836 }
kono
parents:
diff changeset
837 else
kono
parents:
diff changeset
838 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
kono
parents:
diff changeset
839 length, ptr, dfi->swtch);
kono
parents:
diff changeset
840 found:;
kono
parents:
diff changeset
841 ptr = end_ptr;
kono
parents:
diff changeset
842 }
kono
parents:
diff changeset
843
kono
parents:
diff changeset
844 dfi->pstate = -1;
kono
parents:
diff changeset
845 dfi->pflags |= flags;
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
kono
parents:
diff changeset
848 known dumps. */
kono
parents:
diff changeset
849 if (dfi->suffix == NULL)
kono
parents:
diff changeset
850 dump_enable_all (dfi->dkind, dfi->pflags, dfi->pfilename);
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 return 1;
kono
parents:
diff changeset
853 }
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 int
kono
parents:
diff changeset
856 gcc::dump_manager::
kono
parents:
diff changeset
857 dump_switch_p (const char *arg)
kono
parents:
diff changeset
858 {
kono
parents:
diff changeset
859 size_t i;
kono
parents:
diff changeset
860 int any = 0;
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 for (i = TDI_none + 1; i != TDI_end; i++)
kono
parents:
diff changeset
863 any |= dump_switch_p_1 (arg, &dump_files[i], false);
kono
parents:
diff changeset
864
kono
parents:
diff changeset
865 /* Don't glob if we got a hit already */
kono
parents:
diff changeset
866 if (!any)
kono
parents:
diff changeset
867 for (i = TDI_none + 1; i != TDI_end; i++)
kono
parents:
diff changeset
868 any |= dump_switch_p_1 (arg, &dump_files[i], true);
kono
parents:
diff changeset
869
kono
parents:
diff changeset
870 for (i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
871 any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], false);
kono
parents:
diff changeset
872
kono
parents:
diff changeset
873 if (!any)
kono
parents:
diff changeset
874 for (i = 0; i < m_extra_dump_files_in_use; i++)
kono
parents:
diff changeset
875 any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 return any;
kono
parents:
diff changeset
879 }
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
kono
parents:
diff changeset
882 and filename. Return non-zero if it is a recognized switch. */
kono
parents:
diff changeset
883
kono
parents:
diff changeset
884 static int
kono
parents:
diff changeset
885 opt_info_switch_p_1 (const char *arg, dump_flags_t *flags, int *optgroup_flags,
kono
parents:
diff changeset
886 char **filename)
kono
parents:
diff changeset
887 {
kono
parents:
diff changeset
888 const char *option_value;
kono
parents:
diff changeset
889 const char *ptr;
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 option_value = arg;
kono
parents:
diff changeset
892 ptr = option_value;
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 *filename = NULL;
kono
parents:
diff changeset
895 *flags = 0;
kono
parents:
diff changeset
896 *optgroup_flags = 0;
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 if (!ptr)
kono
parents:
diff changeset
899 return 1; /* Handle '-fopt-info' without any additional options. */
kono
parents:
diff changeset
900
kono
parents:
diff changeset
901 while (*ptr)
kono
parents:
diff changeset
902 {
kono
parents:
diff changeset
903 const struct dump_option_value_info *option_ptr;
kono
parents:
diff changeset
904 const char *end_ptr;
kono
parents:
diff changeset
905 const char *eq_ptr;
kono
parents:
diff changeset
906 unsigned length;
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 while (*ptr == '-')
kono
parents:
diff changeset
909 ptr++;
kono
parents:
diff changeset
910 end_ptr = strchr (ptr, '-');
kono
parents:
diff changeset
911 eq_ptr = strchr (ptr, '=');
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 if (eq_ptr && !end_ptr)
kono
parents:
diff changeset
914 end_ptr = eq_ptr;
kono
parents:
diff changeset
915
kono
parents:
diff changeset
916 if (!end_ptr)
kono
parents:
diff changeset
917 end_ptr = ptr + strlen (ptr);
kono
parents:
diff changeset
918 length = end_ptr - ptr;
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 for (option_ptr = optinfo_verbosity_options; option_ptr->name;
kono
parents:
diff changeset
921 option_ptr++)
kono
parents:
diff changeset
922 if (strlen (option_ptr->name) == length
kono
parents:
diff changeset
923 && !memcmp (option_ptr->name, ptr, length))
kono
parents:
diff changeset
924 {
kono
parents:
diff changeset
925 *flags |= option_ptr->value;
kono
parents:
diff changeset
926 goto found;
kono
parents:
diff changeset
927 }
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 for (option_ptr = optgroup_options; option_ptr->name; option_ptr++)
kono
parents:
diff changeset
930 if (strlen (option_ptr->name) == length
kono
parents:
diff changeset
931 && !memcmp (option_ptr->name, ptr, length))
kono
parents:
diff changeset
932 {
kono
parents:
diff changeset
933 *optgroup_flags |= option_ptr->value;
kono
parents:
diff changeset
934 goto found;
kono
parents:
diff changeset
935 }
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 if (*ptr == '=')
kono
parents:
diff changeset
938 {
kono
parents:
diff changeset
939 /* Interpret rest of the argument as a dump filename. This
kono
parents:
diff changeset
940 filename overrides other command line filenames. */
kono
parents:
diff changeset
941 *filename = xstrdup (ptr + 1);
kono
parents:
diff changeset
942 break;
kono
parents:
diff changeset
943 }
kono
parents:
diff changeset
944 else
kono
parents:
diff changeset
945 {
kono
parents:
diff changeset
946 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
kono
parents:
diff changeset
947 length, ptr, arg);
kono
parents:
diff changeset
948 return 0;
kono
parents:
diff changeset
949 }
kono
parents:
diff changeset
950 found:;
kono
parents:
diff changeset
951 ptr = end_ptr;
kono
parents:
diff changeset
952 }
kono
parents:
diff changeset
953
kono
parents:
diff changeset
954 return 1;
kono
parents:
diff changeset
955 }
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 /* Return non-zero if ARG is a recognized switch for
kono
parents:
diff changeset
958 -fopt-info. Return zero otherwise. */
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 int
kono
parents:
diff changeset
961 opt_info_switch_p (const char *arg)
kono
parents:
diff changeset
962 {
kono
parents:
diff changeset
963 dump_flags_t flags;
kono
parents:
diff changeset
964 int optgroup_flags;
kono
parents:
diff changeset
965 char *filename;
kono
parents:
diff changeset
966 static char *file_seen = NULL;
kono
parents:
diff changeset
967 gcc::dump_manager *dumps = g->get_dumps ();
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 if (!opt_info_switch_p_1 (arg, &flags, &optgroup_flags, &filename))
kono
parents:
diff changeset
970 return 0;
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 if (!filename)
kono
parents:
diff changeset
973 filename = xstrdup ("stderr");
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 /* Bail out if a different filename has been specified. */
kono
parents:
diff changeset
976 if (file_seen && strcmp (file_seen, filename))
kono
parents:
diff changeset
977 {
kono
parents:
diff changeset
978 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
kono
parents:
diff changeset
979 arg);
kono
parents:
diff changeset
980 return 1;
kono
parents:
diff changeset
981 }
kono
parents:
diff changeset
982
kono
parents:
diff changeset
983 file_seen = xstrdup (filename);
kono
parents:
diff changeset
984 if (!flags)
kono
parents:
diff changeset
985 flags = MSG_OPTIMIZED_LOCATIONS;
kono
parents:
diff changeset
986 if (!optgroup_flags)
kono
parents:
diff changeset
987 optgroup_flags = OPTGROUP_ALL;
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 return dumps->opt_info_enable_passes (optgroup_flags, flags, filename);
kono
parents:
diff changeset
990 }
kono
parents:
diff changeset
991
kono
parents:
diff changeset
992 /* Print basic block on the dump streams. */
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 void
kono
parents:
diff changeset
995 dump_basic_block (int dump_kind, basic_block bb, int indent)
kono
parents:
diff changeset
996 {
kono
parents:
diff changeset
997 if (dump_file && (dump_kind & pflags))
kono
parents:
diff changeset
998 dump_bb (dump_file, bb, indent, TDF_DETAILS);
kono
parents:
diff changeset
999 if (alt_dump_file && (dump_kind & alt_flags))
kono
parents:
diff changeset
1000 dump_bb (alt_dump_file, bb, indent, TDF_DETAILS);
kono
parents:
diff changeset
1001 }
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 /* Dump FUNCTION_DECL FN as tree dump PHASE. */
kono
parents:
diff changeset
1004
kono
parents:
diff changeset
1005 void
kono
parents:
diff changeset
1006 dump_function (int phase, tree fn)
kono
parents:
diff changeset
1007 {
kono
parents:
diff changeset
1008 FILE *stream;
kono
parents:
diff changeset
1009 dump_flags_t flags;
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 stream = dump_begin (phase, &flags);
kono
parents:
diff changeset
1012 if (stream)
kono
parents:
diff changeset
1013 {
kono
parents:
diff changeset
1014 dump_function_to_file (fn, stream, flags);
kono
parents:
diff changeset
1015 dump_end (phase, stream);
kono
parents:
diff changeset
1016 }
kono
parents:
diff changeset
1017 }
kono
parents:
diff changeset
1018
kono
parents:
diff changeset
1019 /* Print information from the combine pass on dump_file. */
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 void
kono
parents:
diff changeset
1022 print_combine_total_stats (void)
kono
parents:
diff changeset
1023 {
kono
parents:
diff changeset
1024 if (dump_file)
kono
parents:
diff changeset
1025 dump_combine_total_stats (dump_file);
kono
parents:
diff changeset
1026 }
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 /* Enable RTL dump for all the RTL passes. */
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 bool
kono
parents:
diff changeset
1031 enable_rtl_dump_file (void)
kono
parents:
diff changeset
1032 {
kono
parents:
diff changeset
1033 gcc::dump_manager *dumps = g->get_dumps ();
kono
parents:
diff changeset
1034 int num_enabled =
kono
parents:
diff changeset
1035 dumps->dump_enable_all (DK_rtl, dump_flags_t (TDF_DETAILS) | TDF_BLOCKS,
kono
parents:
diff changeset
1036 NULL);
kono
parents:
diff changeset
1037 return num_enabled > 0;
kono
parents:
diff changeset
1038 }