LLVM 22.0.0git
llvm::ConstantFPRange Class Reference

This class represents a range of floating-point values. More...

#include "llvm/IR/ConstantFPRange.h"

Public Member Functions

LLVM_ABI ConstantFPRange (const APFloat &Value)
 Initialize a range to hold the single specified value.
LLVM_ABI ConstantFPRange (APFloat LowerVal, APFloat UpperVal, bool MayBeQNaN, bool MayBeSNaN)
 Initialize a range of values explicitly.
LLVM_ABI bool fcmp (FCmpInst::Predicate Pred, const ConstantFPRange &Other) const
 Does the predicate Pred hold between ranges this and Other?
const APFloatgetLower () const
 Return the lower value for this range.
const APFloatgetUpper () const
 Return the upper value for this range.
bool containsNaN () const
bool containsQNaN () const
bool containsSNaN () const
LLVM_ABI bool isNaNOnly () const
const fltSemanticsgetSemantics () const
 Get the semantics of this ConstantFPRange.
LLVM_ABI bool isFullSet () const
 Return true if this set contains all of the elements possible for this data-type.
LLVM_ABI bool isEmptySet () const
 Return true if this set contains no members.
LLVM_ABI bool contains (const APFloat &Val) const
 Return true if the specified value is in the set.
LLVM_ABI bool contains (const ConstantFPRange &CR) const
 Return true if the other range is a subset of this one.
LLVM_ABI const APFloatgetSingleElement (bool ExcludesNaN=false) const
 If this set contains a single element, return it, otherwise return null.
bool isSingleElement (bool ExcludesNaN=false) const
 Return true if this set contains exactly one member.
LLVM_ABI std::optional< boolgetSignBit () const
 Return true if the sign bit of all values in this range is 1.
LLVM_ABI bool operator== (const ConstantFPRange &CR) const
 Return true if this range is equal to another range.
bool operator!= (const ConstantFPRange &CR) const
 Return true if this range is not equal to another range.
LLVM_ABI FPClassTest classify () const
 Return the FPClassTest which will return true for the value.
LLVM_ABI void print (raw_ostream &OS) const
 Print out the bounds to a stream.
LLVM_ABI void dump () const
 Allow printing from a debugger easily.
LLVM_ABI ConstantFPRange intersectWith (const ConstantFPRange &CR) const
 Return the range that results from the intersection of this range with another range.
LLVM_ABI ConstantFPRange unionWith (const ConstantFPRange &CR) const
 Return the smallest range that results from the union of this range with another range.
LLVM_ABI ConstantFPRange abs () const
 Calculate absolute value range.
LLVM_ABI ConstantFPRange negate () const
 Calculate range of negated values.
ConstantFPRange getWithoutNaN () const
 Get the range without NaNs.
LLVM_ABI ConstantFPRange getWithoutInf () const
 Get the range without infinities.
LLVM_ABI ConstantFPRange cast (const fltSemantics &DstSem, APFloat::roundingMode RM=APFloat::rmNearestTiesToEven) const
 Return a new range in the specified format with the specified rounding mode.
LLVM_ABI ConstantFPRange add (const ConstantFPRange &Other) const
 Return a new range representing the possible values resulting from an addition of a value in this range and a value in Other.
LLVM_ABI ConstantFPRange sub (const ConstantFPRange &Other) const
 Return a new range representing the possible values resulting from a subtraction of a value in this range and a value in Other.

Static Public Member Functions

static ConstantFPRange getEmpty (const fltSemantics &Sem)
 Create empty constant range with the given semantics.
static ConstantFPRange getFull (const fltSemantics &Sem)
 Create full constant range with the given semantics.
static LLVM_ABI ConstantFPRange getFinite (const fltSemantics &Sem)
 Helper for (-inf, inf) to represent all finite values.
static LLVM_ABI ConstantFPRange getNonNaN (const fltSemantics &Sem)
 Helper for [-inf, inf] to represent all non-NaN values.
static ConstantFPRange getNonNaN (APFloat LowerVal, APFloat UpperVal)
 Create a range which doesn't contain NaNs.
static ConstantFPRange getMayBeNaN (APFloat LowerVal, APFloat UpperVal)
 Create a range which may contain NaNs.
static LLVM_ABI ConstantFPRange getNaNOnly (const fltSemantics &Sem, bool MayBeQNaN, bool MayBeSNaN)
 Create a range which only contains NaNs.
static LLVM_ABI ConstantFPRange makeAllowedFCmpRegion (FCmpInst::Predicate Pred, const ConstantFPRange &Other)
 Produce the smallest range such that all values that may satisfy the given predicate with any value contained within Other is contained in the returned range.
