[13/46] Make STMT_VINFO_RELATED_STMT a stmt_vec_info
[official-gcc.git] / gcc / optinfo.h
blobc4cf8adeaff0be1bc35f08717ffb1f18c65fd4da
1 /* Optimization information.
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 it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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/>. */
21 #ifndef GCC_OPTINFO_H
22 #define GCC_OPTINFO_H
24 /* An "optinfo" is a bundle of information describing part of an
25 optimization, which can be emitted to zero or more of several
26 destinations, such as:
28 * saved to a file as an "optimization record"
30 They are generated in response to calls to the "dump_*" API in
31 dumpfile.h; repeated calls to the "dump_*" API are consolidated
32 into a pending optinfo instance, with a "dump_*_loc" starting a new
33 optinfo instance.
35 The data sent to the dump calls are captured within the pending optinfo
36 instance as a sequence of optinfo_items. For example, given:
38 if (dump_enabled_p ())
40 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
41 "not vectorized: live stmt not supported: ");
42 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0);
45 the "dump_printf_loc" call begins a new optinfo containing two items:
46 (1) a text item containing "not vectorized: live stmt not supported: "
47 (2) a gimple item for "stmt"
49 Dump destinations are thus able to access rich metadata about the
50 items when the optinfo is emitted to them, rather than just having plain
51 text. For example, when saving the above optinfo to a file as an
52 "optimization record", the record could capture the source location of
53 "stmt" above, rather than just its textual form.
55 The currently pending optinfo is emitted and deleted:
56 * each time a "dump_*_loc" call occurs (which starts the next optinfo), or
57 * when the dump files are changed (at the end of a pass)
59 Dumping to an optinfo instance is non-trivial (due to building optinfo_item
60 instances), so all usage should be guarded by
62 if (optinfo_enabled_p ())
64 which is off by default. */
67 /* Forward decls. */
68 struct opt_pass;
69 class optinfo_item;
71 /* Should optinfo instances be created?
72 All creation of optinfos should be guarded by this predicate.
73 Return true if any optinfo destinations are active. */
75 extern bool optinfo_enabled_p ();
77 /* Return true if any of the active optinfo destinations make use
78 of inlining information.
79 (if true, then the information is preserved). */
81 extern bool optinfo_wants_inlining_info_p ();
83 /* The various kinds of optinfo. */
85 enum optinfo_kind
87 OPTINFO_KIND_SUCCESS,
88 OPTINFO_KIND_FAILURE,
89 OPTINFO_KIND_NOTE,
90 OPTINFO_KIND_SCOPE
93 extern const char *optinfo_kind_to_string (enum optinfo_kind kind);
95 /* A bundle of information describing part of an optimization. */
97 class optinfo
99 friend class dump_context;
101 public:
102 optinfo (const dump_location_t &loc,
103 enum optinfo_kind kind,
104 opt_pass *pass)
105 : m_loc (loc), m_kind (kind), m_pass (pass), m_items ()
107 ~optinfo ();
109 const dump_user_location_t &
110 get_user_location () const { return m_loc.get_user_location (); }
112 const dump_impl_location_t &
113 get_impl_location () const { return m_loc.get_impl_location (); }
115 enum optinfo_kind get_kind () const { return m_kind; }
116 opt_pass *get_pass () const { return m_pass; }
117 unsigned int num_items () const { return m_items.length (); }
118 const optinfo_item *get_item (unsigned int i) const { return m_items[i]; }
120 location_t get_location_t () const { return m_loc.get_location_t (); }
121 profile_count get_count () const { return m_loc.get_count (); }
123 private:
124 void emit ();
126 /* Pre-canned ways of manipulating the optinfo, for use by friend class
127 dump_context. */
128 void handle_dump_file_kind (dump_flags_t);
129 void add_string (const char *str);
130 void add_printf (const char *format, ...) ATTRIBUTE_PRINTF_2;
131 void add_printf_va (const char *format, va_list ap) ATTRIBUTE_PRINTF (2, 0);
132 void add_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags);
133 void add_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags);
134 void add_tree (tree node, dump_flags_t dump_flags);
135 void add_symtab_node (symtab_node *node);
136 void add_dec (const wide_int_ref &wi, signop sgn);
138 template<unsigned int N, typename C>
139 void add_poly_int (const poly_int<N, C> &value)
141 /* Compare with dump_dec (MSG_NOTE, ). */
143 STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
144 signop sgn = poly_coeff_traits<C>::signedness ? SIGNED : UNSIGNED;
146 if (value.is_constant ())
147 add_dec (value.coeffs[0], sgn);
148 else
150 add_string ("[");
151 for (unsigned int i = 0; i < N; ++i)
153 add_dec (value.coeffs[i], sgn);
154 add_string (i == N - 1 ? "]" : ",");
159 private:
160 dump_location_t m_loc;
161 enum optinfo_kind m_kind;
162 opt_pass *m_pass;
163 auto_vec <optinfo_item *> m_items;
166 /* An enum for discriminating between different kinds of optinfo_item. */
168 enum optinfo_item_kind
170 OPTINFO_ITEM_KIND_TEXT,
171 OPTINFO_ITEM_KIND_TREE,
172 OPTINFO_ITEM_KIND_GIMPLE,
173 OPTINFO_ITEM_KIND_SYMTAB_NODE
176 /* An item within an optinfo. */
178 class optinfo_item
180 public:
181 optinfo_item (enum optinfo_item_kind kind, location_t location,
182 char *text, bool owned);
183 ~optinfo_item ();
185 enum optinfo_item_kind get_kind () const { return m_kind; }
186 location_t get_location () const { return m_location; }
187 const char *get_text () const { return m_text; }
189 private:
190 /* Metadata (e.g. for optimization records). */
191 enum optinfo_item_kind m_kind;
192 location_t m_location;
194 /* The textual form of the item. */
195 char *m_text;
196 bool m_owned;
199 #endif /* #ifndef GCC_OPTINFO_H */