PR c++/81124
[official-gcc.git] / gcc / profile-count.c
blobe64d1b564214c0ebf99ce753b7aee5c071447fe8
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 void
35 profile_count::dump (FILE *f) const
37 if (!initialized_p ())
38 fprintf (f, "uninitialized");
39 else
41 fprintf (f, "%" PRId64, m_val);
42 if (m_quality == count_adjusted)
43 fprintf (f, "(adjusted)");
44 else if (m_quality == count_afdo)
45 fprintf (f, "(auto FDO)");
46 else if (m_quality == count_guessed)
47 fprintf (f, "(guessed)");
51 void
52 profile_count::debug () const
54 dump (stderr);
57 bool
58 profile_count::differs_from_p (profile_count other) const
60 if (!initialized_p () || !other.initialized_p ())
61 return false;
62 if (m_val - other.m_val < 100 || other.m_val - m_val < 100)
63 return false;
64 if (!other.m_val)
65 return true;
66 int64_t ratio = m_val * 100 / other.m_val;
67 return ratio < 99 || ratio > 101;
70 profile_count
71 profile_count::stream_in (struct lto_input_block *ib)
73 profile_count ret;
74 ret.m_val = streamer_read_gcov_count (ib);
75 ret.m_quality = (profile_count_quality) streamer_read_uhwi (ib);
76 return ret;
79 void
80 profile_count::stream_out (struct output_block *ob)
82 streamer_write_gcov_count (ob, m_val);
83 streamer_write_uhwi (ob, m_quality);
86 void
87 profile_count::stream_out (struct lto_output_stream *ob)
89 streamer_write_gcov_count_stream (ob, m_val);
90 streamer_write_uhwi_stream (ob, m_quality);