GCC Middle and Back End API Reference
optinfo.h
Go to the documentation of this file.
1/* Optimization information.
2 Copyright (C) 2018-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_OPTINFO_H
22#define GCC_OPTINFO_H
23
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:
27
28 * saved to a file as an "optimization record"
29
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.
34
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:
37
38 if (dump_enabled_p ())
39 {
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);
43 }
44
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"
48
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.
54
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)
58
59 Dumping to an optinfo instance is non-trivial (due to building optinfo_item
60 instances), so all usage should be guarded by
61
62 if (optinfo_enabled_p ())
63
64 which is off by default. */
65
66
67/* Forward decls. */
68class opt_pass;
69class optinfo_item;
70
71/* Return true if any of the active optinfo destinations make use
72 of inlining information.
73 (if true, then the information is preserved). */
74
76
77class dump_context;
78
79/* A bundle of information describing part of an optimization. */
80
82{
83 friend class dump_context;
84
85 public:
86 /* The various kinds of optinfo. */
87 enum class kind
88 {
93 };
94
96 enum kind kind_,
97 opt_pass *pass)
98 : m_loc (loc), m_kind (kind_), m_pass (pass), m_items ()
99 {}
100 ~optinfo ();
101
102 const dump_location_t &
103 get_dump_location () const { return m_loc; }
104
106 get_user_location () const { return m_loc.get_user_location (); }
107
109 get_impl_location () const { return m_loc.get_impl_location (); }
110
111 enum kind get_kind () const { return m_kind; }
112 opt_pass *get_pass () const { return m_pass; }
113 unsigned int num_items () const { return m_items.length (); }
114 const optinfo_item *get_item (unsigned int i) const { return m_items[i]; }
115
116 location_t get_location_t () const { return m_loc.get_location_t (); }
117 profile_count get_count () const { return m_loc.get_count (); }
118
119 void add_item (std::unique_ptr<optinfo_item> item);
120
121 void emit_for_opt_problem () const;
122
123 static const char *kind_to_string (enum kind k);
124 static dump_flags_t kind_to_dump_flag (enum kind k);
125
126 private:
127 /* Pre-canned ways of manipulating the optinfo, for use by friend class
128 dump_context. */
130
131 private:
135 auto_vec <optinfo_item *> m_items;
136};
137
138/* An item within an optinfo. */
139
141{
142 public:
143 /* An enum for discriminating between different kinds of optinfo_item. */
144 enum class kind
145 {
150 };
151
152 optinfo_item (enum kind kind_, location_t location,
153 char *text);
154 ~optinfo_item ();
155
156 enum kind get_kind () const { return m_kind; }
157 location_t get_location () const { return m_location; }
158 const char *get_text () const { return m_text; }
159
160 private:
161 /* Metadata (e.g. for optimization records). */
163 location_t m_location;
164
165 /* The textual form of the item, owned by the item. */
166 char *m_text;
167};
168
169#endif /* #ifndef GCC_OPTINFO_H */
Definition dump-context.h:44
Definition dumpfile.h:381
Definition dumpfile.h:446
Definition dumpfile.h:340
Definition tree-pass.h:74
Definition optinfo.h:141
location_t m_location
Definition optinfo.h:163
location_t get_location() const
Definition optinfo.h:157
const char * get_text() const
Definition optinfo.h:158
~optinfo_item()
Definition optinfo.cc:47
enum kind m_kind
Definition optinfo.h:162
optinfo_item(enum kind kind_, location_t location, char *text)
Definition optinfo.cc:39
char * m_text
Definition optinfo.h:166
enum kind get_kind() const
Definition optinfo.h:156
kind
Definition optinfo.h:145
@ text
Definition optinfo.h:146
@ symtab_node
Definition optinfo.h:149
@ tree
Definition optinfo.h:147
@ gimple
Definition optinfo.h:148
const optinfo_item * get_item(unsigned int i) const
Definition optinfo.h:114
const dump_impl_location_t & get_impl_location() const
Definition optinfo.h:109
const dump_user_location_t & get_user_location() const
Definition optinfo.h:106
optinfo(const dump_location_t &loc, enum kind kind_, opt_pass *pass)
Definition optinfo.h:95
static const char * kind_to_string(enum kind k)
Definition optinfo.cc:55
void emit_for_opt_problem() const
Definition optinfo.cc:115
profile_count get_count() const
Definition optinfo.h:117
kind
Definition optinfo.h:88
@ success
Definition optinfo.h:89
@ scope
Definition optinfo.h:92
@ failure
Definition optinfo.h:90
@ note
Definition optinfo.h:91
void handle_dump_file_kind(dump_flags_t)
Definition optinfo.cc:134
const dump_location_t & get_dump_location() const
Definition optinfo.h:103
enum kind m_kind
Definition optinfo.h:133
static dump_flags_t kind_to_dump_flag(enum kind k)
Definition optinfo.cc:95
opt_pass * m_pass
Definition optinfo.h:134
void add_item(std::unique_ptr< optinfo_item > item)
Definition optinfo.cc:86
friend class dump_context
Definition optinfo.h:83
enum kind get_kind() const
Definition optinfo.h:111
unsigned int num_items() const
Definition optinfo.h:113
dump_location_t m_loc
Definition optinfo.h:132
~optinfo()
Definition optinfo.cc:74
auto_vec< optinfo_item * > m_items
Definition optinfo.h:135
location_t get_location_t() const
Definition optinfo.h:116
opt_pass * get_pass() const
Definition optinfo.h:112
enum dump_flag dump_flags_t
Definition dumpfile.h:209
bool optinfo_wants_inlining_info_p()
Definition optinfo.cc:151
i
Definition poly-int.h:776
Definition profile-count.h:770