LLVM  8.0.1
Functions
llvm::APIntOps Namespace Reference

Functions

const APIntsmin (const APInt &A, const APInt &B)
 Determine the smaller of two APInts considered to be signed. More...
 
const APIntsmax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be signed. More...
 
const APIntumin (const APInt &A, const APInt &B)
 Determine the smaller of two APInts considered to be signed. More...
 
const APIntumax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be unsigned. More...
 
APInt GreatestCommonDivisor (APInt A, APInt B)
 Compute GCD of two unsigned APInt values. More...
 
double RoundAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value. More...
 
double RoundSignedAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value. More...
 
float RoundAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float vlalue. More...
 
float RoundSignedAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float value. More...
 
APInt RoundDoubleToAPInt (double Double, unsigned width)
 Converts the given double value into a APInt. More...
 
APInt RoundFloatToAPInt (float Float, unsigned width)
 Converts a float value into a APInt. More...
 
APInt RoundingUDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A unsign-divided by B, rounded by the given rounding mode. More...
 
APInt RoundingSDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A sign-divided by B, rounded by the given rounding mode. More...
 
Optional< APIntSolveQuadraticEquationWrap (APInt A, APInt B, APInt C, unsigned RangeWidth)
 Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g. More...
 

Function Documentation

◆ GreatestCommonDivisor()

APInt llvm::APIntOps::GreatestCommonDivisor ( APInt  A,
APInt  B 
)

Compute GCD of two unsigned APInt values.

This function returns the greatest common divisor of the two APInt values using Stein's algorithm.

Returns
the greatest common divisor of A and B.

Definition at line 672 of file APInt.cpp.

References B, llvm::APInt::countTrailingZeros(), llvm::APInt::lshrInPlace(), and llvm::APInt::ugt().

Referenced by gcd(), getConstantPart(), and umax().

◆ RoundAPIntToDouble()

double llvm::APIntOps::RoundAPIntToDouble ( const APInt APIVal)
inline

Converts the given APInt to a double value.

Treats the APInt as an unsigned value for conversion purposes.

Definition at line 2135 of file APInt.h.

References llvm::APInt::roundToDouble().

Referenced by RoundAPIntToFloat(), and llvm::Interpreter::visitAShr().

◆ RoundAPIntToFloat()

float llvm::APIntOps::RoundAPIntToFloat ( const APInt APIVal)
inline

Converts the given APInt to a float vlalue.

Definition at line 2147 of file APInt.h.

References RoundAPIntToDouble().

Referenced by llvm::Interpreter::visitAShr().

◆ RoundDoubleToAPInt()

APInt llvm::APIntOps::RoundDoubleToAPInt ( double  Double,
unsigned  width 
)

Converts the given double value into a APInt.

This function convert a double value to an APInt value.

Definition at line 715 of file APInt.cpp.

References llvm::APInt::APInt(), llvm::bit_cast(), llvm::Intrinsic::exp, and I.

Referenced by llvm::ExecutionEngine::getConstantValue(), RoundFloatToAPInt(), RoundSignedAPIntToFloat(), and llvm::Interpreter::visitAShr().

◆ RoundFloatToAPInt()

APInt llvm::APIntOps::RoundFloatToAPInt ( float  Float,
unsigned  width 
)
inline

Converts a float value into a APInt.

Converts a float value into an APInt value.

Definition at line 2166 of file APInt.h.

References Arg, C, llvm::hash_value(), llvm::NVPTX::PTXCvtMode::RM, RoundDoubleToAPInt(), RoundingSDiv(), RoundingUDiv(), and SolveQuadraticEquationWrap().

Referenced by llvm::ExecutionEngine::getConstantValue(), and llvm::Interpreter::visitAShr().

◆ RoundingSDiv()

APInt llvm::APIntOps::RoundingSDiv ( const APInt A,
const APInt B,
APInt::Rounding  RM 
)

Return A sign-divided by B, rounded by the given rounding mode.

Definition at line 2707 of file APInt.cpp.

References llvm::APInt::DOWN, llvm::APInt::isNegative(), llvm_unreachable, llvm::APInt::sdiv(), llvm::APInt::sdivrem(), llvm::APInt::TOWARD_ZERO, and llvm::APInt::UP.

Referenced by llvm::ConstantRange::makeGuaranteedNoWrapRegion(), and RoundFloatToAPInt().

◆ RoundingUDiv()

APInt llvm::APIntOps::RoundingUDiv ( const APInt A,
const APInt B,
APInt::Rounding  RM 
)

Return A unsign-divided by B, rounded by the given rounding mode.

Definition at line 2689 of file APInt.cpp.

References llvm::APInt::DOWN, llvm_unreachable, llvm::APInt::TOWARD_ZERO, llvm::APInt::udiv(), llvm::APInt::udivrem(), and llvm::APInt::UP.

Referenced by llvm::ConstantRange::makeGuaranteedNoWrapRegion(), and RoundFloatToAPInt().

