LLVM 22.0.0git
Public Member Functions | Friends | List of all members
llvm::DynamicAPInt Class Reference

This class provides support for dynamic arbitrary-precision arithmetic. More...

#include "llvm/ADT/DynamicAPInt.h"

Public Member Functions

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt (int64_t Val)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt (const APInt &Val)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt ()
 
LLVM_ATTRIBUTE_ALWAYS_INLINE ~DynamicAPInt ()
 
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt (const DynamicAPInt &O)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPIntoperator= (const DynamicAPInt &O)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPIntoperator= (int X)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE operator int64_t () const
 
bool operator== (const DynamicAPInt &O) const
 We define the operations here in the header to facilitate inlining.
 
bool operator!= (const DynamicAPInt &O) const
 
bool operator> (const DynamicAPInt &O) const
 
bool operator< (const DynamicAPInt &O) const
 
bool operator<= (const DynamicAPInt &O) const
 
bool operator>= (const DynamicAPInt &O) const
 
DynamicAPInt operator+ (const DynamicAPInt &O) const
 
DynamicAPInt operator- (const DynamicAPInt &O) const
 
DynamicAPInt operator* (const DynamicAPInt &O) const
 
DynamicAPInt operator/ (const DynamicAPInt &O) const
 
DynamicAPInt operator% (const DynamicAPInt &O) const
 This operation cannot overflow.
 
DynamicAPIntoperator+= (const DynamicAPInt &O)
 
DynamicAPIntoperator-= (const DynamicAPInt &O)
 
DynamicAPIntoperator*= (const DynamicAPInt &O)
 
DynamicAPIntoperator/= (const DynamicAPInt &O)
 
DynamicAPIntoperator%= (const DynamicAPInt &O)
 
DynamicAPInt operator- () const
 
DynamicAPIntoperator++ ()
 
DynamicAPIntoperator-- ()
 
DynamicAPInt divByPositive (const DynamicAPInt &O) const
 
DynamicAPIntdivByPositiveInPlace (const DynamicAPInt &O)
 
LLVM_ABI void static_assert_layout ()
 
LLVM_ABI raw_ostreamprint (raw_ostream &OS) const
 
LLVM_DUMP_METHOD void dump () const
 

Friends

DynamicAPInt abs (const DynamicAPInt &X)
 
DynamicAPInt ceilDiv (const DynamicAPInt &LHS, const DynamicAPInt &RHS)
 
DynamicAPInt floorDiv (const DynamicAPInt &LHS, const DynamicAPInt &RHS)
 
DynamicAPInt gcd (const DynamicAPInt &A, const DynamicAPInt &B)
 
DynamicAPInt lcm (const DynamicAPInt &A, const DynamicAPInt &B)
 Returns the least common multiple of A and B.
 
DynamicAPInt mod (const DynamicAPInt &LHS, const DynamicAPInt &RHS)
 is always non-negative.
 
DynamicAPIntoperator+= (DynamicAPInt &A, int64_t B)
 
DynamicAPIntoperator-= (DynamicAPInt &A, int64_t B)
 
DynamicAPIntoperator*= (DynamicAPInt &A, int64_t B)
 
DynamicAPIntoperator/= (DynamicAPInt &A, int64_t B)
 
DynamicAPIntoperator%= (DynamicAPInt &A, int64_t B)
 
bool operator== (const DynamicAPInt &A, int64_t B)
 We provide special implementations of the comparison operators rather than calling through as above, as this would result in a 1.2x slowdown.
 
bool operator!= (const DynamicAPInt &A, int64_t B)
 
bool operator> (const DynamicAPInt &A, int64_t B)
 
bool operator< (const DynamicAPInt &A, int64_t B)
 
bool operator<= (const DynamicAPInt &A, int64_t B)
 
bool operator>= (const DynamicAPInt &A, int64_t B)
 
DynamicAPInt operator+ (const DynamicAPInt &A, int64_t B)
 
DynamicAPInt operator- (const DynamicAPInt &A, int64_t B)
 
DynamicAPInt operator* (const DynamicAPInt &A, int64_t B)
 
DynamicAPInt operator/ (const DynamicAPInt &A, int64_t B)
 
DynamicAPInt operator% (const DynamicAPInt &A, int64_t B)
 
bool operator== (int64_t A, const DynamicAPInt &B)
 
bool operator!= (int64_t A, const DynamicAPInt &B)
 
bool operator> (int64_t A, const DynamicAPInt &B)
 
bool operator< (int64_t A, const DynamicAPInt &B)
 
bool operator<= (int64_t A, const DynamicAPInt &B)
 
bool operator>= (int64_t A, const DynamicAPInt &B)
 
DynamicAPInt operator+ (int64_t A, const DynamicAPInt &B)
 
DynamicAPInt operator- (int64_t A, const DynamicAPInt &B)
 
DynamicAPInt operator* (int64_t A, const DynamicAPInt &B)
 
DynamicAPInt operator/ (int64_t A, const DynamicAPInt &B)
 
DynamicAPInt operator% (int64_t A, const DynamicAPInt &B)
 
