MLIR  19.0.0git
Public Member Functions | Friends | List of all members
mlir::presburger::MPInt Class Reference

This class provides support for multi-precision arithmetic. More...

#include "mlir/Analysis/Presburger/MPInt.h"

Public Member Functions

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt (int64_t val)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt ()
 
LLVM_ATTRIBUTE_ALWAYS_INLINE ~MPInt ()
 
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt (const MPInt &o)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE MPIntoperator= (const MPInt &o)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE MPIntoperator= (int x)
 
LLVM_ATTRIBUTE_ALWAYS_INLINE operator int64_t () const
 
bool operator== (const MPInt &o) const
 We define the operations here in the header to facilitate inlining. More...
 
bool operator!= (const MPInt &o) const
 
bool operator> (const MPInt &o) const
 
bool operator< (const MPInt &o) const
 
bool operator<= (const MPInt &o) const
 
bool operator>= (const MPInt &o) const
 
MPInt operator+ (const MPInt &o) const
 
MPInt operator- (const MPInt &o) const
 
MPInt operator* (const MPInt &o) const
 
MPInt operator/ (const MPInt &o) const
 
MPInt operator% (const MPInt &o) const
 This operation cannot overflow. More...
 
MPIntoperator+= (const MPInt &o)
 
MPIntoperator-= (const MPInt &o)
 
MPIntoperator*= (const MPInt &o)
 
MPIntoperator/= (const MPInt &o)
 
MPIntoperator%= (const MPInt &o)
 
MPInt operator- () const
 
MPIntoperator++ ()
 
MPIntoperator-- ()
 
MPInt divByPositive (const MPInt &o) const
 
MPIntdivByPositiveInPlace (const MPInt &o)
 
llvm::raw_ostream & print (llvm::raw_ostream &os) const
 
void dump () const
 

Friends

MPInt abs (const MPInt &x)
 
MPInt gcdRange (ArrayRef< MPInt > range)
 Compute the gcd of the range. More...
 
MPInt ceilDiv (const MPInt &lhs, const MPInt &rhs)
 
MPInt floorDiv (const MPInt &lhs, const MPInt &rhs)
 
MPInt gcd (const MPInt &a, const MPInt &b)
 
MPInt lcm (const MPInt &a, const MPInt &b)
 Returns the least common multiple of 'a' and 'b'. More...
 
MPInt mod (const MPInt &lhs, const MPInt &rhs)
 is always non-negative. More...
 
MPIntoperator+= (MPInt &a, int64_t b)
 
MPIntoperator-= (MPInt &a, int64_t b)
 
MPIntoperator*= (MPInt &a, int64_t b)
 
MPIntoperator/= (MPInt &a, int64_t b)
 
MPIntoperator%= (MPInt &a, int64_t b)
 
