]>
Commit | Line | Data |
---|---|---|
4df3629e DM |
1 | /* Optimization information. |
2 | Copyright (C) 2018 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 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | ||
25 | #include "backend.h" | |
26 | #include "tree.h" | |
27 | #include "gimple.h" | |
28 | ||
29 | #include "optinfo.h" | |
4a4412b9 | 30 | #include "optinfo-emit-json.h" |
4df3629e DM |
31 | #include "dump-context.h" |
32 | #include "pretty-print.h" | |
33 | #include "gimple-pretty-print.h" | |
34 | #include "cgraph.h" | |
35 | #include "selftest.h" | |
36 | ||
b84e3bde | 37 | /* optinfo_item's ctor. Takes ownership of TEXT. */ |
4df3629e DM |
38 | |
39 | optinfo_item::optinfo_item (enum optinfo_item_kind kind, location_t location, | |
b84e3bde DM |
40 | char *text) |
41 | : m_kind (kind), m_location (location), m_text (text) | |
4df3629e DM |
42 | { |
43 | } | |
44 | ||
45 | /* optinfo_item's dtor. */ | |
46 | ||
47 | optinfo_item::~optinfo_item () | |
48 | { | |
b84e3bde | 49 | free (m_text); |
4df3629e DM |
50 | } |
51 | ||
52 | /* Get a string from KIND. */ | |
53 | ||
54 | const char * | |
55 | optinfo_kind_to_string (enum optinfo_kind kind) | |
56 | { | |
57 | switch (kind) | |
58 | { | |
59 | default: | |
60 | gcc_unreachable (); | |
61 | case OPTINFO_KIND_SUCCESS: | |
62 | return "success"; | |
63 | case OPTINFO_KIND_FAILURE: | |
64 | return "failure"; | |
65 | case OPTINFO_KIND_NOTE: | |
66 | return "note"; | |
67 | case OPTINFO_KIND_SCOPE: | |
68 | return "scope"; | |
69 | } | |
70 | } | |
71 | ||
72 | /* optinfo's dtor. */ | |
73 | ||
74 | optinfo::~optinfo () | |
75 | { | |
76 | /* Cleanup. */ | |
77 | unsigned i; | |
78 | optinfo_item *item; | |
79 | FOR_EACH_VEC_ELT (m_items, i, item) | |
80 | delete item; | |
81 | } | |
82 | ||
b84e3bde DM |
83 | /* Add ITEM to this optinfo. */ |
84 | ||
85 | void | |
86 | optinfo::add_item (optinfo_item *item) | |
87 | { | |
88 | gcc_assert (item); | |
89 | m_items.safe_push (item); | |
90 | } | |
91 | ||
92 | /* Emit the optinfo to all of the "non-immediate" destinations | |
93 | (emission to "immediate" destinations is done by emit_item). */ | |
4df3629e DM |
94 | |
95 | void | |
96 | optinfo::emit () | |
97 | { | |
4a4412b9 DM |
98 | /* -fsave-optimization-record. */ |
99 | optimization_records_maybe_record_optinfo (this); | |
4df3629e DM |
100 | } |
101 | ||
102 | /* Update the optinfo's kind based on DUMP_KIND. */ | |
103 | ||
104 | void | |
105 | optinfo::handle_dump_file_kind (dump_flags_t dump_kind) | |
106 | { | |
107 | if (dump_kind & MSG_OPTIMIZED_LOCATIONS) | |
108 | m_kind = OPTINFO_KIND_SUCCESS; | |
109 | else if (dump_kind & MSG_MISSED_OPTIMIZATION) | |
110 | m_kind = OPTINFO_KIND_FAILURE; | |
111 | else if (dump_kind & MSG_NOTE) | |
112 | m_kind = OPTINFO_KIND_NOTE; | |
113 | } | |
114 | ||
4df3629e DM |
115 | /* Should optinfo instances be created? |
116 | All creation of optinfos should be guarded by this predicate. | |
117 | Return true if any optinfo destinations are active. */ | |
118 | ||
119 | bool optinfo_enabled_p () | |
120 | { | |
4a4412b9 DM |
121 | return (dump_context::get ().forcibly_enable_optinfo_p () |
122 | || optimization_records_enabled_p ()); | |
4df3629e DM |
123 | } |
124 | ||
125 | /* Return true if any of the active optinfo destinations make use | |
126 | of inlining information. | |
127 | (if true, then the information is preserved). */ | |
128 | ||
129 | bool optinfo_wants_inlining_info_p () | |
130 | { | |
4a4412b9 | 131 | return optimization_records_enabled_p (); |
4df3629e | 132 | } |