Daily bump.
[official-gcc.git] / gcc / profile-count.c
blob4d22428a195bc6f03c0023734a0a4ea8cc765296
1 /* Profile counter container type.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
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 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "profile-count.h"
25 #include "options.h"
26 #include "tree.h"
27 #include "basic-block.h"
28 #include "cfg.h"
29 #include "function.h"
30 #include "gimple.h"
31 #include "data-streamer.h"
32 #include "cgraph.h"
34 /* Dump THIS to F. */
36 void
37 profile_count::dump (FILE *f) const
39 if (!initialized_p ())
40 fprintf (f, "uninitialized");
41 else
43 fprintf (f, "%" PRId64, m_val);
44 if (m_quality == profile_adjusted)
45 fprintf (f, " (adjusted)");
46 else if (m_quality == profile_afdo)
47 fprintf (f, " (auto FDO)");
48 else if (m_quality == profile_guessed)
49 fprintf (f, " (guessed)");
53 /* Dump THIS to stderr. */
55 void
56 profile_count::debug () const
58 dump (stderr);
59 fprintf (stderr, "\n");
62 /* Return true if THIS differs from OTHER; tolerate small diferences. */
64 bool
65 profile_count::differs_from_p (profile_count other) const
67 if (!initialized_p () || !other.initialized_p ())
68 return false;
69 if ((uint64_t)m_val - (uint64_t)other.m_val < 100
70 || (uint64_t)other.m_val - (uint64_t)m_val < 100)
71 return false;
72 if (!other.m_val)
73 return true;
74 int64_t ratio = (int64_t)m_val * 100 / other.m_val;
75 return ratio < 99 || ratio > 101;
78 /* Stream THIS from IB. */
80 profile_count
81 profile_count::stream_in (struct lto_input_block *ib)
83 profile_count ret;
84 ret.m_val = streamer_read_gcov_count (ib);
85 ret.m_quality = (profile_quality) streamer_read_uhwi (ib);
86 return ret;
89 /* Stream THIS to OB. */
91 void
92 profile_count::stream_out (struct output_block *ob)
94 streamer_write_gcov_count (ob, m_val);
95 streamer_write_uhwi (ob, m_quality);
98 /* Stream THIS to OB. */
100 void
101 profile_count::stream_out (struct lto_output_stream *ob)
103 streamer_write_gcov_count_stream (ob, m_val);
104 streamer_write_uhwi_stream (ob, m_quality);
107 /* Dump THIS to F. */
109 void
110 profile_probability::dump (FILE *f) const
112 if (!initialized_p ())
113 fprintf (f, "uninitialized");
114 else
116 /* Make difference between 0.00 as a roundoff error and actual 0.
117 Similarly for 1. */
118 if (m_val == 0)
119 fprintf (f, "never");
120 else if (m_val == max_probability)
121 fprintf (f, "always");
122 else
123 fprintf (f, "%3.1f%%", (double)m_val * 100 / max_probability);
124 if (m_quality == profile_adjusted)
125 fprintf (f, " (adjusted)");
126 else if (m_quality == profile_afdo)
127 fprintf (f, " (auto FDO)");
128 else if (m_quality == profile_guessed)
129 fprintf (f, " (guessed)");
133 /* Dump THIS to stderr. */
135 void
136 profile_probability::debug () const
138 dump (stderr);
139 fprintf (stderr, "\n");
142 /* Return true if THIS differs from OTHER; tolerate small diferences. */
144 bool
145 profile_probability::differs_from_p (profile_probability other) const
147 if (!initialized_p () || !other.initialized_p ())
148 return false;
149 if ((uint64_t)m_val - (uint64_t)other.m_val < 10
150 || (uint64_t)other.m_val - (uint64_t)m_val < 10)
151 return false;
152 if (!other.m_val)
153 return true;
154 int64_t ratio = m_val * 100 / other.m_val;
155 return ratio < 99 || ratio > 101;
158 /* Return true if THIS differs significantly from OTHER. */
160 bool
161 profile_probability::differs_lot_from_p (profile_probability other) const
163 if (!initialized_p () || !other.initialized_p ())
164 return false;
165 uint32_t d = m_val > other.m_val ? m_val - other.m_val : other.m_val - m_val;
166 return d > max_probability / 2;
169 /* Stream THIS from IB. */
171 profile_probability
172 profile_probability::stream_in (struct lto_input_block *ib)
174 profile_probability ret;
175 ret.m_val = streamer_read_uhwi (ib);
176 ret.m_quality = (profile_quality) streamer_read_uhwi (ib);
177 return ret;
180 /* Stream THIS to OB. */
182 void
183 profile_probability::stream_out (struct output_block *ob)
185 streamer_write_uhwi (ob, m_val);
186 streamer_write_uhwi (ob, m_quality);
189 /* Stream THIS to OB. */
191 void
192 profile_probability::stream_out (struct lto_output_stream *ob)
194 streamer_write_uhwi_stream (ob, m_val);
195 streamer_write_uhwi_stream (ob, m_quality);