Line data Source code
1 : /* Optimization information.
2 : Copyright (C) 2018-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
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.
11 :
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.
16 :
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/>. */
20 :
21 : #define INCLUDE_STRING
22 : #include "config.h"
23 : #include "system.h"
24 : #include "coretypes.h"
25 :
26 : #include "backend.h"
27 : #include "tree.h"
28 : #include "gimple.h"
29 :
30 : #include "optinfo.h"
31 : #include "optinfo-emit-json.h"
32 : #include "dump-context.h"
33 : #include "pretty-print.h"
34 : #include "gimple-pretty-print.h"
35 : #include "cgraph.h"
36 : #include "selftest.h"
37 :
38 : /* optinfo_item's ctor. Takes ownership of TEXT. */
39 :
40 17948242 : optinfo_item::optinfo_item (enum kind kind_, location_t location,
41 : char *text)
42 17948242 : : m_kind (kind_), m_location (location), m_text (text)
43 : {
44 17948242 : }
45 :
46 : /* optinfo_item's dtor. */
47 :
48 17945715 : optinfo_item::~optinfo_item ()
49 : {
50 17945715 : free (m_text);
51 17945715 : }
52 :
53 : /* Get a string from KIND. */
54 :
55 : const char *
56 48105 : optinfo::kind_to_string (enum kind kind_)
57 : {
58 48105 : switch (kind_)
59 : {
60 0 : default:
61 0 : gcc_unreachable ();
62 : case kind::success:
63 : return "success";
64 2388 : case kind::failure:
65 2388 : return "failure";
66 41386 : case kind::note:
67 41386 : return "note";
68 3998 : case kind::scope:
69 3998 : return "scope";
70 : }
71 : }
72 :
73 : /* optinfo's dtor. */
74 :
75 78092 : optinfo::~optinfo ()
76 : {
77 : /* Cleanup. */
78 78092 : unsigned i;
79 78092 : optinfo_item *item;
80 243603 : FOR_EACH_VEC_ELT (m_items, i, item)
81 165511 : delete item;
82 78092 : }
83 :
84 : /* Add ITEM to this optinfo. */
85 :
86 : void
87 168038 : optinfo::add_item (std::unique_ptr<optinfo_item> item)
88 : {
89 168038 : gcc_assert (item.get ());
90 168038 : m_items.safe_push (item.release ());
91 168038 : }
92 :
93 : /* Get MSG_* flags corresponding to KIND. */
94 :
95 : dump_flags_t
96 6185 : optinfo::kind_to_dump_flag (enum kind kind_)
97 : {
98 6185 : switch (kind_)
99 : {
100 0 : default:
101 0 : gcc_unreachable ();
102 : case kind::success:
103 : return MSG_OPTIMIZED_LOCATIONS;
104 : case kind::failure:
105 : return MSG_MISSED_OPTIMIZATION;
106 : case kind::note:
107 : case kind::scope:
108 : return MSG_NOTE;
109 : }
110 : }
111 :
112 : /* Re-emit this optinfo, both to the "non-immediate" destinations,
113 : *and* to the "immediate" destinations. */
114 :
115 : void
116 6185 : optinfo::emit_for_opt_problem () const
117 : {
118 6185 : dump_flags_t dump_kind = kind_to_dump_flag (get_kind ());
119 6185 : dump_kind |= MSG_PRIORITY_REEMITTED;
120 :
121 : /* Re-emit to "immediate" destinations, without creating a new optinfo. */
122 6185 : dump_context::get ().dump_loc_immediate (dump_kind, get_user_location ());
123 6185 : unsigned i;
124 6185 : optinfo_item *item;
125 23296 : FOR_EACH_VEC_ELT (m_items, i, item)
126 10926 : dump_context::get ().emit_item (*item, dump_kind);
127 :
128 : /* Re-emit to "non-immediate" destinations. */
129 6185 : dump_context::get ().emit_optinfo (*this);
130 6185 : }
131 :
132 : /* Update the optinfo's kind based on DUMP_KIND. */
133 :
134 : void
135 49106 : optinfo::handle_dump_file_kind (dump_flags_t dump_kind)
136 : {
137 : /* Any optinfo for a "scope" should have been emitted separately. */
138 49106 : gcc_assert (m_kind != kind::scope);
139 :
140 49106 : if (dump_kind & MSG_OPTIMIZED_LOCATIONS)
141 389 : m_kind = kind::success;
142 48717 : else if (dump_kind & MSG_MISSED_OPTIMIZATION)
143 2381 : m_kind = kind::failure;
144 46336 : else if (dump_kind & MSG_NOTE)
145 46336 : m_kind = kind::note;
146 49106 : }
147 :
148 : /* Return true if any of the active optinfo destinations make use
149 : of inlining information.
150 : (if true, then the information is preserved). */
151 :
152 1748522 : bool optinfo_wants_inlining_info_p ()
153 : {
154 1748522 : return dump_context::get ().optimization_records_enabled_p ();
155 : }
|