static LLVM_ABI ConstantFPRange makeSatisfyingFCmpRegion (FCmpInst::Predicate Pred, const ConstantFPRange &Other)
 Produce the largest range such that all values in the returned range satisfy the given predicate with all values contained within Other.
static LLVM_ABI std::optional< ConstantFPRangemakeExactFCmpRegion (FCmpInst::Predicate Pred, const APFloat &Other)
 Produce the exact range such that all values in the returned range satisfy the given predicate with any value contained within Other.

Detailed Description

This class represents a range of floating-point values.

Definition at line 37 of file ConstantFPRange.h.

Constructor & Destructor Documentation

◆ ConstantFPRange() [1/2]

ConstantFPRange::ConstantFPRange ( const APFloat & Value)
explicit

Initialize a range to hold the single specified value.

Definition at line 45 of file ConstantFPRange.cpp.

References getSemantics().

◆ ConstantFPRange() [2/2]

ConstantFPRange::ConstantFPRange ( APFloat LowerVal,
APFloat UpperVal,
bool MayBeQNaN,
bool MayBeSNaN )

Initialize a range of values explicitly.

Note: If LowerVal is greater than UpperVal, please use the canonical form [Inf, -Inf].

Definition at line 83 of file ConstantFPRange.cpp.

References assert(), isNonCanonicalEmptySet(), and llvm::move().

Member Function Documentation

◆ abs()

ConstantFPRange ConstantFPRange::abs ( ) const

Calculate absolute value range.

Definition at line 397 of file ConstantFPRange.cpp.

References getSemantics(), llvm::APFloat::getZero(), isNaNOnly(), llvm::maxnum(), and negate().

◆ add()

ConstantFPRange ConstantFPRange::add ( const ConstantFPRange & Other) const

Return a new range representing the possible values resulting from an addition of a value in this range and a value in Other.

Definition at line 464 of file ConstantFPRange.cpp.

References llvm::APFloat::getInf(), getNaNOnly(), llvm::APFloat::getSemantics(), getSemantics(), isEmptySet(), isNaNOnly(), llvm::Other, and removeInf().

Referenced by sub().

◆ cast()

ConstantFPRange ConstantFPRange::cast ( const fltSemantics & DstSem,
APFloat::roundingMode RM = APFloat::rmNearestTiesToEven ) const

Return a new range in the specified format with the specified rounding mode.

Definition at line 447 of file ConstantFPRange.cpp.

References llvm::APFloat::convert(), llvm::APFloat::isNaN(), and llvm::APFloatBase::opInvalidOp.

◆ classify()

FPClassTest ConstantFPRange::classify ( ) const

Return the FPClassTest which will return true for the value.

Definition at line 336 of file ConstantFPRange.cpp.

References assert(), llvm::fcNone, llvm::fcQNan, llvm::fcSNan, and isNaNOnly().

◆ contains() [1/2]

bool ConstantFPRange::contains ( const APFloat & Val) const

Return true if the specified value is in the set.

Definition at line 292 of file ConstantFPRange.cpp.

References assert(), llvm::APFloatBase::cmpGreaterThan, llvm::APFloat::getSemantics(), getSemantics(), llvm::APFloat::isNaN(), llvm::APFloat::isSignaling(), and strictCompare().

Referenced by fcmp().

◆ contains() [2/2]

bool ConstantFPRange::contains ( const ConstantFPRange & CR) const

Return true if the other range is a subset of this one.

Definition at line 302 of file ConstantFPRange.cpp.

References assert(), llvm::APFloatBase::cmpGreaterThan, getSemantics(), and strictCompare().

◆ containsNaN()

bool llvm::ConstantFPRange::containsNaN ( ) const
inline

Definition at line 144 of file ConstantFPRange.h.

◆ containsQNaN()

bool llvm::ConstantFPRange::containsQNaN ( ) const
inline

Definition at line 145 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual().

◆ containsSNaN()

bool llvm::ConstantFPRange::containsSNaN ( ) const
inline

Definition at line 146 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual().

◆ dump()

LLVM_DUMP_METHOD void ConstantFPRange::dump ( ) const

Allow printing from a debugger easily.

Definition at line 376 of file ConstantFPRange.cpp.

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

◆ fcmp()

bool ConstantFPRange::fcmp ( FCmpInst::Predicate Pred,
const ConstantFPRange & Other ) const

Does the predicate Pred hold between ranges this and Other?

NOTE: false does not mean that inverse predicate holds!

Definition at line 277 of file ConstantFPRange.cpp.

References contains(), makeSatisfyingFCmpRegion(), and llvm::Other.

◆ getEmpty()

ConstantFPRange llvm::ConstantFPRange::getEmpty ( const fltSemantics & Sem)
inlinestatic

Create empty constant range with the given semantics.

Definition at line 69 of file ConstantFPRange.h.

