PR target/86547
[official-gcc.git] / gcc / dump-context.h
blobf40ea14d2dccedbb69ade1b0a689a0fff315fe6f
1 /* Support code for handling the various dump_* calls in dumpfile.h
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_DUMP_CONTEXT_H
23 #define GCC_DUMP_CONTEXT_H 1
25 #include "pretty-print.h"
27 /* A class for handling the various dump_* calls.
29 In particular, this class has responsibility for consolidating
30 the "dump_*" calls into optinfo instances (delimited by "dump_*_loc"
31 calls), and emitting them.
33 Putting this in a class (rather than as global state) allows
34 for selftesting of this code. */
36 class dump_context
38 friend class temp_dump_context;
39 public:
40 static dump_context &get () { return *s_current; }
42 ~dump_context ();
44 void refresh_dumps_are_enabled ();
46 void dump_loc (dump_flags_t dump_kind, const dump_location_t &loc);
48 void dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
49 gimple *gs, int spc);
51 void dump_gimple_stmt_loc (dump_flags_t dump_kind,
52 const dump_location_t &loc,
53 dump_flags_t extra_dump_flags,
54 gimple *gs, int spc);
56 void dump_gimple_expr (dump_flags_t dump_kind,
57 dump_flags_t extra_dump_flags,
58 gimple *gs, int spc);
60 void dump_gimple_expr_loc (dump_flags_t dump_kind,
61 const dump_location_t &loc,
62 dump_flags_t extra_dump_flags,
63 gimple *gs,
64 int spc);
66 void dump_generic_expr (dump_flags_t dump_kind,
67 dump_flags_t extra_dump_flags,
68 tree t);
70 void dump_generic_expr_loc (dump_flags_t dump_kind,
71 const dump_location_t &loc,
72 dump_flags_t extra_dump_flags,
73 tree t);
75 void dump_printf_va (dump_flags_t dump_kind, const char *format,
76 va_list ap) ATTRIBUTE_PRINTF (3, 0);
78 void dump_printf_loc_va (dump_flags_t dump_kind, const dump_location_t &loc,
79 const char *format, va_list ap)
80 ATTRIBUTE_PRINTF (4, 0);
82 template<unsigned int N, typename C>
83 void dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value);
85 void dump_symtab_node (dump_flags_t dump_kind, symtab_node *node);
87 /* Managing nested scopes. */
88 unsigned int get_scope_depth () const;
89 void begin_scope (const char *name, const dump_location_t &loc);
90 void end_scope ();
92 /* For use in selftests; if true then optinfo_enabled_p is true. */
93 bool forcibly_enable_optinfo_p () const
95 return m_forcibly_enable_optinfo;
98 void end_any_optinfo ();
100 void emit_item (optinfo_item *item, dump_flags_t dump_kind);
102 private:
103 optinfo &ensure_pending_optinfo ();
104 optinfo &begin_next_optinfo (const dump_location_t &loc);
106 /* For use in selftests; if true then optinfo_enabled_p is true. */
107 bool m_forcibly_enable_optinfo;
109 /* The current nesting depth of dump scopes, for showing nesting
110 via indentation). */
111 unsigned int m_scope_depth;
113 /* The optinfo currently being accumulated since the last dump_*_loc call,
114 if any. */
115 optinfo *m_pending;
117 /* For use in selftests: if non-NULL, then items are to be printed
118 to this, using the given flags. */
119 pretty_printer *m_test_pp;
120 dump_flags_t m_test_pp_flags;
122 /* The currently active dump_context, for use by the dump_* API calls. */
123 static dump_context *s_current;
125 /* The default active context. */
126 static dump_context s_default;
129 #if CHECKING_P
131 /* An RAII-style class for use in selftests for temporarily using a different
132 dump_context. */
134 class temp_dump_context
136 public:
137 temp_dump_context (bool forcibly_enable_optinfo,
138 dump_flags_t test_pp_flags);
139 ~temp_dump_context ();
141 /* Support for selftests. */
142 optinfo *get_pending_optinfo () const { return m_context.m_pending; }
143 const char *get_dumped_text ();
145 private:
146 pretty_printer m_pp;
147 dump_context m_context;
148 dump_context *m_saved;
149 bool m_saved_flag_remarks;
152 #endif /* CHECKING_P */
154 #endif /* GCC_DUMP_CONTEXT_H */