LLVM: include/llvm/ADT/DynamicAPInt.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef LLVM_ADT_DYNAMICAPINT_H
17#define LLVM_ADT_DYNAMICAPINT_H
18
21#include
22
23namespace llvm {
24
25class raw_ostream;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
47 union {
50 };
51
54 ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
57 }
59 initLarge(const detail::SlowDynamicAPInt &O) {
61
62
63
64
65
66 new (&ValLarge) detail::SlowDynamicAPInt(O);
67 } else {
68
69
70
72 }
73 }
74
76 const detail::SlowDynamicAPInt &Val)
79 return ValLarge.Val.BitWidth == 0;
80 }
82 return !isSmall();
83 }
84
85
88 "getSmall should only be called when the value stored is small!");
90 }
93 "getSmall should only be called when the value stored is small!");
95 }
97 getLarge() const {
99 "getLarge should only be called when the value stored is large!");
101 }
104 "getLarge should only be called when the value stored is large!");
106 }
107 explicit operator detail::SlowDynamicAPInt() const {
108 if (isSmall())
109 return detail::SlowDynamicAPInt(getSmall());
110 return getLarge();
111 }
112
113public:
117 }
121 ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
122 }
127 initLarge(O.ValLarge);
128 }
131 initSmall(O.ValSmall);
132 return *this;
133 }
134 initLarge(O.ValLarge);
135 return *this;
136 }
138 initSmall(X);
139 return *this;
140 }
142 if (isSmall())
143 return getSmall();
144 return static_cast<int64_t>(getLarge());
145 }
146
166
167
168
171
176
180
181
182
183
189
201
213
215
217
220};
221
224 return OS;
225}
226
227
228
229hash_code hash_value(const DynamicAPInt &X);
230
231
232
233
235 return int64_t(X);
236}
239}
240
241
242
244 const DynamicAPInt &RHS);
245
246
247
248
249
250
253 if (LLVM_LIKELY(isSmall() && O.isSmall()))
254 return getSmall() == O.getSmall();
256}
259 if (LLVM_LIKELY(isSmall() && O.isSmall()))
260 return getSmall() != O.getSmall();
262}
265 if (LLVM_LIKELY(isSmall() && O.isSmall()))
266 return getSmall() > O.getSmall();
268}
271 if (LLVM_LIKELY(isSmall() && O.isSmall()))
272 return getSmall() < O.getSmall();
274}
277 if (LLVM_LIKELY(isSmall() && O.isSmall()))
278 return getSmall() <= O.getSmall();
280}
283 if (LLVM_LIKELY(isSmall() && O.isSmall()))
284 return getSmall() >= O.getSmall();
286}
287
288
289
290
291
294 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
296 bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result.getSmall());
298 return Result;
301 }
304}
307 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
309 bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result.getSmall());
311 return Result;
314 }
317}
320 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
322 bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result.getSmall());
324 return Result;
327 }
330}
331
332
336 if (LLVM_LIKELY(isSmall() && O.isSmall()))
337 return DynamicAPInt(getSmall() / O.getSmall());
340}
341
344 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
345
347 return -*this;
348 return DynamicAPInt(getSmall() / O.getSmall());
349 }
352}
353
356}
357
363 return -LHS;
365 }
368}
374 return -LHS;
376 }
379}
380
381
388}
389
392 assert(A >= 0 && B >= 0 && "operands must be non-negative!");
394 return DynamicAPInt(std::gcd(A.getSmall(), B.getSmall()));
397}
398
399
404 return (X * Y) / gcd(X, Y);
405}
406
407
410 if (LLVM_LIKELY(isSmall() && O.isSmall()))
411 return DynamicAPInt(getSmall() % O.getSmall());
414}
415
418 if (LLVM_LIKELY(getSmall() != std::numeric_limits<int64_t>::min()))
421 }
423}
424
425
426
427
430 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
431 int64_t Result = getSmall();
432 bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result);
434 getSmall() = Result;
435 return *this;
436 }
437
438
441 }
444}
447 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
448 int64_t Result = getSmall();
449 bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result);
451 getSmall() = Result;
452 return *this;
453 }
454
455
458 }
461}
464 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
465 int64_t Result = getSmall();
466 bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result);
468 getSmall() = Result;
469 return *this;
470 }
471
472
475 }
478}
481 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
482
484 return *this = -*this;
485 getSmall() /= O.getSmall();
486 return *this;
487 }
490}
491
492
496 if (LLVM_LIKELY(isSmall() && O.isSmall())) {
497 getSmall() /= O.getSmall();
498 return *this;
499 }
502}
503
506 return *this = *this % O;
507}
509 return *this += 1;
510}
512 return *this -= 1;
513}
514
515
516
517
519 int64_t B) {
521}
523 int64_t B) {
525}
527 int64_t B) {
529}
531 int64_t B) {
533}
535 int64_t B) {
537}
539 int64_t B) {
541}
543 int64_t B) {
545}
547 int64_t B) {
549}
551 int64_t B) {
553}
555 int64_t B) {
557}
561}
565}
569}
573}
577}
578
579
580
585}
590}
595}
600}
605}
610}
615}
620}
625}
630}
635}
640}
641}
642
643#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_LIKELY(EXPR)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class provides support for dynamic arbitrary-precision arithmetic.
friend DynamicAPInt & operator%=(DynamicAPInt &A, int64_t B)
raw_ostream & print(raw_ostream &OS) const
friend bool operator>=(const DynamicAPInt &A, int64_t B)
friend bool operator>(const DynamicAPInt &A, int64_t B)
friend DynamicAPInt ceilDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
friend bool operator!=(const DynamicAPInt &A, int64_t B)
DynamicAPInt & operator--()
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator=(const DynamicAPInt &O)
friend DynamicAPInt abs(const DynamicAPInt &X)
friend DynamicAPInt gcd(const DynamicAPInt &A, const DynamicAPInt &B)
friend DynamicAPInt lcm(const DynamicAPInt &A, const DynamicAPInt &B)
Returns the least common multiple of A and B.
friend DynamicAPInt operator+(const DynamicAPInt &A, int64_t B)
friend DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt()
friend DynamicAPInt operator/(const DynamicAPInt &A, int64_t B)
friend DynamicAPInt & operator*=(DynamicAPInt &A, int64_t B)
friend DynamicAPInt operator%(const DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator=(int X)
detail::SlowDynamicAPInt ValLarge
friend bool operator<(const DynamicAPInt &A, int64_t B)
void static_assert_layout()
DynamicAPInt divByPositive(const DynamicAPInt &O) const
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt(const DynamicAPInt &O)
friend DynamicAPInt & operator/=(DynamicAPInt &A, int64_t B)
DynamicAPInt operator-() const
LLVM_DUMP_METHOD void dump() const
friend hash_code hash_value(const DynamicAPInt &x)
Redeclarations of friend declaration above to make it discoverable by lookups.
DynamicAPInt & operator++()
friend bool operator<=(const DynamicAPInt &A, int64_t B)
friend DynamicAPInt mod(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
is always non-negative.
friend bool operator==(const DynamicAPInt &A, int64_t B)
We provide special implementations of the comparison operators rather than calling through as above,...
LLVM_ATTRIBUTE_ALWAYS_INLINE ~DynamicAPInt()
friend DynamicAPInt floorDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
friend DynamicAPInt operator*(const DynamicAPInt &A, int64_t B)
friend DynamicAPInt & operator-=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt(int64_t Val)
DynamicAPInt & divByPositiveInPlace(const DynamicAPInt &O)
A simple class providing dynamic arbitrary-precision arithmetic.
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt gcd(const DynamicAPInt &A, const DynamicAPInt &B)
std::enable_if_t< std::is_signed_v< T >, T > MulOverflow(T X, T Y, T &Result)
Multiply two signed integers, computing the two's complement truncated result, returning true if an o...
constexpr bool divideSignedWouldOverflow(U Numerator, V Denominator)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt mod(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
is always non-negative.
hash_code hash_value(const FixedPointSemantics &Val)
APInt operator*(APInt a, uint64_t RHS)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
constexpr T divideFloorSigned(U Numerator, V Denominator)
Returns the integer floor(Numerator / Denominator).
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator-=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt floorDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt operator%(const DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator*=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator/=(DynamicAPInt &A, int64_t B)
bool operator>(int64_t V1, const APSInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt ceilDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS)
static int64_t int64fromDynamicAPInt(const DynamicAPInt &X)
This just calls through to the operator int64_t, but it's useful when a function pointer is required.
constexpr T divideCeilSigned(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt lcm(const DynamicAPInt &A, const DynamicAPInt &B)
Returns the least common multiple of A and B.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt dynamicAPIntFromInt64(int64_t X)
std::enable_if_t< std::is_signed_v< T >, T > AddOverflow(T X, T Y, T &Result)
Add two signed integers, computing the two's complement truncated result, returning true if overflow ...
APInt operator+(APInt a, const APInt &b)
std::enable_if_t< std::is_signed_v< T >, T > SubOverflow(T X, T Y, T &Result)
Subtract two signed integers, computing the two's complement truncated result, returning true if an o...
bool operator<=(int64_t V1, const APSInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator%=(DynamicAPInt &A, int64_t B)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt operator/(const DynamicAPInt &A, int64_t B)