◆ getFinite()

ConstantFPRange ConstantFPRange::getFinite ( const fltSemantics & Sem)
static

Helper for (-inf, inf) to represent all finite values.

Definition at line 92 of file ConstantFPRange.cpp.

References llvm::APFloat::getLargest().

◆ getFull()

ConstantFPRange llvm::ConstantFPRange::getFull ( const fltSemantics & Sem)
inlinestatic

Create full constant range with the given semantics.

Definition at line 74 of file ConstantFPRange.h.

◆ getLower()

const APFloat & llvm::ConstantFPRange::getLower ( ) const
inline

Return the lower value for this range.

Definition at line 139 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual(), and setNaNField().

◆ getMayBeNaN()

ConstantFPRange llvm::ConstantFPRange::getMayBeNaN ( APFloat LowerVal,
APFloat UpperVal )
inlinestatic

Create a range which may contain NaNs.

Definition at line 91 of file ConstantFPRange.h.

◆ getNaNOnly()

ConstantFPRange ConstantFPRange::getNaNOnly ( const fltSemantics & Sem,
bool MayBeQNaN,
bool MayBeSNaN )
static

Create a range which only contains NaNs.

Definition at line 98 of file ConstantFPRange.cpp.

References llvm::APFloat::getInf().

Referenced by add(), makeAllowedFCmpRegion(), and makeSatisfyingFCmpRegion().

◆ getNonNaN() [1/2]

ConstantFPRange llvm::ConstantFPRange::getNonNaN ( APFloat LowerVal,
APFloat UpperVal )
inlinestatic

Create a range which doesn't contain NaNs.

Definition at line 85 of file ConstantFPRange.h.

◆ getNonNaN() [2/2]

ConstantFPRange ConstantFPRange::getNonNaN ( const fltSemantics & Sem)
static

Helper for [-inf, inf] to represent all non-NaN values.

Definition at line 105 of file ConstantFPRange.cpp.

References llvm::APFloat::getInf().

Referenced by makeAllowedFCmpRegion(), makeGreaterThan(), makeLessThan(), and makeSatisfyingFCmpRegion().

◆ getSemantics()

const fltSemantics & llvm::ConstantFPRange::getSemantics ( ) const
inline

Get the semantics of this ConstantFPRange.

Definition at line 150 of file ConstantFPRange.h.

Referenced by abs(), add(), ConstantFPRange(), contains(), contains(), intersectWith(), operator==(), and unionWith().

◆ getSignBit()

std::optional< bool > ConstantFPRange::getSignBit ( ) const

Return true if the sign bit of all values in this range is 1.

Return false if the sign bit of all values in this range is 0. Otherwise, return std::nullopt.

Definition at line 322 of file ConstantFPRange.cpp.

◆ getSingleElement()

const APFloat * ConstantFPRange::getSingleElement ( bool ExcludesNaN = false) const

If this set contains a single element, return it, otherwise return null.

If ExcludesNaN is true, return the non-NaN single element.

Definition at line 316 of file ConstantFPRange.cpp.

References llvm::APFloat::bitwiseIsEqual().

Referenced by isSingleElement().

◆ getUpper()

const APFloat & llvm::ConstantFPRange::getUpper ( ) const
inline

Return the upper value for this range.

Definition at line 142 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual(), and setNaNField().

◆ getWithoutInf()

ConstantFPRange ConstantFPRange::getWithoutInf ( ) const

Get the range without infinities.

It is useful when we apply ninf flag to range of operands/results.

Definition at line 434 of file ConstantFPRange.cpp.

References canonicalizeRange(), isNaNOnly(), and removeInf().

◆ getWithoutNaN()

ConstantFPRange llvm::ConstantFPRange::getWithoutNaN ( ) const
inline

Get the range without NaNs.

It is useful when we apply nnan flag to range of operands/results.

Definition at line 212 of file ConstantFPRange.h.

◆ intersectWith()

ConstantFPRange ConstantFPRange::intersectWith ( const ConstantFPRange & CR) const

Return the range that results from the intersection of this range with another range.

Definition at line 380 of file ConstantFPRange.cpp.

References assert(), canonicalizeRange(), getSemantics(), llvm::maxnum(), and llvm::minnum().

◆ isEmptySet()

bool ConstantFPRange::isEmptySet ( ) const

Return true if this set contains no members.

Definition at line 287 of file ConstantFPRange.cpp.

Referenced by add(), and print().

◆ isFullSet()

bool ConstantFPRange::isFullSet ( ) const

Return true if this set contains all of the elements possible for this data-type.

Definition at line 282 of file ConstantFPRange.cpp.

Referenced by print().

◆ isNaNOnly()

bool ConstantFPRange::isNaNOnly ( ) const

Definition at line 33 of file ConstantFPRange.cpp.