◆ RoundSignedAPIntToDouble()

double llvm::APIntOps::RoundSignedAPIntToDouble ( const APInt APIVal)
inline

Converts the given APInt to a double value.

Treats the APInt as a signed value for conversion purposes.

Definition at line 2142 of file APInt.h.

References llvm::APInt::signedRoundToDouble().

Referenced by llvm::Interpreter::visitAShr().

◆ RoundSignedAPIntToFloat()

float llvm::APIntOps::RoundSignedAPIntToFloat ( const APInt APIVal)
inline

Converts the given APInt to a float value.

Treast the APInt as a signed value for conversion purposes.

Definition at line 2154 of file APInt.h.

References RoundDoubleToAPInt(), and llvm::APInt::signedRoundToDouble().

Referenced by llvm::Interpreter::visitAShr().

◆ smax()

const APInt& llvm::APIntOps::smax ( const APInt A,
const APInt B 
)
inline

Determine the larger of two APInts considered to be signed.

Definition at line 2110 of file APInt.h.

References B, and llvm::APInt::sgt().

Referenced by llvm::ScalarEvolution::getSMaxExpr(), llvm::ConstantRange::operator!=(), and llvm::ConstantRange::smax().

◆ smin()

const APInt& llvm::APIntOps::smin ( const APInt A,
const APInt B 
)
inline

Determine the smaller of two APInts considered to be signed.

Definition at line 2105 of file APInt.h.

References B, and llvm::APInt::slt().

Referenced by llvm::ConstantRange::operator!=(), and llvm::ConstantRange::smin().

◆ SolveQuadraticEquationWrap()

Optional< APInt > llvm::APIntOps::SolveQuadraticEquationWrap ( APInt  A,
APInt  B,
APInt  C,
unsigned  RangeWidth 
)

Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.

32 for i32). This function finds the smallest number n, such that (a) n >= 0 and q(n) = 0, or (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all integers, belong to two different intervals [Rk, Rk+R), where R = 2^BW, and k is an integer. The idea here is to find when q(n) "overflows" 2^BW, while at the same time "allowing" subtraction. In unsigned modulo arithmetic a subtraction (treated as addition of negated numbers) would always count as an overflow, but here we want to allow values to decrease and increase as long as they are within the same interval. Specifically, adding of two negative numbers should not cause an overflow (as long as the magnitude does not exceed the bith width). On the other hand, given a positive number, adding a negative number to it can give a negative result, which would cause the value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is treated as a special case of an overflow.

This function returns None if after finding k that minimizes the positive solution to q(n) = kR, both solutions are contained between two consecutive integers.

There are cases where q(n) > T, and q(n+1) < T (assuming evaluation in arithmetic modulo 2^BW, and treating the values as signed) by the virtue of signed overflow. This function will not find such an n, however it may find a value of n satisfying the inequalities due to an unsigned overflow (if the values are treated as unsigned). To find a solution for a signed overflow, treat it as a problem of finding an unsigned overflow with a range with of BW-1.

The returned value may have a different bit width from the input coefficients.

Definition at line 2738 of file APInt.cpp.

References A, llvm::APInt::abs(), llvm::APInt::APInt(), assert(), B, C, D, llvm::dbgs(), llvm::APInt::getBitWidth(), llvm::APInt::getOneBitSet(), llvm::APInt::isNegative(), llvm::APInt::isNonNegative(), llvm::APInt::isNullValue(), llvm::APInt::isStrictlyPositive(), LLVM_DEBUG, llvm::APInt::negate(), llvm::None, llvm::RISCVFenceField::R, llvm::APInt::sdivrem(), llvm::APInt::sext(), llvm::APInt::sextOrTrunc(), llvm::APInt::sgt(), llvm::APInt::sle(), llvm::APInt::sqrt(), llvm::APInt::srem(), T, llvm::APInt::udiv(), llvm::APInt::urem(), and X.

Referenced by RoundFloatToAPInt(), SolveQuadraticAddRecExact(), and SolveQuadraticAddRecRange().

◆ umax()

const APInt& llvm::APIntOps::umax ( const APInt A,
const APInt B 
)
inline

Determine the larger of two APInts considered to be unsigned.

Definition at line 2120 of file APInt.h.

References B, GreatestCommonDivisor(), and llvm::APInt::ugt().

Referenced by llvm::ConstantRange::binaryOr(), llvm::ScalarEvolution::getUMaxExpr(), llvm::ConstantRange::operator!=(), and llvm::ConstantRange::umax().

◆ umin()

const APInt& llvm::APIntOps::umin ( const APInt A,
const APInt B 
)
inline

Determine the smaller of two APInts considered to be signed.

Definition at line 2115 of file APInt.h.

References B, and llvm::APInt::ult().

Referenced by llvm::ConstantRange::binaryAnd(), foldSignedTruncationCheck(), MergeAliasResults(), llvm::ConstantRange::operator!=(), and llvm::ConstantRange::umin().