1 /* Dump infrastructure for optimizations and intermediate representation.
2 Copyright (C) 2012-2018 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"
29 #include "profile-count.h"
31 #include "langhooks.h"
33 /* If non-NULL, return one past-the-end of the matching SUBPART of
35 #define skip_leading_substring(whole, part) \
36 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
38 static dump_flags_t pflags
; /* current dump_flags */
39 static dump_flags_t alt_flags
; /* current opt_info flags */
41 static void dump_loc (dump_flags_t
, FILE *, source_location
);
42 static FILE *dump_open_alternate_stream (struct dump_file_info
*);
44 /* These are currently used for communicating between passes.
45 However, instead of accessing them directly, the passes can use
46 dump_printf () for dumps. */
47 FILE *dump_file
= NULL
;
48 FILE *alt_dump_file
= NULL
;
49 const char *dump_file_name
;
50 dump_flags_t dump_flags
;
52 #define DUMP_FILE_INFO(suffix, swtch, dkind, num) \
53 {suffix, swtch, NULL, NULL, NULL, NULL, NULL, dkind, TDF_NONE, TDF_NONE, \
54 OPTGROUP_NONE, 0, 0, num, false, false}
56 /* Table of tree dump switches. This must be consistent with the
57 TREE_DUMP_INDEX enumeration in dumpfile.h. */
58 static struct dump_file_info dump_files
[TDI_end
] =
60 DUMP_FILE_INFO (NULL
, NULL
, DK_none
, 0),
61 DUMP_FILE_INFO (".cgraph", "ipa-cgraph", DK_ipa
, 0),
62 DUMP_FILE_INFO (".type-inheritance", "ipa-type-inheritance", DK_ipa
, 0),
63 DUMP_FILE_INFO (".ipa-clones", "ipa-clones", DK_ipa
, 0),
64 DUMP_FILE_INFO (".original", "tree-original", DK_tree
, 0),
65 DUMP_FILE_INFO (".gimple", "tree-gimple", DK_tree
, 0),
66 DUMP_FILE_INFO (".nested", "tree-nested", DK_tree
, 0),
67 #define FIRST_AUTO_NUMBERED_DUMP 1
68 #define FIRST_ME_AUTO_NUMBERED_DUMP 4
70 DUMP_FILE_INFO (NULL
, "lang-all", DK_lang
, 0),
71 DUMP_FILE_INFO (NULL
, "tree-all", DK_tree
, 0),
72 DUMP_FILE_INFO (NULL
, "rtl-all", DK_rtl
, 0),
73 DUMP_FILE_INFO (NULL
, "ipa-all", DK_ipa
, 0),
76 /* Define a name->number mapping for a dump flag value. */
77 template <typename ValueType
>
80 const char *const name
; /* the name of the value */
81 const ValueType value
; /* the value of the name */
84 /* Table of dump options. This must be consistent with the TDF_* flags
85 in dumpfile.h and opt_info_options below. */
86 static const kv_pair
<dump_flags_t
> dump_options
[] =
88 {"address", TDF_ADDRESS
},
89 {"asmname", TDF_ASMNAME
},
93 {"details", (TDF_DETAILS
| MSG_OPTIMIZED_LOCATIONS
94 | MSG_MISSED_OPTIMIZATION
96 {"cselib", TDF_CSELIB
},
98 {"blocks", TDF_BLOCKS
},
100 {"lineno", TDF_LINENO
},
102 {"stmtaddr", TDF_STMTADDR
},
103 {"memsyms", TDF_MEMSYMS
},
105 {"alias", TDF_ALIAS
},
106 {"nouid", TDF_NOUID
},
107 {"enumerate_locals", TDF_ENUMERATE_LOCALS
},
109 {"gimple", TDF_GIMPLE
},
110 {"folding", TDF_FOLDING
},
111 {"optimized", MSG_OPTIMIZED_LOCATIONS
},
112 {"missed", MSG_MISSED_OPTIMIZATION
},
115 {"all", dump_flags_t (~(TDF_RAW
| TDF_SLIM
| TDF_LINENO
| TDF_GRAPH
116 | TDF_STMTADDR
| TDF_RHS_ONLY
| TDF_NOUID
117 | TDF_ENUMERATE_LOCALS
| TDF_SCEV
| TDF_GIMPLE
))},
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 kv_pair
<dump_flags_t
> optinfo_verbosity_options
[] =
126 {"optimized", MSG_OPTIMIZED_LOCATIONS
},
127 {"missed", MSG_MISSED_OPTIMIZATION
},
133 /* Flags used for -fopt-info groups. */
134 static const kv_pair
<optgroup_flags_t
> optgroup_options
[] =
136 {"ipa", OPTGROUP_IPA
},
137 {"loop", OPTGROUP_LOOP
},
138 {"inline", OPTGROUP_INLINE
},
139 {"omp", OPTGROUP_OMP
},
140 {"vec", OPTGROUP_VEC
},
141 {"optall", OPTGROUP_ALL
},
142 {NULL
, OPTGROUP_NONE
}
145 gcc::dump_manager::dump_manager ():
146 m_next_dump (FIRST_AUTO_NUMBERED_DUMP
),
147 m_extra_dump_files (NULL
),
148 m_extra_dump_files_in_use (0),
149 m_extra_dump_files_alloced (0)
153 gcc::dump_manager::~dump_manager ()
155 for (size_t i
= 0; i
< m_extra_dump_files_in_use
; i
++)
157 dump_file_info
*dfi
= &m_extra_dump_files
[i
];
158 /* suffix, swtch, glob are statically allocated for the entries
159 in dump_files, and for statistics, but are dynamically allocated
160 for those for passes. */
161 if (dfi
->owns_strings
)
163 XDELETEVEC (const_cast <char *> (dfi
->suffix
));
164 XDELETEVEC (const_cast <char *> (dfi
->swtch
));
165 XDELETEVEC (const_cast <char *> (dfi
->glob
));
167 /* These, if non-NULL, are always dynamically allocated. */
168 XDELETEVEC (const_cast <char *> (dfi
->pfilename
));
169 XDELETEVEC (const_cast <char *> (dfi
->alt_filename
));
171 XDELETEVEC (m_extra_dump_files
);
176 dump_register (const char *suffix
, const char *swtch
, const char *glob
,
177 dump_kind dkind
, optgroup_flags_t optgroup_flags
,
180 int num
= m_next_dump
++;
182 size_t count
= m_extra_dump_files_in_use
++;
184 if (count
>= m_extra_dump_files_alloced
)
186 if (m_extra_dump_files_alloced
== 0)
187 m_extra_dump_files_alloced
= 512;
189 m_extra_dump_files_alloced
*= 2;
190 m_extra_dump_files
= XRESIZEVEC (struct dump_file_info
,
192 m_extra_dump_files_alloced
);
194 /* Construct a new object in the space allocated above. */
195 new (m_extra_dump_files
+ count
) dump_file_info ();
199 /* Zero out the already constructed object. */
200 m_extra_dump_files
[count
] = 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
].dkind
= dkind
;
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 /* Allow languages and middle-end to register their dumps before the
216 optimization passes. */
222 lang_hooks
.register_dumps (this);
223 /* If this assert fails, some FE registered more than
224 FIRST_ME_AUTO_NUMBERED_DUMP - FIRST_AUTO_NUMBERED_DUMP
225 dump files. Bump FIRST_ME_AUTO_NUMBERED_DUMP accordingly. */
226 gcc_assert (m_next_dump
<= FIRST_ME_AUTO_NUMBERED_DUMP
);
227 m_next_dump
= FIRST_ME_AUTO_NUMBERED_DUMP
;
228 dump_files
[TDI_original
].num
= m_next_dump
++;
229 dump_files
[TDI_gimple
].num
= m_next_dump
++;
230 dump_files
[TDI_nested
].num
= m_next_dump
++;
234 /* Return the dump_file_info for the given phase. */
236 struct dump_file_info
*
238 get_dump_file_info (int phase
) const
241 return &dump_files
[phase
];
242 else if ((size_t) (phase
- TDI_end
) >= m_extra_dump_files_in_use
)
245 return m_extra_dump_files
+ (phase
- TDI_end
);
248 /* Locate the dump_file_info with swtch equal to SWTCH,
249 or return NULL if no such dump_file_info exists. */
251 struct dump_file_info
*
253 get_dump_file_info_by_switch (const char *swtch
) const
255 for (unsigned i
= 0; i
< m_extra_dump_files_in_use
; i
++)
256 if (strcmp (m_extra_dump_files
[i
].swtch
, swtch
) == 0)
257 return &m_extra_dump_files
[i
];
264 /* Return the name of the dump file for the given phase.
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 (int phase
) const
273 struct dump_file_info
*dfi
;
275 if (phase
== TDI_none
)
278 dfi
= get_dump_file_info (phase
);
280 return get_dump_file_name (dfi
);
283 /* Return the name of the dump file for the given dump_file_info.
284 The caller is responsible for calling free on the returned
286 If the dump is not enabled, returns NULL. */
290 get_dump_file_name (struct dump_file_info
*dfi
) const
296 if (dfi
->pstate
== 0)
299 /* If available, use the command line dump filename. */
301 return xstrdup (dfi
->pfilename
);
307 /* (null), LANG, TREE, RTL, IPA. */
308 char suffix
= " ltri"[dfi
->dkind
];
310 if (snprintf (dump_id
, sizeof (dump_id
), ".%03d%c", dfi
->num
, suffix
) < 0)
314 return concat (dump_base_name
, dump_id
, dfi
->suffix
, NULL
);
317 /* Open a dump file called FILENAME. Some filenames are special and
318 refer to the standard streams. TRUNC indicates whether this is the
319 first open (so the file should be truncated, rather than appended).
320 An error message is emitted in the event of failure. */
323 dump_open (const char *filename
, bool trunc
)
325 if (strcmp ("stderr", filename
) == 0)
328 if (strcmp ("stdout", filename
) == 0
329 || strcmp ("-", filename
) == 0)
332 FILE *stream
= fopen (filename
, trunc
? "w" : "a");
335 error ("could not open dump file %qs: %m", filename
);
339 /* For a given DFI, open an alternate dump filename (which could also
340 be a standard stream such as stdout/stderr). If the alternate dump
341 file cannot be opened, return NULL. */
344 dump_open_alternate_stream (struct dump_file_info
*dfi
)
346 if (!dfi
->alt_filename
)
350 return dfi
->alt_stream
;
352 FILE *stream
= dump_open (dfi
->alt_filename
, dfi
->alt_state
< 0);
360 /* Print source location on DFILE if enabled. */
363 dump_loc (dump_flags_t dump_kind
, FILE *dfile
, source_location loc
)
367 if (LOCATION_LOCUS (loc
) > BUILTINS_LOCATION
)
368 fprintf (dfile
, "%s:%d:%d: note: ", LOCATION_FILE (loc
),
369 LOCATION_LINE (loc
), LOCATION_COLUMN (loc
));
370 else if (current_function_decl
)
371 fprintf (dfile
, "%s:%d:%d: note: ",
372 DECL_SOURCE_FILE (current_function_decl
),
373 DECL_SOURCE_LINE (current_function_decl
),
374 DECL_SOURCE_COLUMN (current_function_decl
));
378 /* Dump gimple statement GS with SPC indentation spaces and
379 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
382 dump_gimple_stmt (dump_flags_t dump_kind
, dump_flags_t extra_dump_flags
,
385 if (dump_file
&& (dump_kind
& pflags
))
386 print_gimple_stmt (dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
388 if (alt_dump_file
&& (dump_kind
& alt_flags
))
389 print_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
392 /* Similar to dump_gimple_stmt, except additionally print source location. */
395 dump_gimple_stmt_loc (dump_flags_t dump_kind
, source_location loc
,
396 dump_flags_t extra_dump_flags
, gimple
*gs
, int spc
)
398 if (dump_file
&& (dump_kind
& pflags
))
400 dump_loc (dump_kind
, dump_file
, loc
);
401 print_gimple_stmt (dump_file
, gs
, spc
, 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_gimple_stmt (alt_dump_file
, gs
, spc
, dump_flags
| extra_dump_flags
);
411 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
412 DUMP_KIND is enabled. */
415 dump_generic_expr (dump_flags_t dump_kind
, dump_flags_t extra_dump_flags
,
418 if (dump_file
&& (dump_kind
& pflags
))
419 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
421 if (alt_dump_file
&& (dump_kind
& alt_flags
))
422 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
426 /* Similar to dump_generic_expr, except additionally print the source
430 dump_generic_expr_loc (dump_flags_t dump_kind
, source_location loc
,
431 dump_flags_t extra_dump_flags
, tree t
)
433 if (dump_file
&& (dump_kind
& pflags
))
435 dump_loc (dump_kind
, dump_file
, loc
);
436 print_generic_expr (dump_file
, t
, dump_flags
| extra_dump_flags
);
439 if (alt_dump_file
&& (dump_kind
& alt_flags
))
441 dump_loc (dump_kind
, alt_dump_file
, loc
);
442 print_generic_expr (alt_dump_file
, t
, dump_flags
| extra_dump_flags
);
446 /* Output a formatted message using FORMAT on appropriate dump streams. */
449 dump_printf (dump_flags_t dump_kind
, const char *format
, ...)
451 if (dump_file
&& (dump_kind
& pflags
))
454 va_start (ap
, format
);
455 vfprintf (dump_file
, format
, ap
);
459 if (alt_dump_file
&& (dump_kind
& alt_flags
))
462 va_start (ap
, format
);
463 vfprintf (alt_dump_file
, format
, ap
);
468 /* Similar to dump_printf, except source location is also printed. */
471 dump_printf_loc (dump_flags_t dump_kind
, source_location loc
,
472 const char *format
, ...)
474 if (dump_file
&& (dump_kind
& pflags
))
477 dump_loc (dump_kind
, dump_file
, loc
);
478 va_start (ap
, format
);
479 vfprintf (dump_file
, format
, ap
);
483 if (alt_dump_file
&& (dump_kind
& alt_flags
))
486 dump_loc (dump_kind
, alt_dump_file
, loc
);
487 va_start (ap
, format
);
488 vfprintf (alt_dump_file
, format
, ap
);
493 /* Output VALUE in decimal to appropriate dump streams. */
495 template<unsigned int N
, typename C
>
497 dump_dec (dump_flags_t dump_kind
, const poly_int
<N
, C
> &value
)
499 STATIC_ASSERT (poly_coeff_traits
<C
>::signedness
>= 0);
500 signop sgn
= poly_coeff_traits
<C
>::signedness
? SIGNED
: UNSIGNED
;
501 if (dump_file
&& (dump_kind
& pflags
))
502 print_dec (value
, dump_file
, sgn
);
504 if (alt_dump_file
&& (dump_kind
& alt_flags
))
505 print_dec (value
, alt_dump_file
, sgn
);
508 template void dump_dec (dump_flags_t
, const poly_uint16
&);
509 template void dump_dec (dump_flags_t
, const poly_int64
&);
510 template void dump_dec (dump_flags_t
, const poly_uint64
&);
511 template void dump_dec (dump_flags_t
, const poly_offset_int
&);
512 template void dump_dec (dump_flags_t
, const poly_widest_int
&);
514 /* Start a dump for PHASE. Store user-supplied dump flags in
515 *FLAG_PTR. Return the number of streams opened. Set globals
516 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
517 set dump_flags appropriately for both pass dump stream and
518 -fopt-info stream. */
522 dump_start (int phase
, dump_flags_t
*flag_ptr
)
526 struct dump_file_info
*dfi
;
528 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
531 dfi
= get_dump_file_info (phase
);
532 name
= get_dump_file_name (phase
);
535 stream
= dump_open (name
, dfi
->pstate
< 0);
542 dfi
->pstream
= stream
;
543 dump_file
= dfi
->pstream
;
544 /* Initialize current dump flags. */
545 pflags
= dfi
->pflags
;
548 stream
= dump_open_alternate_stream (dfi
);
551 dfi
->alt_stream
= stream
;
553 alt_dump_file
= dfi
->alt_stream
;
554 /* Initialize current -fopt-info flags. */
555 alt_flags
= dfi
->alt_flags
;
559 *flag_ptr
= dfi
->pflags
;
564 /* Finish a tree dump for PHASE and close associated dump streams. Also
565 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
569 dump_finish (int phase
)
571 struct dump_file_info
*dfi
;
575 dfi
= get_dump_file_info (phase
);
576 if (dfi
->pstream
&& dfi
->pstream
!= stdout
&& dfi
->pstream
!= stderr
)
577 fclose (dfi
->pstream
);
579 if (dfi
->alt_stream
&& dfi
->alt_stream
!= stdout
&& dfi
->alt_stream
!= stderr
)
580 fclose (dfi
->alt_stream
);
582 dfi
->alt_stream
= NULL
;
585 alt_dump_file
= NULL
;
586 dump_flags
= TDF_NONE
;
587 alt_flags
= TDF_NONE
;
591 /* Begin a tree dump for PHASE. Stores any user supplied flag in
592 *FLAG_PTR and returns a stream to write to. If the dump is not
593 enabled, returns NULL.
594 Multiple calls will reopen and append to the dump file. */
597 dump_begin (int phase
, dump_flags_t
*flag_ptr
)
599 return g
->get_dumps ()->dump_begin (phase
, flag_ptr
);
604 dump_begin (int phase
, dump_flags_t
*flag_ptr
)
607 struct dump_file_info
*dfi
;
610 if (phase
== TDI_none
|| !dump_phase_enabled_p (phase
))
613 name
= get_dump_file_name (phase
);
616 dfi
= get_dump_file_info (phase
);
618 stream
= dump_open (name
, dfi
->pstate
< 0);
624 *flag_ptr
= dfi
->pflags
;
626 /* Initialize current flags */
627 pflags
= dfi
->pflags
;
631 /* Returns nonzero if dump PHASE is enabled for at least one stream.
632 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
637 dump_phase_enabled_p (int phase
) const
639 if (phase
== TDI_tree_all
)
642 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
643 if (dump_files
[i
].pstate
|| dump_files
[i
].alt_state
)
645 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
646 if (m_extra_dump_files
[i
].pstate
|| m_extra_dump_files
[i
].alt_state
)
652 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
653 return dfi
->pstate
|| dfi
->alt_state
;
657 /* Returns nonzero if tree dump PHASE has been initialized. */
661 dump_initialized_p (int phase
) const
663 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
664 return dfi
->pstate
> 0 || dfi
->alt_state
> 0;
667 /* Returns the switch name of PHASE. */
670 dump_flag_name (int phase
)
672 return g
->get_dumps ()->dump_flag_name (phase
);
677 dump_flag_name (int phase
) const
679 struct dump_file_info
*dfi
= get_dump_file_info (phase
);
683 /* Finish a tree dump for PHASE. STREAM is the stream created by
687 dump_end (int phase ATTRIBUTE_UNUSED
, FILE *stream
)
689 if (stream
!= stderr
&& stream
!= stdout
)
693 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
694 enabled tree dumps. */
698 dump_enable_all (dump_kind dkind
, dump_flags_t flags
, const char *filename
)
703 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
705 if ((dump_files
[i
].dkind
== dkind
))
707 const char *old_filename
= dump_files
[i
].pfilename
;
708 dump_files
[i
].pstate
= -1;
709 dump_files
[i
].pflags
|= flags
;
711 /* Override the existing filename. */
714 dump_files
[i
].pfilename
= xstrdup (filename
);
715 /* Since it is a command-line provided file, which is
716 common to all the phases, use it in append mode. */
717 dump_files
[i
].pstate
= 1;
719 if (old_filename
&& filename
!= old_filename
)
720 free (CONST_CAST (char *, old_filename
));
724 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
726 if ((m_extra_dump_files
[i
].dkind
== dkind
))
728 const char *old_filename
= m_extra_dump_files
[i
].pfilename
;
729 m_extra_dump_files
[i
].pstate
= -1;
730 m_extra_dump_files
[i
].pflags
|= flags
;
732 /* Override the existing filename. */
735 m_extra_dump_files
[i
].pfilename
= xstrdup (filename
);
736 /* Since it is a command-line provided file, which is
737 common to all the phases, use it in append mode. */
738 m_extra_dump_files
[i
].pstate
= 1;
740 if (old_filename
&& filename
!= old_filename
)
741 free (CONST_CAST (char *, old_filename
));
748 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
749 Enable dumps with FLAGS on FILENAME. Return the number of enabled
754 opt_info_enable_passes (optgroup_flags_t optgroup_flags
, dump_flags_t flags
,
755 const char *filename
)
760 for (i
= TDI_none
+ 1; i
< (size_t) TDI_end
; i
++)
762 if ((dump_files
[i
].optgroup_flags
& optgroup_flags
))
764 const char *old_filename
= dump_files
[i
].alt_filename
;
765 /* Since this file is shared among different passes, it
766 should be opened in append mode. */
767 dump_files
[i
].alt_state
= 1;
768 dump_files
[i
].alt_flags
|= flags
;
770 /* Override the existing filename. */
772 dump_files
[i
].alt_filename
= xstrdup (filename
);
773 if (old_filename
&& filename
!= old_filename
)
774 free (CONST_CAST (char *, old_filename
));
778 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
780 if ((m_extra_dump_files
[i
].optgroup_flags
& optgroup_flags
))
782 const char *old_filename
= m_extra_dump_files
[i
].alt_filename
;
783 /* Since this file is shared among different passes, it
784 should be opened in append mode. */
785 m_extra_dump_files
[i
].alt_state
= 1;
786 m_extra_dump_files
[i
].alt_flags
|= flags
;
788 /* Override the existing filename. */
790 m_extra_dump_files
[i
].alt_filename
= xstrdup (filename
);
791 if (old_filename
&& filename
!= old_filename
)
792 free (CONST_CAST (char *, old_filename
));
799 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
800 relevant details in the dump_files array. */
804 dump_switch_p_1 (const char *arg
, struct dump_file_info
*dfi
, bool doglob
)
806 const char *option_value
;
810 if (doglob
&& !dfi
->glob
)
813 option_value
= skip_leading_substring (arg
, doglob
? dfi
->glob
: dfi
->swtch
);
817 if (*option_value
&& *option_value
!= '-' && *option_value
!= '=')
825 const struct kv_pair
<dump_flags_t
> *option_ptr
;
832 end_ptr
= strchr (ptr
, '-');
833 eq_ptr
= strchr (ptr
, '=');
835 if (eq_ptr
&& !end_ptr
)
839 end_ptr
= ptr
+ strlen (ptr
);
840 length
= end_ptr
- ptr
;
842 for (option_ptr
= dump_options
; option_ptr
->name
; option_ptr
++)
843 if (strlen (option_ptr
->name
) == length
844 && !memcmp (option_ptr
->name
, ptr
, length
))
846 flags
|= option_ptr
->value
;
852 /* Interpret rest of the argument as a dump filename. This
853 filename overrides other command line filenames. */
855 free (CONST_CAST (char *, dfi
->pfilename
));
856 dfi
->pfilename
= xstrdup (ptr
+ 1);
860 warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
861 length
, ptr
, dfi
->swtch
);
867 dfi
->pflags
|= flags
;
869 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
871 if (dfi
->suffix
== NULL
)
872 dump_enable_all (dfi
->dkind
, dfi
->pflags
, dfi
->pfilename
);
879 dump_switch_p (const char *arg
)
884 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
885 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], false);
887 /* Don't glob if we got a hit already */
889 for (i
= TDI_none
+ 1; i
!= TDI_end
; i
++)
890 any
|= dump_switch_p_1 (arg
, &dump_files
[i
], true);
892 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
893 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], false);
896 for (i
= 0; i
< m_extra_dump_files_in_use
; i
++)
897 any
|= dump_switch_p_1 (arg
, &m_extra_dump_files
[i
], true);
903 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
904 and filename. Return non-zero if it is a recognized switch. */
907 opt_info_switch_p_1 (const char *arg
, dump_flags_t
*flags
,
908 optgroup_flags_t
*optgroup_flags
, char **filename
)
910 const char *option_value
;
918 *optgroup_flags
= OPTGROUP_NONE
;
921 return 1; /* Handle '-fopt-info' without any additional options. */
931 end_ptr
= strchr (ptr
, '-');
932 eq_ptr
= strchr (ptr
, '=');
934 if (eq_ptr
&& !end_ptr
)
938 end_ptr
= ptr
+ strlen (ptr
);
939 length
= end_ptr
- ptr
;
941 for (const kv_pair
<dump_flags_t
> *option_ptr
= optinfo_verbosity_options
;
942 option_ptr
->name
; option_ptr
++)
943 if (strlen (option_ptr
->name
) == length
944 && !memcmp (option_ptr
->name
, ptr
, length
))
946 *flags
|= option_ptr
->value
;
950 for (const kv_pair
<optgroup_flags_t
> *option_ptr
= optgroup_options
;
951 option_ptr
->name
; option_ptr
++)
952 if (strlen (option_ptr
->name
) == length
953 && !memcmp (option_ptr
->name
, ptr
, length
))
955 *optgroup_flags
|= option_ptr
->value
;
961 /* Interpret rest of the argument as a dump filename. This
962 filename overrides other command line filenames. */
963 *filename
= xstrdup (ptr
+ 1);
968 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
979 /* Return non-zero if ARG is a recognized switch for
980 -fopt-info. Return zero otherwise. */
983 opt_info_switch_p (const char *arg
)
986 optgroup_flags_t optgroup_flags
;
988 static char *file_seen
= NULL
;
989 gcc::dump_manager
*dumps
= g
->get_dumps ();
991 if (!opt_info_switch_p_1 (arg
, &flags
, &optgroup_flags
, &filename
))
995 filename
= xstrdup ("stderr");
997 /* Bail out if a different filename has been specified. */
998 if (file_seen
&& strcmp (file_seen
, filename
))
1000 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
1005 file_seen
= xstrdup (filename
);
1007 flags
= MSG_OPTIMIZED_LOCATIONS
;
1008 if (!optgroup_flags
)
1009 optgroup_flags
= OPTGROUP_ALL
;
1011 return dumps
->opt_info_enable_passes (optgroup_flags
, flags
, filename
);
1014 /* Print basic block on the dump streams. */
1017 dump_basic_block (dump_flags_t dump_kind
, basic_block bb
, int indent
)
1019 if (dump_file
&& (dump_kind
& pflags
))
1020 dump_bb (dump_file
, bb
, indent
, TDF_DETAILS
);
1021 if (alt_dump_file
&& (dump_kind
& alt_flags
))
1022 dump_bb (alt_dump_file
, bb
, indent
, TDF_DETAILS
);
1025 /* Dump FUNCTION_DECL FN as tree dump PHASE. */
1028 dump_function (int phase
, tree fn
)
1033 stream
= dump_begin (phase
, &flags
);
1036 dump_function_to_file (fn
, stream
, flags
);
1037 dump_end (phase
, stream
);
1041 /* Print information from the combine pass on dump_file. */
1044 print_combine_total_stats (void)
1047 dump_combine_total_stats (dump_file
);
1050 /* Enable RTL dump for all the RTL passes. */
1053 enable_rtl_dump_file (void)
1055 gcc::dump_manager
*dumps
= g
->get_dumps ();
1057 dumps
->dump_enable_all (DK_rtl
, dump_flags_t (TDF_DETAILS
) | TDF_BLOCKS
,
1059 return num_enabled
> 0;