1 /* Dump infrastructure for optimizations and intermediate representation.
2 Copyright (C) 2012-2015 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
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
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/>. */
22 #include "coretypes.h"
25 #include "gimple-pretty-print.h"
26 #include "diagnostic-core.h"
30 /* If non-NULL, return one past-the-end of the matching SUBPART of
32 #define skip_leading_substring(whole, part) \
33 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
35 static int pflags
; /* current dump_flags */
36 static int alt_flags
; /* current opt_info flags */
38 static void dump_loc (int, FILE *, source_location
);
39 static FILE *dump_open_alternate_stream (struct dump_file_info
*);
41 /* These are currently used for communicating between passes.
42 However, instead of accessing them directly, the passes can use
43 dump_printf () for dumps. */
44 FILE *dump_file
= NULL
;
45 FILE *alt_dump_file
= NULL
;
46 const char *dump_file_name
;
49 /* Table of tree dump switches. This must be consistent with the
50 TREE_DUMP_INDEX enumeration in dumpfile.h. */
51 static struct dump_file_info dump_files
[TDI_end
] =
53 {NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0, false},
54 {".cgraph", "ipa-cgraph", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
55 0, 0, 0, 0, 0, false},
56 {".type-inheritance", "ipa-type-inheritance", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
57 0, 0, 0, 0, 0, false},
58 {".tu", "translation-unit", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
59 0, 0, 0, 0, 1, false},
60 {".class", "class-hierarchy", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
61 0, 0, 0, 0, 2, false},
62 {".original", "tree-original", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
63 0, 0, 0, 0, 3, false},
64 {".gimple", "tree-gimple", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
65 0, 0, 0, 0, 4, false},
66 {".nested", "tree-nested", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
67 0, 0, 0, 0, 5, false},
68 #define FIRST_AUTO_NUMBERED_DUMP 6
70 {NULL
, "tree-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
71 0, 0, 0, 0, 0, false},
72 {NULL
, "rtl-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_RTL
,
73 0, 0, 0, 0, 0, false},
74 {NULL
, "ipa-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
75 0, 0, 0, 0, 0, false},
78 /* Define a name->number mapping for a dump flag value. */
79 struct dump_option_value_info
81 const char *const name
; /* the name of the value */
82 const int value
; /* the value of the name */
85 /* Table of dump options. This must be consistent with the TDF_* flags
86 in dumpfile.h and opt_info_options below. */
87 static const struct dump_option_value_info dump_options
[] =
89 {"address", TDF_ADDRESS
},
90 {"asmname", TDF_ASMNAME
},
94 {"details", (TDF_DETAILS
| MSG_OPTIMIZED_LOCATIONS
95 | MSG_MISSED_OPTIMIZATION
97 {"cselib", TDF_CSELIB
},
99 {"blocks", TDF_BLOCKS
},
101 {"lineno", TDF_LINENO
},
103 {"stmtaddr", TDF_STMTADDR
},
104 {"memsyms", TDF_MEMSYMS
},
105 {"verbose", TDF_VERBOSE
},
107 {"alias", TDF_ALIAS
},
108 {"nouid", TDF_NOUID
},
109 {"enumerate_locals", TDF_ENUMERATE_LOCALS
},
111 {"optimized", MSG_OPTIMIZED_LOCATIONS
},
112 {"missed", MSG_MISSED_OPTIMIZATION
},
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
)},
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
},
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
},
144 gcc::dump_manager::dump_manager ():
145 m_next_dump (FIRST_AUTO_NUMBERED_DUMP
),
146 m_extra_dump_files (NULL
),
147 m_extra_dump_files_in_use (0),
148 m_extra_dump_files_alloced (0)
152 gcc::dump_manager::~dump_manager ()
154 for (size_t i
= 0; i
< m_extra_dump_files_in_use
; i
++)
156 dump_file_info
*dfi
= &m_extra_dump_files
[i
];
157 /* suffix, swtch, glob are statically allocated for the entries
158 in dump_files, and for statistics, but are dynamically allocated
159 for those for passes. */
160 if (dfi
->owns_strings
)
162 XDELETEVEC (const_cast <char *> (dfi
->suffix
));
163 XDELETEVEC (const_cast <char *> (dfi
->swtch
));
164 XDELETEVEC (const_cast <char *> (dfi
->glob
));
166 /* These, if non-NULL, are always dynamically allocated. */
167 XDELETEVEC (const_cast <char *> (dfi
->pfilename
));
168 XDELETEVEC (const_cast <char *> (dfi
->alt_filename
));
170 XDELETEVEC (m_extra_dump_files
);
175 dump_register (const char *suffix
, const char *swtch
, const char *glob
,
176 int flags
, int optgroup_flags
,
179 int num
= m_next_dump
++;
181 size_t count
= m_extra_dump_files_in_use
++;
183 if (count
>= m_extra_dump_files_alloced
)
185 if (m_extra_dump_files_alloced
== 0)
186 m_extra_dump_files_alloced
= 32;
188 m_extra_dump_files_alloced
*= 2;
189 m_extra_dump_files
= XRESIZEVEC (struct dump_file_info
,
191 m_extra_dump_files_alloced
);
194 memset (&m_extra_dump_files
[count
], 0, sizeof (struct dump_file_info
));
195 m_extra_dump_files
[count
].suffix
= suffix
;
196 m_extra_dump_files
[count
].swtch
= swtch
;
197 m_extra_dump_files
[count
].glob
= glob
;
198 m_extra_dump_files
[count
].pflags
= flags
;
199 m_extra_dump_files
[count
].optgroup_flags
= optgroup_flags
;
200 m_extra_dump_files
[count
].num
= num
;
201 m_extra_dump_files
[count
].owns_strings
= take_ownership
;
203 return count
+ TDI_end
;
207 /* Return the dump_file_info for the given phase. */
209 struct dump_file_info
*
211 get_dump_file_info (int phase
) const
214 return &dump_files
[phase
];
215 else if ((size_t) (phase
- TDI_end
) >= m_extra_dump_files_in_use
)
218 return m_extra_dump_files
+ (phase
- TDI_end
);
221 /* Locate the dump_file_info with swtch equal to SWTCH,
222 or return NULL if no such dump_file_info exists. */
224 struct dump_file_info
*
226 get_dump_file_info_by_switch (const char *swtch
) const
228 for (unsigned i
= 0; i
< m_extra_dump_files_in_use
; i
++)
229 if (0 == strcmp (m_extra_dump_files
[i
].swtch
, swtch
))
230 return &m_extra_dump_files
[i
];
237 /* Return the name of the dump file for the given phase.
238 The caller is responsible for calling free on the returned
240 If the dump is not enabled, returns NULL. */
244 get_dump_file_name (int phase
) const
246 struct dump_file_info
*dfi
;
248 if (phase
== TDI_none
)
251 dfi
= get_dump_file_info (phase
);
253 return get_dump_file_name (dfi
);
256 /* Return the name of the dump file for the given dump_file_info.
257 The caller is responsible for calling free on the returned
259 If the dump is not enabled, returns NULL. */
263 get_dump_file_name (struct dump_file_info
*dfi
) const
269 if (dfi
->pstate
== 0)
272 /* If available, use the command line dump filename. */
274 return xstrdup (dfi
->pfilename
);
281 if (dfi
->pflags
& TDF_TREE
)
283 else if (dfi
->pflags
& TDF_IPA
)
288 if (snprintf (dump_id
, sizeof (dump_id
), ".%03d%c", dfi
->num
, suffix
) < 0)
292 return concat (dump_base_name
, dump_id
, dfi
->suffix
, NULL
);
295 /* For a given DFI, open an alternate dump filename (which could also
296 be a standard stream such as stdout/stderr). If the alternate dump
297 file cannot be opened, return NULL. */
300 dump_open_alternate_stream (struct dump_file_info
*dfi
)
303 if (!dfi
->alt_filename
)
307 return dfi
->alt_stream
;
309 stream
= strcmp ("stderr", dfi
->alt_filename
) == 0
311 : strcmp ("stdout", dfi
->alt_filename
) == 0
313 : fopen (dfi
->alt_filename
, dfi
->alt_state
< 0 ? "w" : "a");
316 error ("could not open dump file %qs: %m", dfi
->alt_filename
);
323 /* Print source location on DFILE if enabled. */
326 dump_loc (int dump_kind
, FILE *dfile
, source_location loc
)
330 if (LOCATION_LOCUS (loc
) > BUILTINS_LOCATION
)
331 fprintf (dfile
, "%s:%d:%d: note: ", LOCATION_FILE (loc
),
332 LOCATION_LINE (loc
), LOCATION_COLUMN (loc
));
333 else if (current_function_decl
)
334 fprintf (dfile
, "%s:%d:%d: note: ",
335 DECL_SOURCE_FILE (current_function_decl
),
336 DECL_SOURCE_LINE (current_function_decl
),
337 DECL_SOURCE_COLUMN (current_function_decl
));
341 /* Dump gimple statement GS with SPC indentation spaces and
342 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
345 dump_gimple_stmt (int dump_kind
, int extra_dump_flags
, gimple
*gs
, int spc
)
347 if (dump_file
&& (dump_kind
& pflags
))
348 print_gimple_stmt (dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
350 if (alt_dump_file
&& (dump_kind
& alt_flags
))
351 print_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
354 /* Similar to dump_gimple_stmt, except additionally print source location. */
357 dump_gimple_stmt_loc (int dump_kind
, source_location loc
, int extra_dump_flags
,
360 if (dump_file
&& (dump_kind
& pflags
))
362 dump_loc (dump_kind
, dump_file
, loc
);
363 print_gimple_stmt (dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
366 if (alt_dump_file
&& (dump_kind
& alt_flags
))
368 dump_loc (dump_kind
, alt_dump_file
, loc
);
369 print_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
373 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
374 DUMP_KIND is enabled. */
377 dump_generic_expr (int dump_kind
, int extra_dump_flags
, tree t
)
379 if (dump_file
&& (dump_kind
& pflags
))
380 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
382 if (alt_dump_file
&& (dump_kind
& alt_flags
))
383 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
387 /* Similar to dump_generic_expr, except additionally print the source
391 dump_generic_expr_loc (int dump_kind
, source_location loc
,
392 int extra_dump_flags
, tree t
)
394 if (dump_file
&& (dump_kind
& pflags
))
396 dump_loc (dump_kind
, dump_file
, loc
);
397 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
400 if (alt_dump_file
&& (dump_kind
& alt_flags
))
402 dump_loc (dump_kind
, alt_dump_file
, loc
);
403 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
407 /* Output a formatted message using FORMAT on appropriate dump streams. */
410 dump_printf (int dump_kind
, const char *format
, ...)
412 if (dump_file
&& (dump_kind
& pflags
))
415 va_start (ap
, format
);
416 vfprintf (dump_file
, format
, ap
);
420 if (alt_dump_file
&& (dump_kind
& alt_flags
))
423 va_start (ap
, format
);
424 vfprintf (alt_dump_file
, format
, ap
);
429 /* Similar to dump_printf, except source location is also printed. */
432 dump_printf_loc (int dump_kind
, source_location loc
, const char *format
, ...)
434 if (dump_file
&& (dump_kind
& pflags
))
437 dump_loc (dump_kind
, dump_file
, loc
);
438 va_start (ap
, format
);
439 vfprintf (dump_file
, format
, ap
);
443 if (alt_dump_file
&& (dump_kind
& alt_flags
))
446 dump_loc (dump_kind
, alt_dump_file
, loc
);
447 va_start (ap
, format
);
448 vfprintf (alt_dump_file
, format
, ap
);
453 /* Start a dump for PHASE. Store user-supplied dump flags in
454 *FLAG_PTR. Return the number of streams opened. Set globals
455 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
456 set dump_flags appropriately for both pass dump stream and
457 -fopt-info stream. */
461 dump_start (int phase
, int *flag_ptr
)
465 struct dump_file_info
*dfi
;
467 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
470 dfi
= get_dump_file_info (phase
);
471 name
= get_dump_file_name (phase
);
474 stream
= strcmp ("stderr", name
) == 0
476 : strcmp ("stdout", name
) == 0
478 : fopen (name
, dfi
->pstate
< 0 ? "w" : "a");
480 error ("could not open dump file %qs: %m", name
);
487 dfi
->pstream
= stream
;
488 dump_file
= dfi
->pstream
;
489 /* Initialize current dump flags. */
490 pflags
= dfi
->pflags
;
493 stream
= dump_open_alternate_stream (dfi
);
496 dfi
->alt_stream
= stream
;
498 alt_dump_file
= dfi
->alt_stream
;
499 /* Initialize current -fopt-info flags. */
500 alt_flags
= dfi
->alt_flags
;
504 *flag_ptr
= dfi
->pflags
;
509 /* Finish a tree dump for PHASE and close associated dump streams. Also
510 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
514 dump_finish (int phase
)
516 struct dump_file_info
*dfi
;
520 dfi
= get_dump_file_info (phase
);
521 if (dfi
->pstream
&& (!dfi
->pfilename
522 || (strcmp ("stderr", dfi
->pfilename
) != 0
523 && strcmp ("stdout", dfi
->pfilename
) != 0)))
524 fclose (dfi
->pstream
);
526 if (dfi
->alt_stream
&& strcmp ("stderr", dfi
->alt_filename
) != 0
527 && strcmp ("stdout", dfi
->alt_filename
) != 0)
528 fclose (dfi
->alt_stream
);
530 dfi
->alt_stream
= NULL
;
533 alt_dump_file
= NULL
;
534 dump_flags
= TDI_none
;
539 /* Begin a tree dump for PHASE. Stores any user supplied flag in
540 *FLAG_PTR and returns a stream to write to. If the dump is not
541 enabled, returns NULL.
542 Multiple calls will reopen and append to the dump file. */
545 dump_begin (int phase
, int *flag_ptr
)
547 return g
->get_dumps ()->dump_begin (phase
, flag_ptr
);
552 dump_begin (int phase
, int *flag_ptr
)
555 struct dump_file_info
*dfi
;
558 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
561 name
= get_dump_file_name (phase
);
564 dfi
= get_dump_file_info (phase
);
566 stream
= strcmp ("stderr", name
) == 0
568 : strcmp ("stdout", name
) == 0
570 : fopen (name
, dfi
->pstate
< 0 ? "w" : "a");
573 error ("could not open dump file %qs: %m", name
);
579 *flag_ptr
= dfi
->pflags
;
581 /* Initialize current flags */
582 pflags
= dfi
->pflags
;
586 /* Returns nonzero if dump PHASE is enabled for at least one stream.
587 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
592 dump_phase_enabled_p (int phase
) const
594 if (phase
== TDI_tree_all
)
597 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
598 if (dump_files
[i
].pstate
|| dump_files
[i
].alt_state
)
600 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
601 if (m_extra_dump_files
[i
].pstate
|| m_extra_dump_files
[i
].alt_state
)
607 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
608 return dfi
->pstate
|| dfi
->alt_state
;
612 /* Returns nonzero if tree dump PHASE has been initialized. */
616 dump_initialized_p (int phase
) const
618 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
619 return dfi
->pstate
> 0 || dfi
->alt_state
> 0;
622 /* Returns the switch name of PHASE. */
625 dump_flag_name (int phase
)
627 return g
->get_dumps ()->dump_flag_name (phase
);
632 dump_flag_name (int phase
) const
634 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
638 /* Finish a tree dump for PHASE. STREAM is the stream created by
642 dump_end (int phase ATTRIBUTE_UNUSED
, FILE *stream
)
644 if (stream
!= stderr
&& stream
!= stdout
)
648 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
649 enabled tree dumps. */
653 dump_enable_all (int flags
, const char *filename
)
655 int ir_dump_type
= (flags
& (TDF_TREE
| TDF_RTL
| TDF_IPA
));
659 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
661 if ((dump_files
[i
].pflags
& ir_dump_type
))
663 const char *old_filename
= dump_files
[i
].pfilename
;
664 dump_files
[i
].pstate
= -1;
665 dump_files
[i
].pflags
|= flags
;
667 /* Override the existing filename. */
670 dump_files
[i
].pfilename
= xstrdup (filename
);
671 /* Since it is a command-line provided file, which is
672 common to all the phases, use it in append mode. */
673 dump_files
[i
].pstate
= 1;
675 if (old_filename
&& filename
!= old_filename
)
676 free (CONST_CAST (char *, old_filename
));
680 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
682 if ((m_extra_dump_files
[i
].pflags
& ir_dump_type
))
684 const char *old_filename
= m_extra_dump_files
[i
].pfilename
;
685 m_extra_dump_files
[i
].pstate
= -1;
686 m_extra_dump_files
[i
].pflags
|= flags
;
688 /* Override the existing filename. */
691 m_extra_dump_files
[i
].pfilename
= xstrdup (filename
);
692 /* Since it is a command-line provided file, which is
693 common to all the phases, use it in append mode. */
694 m_extra_dump_files
[i
].pstate
= 1;
696 if (old_filename
&& filename
!= old_filename
)
697 free (CONST_CAST (char *, old_filename
));
704 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
705 Enable dumps with FLAGS on FILENAME. Return the number of enabled
710 opt_info_enable_passes (int optgroup_flags
, int flags
, const char *filename
)
715 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
717 if ((dump_files
[i
].optgroup_flags
& optgroup_flags
))
719 const char *old_filename
= dump_files
[i
].alt_filename
;
720 /* Since this file is shared among different passes, it
721 should be opened in append mode. */
722 dump_files
[i
].alt_state
= 1;
723 dump_files
[i
].alt_flags
|= flags
;
725 /* Override the existing filename. */
727 dump_files
[i
].alt_filename
= xstrdup (filename
);
728 if (old_filename
&& filename
!= old_filename
)
729 free (CONST_CAST (char *, old_filename
));
733 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
735 if ((m_extra_dump_files
[i
].optgroup_flags
& optgroup_flags
))
737 const char *old_filename
= m_extra_dump_files
[i
].alt_filename
;
738 /* Since this file is shared among different passes, it
739 should be opened in append mode. */
740 m_extra_dump_files
[i
].alt_state
= 1;
741 m_extra_dump_files
[i
].alt_flags
|= flags
;
743 /* Override the existing filename. */
745 m_extra_dump_files
[i
].alt_filename
= xstrdup (filename
);
746 if (old_filename
&& filename
!= old_filename
)
747 free (CONST_CAST (char *, old_filename
));
754 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
755 relevant details in the dump_files array. */
759 dump_switch_p_1 (const char *arg
, struct dump_file_info
*dfi
, bool doglob
)
761 const char *option_value
;
765 if (doglob
&& !dfi
->glob
)
768 option_value
= skip_leading_substring (arg
, doglob
? dfi
->glob
: dfi
->swtch
);
772 if (*option_value
&& *option_value
!= '-' && *option_value
!= '=')
780 const struct dump_option_value_info
*option_ptr
;
787 end_ptr
= strchr (ptr
, '-');
788 eq_ptr
= strchr (ptr
, '=');
790 if (eq_ptr
&& !end_ptr
)
794 end_ptr
= ptr
+ strlen (ptr
);
795 length
= end_ptr
- ptr
;
797 for (option_ptr
= dump_options
; option_ptr
->name
; option_ptr
++)
798 if (strlen (option_ptr
->name
) == length
799 && !memcmp (option_ptr
->name
, ptr
, length
))
801 flags
|= option_ptr
->value
;
807 /* Interpret rest of the argument as a dump filename. This
808 filename overrides other command line filenames. */
810 free (CONST_CAST (char *, dfi
->pfilename
));
811 dfi
->pfilename
= xstrdup (ptr
+ 1);
815 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
816 length
, ptr
, dfi
->swtch
);
822 dfi
->pflags
|= flags
;
824 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
826 if (dfi
->suffix
== NULL
)
827 dump_enable_all (dfi
->pflags
, dfi
->pfilename
);
834 dump_switch_p (const char *arg
)
839 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
840 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], false);
842 /* Don't glob if we got a hit already */
844 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
845 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], true);
847 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
848 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], false);
851 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
852 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], true);
858 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
859 and filename. Return non-zero if it is a recognized switch. */
862 opt_info_switch_p_1 (const char *arg
, int *flags
, int *optgroup_flags
,
865 const char *option_value
;
876 return 1; /* Handle '-fopt-info' without any additional options. */
880 const struct dump_option_value_info
*option_ptr
;
887 end_ptr
= strchr (ptr
, '-');
888 eq_ptr
= strchr (ptr
, '=');
890 if (eq_ptr
&& !end_ptr
)
894 end_ptr
= ptr
+ strlen (ptr
);
895 length
= end_ptr
- ptr
;
897 for (option_ptr
= optinfo_verbosity_options
; option_ptr
->name
;
899 if (strlen (option_ptr
->name
) == length
900 && !memcmp (option_ptr
->name
, ptr
, length
))
902 *flags
|= option_ptr
->value
;
906 for (option_ptr
= optgroup_options
; option_ptr
->name
; option_ptr
++)
907 if (strlen (option_ptr
->name
) == length
908 && !memcmp (option_ptr
->name
, ptr
, length
))
910 *optgroup_flags
|= option_ptr
->value
;
916 /* Interpret rest of the argument as a dump filename. This
917 filename overrides other command line filenames. */
918 *filename
= xstrdup (ptr
+ 1);
923 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
934 /* Return non-zero if ARG is a recognized switch for
935 -fopt-info. Return zero otherwise. */
938 opt_info_switch_p (const char *arg
)
943 static char *file_seen
= NULL
;
944 gcc::dump_manager
*dumps
= g
->get_dumps ();
946 if (!opt_info_switch_p_1 (arg
, &flags
, &optgroup_flags
, &filename
))
950 filename
= xstrdup ("stderr");
952 /* Bail out if a different filename has been specified. */
953 if (file_seen
&& strcmp (file_seen
, filename
))
955 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
960 file_seen
= xstrdup (filename
);
962 flags
= MSG_OPTIMIZED_LOCATIONS
;
964 optgroup_flags
= OPTGROUP_ALL
;
966 return dumps
->opt_info_enable_passes (optgroup_flags
, flags
, filename
);
969 /* Print basic block on the dump streams. */
972 dump_basic_block (int dump_kind
, basic_block bb
, int indent
)
974 if (dump_file
&& (dump_kind
& pflags
))
975 dump_bb (dump_file
, bb
, indent
, TDF_DETAILS
);
976 if (alt_dump_file
&& (dump_kind
& alt_flags
))
977 dump_bb (alt_dump_file
, bb
, indent
, TDF_DETAILS
);
980 /* Print information from the combine pass on dump_file. */
983 print_combine_total_stats (void)
986 dump_combine_total_stats (dump_file
);
989 /* Enable RTL dump for all the RTL passes. */
992 enable_rtl_dump_file (void)
994 gcc::dump_manager
*dumps
= g
->get_dumps ();
996 dumps
->dump_enable_all (TDF_RTL
| TDF_DETAILS
| TDF_BLOCKS
, NULL
);
997 return num_enabled
> 0;