c-family/
[official-gcc.git] / gcc / dumpfile.c
blob0f36afae42a3aa69fcc84878a1664ca0330fd114
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;
47 /* Table of tree dump switches. This must be consistent with the
48 TREE_DUMP_INDEX enumeration in dumpfile.h. */
49 static struct dump_file_info dump_files[TDI_end] =
51 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0},
52 {".cgraph", "ipa-cgraph", NULL, NULL, NULL, NULL, NULL, TDF_IPA,
53 0, 0, 0, 0},
54 {".tu", "translation-unit", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
55 0, 0, 0, 1},
56 {".class", "class-hierarchy", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
57 0, 0, 0, 2},
58 {".original", "tree-original", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
59 0, 0, 0, 3},
60 {".gimple", "tree-gimple", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
61 0, 0, 0, 4},
62 {".nested", "tree-nested", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
63 0, 0, 0, 5},
64 {".vcg", "tree-vcg", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
65 0, 0, 0, 6},
66 #define FIRST_AUTO_NUMBERED_DUMP 7
68 {NULL, "tree-all", NULL, NULL, NULL, NULL, NULL, TDF_TREE,
69 0, 0, 0, 0},
70 {NULL, "rtl-all", NULL, NULL, NULL, NULL, NULL, TDF_RTL,
71 0, 0, 0, 0},
72 {NULL, "ipa-all", NULL, NULL, NULL, NULL, NULL, TDF_IPA,
73 0, 0, 0, 0},
76 /* Dynamically registered tree dump files and switches. */
77 static struct dump_file_info *extra_dump_files;
78 static size_t extra_dump_files_in_use;
79 static size_t extra_dump_files_alloced;
81 /* Define a name->number mapping for a dump flag value. */
82 struct dump_option_value_info
84 const char *const name; /* the name of the value */
85 const int value; /* the value of the name */
88 /* Table of dump options. This must be consistent with the TDF_* flags
89 in dumpfile.h and opt_info_options below. */
90 static const struct dump_option_value_info dump_options[] =
92 {"address", TDF_ADDRESS},
93 {"asmname", TDF_ASMNAME},
94 {"slim", TDF_SLIM},
95 {"raw", TDF_RAW},
96 {"graph", TDF_GRAPH},
97 {"details", (TDF_DETAILS | MSG_OPTIMIZED_LOCATIONS
98 | MSG_MISSED_OPTIMIZATION
99 | MSG_NOTE)},
100 {"cselib", TDF_CSELIB},
101 {"stats", TDF_STATS},
102 {"blocks", TDF_BLOCKS},
103 {"vops", TDF_VOPS},
104 {"lineno", TDF_LINENO},
105 {"uid", TDF_UID},
106 {"stmtaddr", TDF_STMTADDR},
107 {"memsyms", TDF_MEMSYMS},
108 {"verbose", TDF_VERBOSE},
109 {"eh", TDF_EH},
110 {"alias", TDF_ALIAS},
111 {"nouid", TDF_NOUID},
112 {"enumerate_locals", TDF_ENUMERATE_LOCALS},
113 {"scev", TDF_SCEV},
114 {"all", ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_TREE | TDF_RTL | TDF_IPA
115 | TDF_STMTADDR | TDF_GRAPH | TDF_DIAGNOSTIC | TDF_VERBOSE
116 | TDF_RHS_ONLY | TDF_NOUID | TDF_ENUMERATE_LOCALS | TDF_SCEV)},
117 {NULL, 0}
120 /* A subset of the dump_options table which is used for opt-info
121 options. This must be consistent with the MSG_* flags in
122 dump_options.
124 static const struct dump_option_value_info opt_info_options[] =
126 {"optimized", MSG_OPTIMIZED_LOCATIONS},
127 {"missed", MSG_MISSED_OPTIMIZATION},
128 {"note", MSG_NOTE},
129 {"optall", (MSG_OPTIMIZED_LOCATIONS
130 | MSG_MISSED_OPTIMIZATION
131 | MSG_NOTE)},
132 {NULL, 0}
135 unsigned int
136 dump_register (const char *suffix, const char *swtch, const char *glob,
137 int flags)
139 static int next_dump = FIRST_AUTO_NUMBERED_DUMP;
140 int num = next_dump++;
142 size_t count = extra_dump_files_in_use++;
144 if (count >= extra_dump_files_alloced)
146 if (extra_dump_files_alloced == 0)
147 extra_dump_files_alloced = 32;
148 else
149 extra_dump_files_alloced *= 2;
150 extra_dump_files = XRESIZEVEC (struct dump_file_info,
151 extra_dump_files,
152 extra_dump_files_alloced);
155 memset (&extra_dump_files[count], 0, sizeof (struct dump_file_info));
156 extra_dump_files[count].suffix = suffix;
157 extra_dump_files[count].swtch = swtch;
158 extra_dump_files[count].glob = glob;
159 extra_dump_files[count].pflags = flags;
160 extra_dump_files[count].num = num;
162 return count + TDI_end;
166 /* Return the dump_file_info for the given phase. */
168 struct dump_file_info *
169 get_dump_file_info (int phase)
171 if (phase < TDI_end)
172 return &dump_files[phase];
173 else if ((size_t) (phase - TDI_end) >= extra_dump_files_in_use)
174 return NULL;
175 else
176 return extra_dump_files + (phase - TDI_end);
180 /* Return the name of the dump file for the given phase.
181 If the dump is not enabled, returns NULL. */
183 char *
184 get_dump_file_name (int phase)
186 char dump_id[10];
187 struct dump_file_info *dfi;
189 if (phase == TDI_none)
190 return NULL;
192 dfi = get_dump_file_info (phase);
193 if (dfi->pstate == 0)
194 return NULL;
196 /* If available, use the command line dump filename. */
197 if (dfi->pfilename)
198 return xstrdup (dfi->pfilename);
200 if (dfi->num < 0)
201 dump_id[0] = '\0';
202 else
204 char suffix;
205 if (dfi->pflags & TDF_TREE)
206 suffix = 't';
207 else if (dfi->pflags & TDF_IPA)
208 suffix = 'i';
209 else
210 suffix = 'r';
212 if (snprintf (dump_id, sizeof (dump_id), ".%03d%c", dfi->num, suffix) < 0)
213 dump_id[0] = '\0';
216 return concat (dump_base_name, dump_id, dfi->suffix, NULL);
219 /* For a given DFI, open an alternate dump filename (which could also
220 be a standard stream such as stdout/stderr). If the alternate dump
221 file cannot be opened, return NULL. */
223 static FILE *
224 dump_open_alternate_stream (struct dump_file_info *dfi)
226 FILE *stream ;
227 if (!dfi->alt_filename)
228 return NULL;
230 if (dfi->alt_stream)
231 return dfi->alt_stream;
233 stream = strcmp("stderr", dfi->alt_filename) == 0
234 ? stderr
235 : strcmp("stdout", dfi->alt_filename) == 0
236 ? stdout
237 : fopen (dfi->alt_filename, dfi->alt_state < 0 ? "w" : "a");
239 if (!stream)
240 error ("could not open dump file %qs: %m", dfi->alt_filename);
241 else
242 dfi->alt_state = 1;
244 return stream;
247 /* Print source location on DFILE if enabled. */
249 void
250 dump_loc (int dump_kind, FILE *dfile, source_location loc)
252 /* Currently vectorization passes print location information. */
253 if (dump_kind)
255 if (loc == UNKNOWN_LOCATION)
256 fprintf (dfile, "\n%s:%d: note: ",
257 DECL_SOURCE_FILE (current_function_decl),
258 DECL_SOURCE_LINE (current_function_decl));
259 else
260 fprintf (dfile, "\n%d: ", LOCATION_LINE (loc));
264 /* Dump gimple statement GS with SPC indentation spaces and
265 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
267 void
268 dump_gimple_stmt (int dump_kind, int extra_dump_flags, gimple gs, int spc)
270 if (dump_file && (dump_kind & pflags))
271 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
273 if (alt_dump_file && (dump_kind & alt_flags))
274 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
277 /* Similar to dump_gimple_stmt, except additionally print source location. */
279 void
280 dump_gimple_stmt_loc (int dump_kind, source_location loc, int extra_dump_flags,
281 gimple gs, int spc)
283 if (dump_file && (dump_kind & pflags))
285 dump_loc (dump_kind, dump_file, loc);
286 print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
289 if (alt_dump_file && (dump_kind & alt_flags))
291 dump_loc (dump_kind, alt_dump_file, loc);
292 print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
296 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
297 DUMP_KIND is enabled. */
299 void
300 dump_generic_expr (int dump_kind, int extra_dump_flags, tree t)
302 if (dump_file && (dump_kind & pflags))
303 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
305 if (alt_dump_file && (dump_kind & alt_flags))
306 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
310 /* Similar to dump_generic_expr, except additionally print the source
311 location. */
313 void
314 dump_generic_expr_loc (int dump_kind, source_location loc,
315 int extra_dump_flags, tree t)
317 if (dump_file && (dump_kind & pflags))
319 dump_loc (dump_kind, dump_file, loc);
320 print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
323 if (alt_dump_file && (dump_kind & alt_flags))
325 dump_loc (dump_kind, alt_dump_file, loc);
326 print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
330 /* Output a formatted message using FORMAT on appropriate dump streams. */
332 void
333 dump_printf (int dump_kind, const char *format, ...)
335 if (dump_file && (dump_kind & pflags))
337 va_list ap;
338 va_start (ap, format);
339 vfprintf (dump_file, format, ap);
340 va_end (ap);
343 if (alt_dump_file && (dump_kind & alt_flags))
345 va_list ap;
346 va_start (ap, format);
347 vfprintf (alt_dump_file, format, ap);
348 va_end (ap);
352 /* Similar to dump_printf, except source location is also printed. */
354 void
355 dump_printf_loc (int dump_kind, source_location loc, const char *format, ...)
357 if (dump_file && (dump_kind & pflags))
359 va_list ap;
360 dump_loc (dump_kind, dump_file, loc);
361 va_start (ap, format);
362 vfprintf (dump_file, format, ap);
363 va_end (ap);
366 if (alt_dump_file && (dump_kind & alt_flags))
368 va_list ap;
369 dump_loc (dump_kind, alt_dump_file, loc);
370 va_start (ap, format);
371 vfprintf (alt_dump_file, format, ap);
372 va_end (ap);
376 /* Start a dump for PHASE. Store user-supplied dump flags in
377 *FLAG_PTR. Return the number of streams opened. Set globals
378 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
379 set dump_flags appropriately for both pass dump stream and opt-info
380 stream. */
383 dump_start (int phase, int *flag_ptr)
385 int count = 0;
386 char *name;
387 struct dump_file_info *dfi;
388 FILE *stream;
389 if (phase == TDI_none || !dump_phase_enabled_p (phase))
390 return 0;
392 dfi = get_dump_file_info (phase);
393 name = get_dump_file_name (phase);
394 if (name)
396 stream = strcmp("stderr", name) == 0
397 ? stderr
398 : strcmp("stdout", name) == 0
399 ? stdout
400 : fopen (name, dfi->pstate < 0 ? "w" : "a");
401 if (!stream)
402 error ("could not open dump file %qs: %m", name);
403 else
405 dfi->pstate = 1;
406 count++;
408 free (name);
409 dfi->pstream = stream;
410 dump_file = dfi->pstream;
411 /* Initialize current dump flags. */
412 pflags = dfi->pflags;
415 stream = dump_open_alternate_stream (dfi);
416 if (stream)
418 dfi->alt_stream = stream;
419 count++;
420 alt_dump_file = dfi->alt_stream;
421 /* Initialize current opt-info flags. */
422 alt_flags = dfi->alt_flags;
425 if (flag_ptr)
426 *flag_ptr = dfi->pflags;
428 return count;
431 /* Finish a tree dump for PHASE and close associated dump streams. Also
432 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
434 void
435 dump_finish (int phase)
437 struct dump_file_info *dfi;
439 if (phase < 0)
440 return;
441 dfi = get_dump_file_info (phase);
442 if (dfi->pstream)
443 fclose (dfi->pstream);
445 if (dfi->alt_stream && strcmp("stderr", dfi->alt_filename) != 0
446 && strcmp("stdout", dfi->alt_filename) != 0)
447 fclose (dfi->alt_stream);
449 dfi->alt_stream = NULL;
450 dfi->pstream = NULL;
451 dump_file = NULL;
452 alt_dump_file = NULL;
453 dump_flags = TDI_none;
454 alt_flags = 0;
455 pflags = 0;
458 /* Begin a tree dump for PHASE. Stores any user supplied flag in
459 *FLAG_PTR and returns a stream to write to. If the dump is not
460 enabled, returns NULL.
461 Multiple calls will reopen and append to the dump file. */
463 FILE *
464 dump_begin (int phase, int *flag_ptr)
466 char *name;
467 struct dump_file_info *dfi;
468 FILE *stream;
470 if (phase == TDI_none || !dump_phase_enabled_p (phase))
471 return NULL;
473 name = get_dump_file_name (phase);
474 if (!name)
475 return NULL;
476 dfi = get_dump_file_info (phase);
478 stream = strcmp("stderr", name) == 0
479 ? stderr
480 : strcmp("stdout", name) == 0
481 ? stdout
482 : fopen (name, dfi->pstate < 0 ? "w" : "a");
484 if (!stream)
485 error ("could not open dump file %qs: %m", name);
486 else
487 dfi->pstate = 1;
488 free (name);
490 if (flag_ptr)
491 *flag_ptr = dfi->pflags;
493 /* Initialize current flags */
494 pflags = dfi->pflags;
495 return stream;
498 /* Returns nonzero if dump PHASE is enabled for at least one stream.
499 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
500 any phase. */
502 static int
503 dump_phase_enabled_p (int phase)
505 if (phase == TDI_tree_all)
507 size_t i;
508 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
509 if (dump_files[i].pstate || dump_files[i].alt_state)
510 return 1;
511 for (i = 0; i < extra_dump_files_in_use; i++)
512 if (extra_dump_files[i].pstate || extra_dump_files[i].alt_state)
513 return 1;
514 return 0;
516 else
518 struct dump_file_info *dfi = get_dump_file_info (phase);
519 return dfi->pstate || dfi->alt_state;
523 /* Returns nonzero if tree dump PHASE has been initialized. */
526 dump_initialized_p (int phase)
528 struct dump_file_info *dfi = get_dump_file_info (phase);
529 return dfi->pstate > 0 || dfi->alt_state > 0;
532 /* Returns the switch name of PHASE. */
534 const char *
535 dump_flag_name (int phase)
537 struct dump_file_info *dfi = get_dump_file_info (phase);
538 return dfi->swtch;
541 /* Finish a tree dump for PHASE. STREAM is the stream created by
542 dump_begin. */
544 void
545 dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream)
547 if (stream != stderr && stream != stdout)
548 fclose (stream);
551 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
552 enabled tree dumps. */
554 static int
555 dump_enable_all (int flags, const char *filename)
557 int ir_dump_type = (flags & (TDF_TREE | TDF_RTL | TDF_IPA));
558 int n = 0;
559 size_t i;
561 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
563 if ((dump_files[i].pflags & ir_dump_type))
565 const char *old_filename = dump_files[i].pfilename;
566 dump_files[i].pstate = -1;
567 dump_files[i].pflags |= flags;
568 n++;
569 /* Override the existing filename. */
570 if (filename)
572 dump_files[i].pfilename = xstrdup (filename);
573 /* Since it is a command-line provided file, which is
574 common to all the phases, use it in append mode. */
575 dump_files[i].pstate = 1;
577 if (old_filename && filename != old_filename)
578 free (CONST_CAST (char *, old_filename));
582 for (i = 0; i < extra_dump_files_in_use; i++)
584 if ((extra_dump_files[i].pflags & ir_dump_type))
586 const char *old_filename = extra_dump_files[i].pfilename;
587 extra_dump_files[i].pstate = -1;
588 extra_dump_files[i].pflags |= flags;
589 n++;
590 /* Override the existing filename. */
591 if (filename)
593 extra_dump_files[i].pfilename = xstrdup (filename);
594 /* Since it is a command-line provided file, which is
595 common to all the phases, use it in append mode. */
596 extra_dump_files[i].pstate = 1;
598 if (old_filename && filename != old_filename)
599 free (CONST_CAST (char *, old_filename));
603 return n;
606 /* Enable opt-info dumps on all IR_DUMP_TYPE passes with FLAGS on
607 FILENAME. Return the number of enabled dumps. */
609 static int
610 opt_info_enable_all (int ir_dump_type, int flags, const char *filename)
612 int n = 0;
613 size_t i;
615 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
617 if ((dump_files[i].pflags & ir_dump_type))
619 const char *old_filename = dump_files[i].alt_filename;
620 /* Since this file is shared among different passes, it
621 should be opened in append mode. */
622 dump_files[i].alt_state = 1;
623 dump_files[i].alt_flags |= flags;
624 n++;
625 /* Override the existing filename. */
626 if (filename)
627 dump_files[i].alt_filename = xstrdup (filename);
628 if (old_filename && filename != old_filename)
629 free (CONST_CAST (char *, old_filename));
633 for (i = 0; i < extra_dump_files_in_use; i++)
635 if ((extra_dump_files[i].pflags & ir_dump_type))
637 const char *old_filename = extra_dump_files[i].alt_filename;
638 /* Since this file is shared among different passes, it
639 should be opened in append mode. */
640 extra_dump_files[i].alt_state = 1;
641 extra_dump_files[i].alt_flags |= flags;
642 n++;
643 /* Override the existing filename. */
644 if (filename)
645 extra_dump_files[i].alt_filename = xstrdup (filename);
646 if (old_filename && filename != old_filename)
647 free (CONST_CAST (char *, old_filename));
651 return n;
654 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
655 relevant details in the dump_files array. */
657 static int
658 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
660 const char *option_value;
661 const char *ptr;
662 int flags;
664 if (doglob && !dfi->glob)
665 return 0;
667 option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
668 if (!option_value)
669 return 0;
671 if (*option_value && *option_value != '-' && *option_value != '=')
672 return 0;
674 ptr = option_value;
675 flags = 0;
677 while (*ptr)
679 const struct dump_option_value_info *option_ptr;
680 const char *end_ptr;
681 const char *eq_ptr;
682 unsigned length;
684 while (*ptr == '-')
685 ptr++;
686 end_ptr = strchr (ptr, '-');
687 eq_ptr = strchr (ptr, '=');
689 if (eq_ptr && !end_ptr)
690 end_ptr = eq_ptr;
692 if (!end_ptr)
693 end_ptr = ptr + strlen (ptr);
694 length = end_ptr - ptr;
696 for (option_ptr = dump_options; option_ptr->name; option_ptr++)
697 if (strlen (option_ptr->name) == length
698 && !memcmp (option_ptr->name, ptr, length))
700 flags |= option_ptr->value;
701 goto found;
704 if (*ptr == '=')
706 /* Interpret rest of the argument as a dump filename. This
707 filename overrides other command line filenames. */
708 if (dfi->pfilename)
709 free (CONST_CAST (char *, dfi->pfilename));
710 dfi->pfilename = xstrdup (ptr + 1);
711 break;
713 else
714 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
715 length, ptr, dfi->swtch);
716 found:;
717 ptr = end_ptr;
720 dfi->pstate = -1;
721 dfi->pflags |= flags;
723 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
724 known dumps. */
725 if (dfi->suffix == NULL)
726 dump_enable_all (dfi->pflags, dfi->pfilename);
728 return 1;
732 dump_switch_p (const char *arg)
734 size_t i;
735 int any = 0;
737 for (i = TDI_none + 1; i != TDI_end; i++)
738 any |= dump_switch_p_1 (arg, &dump_files[i], false);
740 /* Don't glob if we got a hit already */
741 if (!any)
742 for (i = TDI_none + 1; i != TDI_end; i++)
743 any |= dump_switch_p_1 (arg, &dump_files[i], true);
745 for (i = 0; i < extra_dump_files_in_use; i++)
746 any |= dump_switch_p_1 (arg, &extra_dump_files[i], false);
748 if (!any)
749 for (i = 0; i < extra_dump_files_in_use; i++)
750 any |= dump_switch_p_1 (arg, &extra_dump_files[i], true);
753 return any;
756 /* Parse ARG as a -fopt-info switch and store flags and filename.
757 Return non-zero if it is a recognized switch. */
759 static int
760 opt_info_switch_p_1 (const char *arg, int *flags, char **filename)
762 const char *option_value;
763 const char *ptr;
765 option_value = arg;
766 ptr = option_value;
768 *filename = NULL;
769 *flags = 0;
771 if (!ptr)
772 return 1;
774 while (*ptr)
776 const struct dump_option_value_info *option_ptr;
777 const char *end_ptr;
778 const char *eq_ptr;
779 unsigned length;
781 while (*ptr == '-')
782 ptr++;
783 end_ptr = strchr (ptr, '-');
784 eq_ptr = strchr (ptr, '=');
786 if (eq_ptr && !end_ptr)
787 end_ptr = eq_ptr;
789 if (!end_ptr)
790 end_ptr = ptr + strlen (ptr);
791 length = end_ptr - ptr;
793 for (option_ptr = opt_info_options; option_ptr->name; option_ptr++)
794 if (strlen (option_ptr->name) == length
795 && !memcmp (option_ptr->name, ptr, length))
797 *flags |= option_ptr->value;
798 goto found;
801 if (*ptr == '=')
803 /* Interpret rest of the argument as a dump filename. This
804 filename overrides other command line filenames. */
805 *filename = xstrdup (ptr + 1);
806 break;
808 else
809 warning (0, "ignoring unknown option %q.*s in %<-fopt-info=%s%>",
810 length, ptr, arg);
811 found:;
812 ptr = end_ptr;
815 return 1;
818 /* Return non-zero if ARG is a recognized switch for
819 -fopt-info. Return zero otherwise. */
822 opt_info_switch_p (const char *arg)
824 int flags;
825 char *filename;
827 opt_info_switch_p_1 (arg, &flags, &filename);
829 if (!filename)
830 filename = xstrdup ("stderr");
831 if (!flags)
832 flags = MSG_ALL;
834 return opt_info_enable_all ((TDF_TREE | TDF_RTL | TDF_IPA), flags, filename);
837 /* Print basic block on the dump streams. */
839 void
840 dump_basic_block (int dump_kind, basic_block bb, int indent)
842 if (dump_file && (dump_kind & pflags))
843 dump_bb (dump_file, bb, indent, TDF_DETAILS);
844 if (alt_dump_file && (dump_kind & alt_flags))
845 dump_bb (alt_dump_file, bb, indent, TDF_DETAILS);
848 /* Print information from the combine pass on dump_file. */
850 void
851 print_combine_total_stats (void)
853 if (dump_file)
854 dump_combine_total_stats (dump_file);
857 /* Enable RTL dump for all the RTL passes. */
859 bool
860 enable_rtl_dump_file (void)
862 return dump_enable_all (TDF_RTL | TDF_DETAILS | TDF_BLOCKS, NULL) > 0;