LLVM: include/llvm/ADT/Statistic.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef LLVM_ADT_STATISTIC_H
27#define LLVM_ADT_STATISTIC_H
28
29#include "llvm/Config/llvm-config.h"
31#include
32#include
33#include
34
35
36
37
38#if !defined(NDEBUG) || LLVM_FORCE_ENABLE_STATS
39#define LLVM_ENABLE_STATS 1
40#else
41#define LLVM_ENABLE_STATS 0
42#endif
43
44namespace llvm {
45
46class raw_ostream;
47class raw_fd_ostream;
48class StringRef;
49
51public:
55
56 std::atomic<uint64_t> Value;
58
63
67
69
70
72
74 Value.store(Val, std::memory_order_relaxed);
75 return init();
76 }
77
79 Value.fetch_add(1, std::memory_order_relaxed);
80 return init();
81 }
82
85 return Value.fetch_add(1, std::memory_order_relaxed);
86 }
87
89 Value.fetch_sub(1, std::memory_order_relaxed);
90 return init();
91 }
92
95 return Value.fetch_sub(1, std::memory_order_relaxed);
96 }
97
99 if (V == 0)
100 return *this;
101 Value.fetch_add(V, std::memory_order_relaxed);
102 return init();
103 }
104
106 if (V == 0)
107 return *this;
108 Value.fetch_sub(V, std::memory_order_relaxed);
109 return init();
110 }
111
113 uint64_t PrevMax = Value.load(std::memory_order_relaxed);
114
115
116 while (V > PrevMax && .compare_exchange_weak(
117 PrevMax, V, std::memory_order_relaxed)) {
118 }
120 }
121
122protected:
124 if (.load(std::memory_order_acquire))
126 return *this;
127 }
128
130};
131
133public:
136
138
139
141
143
145
147
149
151
153
155
157};
158
159#if LLVM_ENABLE_STATS
160using Statistic = TrackingStatistic;
161#else
163#endif
164
165
166
167#if LLVM_ENABLE_STATS
168#define STATISTIC(VARNAME, DESC) \
169 static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC}
170#else
171#define STATISTIC(VARNAME, DESC) \
172 static llvm::Statistic VARNAME [[maybe_unused]] = {DEBUG_TYPE, #VARNAME, DESC}
173#endif
174
175
176
177#define ALWAYS_ENABLED_STATISTIC(VARNAME, DESC) \
178 static llvm::TrackingStatistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC}
179
180
182
183
185
186
188
189
191
192
194
195
196
197
198
200
201
202
203
204
205
206
207
209
210
211
212
213
214
215
216
217
218
219
220
221
222
224
225}
226
227#endif
Definition Statistic.h:132
uint64_t getValue() const
Definition Statistic.h:137
void updateMax(uint64_t V)
Definition Statistic.h:156
const NoopStatistic & operator++()
Definition Statistic.h:144
const NoopStatistic & operator--()
Definition Statistic.h:148
uint64_t operator--(int)
Definition Statistic.h:150
const NoopStatistic & operator=(uint64_t Val)
Definition Statistic.h:142
constexpr NoopStatistic(const char *, const char *, const char *)
Definition Statistic.h:134
uint64_t operator++(int)
Definition Statistic.h:146
const NoopStatistic & operator+=(const uint64_t &V)
Definition Statistic.h:152
const NoopStatistic & operator-=(const uint64_t &V)
Definition Statistic.h:154
const TrackingStatistic & operator--()
Definition Statistic.h:88
const char * getDesc() const
Definition Statistic.h:66
uint64_t getValue() const
Definition Statistic.h:68
uint64_t operator++(int)
Definition Statistic.h:83
const char * getDebugType() const
Definition Statistic.h:64
std::atomic< uint64_t > Value
Definition Statistic.h:56
const char *const Name
Definition Statistic.h:53
TrackingStatistic & init()
Definition Statistic.h:123
void updateMax(uint64_t V)
Definition Statistic.h:112
const TrackingStatistic & operator=(uint64_t Val)
Definition Statistic.h:73
uint64_t operator--(int)
Definition Statistic.h:93
const char * getName() const
Definition Statistic.h:65
const TrackingStatistic & operator++()
Definition Statistic.h:78
const char *const Desc
Definition Statistic.h:54
std::atomic< bool > Initialized
Definition Statistic.h:57
const TrackingStatistic & operator-=(uint64_t V)
Definition Statistic.h:105
const char *const DebugType
Definition Statistic.h:52
constexpr TrackingStatistic(const char *DebugType, const char *Name, const char *Desc)
Definition Statistic.h:59
const TrackingStatistic & operator+=(uint64_t V)
Definition Statistic.h:98
LLVM_ABI void RegisterStatistic()
RegisterStatistic - The first time a statistic is bumped, this method is called.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::unique_ptr< raw_ostream > CreateInfoOutputFile()
Return a stream to print our output on.
LLVM_ABI void ResetStatistics()
Reset the statistics.
LLVM_ABI void EnableStatistics(bool DoPrintOnExit=true)
Enable the collection and printing of statistics.
NoopStatistic Statistic
Definition Statistic.h:162
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
LLVM_ABI void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
LLVM_ABI std::vector< std::pair< StringRef, uint64_t > > GetStatistics()
Get the statistics.
LLVM_ABI void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.