LLVM: include/llvm/Support/Chrono.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_SUPPORT_CHRONO_H
10#define LLVM_SUPPORT_CHRONO_H
11
14
15#include
16#include
17#include
18
19namespace llvm {
20
22
23namespace sys {
24
25
26
27
28
29
30
31
32
33template
34using TimePoint = std::chrono::time_point<std::chrono::system_clock, D>;
35
36
37
39
40template
41using UtcTime = std::chrono::time_point<UtcClock, D>;
42
43
45 using namespace std::chrono;
47}
48
49
51 using namespace std::chrono;
52 return system_clock::to_time_t(
53 time_point_cast<system_clock::time_point::duration>(TP));
54}
55
56
58 using namespace std::chrono;
59 return system_clock::to_time_t(time_point<system_clock, seconds>(
60 duration_cast(TP.time_since_epoch())));
61}
62
63
66 using namespace std::chrono;
67 return time_point_cast(system_clock::from_time_t(T));
68}
69
70
73 using namespace std::chrono;
74 return time_point_cast(system_clock::from_time_t(T))
75 + nanoseconds(nsec);
76}
77
78}
79
82
83
84
85
86
87
88
89
90
91template <>
96
101
103template struct unit { static const char value[]; };
105
106template <> struct unit<std::ratio<3600>> {
108};
109template <> struct unit<std::ratio<60>> {
111};
124}
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150template <typename Rep, typename Period>
152private:
153 using Dur = std::chrono::duration<Rep, Period>;
154 using InternalRep =
155 std::conditional_t<std::chrono::treat_as_floating_point::value,
156 double, intmax_t>;
157
158 template static InternalRep getAs(const Dur &D) {
159 using namespace std::chrono;
160 return duration_cast<duration<InternalRep, AsPeriod>>(D).count();
161 }
162
163 static std::pair<InternalRep, StringRef> consumeUnit(StringRef &Style,
164 const Dur &D) {
165 using namespace std::chrono;
166 if (Style.consume_front("ns"))
167 return {getAsstd::nano(D), "ns"};
168 if (Style.consume_front("us"))
169 return {getAsstd::micro(D), "us"};
170 if (Style.consume_front("ms"))
171 return {getAsstd::milli(D), "ms"};
172 if (Style.consume_front("s"))
173 return {getAs<std::ratio<1>>(D), "s"};
174 if (Style.consume_front("m"))
175 return {getAs<std::ratio<60>>(D), "m"};
176 if (Style.consume_front("h"))
177 return {getAs<std::ratio<3600>>(D), "h"};
179 }
180
181 static bool consumeShowUnit(StringRef &Style) {
182 if (Style.empty())
183 return true;
184 if (Style.consume_front("-"))
185 return false;
186 if (Style.consume_front("+"))
187 return true;
188 assert(0 && "Unrecognised duration format");
189 return true;
190 }
191
192public:
194 InternalRep count;
196 std::tie(count, unit) = consumeUnit(Style, D);
197 bool show_unit = consumeShowUnit(Style);
198
200
201 if (show_unit) {
203 Stream << " " << unit;
204 }
205 }
206};
207
208}
209
210#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
This class implements an extremely fast bulk output stream that can only output to a stream.
std::chrono::time_point< UtcClock, D > UtcTime
Definition Chrono.h:41
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition Chrono.h:34
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
Definition Chrono.h:65
UtcTime< std::chrono::seconds > toUtcTime(std::time_t T)
Convert a std::time_t to a UtcTime.
Definition Chrono.h:44
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
Definition Chrono.h:50
This is an optimization pass for GlobalISel generic memory operations.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Implement std::hash so that hash_code can be used in STL containers.
static LLVM_ABI const char value[]
Definition Chrono.h:119
static LLVM_ABI const char value[]
Definition Chrono.h:116
static LLVM_ABI const char value[]
Definition Chrono.h:122
static LLVM_ABI const char value[]
Definition Chrono.h:113
static LLVM_ABI const char value[]
Definition Chrono.h:107
static LLVM_ABI const char value[]
Definition Chrono.h:110
static const char value[]
Definition Chrono.h:103
static void format(const Dur &D, llvm::raw_ostream &Stream, StringRef Style)
Definition Chrono.h:193
static LLVM_ABI void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS, StringRef Style)
static LLVM_ABI void format(const sys::UtcTime< std::chrono::seconds > &TP, llvm::raw_ostream &OS, StringRef Style)