1 /* Dump infrastructure for optimizations and intermediate representation.
2 Copyright (C) 2012-2017 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"
31 /* If non-NULL, return one past-the-end of the matching SUBPART of
33 #define skip_leading_substring(whole, part) \
34 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
36 static int pflags
; /* current dump_flags */
37 static int alt_flags
; /* current opt_info flags */
39 static void dump_loc (int, FILE *, source_location
);
40 static FILE *dump_open_alternate_stream (struct dump_file_info
*);
42 /* These are currently used for communicating between passes.
43 However, instead of accessing them directly, the passes can use
44 dump_printf () for dumps. */
45 FILE *dump_file
= NULL
;
46 FILE *alt_dump_file
= NULL
;
47 const char *dump_file_name
;
50 /* Table of tree dump switches. This must be consistent with the
51 TREE_DUMP_INDEX enumeration in dumpfile.h. */
52 static struct dump_file_info dump_files
[TDI_end
] =
54 {NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0, false, false},
55 {".cgraph", "ipa-cgraph", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
56 0, 0, 0, 0, 0, false, false},
57 {".type-inheritance", "ipa-type-inheritance", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
58 0, 0, 0, 0, 0, false, false},
59 {".ipa-clones", "ipa-clones", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
60 0, 0, 0, 0, 0, false, false},
61 {".tu", "translation-unit", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_LANG
,
62 0, 0, 0, 0, 1, false, false},
63 {".class", "class-hierarchy", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_LANG
,
64 0, 0, 0, 0, 2, false, false},
65 {".original", "tree-original", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
66 0, 0, 0, 0, 3, false, false},
67 {".gimple", "tree-gimple", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
68 0, 0, 0, 0, 4, false, false},
69 {".nested", "tree-nested", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
70 0, 0, 0, 0, 5, false, false},
71 #define FIRST_AUTO_NUMBERED_DUMP 6
73 {NULL
, "lang-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_LANG
,
74 0, 0, 0, 0, 0, false, false},
75 {NULL
, "tree-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_TREE
,
76 0, 0, 0, 0, 0, false, false},
77 {NULL
, "rtl-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_RTL
,
78 0, 0, 0, 0, 0, false, false},
79 {NULL
, "ipa-all", NULL
, NULL
, NULL
, NULL
, NULL
, TDF_IPA
,
80 0, 0, 0, 0, 0, false, false},
83 /* Define a name->number mapping for a dump flag value. */
84 struct dump_option_value_info
86 const char *const name
; /* the name of the value */
87 const int value
; /* the value of the name */
90 /* Table of dump options. This must be consistent with the TDF_* flags
91 in dumpfile.h and opt_info_options below. */
92 static const struct dump_option_value_info dump_options
[] =
94 {"address", TDF_ADDRESS
},
95 {"asmname", TDF_ASMNAME
},
99 {"details", (TDF_DETAILS
| MSG_OPTIMIZED_LOCATIONS
100 | MSG_MISSED_OPTIMIZATION
102 {"cselib", TDF_CSELIB
},
103 {"stats", TDF_STATS
},
104 {"blocks", TDF_BLOCKS
},
106 {"lineno", TDF_LINENO
},
108 {"stmtaddr", TDF_STMTADDR
},
109 {"memsyms", TDF_MEMSYMS
},
110 {"verbose", TDF_VERBOSE
},
112 {"alias", TDF_ALIAS
},
113 {"nouid", TDF_NOUID
},
114 {"enumerate_locals", TDF_ENUMERATE_LOCALS
},
116 {"gimple", TDF_GIMPLE
},
117 {"optimized", MSG_OPTIMIZED_LOCATIONS
},
118 {"missed", MSG_MISSED_OPTIMIZATION
},
121 {"all", ~(TDF_KIND_MASK
| TDF_RAW
| TDF_SLIM
| TDF_LINENO
122 | TDF_STMTADDR
| TDF_GRAPH
| TDF_DIAGNOSTIC
| TDF_VERBOSE
123 | TDF_RHS_ONLY
| TDF_NOUID
| TDF_ENUMERATE_LOCALS
| TDF_SCEV
128 /* A subset of the dump_options table which is used for -fopt-info
129 types. This must be consistent with the MSG_* flags in dumpfile.h.
131 static const struct dump_option_value_info optinfo_verbosity_options
[] =
133 {"optimized", MSG_OPTIMIZED_LOCATIONS
},
134 {"missed", MSG_MISSED_OPTIMIZATION
},
140 /* Flags used for -fopt-info groups. */
141 static const struct dump_option_value_info optgroup_options
[] =
143 {"ipa", OPTGROUP_IPA
},
144 {"loop", OPTGROUP_LOOP
},
145 {"inline", OPTGROUP_INLINE
},
146 {"omp", OPTGROUP_OMP
},
147 {"vec", OPTGROUP_VEC
},
148 {"optall", OPTGROUP_ALL
},
152 gcc::dump_manager::dump_manager ():
153 m_next_dump (FIRST_AUTO_NUMBERED_DUMP
),
154 m_extra_dump_files (NULL
),
155 m_extra_dump_files_in_use (0),
156 m_extra_dump_files_alloced (0)
160 gcc::dump_manager::~dump_manager ()
162 for (size_t i
= 0; i
< m_extra_dump_files_in_use
; i
++)
164 dump_file_info
*dfi
= &m_extra_dump_files
[i
];
165 /* suffix, swtch, glob are statically allocated for the entries
166 in dump_files, and for statistics, but are dynamically allocated
167 for those for passes. */
168 if (dfi
->owns_strings
)
170 XDELETEVEC (const_cast <char *> (dfi
->suffix
));
171 XDELETEVEC (const_cast <char *> (dfi
->swtch
));
172 XDELETEVEC (const_cast <char *> (dfi
->glob
));
174 /* These, if non-NULL, are always dynamically allocated. */
175 XDELETEVEC (const_cast <char *> (dfi
->pfilename
));
176 XDELETEVEC (const_cast <char *> (dfi
->alt_filename
));
178 XDELETEVEC (m_extra_dump_files
);
183 dump_register (const char *suffix
, const char *swtch
, const char *glob
,
184 int flags
, int optgroup_flags
,
187 int num
= m_next_dump
++;
189 size_t count
= m_extra_dump_files_in_use
++;
191 if (count
>= m_extra_dump_files_alloced
)
193 if (m_extra_dump_files_alloced
== 0)
194 m_extra_dump_files_alloced
= 32;
196 m_extra_dump_files_alloced
*= 2;
197 m_extra_dump_files
= XRESIZEVEC (struct dump_file_info
,
199 m_extra_dump_files_alloced
);
202 memset (&m_extra_dump_files
[count
], 0, sizeof (struct dump_file_info
));
203 m_extra_dump_files
[count
].suffix
= suffix
;
204 m_extra_dump_files
[count
].swtch
= swtch
;
205 m_extra_dump_files
[count
].glob
= glob
;
206 m_extra_dump_files
[count
].pflags
= flags
;
207 m_extra_dump_files
[count
].optgroup_flags
= optgroup_flags
;
208 m_extra_dump_files
[count
].num
= num
;
209 m_extra_dump_files
[count
].owns_strings
= take_ownership
;
211 return count
+ TDI_end
;
215 /* Return the dump_file_info for the given phase. */
217 struct dump_file_info
*
219 get_dump_file_info (int phase
) const
222 return &dump_files
[phase
];
223 else if ((size_t) (phase
- TDI_end
) >= m_extra_dump_files_in_use
)
226 return m_extra_dump_files
+ (phase
- TDI_end
);
229 /* Locate the dump_file_info with swtch equal to SWTCH,
230 or return NULL if no such dump_file_info exists. */
232 struct dump_file_info
*
234 get_dump_file_info_by_switch (const char *swtch
) const
236 for (unsigned i
= 0; i
< m_extra_dump_files_in_use
; i
++)
237 if (0 == strcmp (m_extra_dump_files
[i
].swtch
, swtch
))
238 return &m_extra_dump_files
[i
];
245 /* Return the name of the dump file for the given phase.
246 The caller is responsible for calling free on the returned
248 If the dump is not enabled, returns NULL. */
252 get_dump_file_name (int phase
) const
254 struct dump_file_info
*dfi
;
256 if (phase
== TDI_none
)
259 dfi
= get_dump_file_info (phase
);
261 return get_dump_file_name (dfi
);
264 /* Return the name of the dump file for the given dump_file_info.
265 The caller is responsible for calling free on the returned
267 If the dump is not enabled, returns NULL. */
271 get_dump_file_name (struct dump_file_info
*dfi
) const
277 if (dfi
->pstate
== 0)
280 /* If available, use the command line dump filename. */
282 return xstrdup (dfi
->pfilename
);
288 /* LANG, TREE, RTL, IPA. */
289 char suffix
= "ltri"[TDF_KIND (dfi
->pflags
)];
291 if (snprintf (dump_id
, sizeof (dump_id
), ".%03d%c", dfi
->num
, suffix
)
296 return concat (dump_base_name
, dump_id
, dfi
->suffix
, NULL
);
299 /* For a given DFI, open an alternate dump filename (which could also
300 be a standard stream such as stdout/stderr). If the alternate dump
301 file cannot be opened, return NULL. */
304 dump_open_alternate_stream (struct dump_file_info
*dfi
)
307 if (!dfi
->alt_filename
)
311 return dfi
->alt_stream
;
313 stream
= strcmp ("stderr", dfi
->alt_filename
) == 0
315 : strcmp ("stdout", dfi
->alt_filename
) == 0
317 : fopen (dfi
->alt_filename
, dfi
->alt_state
< 0 ? "w" : "a");
320 error ("could not open dump file %qs: %m", dfi
->alt_filename
);
327 /* Print source location on DFILE if enabled. */
330 dump_loc (int dump_kind
, FILE *dfile
, source_location loc
)
334 if (LOCATION_LOCUS (loc
) > BUILTINS_LOCATION
)
335 fprintf (dfile
, "%s:%d:%d: note: ", LOCATION_FILE (loc
),
336 LOCATION_LINE (loc
), LOCATION_COLUMN (loc
));
337 else if (current_function_decl
)
338 fprintf (dfile
, "%s:%d:%d: note: ",
339 DECL_SOURCE_FILE (current_function_decl
),
340 DECL_SOURCE_LINE (current_function_decl
),
341 DECL_SOURCE_COLUMN (current_function_decl
));
345 /* Dump gimple statement GS with SPC indentation spaces and
346 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
349 dump_gimple_stmt (int dump_kind
, int extra_dump_flags
, gimple
*gs
, int spc
)
351 if (dump_file
&& (dump_kind
& pflags
))
352 print_gimple_stmt (dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
354 if (alt_dump_file
&& (dump_kind
& alt_flags
))
355 print_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
358 /* Similar to dump_gimple_stmt, except additionally print source location. */
361 dump_gimple_stmt_loc (int dump_kind
, source_location loc
, int extra_dump_flags
,
364 if (dump_file
&& (dump_kind
& pflags
))
366 dump_loc (dump_kind
, dump_file
, loc
);
367 print_gimple_stmt (dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
370 if (alt_dump_file
&& (dump_kind
& alt_flags
))
372 dump_loc (dump_kind
, alt_dump_file
, loc
);
373 print_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
377 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
378 DUMP_KIND is enabled. */
381 dump_generic_expr (int dump_kind
, int extra_dump_flags
, tree t
)
383 if (dump_file
&& (dump_kind
& pflags
))
384 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
386 if (alt_dump_file
&& (dump_kind
& alt_flags
))
387 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
391 /* Similar to dump_generic_expr, except additionally print the source
395 dump_generic_expr_loc (int dump_kind
, source_location loc
,
396 int extra_dump_flags
, tree t
)
398 if (dump_file
&& (dump_kind
& pflags
))
400 dump_loc (dump_kind
, dump_file
, loc
);
401 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
404 if (alt_dump_file
&& (dump_kind
& alt_flags
))
406 dump_loc (dump_kind
, alt_dump_file
, loc
);
407 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
411 /* Output a formatted message using FORMAT on appropriate dump streams. */
414 dump_printf (int dump_kind
, const char *format
, ...)
416 if (dump_file
&& (dump_kind
& pflags
))
419 va_start (ap
, format
);
420 vfprintf (dump_file
, format
, ap
);
424 if (alt_dump_file
&& (dump_kind
& alt_flags
))
427 va_start (ap
, format
);
428 vfprintf (alt_dump_file
, format
, ap
);
433 /* Similar to dump_printf, except source location is also printed. */
436 dump_printf_loc (int dump_kind
, source_location loc
, const char *format
, ...)
438 if (dump_file
&& (dump_kind
& pflags
))
441 dump_loc (dump_kind
, dump_file
, loc
);
442 va_start (ap
, format
);
443 vfprintf (dump_file
, format
, ap
);
447 if (alt_dump_file
&& (dump_kind
& alt_flags
))
450 dump_loc (dump_kind
, alt_dump_file
, loc
);
451 va_start (ap
, format
);
452 vfprintf (alt_dump_file
, format
, ap
);
457 /* Start a dump for PHASE. Store user-supplied dump flags in
458 *FLAG_PTR. Return the number of streams opened. Set globals
459 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
460 set dump_flags appropriately for both pass dump stream and
461 -fopt-info stream. */
465 dump_start (int phase
, int *flag_ptr
)
469 struct dump_file_info
*dfi
;
471 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
474 dfi
= get_dump_file_info (phase
);
475 name
= get_dump_file_name (phase
);
478 stream
= strcmp ("stderr", name
) == 0
480 : strcmp ("stdout", name
) == 0
482 : fopen (name
, dfi
->pstate
< 0 ? "w" : "a");
484 error ("could not open dump file %qs: %m", name
);
491 dfi
->pstream
= stream
;
492 dump_file
= dfi
->pstream
;
493 /* Initialize current dump flags. */
494 pflags
= TDF_FLAGS (dfi
->pflags
);
497 stream
= dump_open_alternate_stream (dfi
);
500 dfi
->alt_stream
= stream
;
502 alt_dump_file
= dfi
->alt_stream
;
503 /* Initialize current -fopt-info flags. */
504 alt_flags
= TDF_FLAGS (dfi
->alt_flags
);
508 *flag_ptr
= dfi
->pflags
;
513 /* Finish a tree dump for PHASE and close associated dump streams. Also
514 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
518 dump_finish (int phase
)
520 struct dump_file_info
*dfi
;
524 dfi
= get_dump_file_info (phase
);
525 if (dfi
->pstream
&& (!dfi
->pfilename
526 || (strcmp ("stderr", dfi
->pfilename
) != 0
527 && strcmp ("stdout", dfi
->pfilename
) != 0)))
528 fclose (dfi
->pstream
);
530 if (dfi
->alt_stream
&& strcmp ("stderr", dfi
->alt_filename
) != 0
531 && strcmp ("stdout", dfi
->alt_filename
) != 0)
532 fclose (dfi
->alt_stream
);
534 dfi
->alt_stream
= NULL
;
537 alt_dump_file
= NULL
;
538 dump_flags
= TDI_none
;
543 /* Begin a tree dump for PHASE. Stores any user supplied flag in
544 *FLAG_PTR and returns a stream to write to. If the dump is not
545 enabled, returns NULL.
546 Multiple calls will reopen and append to the dump file. */
549 dump_begin (int phase
, int *flag_ptr
)
551 return g
->get_dumps ()->dump_begin (phase
, flag_ptr
);
556 dump_begin (int phase
, int *flag_ptr
)
559 struct dump_file_info
*dfi
;
562 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
565 name
= get_dump_file_name (phase
);
568 dfi
= get_dump_file_info (phase
);
570 stream
= strcmp ("stderr", name
) == 0
572 : strcmp ("stdout", name
) == 0
574 : fopen (name
, dfi
->pstate
< 0 ? "w" : "a");
577 error ("could not open dump file %qs: %m", name
);
583 *flag_ptr
= dfi
->pflags
;
585 /* Initialize current flags */
586 pflags
= dfi
->pflags
;
590 /* Returns nonzero if dump PHASE is enabled for at least one stream.
591 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
596 dump_phase_enabled_p (int phase
) const
598 if (phase
== TDI_tree_all
)
601 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
602 if (dump_files
[i
].pstate
|| dump_files
[i
].alt_state
)
604 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
605 if (m_extra_dump_files
[i
].pstate
|| m_extra_dump_files
[i
].alt_state
)
611 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
612 return dfi
->pstate
|| dfi
->alt_state
;
616 /* Returns nonzero if tree dump PHASE has been initialized. */
620 dump_initialized_p (int phase
) const
622 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
623 return dfi
->pstate
> 0 || dfi
->alt_state
> 0;
626 /* Returns the switch name of PHASE. */
629 dump_flag_name (int phase
)
631 return g
->get_dumps ()->dump_flag_name (phase
);
636 dump_flag_name (int phase
) const
638 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
642 /* Finish a tree dump for PHASE. STREAM is the stream created by
646 dump_end (int phase ATTRIBUTE_UNUSED
, FILE *stream
)
648 if (stream
!= stderr
&& stream
!= stdout
)
652 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
653 enabled tree dumps. */
657 dump_enable_all (int flags
, const char *filename
)
659 int ir_dump_type
= TDF_KIND (flags
);
663 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
665 if (TDF_KIND (dump_files
[i
].pflags
) == ir_dump_type
)
667 const char *old_filename
= dump_files
[i
].pfilename
;
668 dump_files
[i
].pstate
= -1;
669 dump_files
[i
].pflags
|= flags
;
671 /* Override the existing filename. */
674 dump_files
[i
].pfilename
= xstrdup (filename
);
675 /* Since it is a command-line provided file, which is
676 common to all the phases, use it in append mode. */
677 dump_files
[i
].pstate
= 1;
679 if (old_filename
&& filename
!= old_filename
)
680 free (CONST_CAST (char *, old_filename
));
684 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
686 if (TDF_KIND (m_extra_dump_files
[i
].pflags
) == ir_dump_type
)
688 const char *old_filename
= m_extra_dump_files
[i
].pfilename
;
689 m_extra_dump_files
[i
].pstate
= -1;
690 m_extra_dump_files
[i
].pflags
|= flags
;
692 /* Override the existing filename. */
695 m_extra_dump_files
[i
].pfilename
= xstrdup (filename
);
696 /* Since it is a command-line provided file, which is
697 common to all the phases, use it in append mode. */
698 m_extra_dump_files
[i
].pstate
= 1;
700 if (old_filename
&& filename
!= old_filename
)
701 free (CONST_CAST (char *, old_filename
));
708 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
709 Enable dumps with FLAGS on FILENAME. Return the number of enabled
714 opt_info_enable_passes (int optgroup_flags
, int flags
, const char *filename
)
719 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
721 if ((dump_files
[i
].optgroup_flags
& optgroup_flags
))
723 const char *old_filename
= dump_files
[i
].alt_filename
;
724 /* Since this file is shared among different passes, it
725 should be opened in append mode. */
726 dump_files
[i
].alt_state
= 1;
727 dump_files
[i
].alt_flags
|= flags
;
729 /* Override the existing filename. */
731 dump_files
[i
].alt_filename
= xstrdup (filename
);
732 if (old_filename
&& filename
!= old_filename
)
733 free (CONST_CAST (char *, old_filename
));
737 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
739 if ((m_extra_dump_files
[i
].optgroup_flags
& optgroup_flags
))
741 const char *old_filename
= m_extra_dump_files
[i
].alt_filename
;
742 /* Since this file is shared among different passes, it
743 should be opened in append mode. */
744 m_extra_dump_files
[i
].alt_state
= 1;
745 m_extra_dump_files
[i
].alt_flags
|= flags
;
747 /* Override the existing filename. */
749 m_extra_dump_files
[i
].alt_filename
= xstrdup (filename
);
750 if (old_filename
&& filename
!= old_filename
)
751 free (CONST_CAST (char *, old_filename
));
758 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
759 relevant details in the dump_files array. */
763 dump_switch_p_1 (const char *arg
, struct dump_file_info
*dfi
, bool doglob
)
765 const char *option_value
;
769 if (doglob
&& !dfi
->glob
)
772 option_value
= skip_leading_substring (arg
, doglob
? dfi
->glob
: dfi
->swtch
);
776 if (*option_value
&& *option_value
!= '-' && *option_value
!= '=')
784 const struct dump_option_value_info
*option_ptr
;
791 end_ptr
= strchr (ptr
, '-');
792 eq_ptr
= strchr (ptr
, '=');
794 if (eq_ptr
&& !end_ptr
)
798 end_ptr
= ptr
+ strlen (ptr
);
799 length
= end_ptr
- ptr
;
801 for (option_ptr
= dump_options
; option_ptr
->name
; option_ptr
++)
802 if (strlen (option_ptr
->name
) == length
803 && !memcmp (option_ptr
->name
, ptr
, length
))
805 flags
|= option_ptr
->value
;
811 /* Interpret rest of the argument as a dump filename. This
812 filename overrides other command line filenames. */
814 free (CONST_CAST (char *, dfi
->pfilename
));
815 dfi
->pfilename
= xstrdup (ptr
+ 1);
819 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
820 length
, ptr
, dfi
->swtch
);
826 dfi
->pflags
|= flags
;
828 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
830 if (dfi
->suffix
== NULL
)
831 dump_enable_all (dfi
->pflags
, dfi
->pfilename
);
838 dump_switch_p (const char *arg
)
843 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
844 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], false);
846 /* Don't glob if we got a hit already */
848 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
849 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], true);
851 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
852 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], false);
855 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
856 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], true);
862 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
863 and filename. Return non-zero if it is a recognized switch. */
866 opt_info_switch_p_1 (const char *arg
, int *flags
, int *optgroup_flags
,
869 const char *option_value
;
880 return 1; /* Handle '-fopt-info' without any additional options. */
884 const struct dump_option_value_info
*option_ptr
;
891 end_ptr
= strchr (ptr
, '-');
892 eq_ptr
= strchr (ptr
, '=');
894 if (eq_ptr
&& !end_ptr
)
898 end_ptr
= ptr
+ strlen (ptr
);
899 length
= end_ptr
- ptr
;
901 for (option_ptr
= optinfo_verbosity_options
; option_ptr
->name
;
903 if (strlen (option_ptr
->name
) == length
904 && !memcmp (option_ptr
->name
, ptr
, length
))
906 *flags
|= option_ptr
->value
;
910 for (option_ptr
= optgroup_options
; option_ptr
->name
; option_ptr
++)
911 if (strlen (option_ptr
->name
) == length
912 && !memcmp (option_ptr
->name
, ptr
, length
))
914 *optgroup_flags
|= option_ptr
->value
;
920 /* Interpret rest of the argument as a dump filename. This
921 filename overrides other command line filenames. */
922 *filename
= xstrdup (ptr
+ 1);
927 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
938 /* Return non-zero if ARG is a recognized switch for
939 -fopt-info. Return zero otherwise. */
942 opt_info_switch_p (const char *arg
)
947 static char *file_seen
= NULL
;
948 gcc::dump_manager
*dumps
= g
->get_dumps ();
950 if (!opt_info_switch_p_1 (arg
, &flags
, &optgroup_flags
, &filename
))
954 filename
= xstrdup ("stderr");
956 /* Bail out if a different filename has been specified. */
957 if (file_seen
&& strcmp (file_seen
, filename
))
959 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
964 file_seen
= xstrdup (filename
);
966 flags
= MSG_OPTIMIZED_LOCATIONS
;
968 optgroup_flags
= OPTGROUP_ALL
;
970 return dumps
->opt_info_enable_passes (optgroup_flags
, flags
, filename
);
973 /* Print basic block on the dump streams. */
976 dump_basic_block (int dump_kind
, basic_block bb
, int indent
)
978 if (dump_file
&& (dump_kind
& pflags
))
979 dump_bb (dump_file
, bb
, indent
, TDF_DETAILS
);
980 if (alt_dump_file
&& (dump_kind
& alt_flags
))
981 dump_bb (alt_dump_file
, bb
, indent
, TDF_DETAILS
);
984 /* Dump FUNCTION_DECL FN as tree dump PHASE. */
987 dump_function (int phase
, tree fn
)
992 stream
= dump_begin (phase
, &flags
);
995 dump_function_to_file (fn
, stream
, flags
);
996 dump_end (phase
, stream
);
1000 /* Print information from the combine pass on dump_file. */
1003 print_combine_total_stats (void)
1006 dump_combine_total_stats (dump_file
);
1009 /* Enable RTL dump for all the RTL passes. */
1012 enable_rtl_dump_file (void)
1014 gcc::dump_manager
*dumps
= g
->get_dumps ();
1016 dumps
->dump_enable_all (TDF_RTL
| TDF_DETAILS
| TDF_BLOCKS
, NULL
);
1017 return num_enabled
> 0;