xref: /netbsd/external/gpl3/gcc.old/dist/gcc/optinfo.h (revision 0bfacb9b)
1760c2415Smrg /* Optimization information.
2*0bfacb9bSmrg    Copyright (C) 2018-2020 Free Software Foundation, Inc.
3760c2415Smrg    Contributed by David Malcolm <dmalcolm@redhat.com>.
4760c2415Smrg 
5760c2415Smrg This file is part of GCC.
6760c2415Smrg 
7760c2415Smrg GCC is free software; you can redistribute it and/or modify it under
8760c2415Smrg the terms of the GNU General Public License as published by the Free
9760c2415Smrg Software Foundation; either version 3, or (at your option) any later
10760c2415Smrg version.
11760c2415Smrg 
12760c2415Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13760c2415Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14760c2415Smrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15760c2415Smrg for more details.
16760c2415Smrg 
17760c2415Smrg You should have received a copy of the GNU General Public License
18760c2415Smrg along with GCC; see the file COPYING3.  If not see
19760c2415Smrg <http://www.gnu.org/licenses/>.  */
20760c2415Smrg 
21760c2415Smrg #ifndef GCC_OPTINFO_H
22760c2415Smrg #define GCC_OPTINFO_H
23760c2415Smrg 
24760c2415Smrg /* An "optinfo" is a bundle of information describing part of an
25760c2415Smrg    optimization, which can be emitted to zero or more of several
26760c2415Smrg    destinations, such as:
27760c2415Smrg 
28760c2415Smrg    * saved to a file as an "optimization record"
29760c2415Smrg 
30760c2415Smrg    They are generated in response to calls to the "dump_*" API in
31760c2415Smrg    dumpfile.h; repeated calls to the "dump_*" API are consolidated
32760c2415Smrg    into a pending optinfo instance, with a "dump_*_loc" starting a new
33760c2415Smrg    optinfo instance.
34760c2415Smrg 
35760c2415Smrg    The data sent to the dump calls are captured within the pending optinfo
36760c2415Smrg    instance as a sequence of optinfo_items.  For example, given:
37760c2415Smrg 
38760c2415Smrg       if (dump_enabled_p ())
39760c2415Smrg         {
40760c2415Smrg           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
41760c2415Smrg                            "not vectorized: live stmt not supported: ");
42760c2415Smrg           dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0);
43760c2415Smrg         }
44760c2415Smrg 
45760c2415Smrg    the "dump_printf_loc" call begins a new optinfo containing two items:
46760c2415Smrg    (1) a text item containing "not vectorized: live stmt not supported: "
47760c2415Smrg    (2) a gimple item for "stmt"
48760c2415Smrg 
49760c2415Smrg    Dump destinations are thus able to access rich metadata about the
50760c2415Smrg    items when the optinfo is emitted to them, rather than just having plain
51760c2415Smrg    text.  For example, when saving the above optinfo to a file as an
52760c2415Smrg    "optimization record", the record could capture the source location of
53760c2415Smrg    "stmt" above, rather than just its textual form.
54760c2415Smrg 
55760c2415Smrg    The currently pending optinfo is emitted and deleted:
56760c2415Smrg    * each time a "dump_*_loc" call occurs (which starts the next optinfo), or
57760c2415Smrg    * when the dump files are changed (at the end of a pass)
58760c2415Smrg 
59760c2415Smrg    Dumping to an optinfo instance is non-trivial (due to building optinfo_item
60760c2415Smrg    instances), so all usage should be guarded by
61760c2415Smrg 
62760c2415Smrg      if (optinfo_enabled_p ())
63760c2415Smrg 
64760c2415Smrg    which is off by default.  */
65760c2415Smrg 
66760c2415Smrg 
67760c2415Smrg /* Forward decls.  */
68*0bfacb9bSmrg class opt_pass;
69760c2415Smrg class optinfo_item;
70760c2415Smrg 
71760c2415Smrg /* Return true if any of the active optinfo destinations make use
72760c2415Smrg    of inlining information.
73760c2415Smrg    (if true, then the information is preserved).  */
74760c2415Smrg 
75760c2415Smrg extern bool optinfo_wants_inlining_info_p ();
76760c2415Smrg 
77760c2415Smrg /* The various kinds of optinfo.  */
78760c2415Smrg 
79760c2415Smrg enum optinfo_kind
80760c2415Smrg {
81760c2415Smrg   OPTINFO_KIND_SUCCESS,
82760c2415Smrg   OPTINFO_KIND_FAILURE,
83760c2415Smrg   OPTINFO_KIND_NOTE,
84760c2415Smrg   OPTINFO_KIND_SCOPE
85760c2415Smrg };
86760c2415Smrg 
87760c2415Smrg extern const char *optinfo_kind_to_string (enum optinfo_kind kind);
88760c2415Smrg 
89760c2415Smrg class dump_context;
90760c2415Smrg 
91760c2415Smrg /* A bundle of information describing part of an optimization.  */
92760c2415Smrg 
93760c2415Smrg class optinfo
94760c2415Smrg {
95760c2415Smrg   friend class dump_context;
96760c2415Smrg 
97760c2415Smrg  public:
optinfo(const dump_location_t & loc,enum optinfo_kind kind,opt_pass * pass)98760c2415Smrg   optinfo (const dump_location_t &loc,
99760c2415Smrg 	   enum optinfo_kind kind,
100760c2415Smrg 	   opt_pass *pass)
101760c2415Smrg   : m_loc (loc), m_kind (kind), m_pass (pass), m_items ()
102760c2415Smrg   {}
103760c2415Smrg   ~optinfo ();
104760c2415Smrg 
105760c2415Smrg   const dump_location_t &
get_dump_location()106760c2415Smrg   get_dump_location () const { return m_loc; }
107760c2415Smrg 
108760c2415Smrg   const dump_user_location_t &
get_user_location()109760c2415Smrg   get_user_location () const { return m_loc.get_user_location (); }
110760c2415Smrg 
111760c2415Smrg   const dump_impl_location_t &
get_impl_location()112760c2415Smrg   get_impl_location () const { return m_loc.get_impl_location (); }
113760c2415Smrg 
get_kind()114760c2415Smrg   enum optinfo_kind get_kind () const { return m_kind; }
get_pass()115760c2415Smrg   opt_pass *get_pass () const { return m_pass; }
num_items()116760c2415Smrg   unsigned int num_items () const { return m_items.length (); }
get_item(unsigned int i)117760c2415Smrg   const optinfo_item *get_item (unsigned int i) const { return m_items[i]; }
118760c2415Smrg 
get_location_t()119760c2415Smrg   location_t get_location_t () const { return m_loc.get_location_t (); }
get_count()120760c2415Smrg   profile_count get_count () const { return m_loc.get_count (); }
121760c2415Smrg 
122760c2415Smrg   void add_item (optinfo_item *item);
123760c2415Smrg 
124760c2415Smrg   void emit_for_opt_problem () const;
125760c2415Smrg 
126760c2415Smrg  private:
127760c2415Smrg   /* Pre-canned ways of manipulating the optinfo, for use by friend class
128760c2415Smrg      dump_context.  */
129760c2415Smrg   void handle_dump_file_kind (dump_flags_t);
130760c2415Smrg 
131760c2415Smrg  private:
132760c2415Smrg   dump_location_t m_loc;
133760c2415Smrg   enum optinfo_kind m_kind;
134760c2415Smrg   opt_pass *m_pass;
135760c2415Smrg   auto_vec <optinfo_item *> m_items;
136760c2415Smrg };
137760c2415Smrg 
138760c2415Smrg /* An enum for discriminating between different kinds of optinfo_item.  */
139760c2415Smrg 
140760c2415Smrg enum optinfo_item_kind
141760c2415Smrg {
142760c2415Smrg   OPTINFO_ITEM_KIND_TEXT,
143760c2415Smrg   OPTINFO_ITEM_KIND_TREE,
144760c2415Smrg   OPTINFO_ITEM_KIND_GIMPLE,
145760c2415Smrg   OPTINFO_ITEM_KIND_SYMTAB_NODE
146760c2415Smrg };
147760c2415Smrg 
148760c2415Smrg /* An item within an optinfo.  */
149760c2415Smrg 
150760c2415Smrg class optinfo_item
151760c2415Smrg {
152760c2415Smrg  public:
153760c2415Smrg   optinfo_item (enum optinfo_item_kind kind, location_t location,
154760c2415Smrg 		char *text);
155760c2415Smrg   ~optinfo_item ();
156760c2415Smrg 
get_kind()157760c2415Smrg   enum optinfo_item_kind get_kind () const { return m_kind; }
get_location()158760c2415Smrg   location_t get_location () const { return m_location; }
get_text()159760c2415Smrg   const char *get_text () const { return m_text; }
160760c2415Smrg 
161760c2415Smrg  private:
162760c2415Smrg   /* Metadata (e.g. for optimization records).  */
163760c2415Smrg   enum optinfo_item_kind m_kind;
164760c2415Smrg   location_t m_location;
165760c2415Smrg 
166760c2415Smrg   /* The textual form of the item, owned by the item.  */
167760c2415Smrg   char *m_text;
168760c2415Smrg };
169760c2415Smrg 
170760c2415Smrg #endif /* #ifndef GCC_OPTINFO_H */
171