]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/profile-count.c
2017-05-23 Jan Hubicka <hubicka@ucw.cz>
[thirdparty/gcc.git] / gcc / profile-count.c
1 /* Profile counter container type.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
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 #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"
33
34 void
35 profile_count::dump (FILE *f) const
36 {
37 if (!initialized_p ())
38 fprintf (f, "uninitialized");
39 else
40 fprintf (f, "%" PRId64, m_val);
41 }
42
43 void
44 profile_count::debug () const
45 {
46 dump (stderr);
47 }
48
49 bool
50 profile_count::differs_from_p (profile_count other) const
51 {
52 if (!initialized_p () || !other.initialized_p ())
53 return false;
54 if (m_val - other.m_val < 100 && other.m_val - m_val < 100)
55 return false;
56 if (!other.m_val)
57 return true;
58 int64_t ratio = m_val * 100 / other.m_val;
59 return ratio < 99 || ratio > 101;
60 }
61
62 profile_count
63 profile_count::stream_in (struct lto_input_block *ib)
64 {
65 profile_count ret;
66 ret.m_val = streamer_read_gcov_count (ib);
67 return ret;
68 }
69
70 void
71 profile_count::stream_out (struct output_block *ob)
72 {
73 streamer_write_gcov_count (ob, m_val);
74 }
75
76 void
77 profile_count::stream_out (struct lto_output_stream *ob)
78 {
79 streamer_write_gcov_count_stream (ob, m_val);
80 }