bool operator== (const MPInt &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. More...
 
bool operator!= (const MPInt &a, int64_t b)
 
bool operator> (const MPInt &a, int64_t b)
 
bool operator< (const MPInt &a, int64_t b)
 
bool operator<= (const MPInt &a, int64_t b)
 
bool operator>= (const MPInt &a, int64_t b)
 
MPInt operator+ (const MPInt &a, int64_t b)
 
MPInt operator- (const MPInt &a, int64_t b)
 
MPInt operator* (const MPInt &a, int64_t b)
 
MPInt operator/ (const MPInt &a, int64_t b)
 
MPInt operator% (const MPInt &a, int64_t b)
 
bool operator== (int64_t a, const MPInt &b)
 
bool operator!= (int64_t a, const MPInt &b)
 
bool operator> (int64_t a, const MPInt &b)
 
bool operator< (int64_t a, const MPInt &b)
 
bool operator<= (int64_t a, const MPInt &b)
 
bool operator>= (int64_t a, const MPInt &b)
 
MPInt operator+ (int64_t a, const MPInt &b)
 
MPInt operator- (int64_t a, const MPInt &b)
 
MPInt operator* (int64_t a, const MPInt &b)
 
MPInt operator/ (int64_t a, const MPInt &b)
 
MPInt operator% (int64_t a, const MPInt &b)
 
llvm::hash_code hash_value (const MPInt &x)
 Redeclarations of friend declaration above to make it discoverable by lookups. More...
 

Detailed Description

This class provides support for multi-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 holdsLarge is true, a SlowMPInt is held in the union. If it is false, the int64_t is held. Using std::variant instead would lead to significantly worse performance.

Definition at line 87 of file MPInt.h.

Constructor & Destructor Documentation

◆ MPInt() [1/3]

LLVM_ATTRIBUTE_ALWAYS_INLINE mlir::presburger::MPInt::MPInt ( int64_t  val)
inlineexplicit

Definition at line 151 of file MPInt.h.

◆ MPInt() [2/3]

LLVM_ATTRIBUTE_ALWAYS_INLINE mlir::presburger::MPInt::MPInt ( )
inline

◆ ~MPInt()

LLVM_ATTRIBUTE_ALWAYS_INLINE mlir::presburger::MPInt::~MPInt ( )
inline

Definition at line 154 of file MPInt.h.

References valLarge.

◆ MPInt() [3/3]

LLVM_ATTRIBUTE_ALWAYS_INLINE mlir::presburger::MPInt::MPInt ( const MPInt o)
inline

Definition at line 158 of file MPInt.h.

References valLarge.

Member Function Documentation

◆ divByPositive()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::divByPositive ( const MPInt o) const

Definition at line 353 of file MPInt.h.

References MPInt().

◆ divByPositiveInPlace()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::divByPositiveInPlace ( const MPInt o)

Definition at line 487 of file MPInt.h.

References MPInt().

◆ dump()

void MPInt::dump ( ) const

Definition at line 32 of file MPInt.cpp.

References print().

◆ operator int64_t()

LLVM_ATTRIBUTE_ALWAYS_INLINE mlir::presburger::MPInt::operator int64_t ( ) const
inlineexplicit

Definition at line 175 of file MPInt.h.

◆ operator!=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator!= ( const MPInt o) const

Definition at line 289 of file MPInt.h.

◆ operator%()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator% ( const MPInt o) const

This operation cannot overflow.

Definition at line 414 of file MPInt.h.

References MPInt().

◆ operator%=()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator%= ( const MPInt o)

Definition at line 496 of file MPInt.h.

◆ operator*()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator* ( const MPInt o) const

Definition at line 340 of file MPInt.h.

References MPInt(), and mlir::presburger::detail::mulOverflow().

◆ operator*=()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator*= ( const MPInt o)

Definition at line 460 of file MPInt.h.

References MPInt(), and mlir::presburger::detail::mulOverflow().

◆ operator+()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator+ ( const MPInt o) const

Arithmetic operators.

Definition at line 318 of file MPInt.h.

References mlir::presburger::detail::addOverflow(), and MPInt().

◆ operator++()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator++ ( )

Definition at line 499 of file MPInt.h.

◆ operator+=()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator+= ( const MPInt o)

Assignment operators, preincrement, predecrement.

Definition at line 432 of file MPInt.h.

References mlir::presburger::detail::addOverflow(), and MPInt().

◆ operator-() [1/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator- ( ) const

Definition at line 420 of file MPInt.h.

References min(), and MPInt().

◆ operator-() [2/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator- ( const MPInt o) const

Definition at line 329 of file MPInt.h.

References MPInt(), and mlir::presburger::detail::subOverflow().

◆ operator--()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator-- ( )

Definition at line 500 of file MPInt.h.

◆ operator-=()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator-= ( const MPInt o)

Definition at line 446 of file MPInt.h.

References MPInt(), and mlir::presburger::detail::subOverflow().

◆ operator/()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mlir::presburger::MPInt::operator/ ( const MPInt o) const

Definition at line 360 of file MPInt.h.

References mlir::presburger::detail::divWouldOverflow(), and MPInt().

◆ operator/=()

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt & mlir::presburger::MPInt::operator/= ( const MPInt o)

Definition at line 474 of file MPInt.h.

References mlir::presburger::detail::divWouldOverflow(), and MPInt().

◆ operator<()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator< ( const MPInt o) const

Definition at line 299 of file MPInt.h.

◆ operator<=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator<= ( const MPInt o) const

Definition at line 304 of file MPInt.h.

◆ operator=() [1/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt& mlir::presburger::MPInt::operator= ( const MPInt o)
inline

Definition at line 163 of file MPInt.h.

References valLarge, and valSmall.

◆ operator=() [2/2]

LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt& mlir::presburger::MPInt::operator= ( int  x)
inline

Definition at line 171 of file MPInt.h.

◆ operator==()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator== ( const MPInt o) const

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


Comparison operators.

Definition at line 284 of file MPInt.h.

◆ operator>()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator> ( const MPInt o) const

Definition at line 294 of file MPInt.h.

◆ operator>=()

LLVM_ATTRIBUTE_ALWAYS_INLINE bool mlir::presburger::MPInt::operator>= ( const MPInt o) const

Definition at line 309 of file MPInt.h.

◆ print()

llvm::raw_ostream & MPInt::print ( llvm::raw_ostream &  os) const

Printing.

Definition at line 26 of file MPInt.cpp.

References valLarge, and valSmall.

Referenced by dump(), and mlir::presburger::operator<<().

Friends And Related Function Documentation

◆ abs

MPInt abs ( const MPInt x)
friend

Definition at line 370 of file MPInt.h.

◆ ceilDiv

MPInt ceilDiv ( const MPInt lhs,
const MPInt rhs 
)
friend

Definition at line 374 of file MPInt.h.

◆ floorDiv

MPInt floorDiv ( const MPInt lhs,
const MPInt rhs 
)
friend

Definition at line 382 of file MPInt.h.

Referenced by mlir::FlatLinearConstraints::getSliceBounds().

◆ gcd

MPInt gcd ( const MPInt a,
const MPInt b 
)
friend

Definition at line 399 of file MPInt.h.

◆ gcdRange

MPInt gcdRange ( ArrayRef< MPInt range)
friend

Compute the gcd of the range.

◆ hash_value

llvm::hash_code hash_value ( const MPInt x)
friend

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

◆ lcm

MPInt lcm ( const MPInt a,
const MPInt b 
)
friend

Returns the least common multiple of 'a' and 'b'.

Definition at line 407 of file MPInt.h.

◆ mod

MPInt mod ( const MPInt lhs,
const MPInt rhs 
)
friend

is always non-negative.

Definition at line 393 of file MPInt.h.

◆ operator!= [1/2]

bool operator!= ( const MPInt a,
int64_t  b 
)
friend

Definition at line 558 of file MPInt.h.

◆ operator!= [2/2]

bool operator!= ( int64_t  a,
const MPInt b 
)
friend

Definition at line 588 of file MPInt.h.

◆ operator% [1/2]

MPInt operator% ( const MPInt a,
int64_t  b 
)
friend

Definition at line 532 of file MPInt.h.

◆ operator% [2/2]

MPInt operator% ( int64_t  a,
const MPInt b 
)
friend

Definition at line 547 of file MPInt.h.

◆ operator%=

MPInt& operator%= ( MPInt a,
int64_t  b 
)
friend

Definition at line 517 of file MPInt.h.

◆ operator* [1/2]

MPInt operator* ( const MPInt a,
int64_t  b 
)
friend

Definition at line 526 of file MPInt.h.

◆ operator* [2/2]

MPInt operator* ( int64_t  a,
const MPInt b 
)
friend

Definition at line 541 of file MPInt.h.

◆ operator*=

MPInt& operator*= ( MPInt a,
int64_t  b 
)
friend

Definition at line 511 of file MPInt.h.

◆ operator+ [1/2]

MPInt operator+ ( const MPInt a,
int64_t  b 
)
friend

Definition at line 520 of file MPInt.h.

◆ operator+ [2/2]

MPInt operator+ ( int64_t  a,
const MPInt b 
)
friend

Definition at line 535 of file MPInt.h.

◆ operator+=

MPInt& operator+= ( MPInt a,
int64_t  b 
)
friend

Convenience operator overloads for int64_t.


Convenience operator overloads for int64_t.

Definition at line 505 of file MPInt.h.

◆ operator- [1/2]

MPInt operator- ( const MPInt a,
int64_t  b 
)
friend

Definition at line 523 of file MPInt.h.

◆ operator- [2/2]

MPInt operator- ( int64_t  a,
const MPInt b 
)
friend

Definition at line 538 of file MPInt.h.

◆ operator-=

MPInt& operator-= ( MPInt a,
int64_t  b 
)
friend

Definition at line 508 of file MPInt.h.

◆ operator/ [1/2]

MPInt operator/ ( const MPInt a,
int64_t  b 
)
friend

Definition at line 529 of file MPInt.h.

◆ operator/ [2/2]

MPInt operator/ ( int64_t  a,
const MPInt b 
)
friend

Definition at line 544 of file MPInt.h.

◆ operator/=

MPInt& operator/= ( MPInt a,
int64_t  b 
)
friend

Definition at line 514 of file MPInt.h.

◆ operator< [1/2]

bool operator< ( const MPInt a,
int64_t  b 
)
friend

Definition at line 568 of file MPInt.h.

◆ operator< [2/2]

bool operator< ( int64_t  a,
const MPInt b 
)
friend

Definition at line 598 of file MPInt.h.

◆ operator<= [1/2]

bool operator<= ( const MPInt a,
int64_t  b 
)
friend

Definition at line 573 of file MPInt.h.

◆ operator<= [2/2]

bool operator<= ( int64_t  a,
const MPInt b 
)
friend

Definition at line 603 of file MPInt.h.

◆ operator== [1/2]

bool operator== ( const MPInt 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 553 of file MPInt.h.

◆ operator== [2/2]

bool operator== ( int64_t  a,
const MPInt b 
)
friend

Definition at line 583 of file MPInt.h.

◆ operator> [1/2]

bool operator> ( const MPInt a,
int64_t  b 
)
friend

Definition at line 563 of file MPInt.h.

◆ operator> [2/2]

bool operator> ( int64_t  a,
const MPInt b 
)
friend

Definition at line 593 of file MPInt.h.

◆ operator>= [1/2]

bool operator>= ( const MPInt a,
int64_t  b 
)
friend

Definition at line 578 of file MPInt.h.

◆ operator>= [2/2]

bool operator>= ( int64_t  a,
const MPInt b 
)
friend

Definition at line 608 of file MPInt.h.

Member Data Documentation

◆ valLarge

detail::SlowMPInt mlir::presburger::MPInt::valLarge

Definition at line 91 of file MPInt.h.

Referenced by MPInt(), operator=(), print(), and ~MPInt().

◆ valSmall

int64_t mlir::presburger::MPInt::valSmall

Definition at line 90 of file MPInt.h.

Referenced by operator=(), and print().


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