Referenced by abs(), add(), classify(), getWithoutInf(), and print().

◆ isSingleElement()

bool llvm::ConstantFPRange::isSingleElement ( bool ExcludesNaN = false) const
inline

Return true if this set contains exactly one member.

If ExcludesNaN is true, return true if this set contains exactly one non-NaN member.

Definition at line 172 of file ConstantFPRange.h.

References getSingleElement().

◆ makeAllowedFCmpRegion()

ConstantFPRange ConstantFPRange::makeAllowedFCmpRegion ( FCmpInst::Predicate Pred,
const ConstantFPRange & Other )
static

Produce the smallest range such that all values that may satisfy the given predicate with any value contained within Other is contained in the returned range.

Formally, this returns a superset of 'union over all y in Other . { x : fcmp op x y is true }'. If the exact answer is not representable as a ConstantFPRange, the return value will be a proper superset of the above.

Example: Pred = ole and Other = float [2, 5] returns Result = [-inf, 5]

Definition at line 164 of file ConstantFPRange.cpp.

References extendZeroIfEqual(), llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::APFloat::getInf(), llvm::APFloat::getLargest(), getNaNOnly(), getNonNaN(), llvm::CmpInst::isOrdered(), llvm::CmpInst::isUnordered(), llvm_unreachable, makeGreaterThan(), makeLessThan(), llvm::Other, and setNaNField().

◆ makeExactFCmpRegion()

std::optional< ConstantFPRange > ConstantFPRange::makeExactFCmpRegion ( FCmpInst::Predicate Pred,
const APFloat & Other )
static

Produce the exact range such that all values in the returned range satisfy the given predicate with any value contained within Other.

Formally, this returns { x : fcmp op x Other is true }.

Example: Pred = olt and Other = float 3 returns [-inf, 3) If the exact answer is not representable as a ConstantFPRange, returns std::nullopt.

Definition at line 269 of file ConstantFPRange.cpp.

References llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_UNE, makeSatisfyingFCmpRegion(), and llvm::Other.

Referenced by isImpliedCondFCmps(), and simplifyAndOrOfFCmpsWithConstants().

◆ makeSatisfyingFCmpRegion()

ConstantFPRange ConstantFPRange::makeSatisfyingFCmpRegion ( FCmpInst::Predicate Pred,
const ConstantFPRange & Other )
static

Produce the largest range such that all values in the returned range satisfy the given predicate with all values contained within Other.

Formally, this returns a subset of 'intersection over all y in Other . { x : fcmp op x y is true }'. If the exact answer is not representable as a ConstantFPRange, the return value will be a proper subset of the above.

Example: Pred = ole and Other = float [2, 5] returns [-inf, 2]

Definition at line 222 of file ConstantFPRange.cpp.

References extendZeroIfEqual(), llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::fcNan, llvm::fcZero, getNaNOnly(), getNonNaN(), llvm::CmpInst::isOrdered(), llvm::CmpInst::isUnordered(), llvm_unreachable, makeGreaterThan(), makeLessThan(), llvm::Other, and setNaNField().

Referenced by fcmp(), and makeExactFCmpRegion().

◆ negate()

ConstantFPRange ConstantFPRange::negate ( ) const

Calculate range of negated values.

Definition at line 413 of file ConstantFPRange.cpp.

Referenced by abs().

◆ operator!=()

bool llvm::ConstantFPRange::operator!= ( const ConstantFPRange & CR) const
inline

Return true if this range is not equal to another range.

Definition at line 184 of file ConstantFPRange.h.

References operator==().

◆ operator==()

bool ConstantFPRange::operator== ( const ConstantFPRange & CR) const

Return true if this range is equal to another range.

Definition at line 328 of file ConstantFPRange.cpp.

References assert(), and getSemantics().

◆ print()

void ConstantFPRange::print ( raw_ostream & OS) const

Print out the bounds to a stream.

Definition at line 352 of file ConstantFPRange.cpp.

References isEmptySet(), isFullSet(), and isNaNOnly().

Referenced by dump(), and llvm::operator<<().

◆ sub()

ConstantFPRange ConstantFPRange::sub ( const ConstantFPRange & Other) const

Return a new range representing the possible values resulting from a subtraction of a value in this range and a value in Other.

Definition at line 505 of file ConstantFPRange.cpp.

References add(), and llvm::Other.

◆ unionWith()

ConstantFPRange ConstantFPRange::unionWith ( const ConstantFPRange & CR) const

Return the smallest range that results from the union of this range with another range.

The resultant range is guaranteed to include the elements of both sets, but may contain more.

Definition at line 390 of file ConstantFPRange.cpp.

References assert(), getSemantics(), llvm::maxnum(), and llvm::minnum().


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