LLVM 20.0.0git
|
This class provides support for dynamic arbitrary-precision arithmetic. More...
#include "llvm/ADT/DynamicAPInt.h"
This class provides support for dynamic arbitrary-precision arithmetic.
Unlike APInt, this extends the precision as necessary to prevent overflows and supports operations between objects with differing internal precisions.
This is optimized for small-values by providing fast-paths for the cases when the value stored fits in 64-bits. We annotate all fastpaths by using the LLVM_LIKELY/LLVM_UNLIKELY annotations. Removing these would result in a 1.2x performance slowdown.
We always_inline all operations; removing these results in a 1.5x performance slowdown.
When isLarge returns true, a SlowMPInt is held in the union. If isSmall returns true, the int64_t is held. We don't have a separate field for indicating this, and instead "steal" memory from ValLarge when it is not in use because we know that the memory layout of APInt is such that BitWidth doesn't overlap with ValSmall (see static_assert_layout). Using std::variant instead would lead to significantly worse performance.
Definition at line 46 of file DynamicAPInt.h.
|
inlineexplicit |
Definition at line 114 of file DynamicAPInt.h.
References ValLarge.
|
inline |
Definition at line 118 of file DynamicAPInt.h.
Referenced by divByPositive(), divByPositiveInPlace(), operator%(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), and operator/=().
|
inline |
Definition at line 119 of file DynamicAPInt.h.
References LLVM_UNLIKELY, and ValLarge.
|
inline |
Definition at line 123 of file DynamicAPInt.h.
References LLVM_UNLIKELY, and ValLarge.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::divByPositive | ( | const DynamicAPInt & | O | ) | const |
Definition at line 334 of file DynamicAPInt.h.
References assert(), DynamicAPInt(), and LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::divByPositiveInPlace | ( | const DynamicAPInt & | O | ) |
Definition at line 494 of file DynamicAPInt.h.
References assert(), DynamicAPInt(), and LLVM_LIKELY.
void DynamicAPInt::dump | ( | ) | const |
Definition at line 35 of file DynamicAPInt.cpp.
References llvm::dbgs(), and print().
|
inlineexplicit |
Definition at line 141 of file DynamicAPInt.h.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator!= | ( | const DynamicAPInt & | O | ) | const |
Definition at line 258 of file DynamicAPInt.h.
References LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator% | ( | const DynamicAPInt & | O | ) | const |
This operation cannot overflow.
Definition at line 409 of file DynamicAPInt.h.
References DynamicAPInt(), and LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator%= | ( | const DynamicAPInt & | O | ) |
Definition at line 505 of file DynamicAPInt.h.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator* | ( | const DynamicAPInt & | O | ) | const |
Definition at line 319 of file DynamicAPInt.h.
References DynamicAPInt(), LLVM_LIKELY, and llvm::MulOverflow().
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator*= | ( | const DynamicAPInt & | O | ) |
Definition at line 463 of file DynamicAPInt.h.
References DynamicAPInt(), LLVM_LIKELY, and llvm::MulOverflow().
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator+ | ( | const DynamicAPInt & | O | ) | const |
Definition at line 293 of file DynamicAPInt.h.
References llvm::AddOverflow(), DynamicAPInt(), and LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator++ | ( | ) |
Definition at line 508 of file DynamicAPInt.h.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator+= | ( | const DynamicAPInt & | O | ) |
Definition at line 429 of file DynamicAPInt.h.
References llvm::AddOverflow(), DynamicAPInt(), and LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator- | ( | ) | const |
Definition at line 416 of file DynamicAPInt.h.
References DynamicAPInt(), and LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator- | ( | const DynamicAPInt & | O | ) | const |
Definition at line 306 of file DynamicAPInt.h.
References DynamicAPInt(), LLVM_LIKELY, and llvm::SubOverflow().
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator-- | ( | ) |
Definition at line 511 of file DynamicAPInt.h.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator-= | ( | const DynamicAPInt & | O | ) |
Definition at line 446 of file DynamicAPInt.h.
References DynamicAPInt(), LLVM_LIKELY, and llvm::SubOverflow().
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator/ | ( | const DynamicAPInt & | O | ) | const |
Definition at line 343 of file DynamicAPInt.h.
References llvm::divideSignedWouldOverflow(), DynamicAPInt(), LLVM_LIKELY, and LLVM_UNLIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator/= | ( | const DynamicAPInt & | O | ) |
Definition at line 480 of file DynamicAPInt.h.
References llvm::divideSignedWouldOverflow(), DynamicAPInt(), LLVM_LIKELY, and LLVM_UNLIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator< | ( | const DynamicAPInt & | O | ) | const |
Definition at line 269 of file DynamicAPInt.h.
References LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator<= | ( | const DynamicAPInt & | O | ) | const |
Definition at line 275 of file DynamicAPInt.h.
References LLVM_LIKELY.
|
inline |
Definition at line 129 of file DynamicAPInt.h.
References LLVM_LIKELY.
|
inline |
Definition at line 137 of file DynamicAPInt.h.
References X.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator== | ( | const DynamicAPInt & | O | ) | const |
We define the operations here in the header to facilitate inlining.
Definition at line 252 of file DynamicAPInt.h.
References LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator> | ( | const DynamicAPInt & | O | ) | const |
Definition at line 264 of file DynamicAPInt.h.
References LLVM_LIKELY.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator>= | ( | const DynamicAPInt & | O | ) | const |
Definition at line 282 of file DynamicAPInt.h.
References LLVM_LIKELY.
raw_ostream & DynamicAPInt::print | ( | raw_ostream & | OS | ) | const |
void DynamicAPInt::static_assert_layout | ( | ) |
Definition at line 21 of file DynamicAPInt.cpp.
|
friend |
Definition at line 354 of file DynamicAPInt.h.
|
friend |
Definition at line 358 of file DynamicAPInt.h.
|
friend |
Definition at line 369 of file DynamicAPInt.h.
|
friend |
Definition at line 390 of file DynamicAPInt.h.
|
friend |
Redeclarations of friend declaration above to make it discoverable by lookups.
|
friend |
Returns the least common multiple of A and B.
Definition at line 400 of file DynamicAPInt.h.
|
friend |
is always non-negative.
Definition at line 382 of file DynamicAPInt.h.
|
friend |
Definition at line 586 of file DynamicAPInt.h.
|
friend |
Definition at line 616 of file DynamicAPInt.h.
|
friend |
Definition at line 554 of file DynamicAPInt.h.
|
friend |
Definition at line 574 of file DynamicAPInt.h.
|
friend |
Definition at line 534 of file DynamicAPInt.h.
|
friend |
Definition at line 546 of file DynamicAPInt.h.
|
friend |
Definition at line 566 of file DynamicAPInt.h.
|
friend |
Definition at line 526 of file DynamicAPInt.h.
|
friend |
Definition at line 538 of file DynamicAPInt.h.
|
friend |
Definition at line 558 of file DynamicAPInt.h.
|
friend |
Definition at line 518 of file DynamicAPInt.h.
|
friend |
Definition at line 542 of file DynamicAPInt.h.
|
friend |
Definition at line 562 of file DynamicAPInt.h.
|
friend |
Definition at line 522 of file DynamicAPInt.h.
|
friend |
Definition at line 550 of file DynamicAPInt.h.
|
friend |
Definition at line 570 of file DynamicAPInt.h.
|
friend |
Definition at line 530 of file DynamicAPInt.h.
|
friend |
Definition at line 596 of file DynamicAPInt.h.
|
friend |
Definition at line 626 of file DynamicAPInt.h.
|
friend |
Definition at line 601 of file DynamicAPInt.h.
|
friend |
Definition at line 631 of file DynamicAPInt.h.
|
friend |
We provide special implementations of the comparison operators rather than calling through as above, as this would result in a 1.2x slowdown.
Definition at line 581 of file DynamicAPInt.h.
|
friend |
Definition at line 611 of file DynamicAPInt.h.
|
friend |
Definition at line 591 of file DynamicAPInt.h.
|
friend |
Definition at line 621 of file DynamicAPInt.h.
|
friend |
Definition at line 606 of file DynamicAPInt.h.
|
friend |
Definition at line 636 of file DynamicAPInt.h.
detail::SlowDynamicAPInt llvm::DynamicAPInt::ValLarge |
Definition at line 49 of file DynamicAPInt.h.
Referenced by DynamicAPInt(), print(), static_assert_layout(), and ~DynamicAPInt().
int64_t llvm::DynamicAPInt::ValSmall |
Definition at line 48 of file DynamicAPInt.h.
Referenced by print(), and static_assert_layout().