LLVM_ABI friend hash_code hash_value (const DynamicAPInt &x)
 Redeclarations of friend declaration above to make it discoverable by lookups.
 

Detailed Description

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 48 of file DynamicAPInt.h.

Constructor & Destructor Documentation

◆ DynamicAPInt() [1/4]

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::DynamicAPInt ( int64_t  Val)
inlineexplicit

Definition at line 116 of file DynamicAPInt.h.

References ValLarge.

◆ DynamicAPInt() [2/4]

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::DynamicAPInt ( const APInt Val)
inlineexplicit

◆ DynamicAPInt() [3/4]

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::DynamicAPInt ( )
inline

◆ ~DynamicAPInt()

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::~DynamicAPInt ( )
inline

Definition at line 129 of file DynamicAPInt.h.

References LLVM_UNLIKELY, and ValLarge.

◆ DynamicAPInt() [4/4]

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::DynamicAPInt ( const DynamicAPInt O)
inline

Definition at line 133 of file DynamicAPInt.h.

References LLVM_UNLIKELY, and ValLarge.

Member Function Documentation

◆ divByPositive()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::divByPositive ( const DynamicAPInt O) const

Definition at line 347 of file DynamicAPInt.h.

References assert(), DynamicAPInt(), and LLVM_LIKELY.

◆ divByPositiveInPlace()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::divByPositiveInPlace ( const DynamicAPInt O)

Definition at line 507 of file DynamicAPInt.h.

References assert(), DynamicAPInt(), and LLVM_LIKELY.

◆ dump()

LLVM_DUMP_METHOD void DynamicAPInt::dump ( ) const

Definition at line 36 of file DynamicAPInt.cpp.

References llvm::dbgs(), and print().

◆ operator int64_t()

LLVM_ATTRIBUTE_ALWAYS_INLINE llvm::DynamicAPInt::operator int64_t ( ) const
inlineexplicit

Definition at line 151 of file DynamicAPInt.h.

◆ operator!=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator!= ( const DynamicAPInt O) const

Definition at line 271 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator%()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator% ( const DynamicAPInt O) const

This operation cannot overflow.

Definition at line 422 of file DynamicAPInt.h.

References DynamicAPInt(), and LLVM_LIKELY.

◆ operator%=()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator%= ( const DynamicAPInt O)

Definition at line 518 of file DynamicAPInt.h.

◆ operator*()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator* ( const DynamicAPInt O) const

Definition at line 332 of file DynamicAPInt.h.

References DynamicAPInt(), LLVM_LIKELY, and llvm::MulOverflow().

◆ operator*=()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator*= ( const DynamicAPInt O)

Definition at line 476 of file DynamicAPInt.h.

References DynamicAPInt(), LLVM_LIKELY, and llvm::MulOverflow().

◆ operator+()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator+ ( const DynamicAPInt O) const

Arithmetic operators.

Definition at line 306 of file DynamicAPInt.h.

References llvm::AddOverflow(), DynamicAPInt(), and LLVM_LIKELY.

◆ operator++()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator++ ( )

Definition at line 521 of file DynamicAPInt.h.

◆ operator+=()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator+= ( const DynamicAPInt O)

Assignment operators, preincrement, predecrement.

Definition at line 442 of file DynamicAPInt.h.

References llvm::AddOverflow(), DynamicAPInt(), and LLVM_LIKELY.

