Initial import of asan from the Google branch
[official-gcc.git] / gcc / dumpfile.c
blob55543cc158ab95306aa0bdeb21665c7af80fefeb
1 /* Dump infrastructure for optimizations and intermediate representation.
2 Copyright (C) 2012 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "diagnostic-core.h"
24 #include "dumpfile.h"
25 #include "gimple-pretty-print.h"
26 #include "tree.h"
28 /* If non-NULL, return one past-the-end of the matching SUBPART of
29 the WHOLE string. */
30 #define skip_leading_substring(whole, part) \
31 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
33 static int pflags; /* current dump_flags */
34 static int alt_flags; /* current opt_info flags */
36 static void dump_loc (int, FILE *, source_location);
37 static int dump_phase_enabled_p (int);
38 static FILE *dump_open_alternate_stream (struct dump_file_info *);
40 /* These are currently used for communicating between passes.
41 However, instead of accessing them directly, the passes can use
42 dump_printf () for dumps. */
43 FILE *dump_file = NULL;
44 FILE *alt_dump_file = NULL;
45 const char *dump_file_name;
46 int dump_flags;
48 /* Table of tree dump switches. This must be consistent with the
49 TREE_DUMP_INDEX enumeration in dumpfile.h. */
50 static struct dump_file_info dump_files[TDI_end] =
52 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0},
53 {".cgraph", "ipa-cgraph", NULL, NULL, NULL, NULL, NULL, TDF_IPA,
54 0, 0, 0, 0, 0},
55 {".tu", "translation-unit", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
56 0, 0, 0, 0, 1},
57 {".class", "class-hierarchy", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
58 0, 0, 0, 0, 2},
59 {".original", "tree-original", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
60 0, 0, 0, 0, 3},
61 {".gimple", "tree-gimple", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
62 0, 0, 0, 0, 4},
63 {".nested", "tree-nested", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
64 0, 0, 0, 0, 5},
65 {".vcg", "tree-vcg", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
66 0, 0, 0, 0, 6},
67 #define FIRST_AUTO_NUMBERED_DUMP 7
69 {NULL, "tree-all", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
70 0, 0, 0, 0, 0},
71 {NULL, "rtl-all", NULL, NULL, NULL, NULL, NULL, TDF_RTL,
72 0, 0, 0, 0, 0},
73 {NULL, "ipa-all", NULL, NULL, NULL, NULL, NULL, TDF_IPA,
74 0, 0, 0, 0, 0},
77 /* Dynamically registered tree dump files and switches. */
78 static struct dump_file_info *extra_dump_files;
79 static size_t extra_dump_files_in_use;
80 static size_t extra_dump_files_alloced;
82 /* Define a name->number mapping for a dump flag value. */
83 struct dump_option_value_info
85 const char *const name; /* the name of the value */
86 const int value; /* the value of the name */
89 /* Table of dump options. This must be consistent with the TDF_* flags
90 in dumpfile.h and opt_info_options below. */
91 static const struct dump_option_value_info dump_options[] =
93 {"address", TDF_ADDRESS},
94 {"asmname", TDF_ASMNAME},
95 {"slim", TDF_SLIM},
96 {"raw", TDF_RAW},
97 {"graph", TDF_GRAPH},
98 {"details", (TDF_DETAILS | MSG_OPTIMIZED_LOCATIONS
99 | MSG_MISSED_OPTIMIZATION
100 | MSG_NOTE)},
101 {"cselib", TDF_CSELIB},
102 {"stats", TDF_STATS},
103 {"blocks", TDF_BLOCKS},
104 {"vops", TDF_VOPS},
105 {"lineno", TDF_LINENO},
106 {"uid", TDF_UID},
107 {"stmtaddr", TDF_STMTADDR},
108 {"memsyms", TDF_MEMSYMS},
109 {"verbose", TDF_VERBOSE},
110 {"eh", TDF_EH},
111 {"alias", TDF_ALIAS},
112 {"nouid", TDF_NOUID},
113 {"enumerate_locals", TDF_ENUMERATE_LOCALS},
114 {"scev", TDF_SCEV},
115 {"all", ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_TREE | TDF_RTL | TDF_IPA
116 | TDF_STMTADDR | TDF_GRAPH | TDF_DIAGNOSTIC | TDF_VERBOSE
117 | TDF_RHS_ONLY | TDF_NOUID | TDF_ENUMERATE_LOCALS | TDF_SCEV)},
118 {NULL, 0}
121 /* A subset of the dump_options table which is used for -fopt-info
122 types. This must be consistent with the MSG_* flags in dumpfile.h.
124 static const struct dump_option_value_info optinfo_verbosity_options[] =
126 {"optimized", MSG_OPTIMIZED_LOCATIONS},
127 {"missed", MSG_MISSED_OPTIMIZATION},
128 {"note", MSG_NOTE},
129 {"all", MSG_ALL},
130 {NULL, 0}
133 /* Flags used for -fopt-info groups. */
134 static const struct dump_option_value_info optgroup_options[] =
136 {"ipa", OPTGROUP_IPA},
137 {"loop", OPTGROUP_LOOP},
138 {"inline", OPTGROUP_INLINE},
139 {"vec", OPTGROUP_VEC},
140 {"optall", OPTGROUP_ALL},
141 {NULL, 0}
144 unsigned int
145 dump_register (const char *suffix, const char *swtch, const char *glob,
146 int flags, int optgroup_flags)
148 static int next_dump = FIRST_AUTO_NUMBERED_DUMP;
149 int num = next_dump++;
151 size_t count = extra_dump_files_in_use++;
153 if (count >= extra_dump_files_alloced)
155 if (extra_dump_files_alloced == 0)
156 extra_dump_files_alloced = 32;
157 else
158 extra_dump_files_alloced *= 2;
159 extra_dump_files = XRESIZEVEC (struct dump_file_info,
160 extra_dump_files,
161 extra_dump_files_alloced);
164 memset (&extra_dump_files[count], 0, sizeof (struct dump_file_info));
165 extra_dump_files[count].suffix = suffix;
166 extra_dump_files[count].swtch = swtch;
167 extra_dump_files[count].glob = glob;
168 extra_dump_files[count].pflags = flags;
169 extra_dump_files[count].optgroup_flags = optgroup_flags;
170 extra_dump_files[count].num = num;
172 return count + TDI_end;
176 /* Return the dump_file_info for the given phase. */
178 struct dump_file_info *
179 get_dump_file_info (int phase)
181 if (phase < TDI_end)
182 return &dump_files[phase];
183 else if ((size_t) (phase - TDI_end) >= extra_dump_files_in_use)
184 return NULL;
185 else
186 return extra_dump_files + (phase - TDI_end);
190 /* Return the name of the dump file for the given phase.
191 If the dump is not enabled, returns NULL. */
193 char *
194 get_dump_file_name (int phase)
196 char dump_id[10];
197 struct dump_file_info *dfi;
199 if (phase == TDI_none)
200 return NULL;
202 dfi = get_dump_file_info (phase);
203 if (dfi->pstate == 0)
204 return NULL;
206 /* If available, use the command line dump filename. */
207 if (dfi->pfilename)
208 return xstrdup (dfi->pfilename);
210 if (dfi->num < 0)
211 dump_id[0] = '\0';
212 else
214 char suffix;
215 if (dfi->pflags & TDF_TREE)
216 suffix = 't';
217 else if (dfi->pflags & TDF_IPA)
218 suffix = 'i';
219 else
220 suffix = 'r';
222 if (snprintf (dump_id, sizeof (dump_id), ".%03d%c", dfi->num, suffix) < 0)
223 dump_id[0] = '\0';
226 return concat (dump_base_name, dump_id, dfi->suffix, NULL);
229 /* For a given DFI, open an alternate dump filename (which could also
230 be a standard stream such as stdout/stderr). If the alternate dump
231 file cannot be opened, return NULL. */
233 static FILE *
234 dump_open_alternate_stream (struct dump_file_info *dfi)
236 FILE *stream ;
237 if (!dfi->alt_filename)
238 return NULL;
240 if (dfi->alt_stream)
241 return dfi->alt_stream;
243 stream = strcmp("stderr", dfi->alt_filename) == 0
244 ? stderr
245 : strcmp("stdout", dfi->alt_filename) == 0
246 ? stdout
247 : fopen (dfi->alt_filename, dfi->alt_state < 0 ? "w" : "a");
249 if (!stream)
250 error ("could not open dump file %qs: %m", dfi->alt_filename);
251 else
252 dfi->alt_state = 1;
254 return stream;
257 /* Print source location on DFILE if enabled. */
259 void
260 dump_loc (int dump_kind, FILE *dfile, source_location loc)
262 /* Currently vectorization passes print location information. */
263 if (dump_kind)
265 if (loc == UNKNOWN_LOCATION)
266 fprintf (dfile, "\n%s:%d: note: ",
267 DECL_SOURCE_FILE (current_function_decl),
268 DECL_SOURCE_LINE (current_function_decl));
269 else
270 fprintf (dfile, "\n%d: ", LOCATION_LINE (loc));
274 /* Dump gimple statement GS with SPC indentation spaces and
275 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
277 void
278 dump_gimple_stmt (int dump_kind, int extra_dump_flags, gimple gs, int spc)
280 if (dump_file && (dump_kind & pflags))
281 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
283 if (alt_dump_file && (dump_kind & alt_flags))
284 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
287 /* Similar to dump_gimple_stmt, except additionally print source location. */
289 void
290 dump_gimple_stmt_loc (int dump_kind, source_location loc, int extra_dump_flags,
291 gimple gs, int spc)
293 if (dump_file && (dump_kind & pflags))
295 dump_loc (dump_kind, dump_file, loc);
296 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
299 if (alt_dump_file && (dump_kind & alt_flags))
301 dump_loc (dump_kind, alt_dump_file, loc);
302 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
306 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
307 DUMP_KIND is enabled. */
309 void
310 dump_generic_expr (int dump_kind, int extra_dump_flags, tree t)
312 if (dump_file && (dump_kind & pflags))
313 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
315 if (alt_dump_file && (dump_kind & alt_flags))
316 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
320 /* Similar to dump_generic_expr, except additionally print the source
321 location. */
323 void
324 dump_generic_expr_loc (int dump_kind, source_location loc,
325 int extra_dump_flags, tree t)
327 if (dump_file && (dump_kind & pflags))
329 dump_loc (dump_kind, dump_file, loc);
330 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
333 if (alt_dump_file && (dump_kind & alt_flags))
335 dump_loc (dump_kind, alt_dump_file, loc);
336 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
340 /* Output a formatted message using FORMAT on appropriate dump streams. */
342 void
343 dump_printf (int dump_kind, const char *format, ...)
345 if (dump_file && (dump_kind & pflags))
347 va_list ap;
348 va_start (ap, format);
349 vfprintf (dump_file, format, ap);
350 va_end (ap);
353 if (alt_dump_file && (dump_kind & alt_flags))
355 va_list ap;
356 va_start (ap, format);
357 vfprintf (alt_dump_file, format, ap);
358 va_end (ap);
362 /* Similar to dump_printf, except source location is also printed. */
364 void
365 dump_printf_loc (int dump_kind, source_location loc, const char *format, ...)
367 if (dump_file && (dump_kind & pflags))
369 va_list ap;
370 dump_loc (dump_kind, dump_file, loc);
371 va_start (ap, format);
372 vfprintf (dump_file, format, ap);
373 va_end (ap);
376 if (alt_dump_file && (dump_kind & alt_flags))
378 va_list ap;
379 dump_loc (dump_kind, alt_dump_file, loc);
380 va_start (ap, format);
381 vfprintf (alt_dump_file, format, ap);
382 va_end (ap);
386 /* Start a dump for PHASE. Store user-supplied dump flags in
387 *FLAG_PTR. Return the number of streams opened. Set globals
388 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
389 set dump_flags appropriately for both pass dump stream and
390 -fopt-info stream. */
393 dump_start (int phase, int *flag_ptr)
395 int count = 0;
396 char *name;
397 struct dump_file_info *dfi;
398 FILE *stream;
399 if (phase == TDI_none || !dump_phase_enabled_p (phase))
400 return 0;
402 dfi = get_dump_file_info (phase);
403 name = get_dump_file_name (phase);
404 if (name)
406 stream = strcmp("stderr", name) == 0
407 ? stderr
408 : strcmp("stdout", name) == 0
409 ? stdout
410 : fopen (name, dfi->pstate < 0 ? "w" : "a");
411 if (!stream)
412 error ("could not open dump file %qs: %m", name);
413 else
415 dfi->pstate = 1;
416 count++;
418 free (name);
419 dfi->pstream = stream;
420 dump_file = dfi->pstream;
421 /* Initialize current dump flags. */
422 pflags = dfi->pflags;
425 stream = dump_open_alternate_stream (dfi);
426 if (stream)
428 dfi->alt_stream = stream;
429 count++;
430 alt_dump_file = dfi->alt_stream;
431 /* Initialize current -fopt-info flags. */
432 alt_flags = dfi->alt_flags;
435 if (flag_ptr)
436 *flag_ptr = dfi->pflags;
438 return count;
441 /* Finish a tree dump for PHASE and close associated dump streams. Also
442 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
444 void
445 dump_finish (int phase)
447 struct dump_file_info *dfi;
449 if (phase < 0)
450 return;
451 dfi = get_dump_file_info (phase);
452 if (dfi->pstream)
453 fclose (dfi->pstream);
455 if (dfi->alt_stream && strcmp("stderr", dfi->alt_filename) != 0
456 && strcmp("stdout", dfi->alt_filename) != 0)
457 fclose (dfi->alt_stream);
459 dfi->alt_stream = NULL;
460 dfi->pstream = NULL;
461 dump_file = NULL;
462 alt_dump_file = NULL;
463 dump_flags = TDI_none;
464 alt_flags = 0;
465 pflags = 0;
468 /* Begin a tree dump for PHASE. Stores any user supplied flag in
469 *FLAG_PTR and returns a stream to write to. If the dump is not
470 enabled, returns NULL.
471 Multiple calls will reopen and append to the dump file. */
473 FILE *
474 dump_begin (int phase, int *flag_ptr)
476 char *name;
477 struct dump_file_info *dfi;
478 FILE *stream;
480 if (phase == TDI_none || !dump_phase_enabled_p (phase))
481 return NULL;
483 name = get_dump_file_name (phase);
484 if (!name)
485 return NULL;
486 dfi = get_dump_file_info (phase);
488 stream = strcmp("stderr", name) == 0
489 ? stderr
490 : strcmp("stdout", name) == 0
491 ? stdout
492 : fopen (name, dfi->pstate < 0 ? "w" : "a");
494 if (!stream)
495 error ("could not open dump file %qs: %m", name);
496 else
497 dfi->pstate = 1;
498 free (name);
500 if (flag_ptr)
501 *flag_ptr = dfi->pflags;
503 /* Initialize current flags */
504 pflags = dfi->pflags;
505 return stream;
508 /* Returns nonzero if dump PHASE is enabled for at least one stream.
509 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
510 any phase. */
512 static int
513 dump_phase_enabled_p (int phase)
515 if (phase == TDI_tree_all)
517 size_t i;
518 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
519 if (dump_files[i].pstate || dump_files[i].alt_state)
520 return 1;
521 for (i = 0; i < extra_dump_files_in_use; i++)
522 if (extra_dump_files[i].pstate || extra_dump_files[i].alt_state)
523 return 1;
524 return 0;
526 else
528 struct dump_file_info *dfi = get_dump_file_info (phase);
529 return dfi->pstate || dfi->alt_state;
533 /* Returns nonzero if tree dump PHASE has been initialized. */
536 dump_initialized_p (int phase)
538 struct dump_file_info *dfi = get_dump_file_info (phase);
539 return dfi->pstate > 0 || dfi->alt_state > 0;
542 /* Returns the switch name of PHASE. */
544 const char *
545 dump_flag_name (int phase)
547 struct dump_file_info *dfi = get_dump_file_info (phase);
548 return dfi->swtch;
551 /* Finish a tree dump for PHASE. STREAM is the stream created by
552 dump_begin. */
554 void
555 dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream)
557 if (stream != stderr && stream != stdout)
558 fclose (stream);
561 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
562 enabled tree dumps. */
564 static int
565 dump_enable_all (int flags, const char *filename)
567 int ir_dump_type = (flags & (TDF_TREE | TDF_RTL | TDF_IPA));
568 int n = 0;
569 size_t i;
571 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
573 if ((dump_files[i].pflags & ir_dump_type))
575 const char *old_filename = dump_files[i].pfilename;
576 dump_files[i].pstate = -1;
577 dump_files[i].pflags |= flags;
578 n++;
579 /* Override the existing filename. */
580 if (filename)
582 dump_files[i].pfilename = xstrdup (filename);
583 /* Since it is a command-line provided file, which is
584 common to all the phases, use it in append mode. */
585 dump_files[i].pstate = 1;
587 if (old_filename && filename != old_filename)
588 free (CONST_CAST (char *, old_filename));
592 for (i = 0; i < extra_dump_files_in_use; i++)
594 if ((extra_dump_files[i].pflags & ir_dump_type))
596 const char *old_filename = extra_dump_files[i].pfilename;
597 extra_dump_files[i].pstate = -1;
598 extra_dump_files[i].pflags |= flags;
599 n++;
600 /* Override the existing filename. */
601 if (filename)
603 extra_dump_files[i].pfilename = xstrdup (filename);
604 /* Since it is a command-line provided file, which is
605 common to all the phases, use it in append mode. */
606 extra_dump_files[i].pstate = 1;
608 if (old_filename && filename != old_filename)
609 free (CONST_CAST (char *, old_filename));
613 return n;
616 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
617 Enable dumps with FLAGS on FILENAME. Return the number of enabled
618 dumps. */
620 static int
621 opt_info_enable_passes (int optgroup_flags, int flags, const char *filename)
623 int n = 0;
624 size_t i;
626 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
628 if ((dump_files[i].optgroup_flags & optgroup_flags))
630 const char *old_filename = dump_files[i].alt_filename;
631 /* Since this file is shared among different passes, it
632 should be opened in append mode. */
633 dump_files[i].alt_state = 1;
634 dump_files[i].alt_flags |= flags;
635 n++;
636 /* Override the existing filename. */
637 if (filename)
638 dump_files[i].alt_filename = xstrdup (filename);
639 if (old_filename && filename != old_filename)
640 free (CONST_CAST (char *, old_filename));
644 for (i = 0; i < extra_dump_files_in_use; i++)
646 if ((extra_dump_files[i].optgroup_flags & optgroup_flags))
648 const char *old_filename = extra_dump_files[i].alt_filename;
649 /* Since this file is shared among different passes, it
650 should be opened in append mode. */
651 extra_dump_files[i].alt_state = 1;
652 extra_dump_files[i].alt_flags |= flags;
653 n++;
654 /* Override the existing filename. */
655 if (filename)
656 extra_dump_files[i].alt_filename = xstrdup (filename);
657 if (old_filename && filename != old_filename)
658 free (CONST_CAST (char *, old_filename));
662 return n;
665 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
666 relevant details in the dump_files array. */
668 static int
669 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
671 const char *option_value;
672 const char *ptr;
673 int flags;
675 if (doglob && !dfi->glob)
676 return 0;
678 option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
679 if (!option_value)
680 return 0;
682 if (*option_value && *option_value != '-' && *option_value != '=')
683 return 0;
685 ptr = option_value;
686 flags = 0;
688 while (*ptr)
690 const struct dump_option_value_info *option_ptr;
691 const char *end_ptr;
692 const char *eq_ptr;
693 unsigned length;
695 while (*ptr == '-')
696 ptr++;
697 end_ptr = strchr (ptr, '-');
698 eq_ptr = strchr (ptr, '=');
700 if (eq_ptr && !end_ptr)
701 end_ptr = eq_ptr;
703 if (!end_ptr)
704 end_ptr = ptr + strlen (ptr);
705 length = end_ptr - ptr;
707 for (option_ptr = dump_options; option_ptr->name; option_ptr++)
708 if (strlen (option_ptr->name) == length
709 && !memcmp (option_ptr->name, ptr, length))
711 flags |= option_ptr->value;
712 goto found;
715 if (*ptr == '=')
717 /* Interpret rest of the argument as a dump filename. This
718 filename overrides other command line filenames. */
719 if (dfi->pfilename)
720 free (CONST_CAST (char *, dfi->pfilename));
721 dfi->pfilename = xstrdup (ptr + 1);
722 break;
724 else
725 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
726 length, ptr, dfi->swtch);
727 found:;
728 ptr = end_ptr;
731 dfi->pstate = -1;
732 dfi->pflags |= flags;
734 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
735 known dumps. */
736 if (dfi->suffix == NULL)
737 dump_enable_all (dfi->pflags, dfi->pfilename);
739 return 1;
743 dump_switch_p (const char *arg)
745 size_t i;
746 int any = 0;
748 for (i = TDI_none + 1; i != TDI_end; i++)
749 any |= dump_switch_p_1 (arg, &dump_files[i], false);
751 /* Don't glob if we got a hit already */
752 if (!any)
753 for (i = TDI_none + 1; i != TDI_end; i++)
754 any |= dump_switch_p_1 (arg, &dump_files[i], true);
756 for (i = 0; i < extra_dump_files_in_use; i++)
757 any |= dump_switch_p_1 (arg, &extra_dump_files[i], false);
759 if (!any)
760 for (i = 0; i < extra_dump_files_in_use; i++)
761 any |= dump_switch_p_1 (arg, &extra_dump_files[i], true);
764 return any;
767 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
768 and filename. Return non-zero if it is a recognized switch. */
770 static int
771 opt_info_switch_p_1 (const char *arg, int *flags, int *optgroup_flags,
772 char **filename)
774 const char *option_value;
775 const char *ptr;
777 option_value = arg;
778 ptr = option_value;
780 *filename = NULL;
781 *flags = 0;
782 *optgroup_flags = 0;
784 if (!ptr)
785 return 1; /* Handle '-fopt-info' without any additional options. */
787 while (*ptr)
789 const struct dump_option_value_info *option_ptr;
790 const char *end_ptr;
791 const char *eq_ptr;
792 unsigned length;
794 while (*ptr == '-')
795 ptr++;
796 end_ptr = strchr (ptr, '-');
797 eq_ptr = strchr (ptr, '=');
799 if (eq_ptr && !end_ptr)
800 end_ptr = eq_ptr;
802 if (!end_ptr)
803 end_ptr = ptr + strlen (ptr);
804 length = end_ptr - ptr;
806 for (option_ptr = optinfo_verbosity_options; option_ptr->name;
807 option_ptr++)
808 if (strlen (option_ptr->name) == length
809 && !memcmp (option_ptr->name, ptr, length))
811 *flags |= option_ptr->value;
812 goto found;
815 for (option_ptr = optgroup_options; option_ptr->name; option_ptr++)
816 if (strlen (option_ptr->name) == length
817 && !memcmp (option_ptr->name, ptr, length))
819 *optgroup_flags |= option_ptr->value;
820 goto found;
823 if (*ptr == '=')
825 /* Interpret rest of the argument as a dump filename. This
826 filename overrides other command line filenames. */
827 *filename = xstrdup (ptr + 1);
828 break;
830 else
832 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
833 length, ptr, arg);
834 return 0;
836 found:;
837 ptr = end_ptr;
840 return 1;
843 /* Return non-zero if ARG is a recognized switch for
844 -fopt-info. Return zero otherwise. */
847 opt_info_switch_p (const char *arg)
849 int flags;
850 int optgroup_flags;
851 char *filename;
852 static char *file_seen = NULL;
854 if (!opt_info_switch_p_1 (arg, &flags, &optgroup_flags, &filename))
855 return 0;
857 if (!filename)
858 filename = xstrdup ("stderr");
860 /* Bail out if a different filename has been specified. */
861 if (file_seen && strcmp (file_seen, filename))
863 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
864 arg);
865 return 1;
868 file_seen = xstrdup (filename);
869 if (!flags)
870 flags = MSG_ALL;
871 if (!optgroup_flags)
872 optgroup_flags = OPTGROUP_ALL;
874 return opt_info_enable_passes (optgroup_flags, flags, filename);
877 /* Print basic block on the dump streams. */
879 void
880 dump_basic_block (int dump_kind, basic_block bb, int indent)
882 if (dump_file && (dump_kind & pflags))
883 dump_bb (dump_file, bb, indent, TDF_DETAILS);
884 if (alt_dump_file && (dump_kind & alt_flags))
885 dump_bb (alt_dump_file, bb, indent, TDF_DETAILS);
888 /* Print information from the combine pass on dump_file. */
890 void
891 print_combine_total_stats (void)
893 if (dump_file)
894 dump_combine_total_stats (dump_file);
897 /* Enable RTL dump for all the RTL passes. */
899 bool
900 enable_rtl_dump_file (void)
902 return dump_enable_all (TDF_RTL | TDF_DETAILS | TDF_BLOCKS, NULL) > 0;