◆ operator-() [1/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator- ( ) const

Definition at line 429 of file DynamicAPInt.h.

References DynamicAPInt(), and LLVM_LIKELY.

◆ operator-() [2/2]

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::SubOverflow().

◆ operator--()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator-- ( )

Definition at line 524 of file DynamicAPInt.h.

◆ operator-=()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator-= ( const DynamicAPInt O)

Definition at line 459 of file DynamicAPInt.h.

References DynamicAPInt(), LLVM_LIKELY, and llvm::SubOverflow().

◆ operator/()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt llvm::DynamicAPInt::operator/ ( const DynamicAPInt O) const

◆ operator/=()

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator/= ( const DynamicAPInt O)

◆ operator<()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator< ( const DynamicAPInt O) const

Definition at line 282 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator<=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator<= ( const DynamicAPInt O) const

Definition at line 288 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator=() [1/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator= ( const DynamicAPInt O)
inline

Definition at line 139 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator=() [2/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & llvm::DynamicAPInt::operator= ( int  X)
inline

Definition at line 147 of file DynamicAPInt.h.

References X.

◆ operator==()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator== ( const DynamicAPInt O) const

We define the operations here in the header to facilitate inlining.


Comparison operators.

Definition at line 265 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator>()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator> ( const DynamicAPInt O) const

Definition at line 277 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ operator>=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool llvm::DynamicAPInt::operator>= ( const DynamicAPInt O) const

Definition at line 295 of file DynamicAPInt.h.

References LLVM_LIKELY.

◆ print()

raw_ostream & DynamicAPInt::print ( raw_ostream OS) const

Definition at line 29 of file DynamicAPInt.cpp.

References OS, ValLarge, and ValSmall.

Referenced by dump().

◆ static_assert_layout()

void DynamicAPInt::static_assert_layout ( )

Definition at line 21 of file DynamicAPInt.cpp.

References offsetof, ValLarge, and ValSmall.

Friends And Related Function Documentation

◆ abs

DynamicAPInt abs ( const DynamicAPInt X)
friend

Definition at line 367 of file DynamicAPInt.h.

◆ ceilDiv

DynamicAPInt ceilDiv ( const DynamicAPInt LHS,
const DynamicAPInt RHS 
)
friend

Definition at line 371 of file DynamicAPInt.h.

◆ floorDiv

DynamicAPInt floorDiv ( const DynamicAPInt LHS,
const DynamicAPInt RHS 
)
friend

Definition at line 382 of file DynamicAPInt.h.

◆ gcd

DynamicAPInt gcd ( const DynamicAPInt A,
const DynamicAPInt B 
)
friend

Definition at line 403 of file DynamicAPInt.h.

◆ hash_value

LLVM_ABI friend hash_code hash_value ( const DynamicAPInt x)
friend

Redeclarations of friend declaration above to make it discoverable by lookups.

◆ lcm

DynamicAPInt lcm ( const DynamicAPInt A,
const DynamicAPInt B 
)
friend

Returns the least common multiple of A and B.

Definition at line 413 of file DynamicAPInt.h.

◆ mod

DynamicAPInt mod ( const DynamicAPInt LHS,
const DynamicAPInt RHS 
)
friend

is always non-negative.

Definition at line 395 of file DynamicAPInt.h.

◆ operator!= [1/2]

bool operator!= ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 599 of file DynamicAPInt.h.

◆ operator!= [2/2]

bool operator!= ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 629 of file DynamicAPInt.h.

◆ operator% [1/2]

DynamicAPInt operator% ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 567 of file DynamicAPInt.h.

◆ operator% [2/2]

DynamicAPInt operator% ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 587 of file DynamicAPInt.h.

◆ operator%=

DynamicAPInt & operator%= ( DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 547 of file DynamicAPInt.h.

◆ operator* [1/2]

DynamicAPInt operator* ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 559 of file DynamicAPInt.h.

◆ operator* [2/2]

DynamicAPInt operator* ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 579 of file DynamicAPInt.h.

◆ operator*=

DynamicAPInt & operator*= ( DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 539 of file DynamicAPInt.h.

◆ operator+ [1/2]

DynamicAPInt operator+ ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 551 of file DynamicAPInt.h.

◆ operator+ [2/2]

DynamicAPInt operator+ ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 571 of file DynamicAPInt.h.

◆ operator+=

DynamicAPInt & operator+= ( DynamicAPInt A,
int64_t  B 
)
friend

Convenience operator overloads for int64_t.


Convenience operator overloads for int64_t.

Definition at line 531 of file DynamicAPInt.h.

◆ operator- [1/2]

DynamicAPInt operator- ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 555 of file DynamicAPInt.h.

◆ operator- [2/2]

DynamicAPInt operator- ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 575 of file DynamicAPInt.h.

◆ operator-=

DynamicAPInt & operator-= ( DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 535 of file DynamicAPInt.h.

◆ operator/ [1/2]

DynamicAPInt operator/ ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 563 of file DynamicAPInt.h.

◆ operator/ [2/2]

DynamicAPInt operator/ ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 583 of file DynamicAPInt.h.

◆ operator/=

DynamicAPInt & operator/= ( DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 543 of file DynamicAPInt.h.

◆ operator< [1/2]

bool operator< ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 609 of file DynamicAPInt.h.

◆ operator< [2/2]

bool operator< ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 639 of file DynamicAPInt.h.

◆ operator<= [1/2]

bool operator<= ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 614 of file DynamicAPInt.h.

◆ operator<= [2/2]

bool operator<= ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 644 of file DynamicAPInt.h.

◆ operator== [1/2]

bool operator== ( const DynamicAPInt A,
int64_t  B 
)
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 594 of file DynamicAPInt.h.

◆ operator== [2/2]

bool operator== ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 624 of file DynamicAPInt.h.

◆ operator> [1/2]

bool operator> ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 604 of file DynamicAPInt.h.

◆ operator> [2/2]

bool operator> ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 634 of file DynamicAPInt.h.

◆ operator>= [1/2]

bool operator>= ( const DynamicAPInt A,
int64_t  B 
)
friend

Definition at line 619 of file DynamicAPInt.h.

◆ operator>= [2/2]

bool operator>= ( int64_t  A,
const DynamicAPInt B 
)
friend

Definition at line 649 of file DynamicAPInt.h.

Member Data Documentation

◆ ValLarge

detail::SlowDynamicAPInt llvm::DynamicAPInt::ValLarge

Definition at line 51 of file DynamicAPInt.h.

Referenced by DynamicAPInt(), print(), static_assert_layout(), and ~DynamicAPInt().

◆ ValSmall

int64_t llvm::DynamicAPInt::ValSmall

Definition at line 50 of file DynamicAPInt.h.

Referenced by DynamicAPInt(), print(), and static_assert_layout().


The documentation for this class was generated from the following files: