LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::ConstantFPRange Class Reference

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

#include "llvm/IR/ConstantFPRange.h"

Public Member Functions

 ConstantFPRange (const APFloat &Value)
 Initialize a range to hold the single specified value.
 
 ConstantFPRange (APFloat LowerVal, APFloat UpperVal, bool MayBeQNaN, bool MayBeSNaN)
 Initialize a range of values explicitly.
 
bool 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!
 
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
 
bool isNaNOnly () const
 
const fltSemanticsgetSemantics () const
 Get the semantics of this ConstantFPRange.
 
bool isFullSet () const
 Return true if this set contains all of the elements possible for this data-type.
 
bool isEmptySet () const
 Return true if this set contains no members.
 
bool contains (const APFloat &Val) const
 Return true if the specified value is in the set.
 
bool contains (const ConstantFPRange &CR) const
 Return true if the other range is a subset of this one.
 
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.
 
std::optional< boolgetSignBit () const
 Return true if the sign bit of all values in this range is 1.
 
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.
 
FPClassTest classify () const
 Return the FPClassTest which will return true for the value.
 
void print (raw_ostream &OS) const
 Print out the bounds to a stream.
 
void dump () const
 Allow printing from a debugger easily.
 
ConstantFPRange intersectWith (const ConstantFPRange &CR) const
 Return the range that results from the intersection of this range with another range.
 
ConstantFPRange unionWith (const ConstantFPRange &CR) const
 Return the smallest range that results from the union of this range with another range.
 

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 ConstantFPRange getFinite (const fltSemantics &Sem)
 Helper for (-inf, inf) to represent all finite values.
 
static 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 ConstantFPRange getNaNOnly (const fltSemantics &Sem, bool MayBeQNaN, bool MayBeSNaN)
 Create a range which only contains NaNs.
 
static 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 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 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 36 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.

◆ 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(), llvm::APFloat::getSemantics(), and isNonCanonicalEmptySet().

Member Function Documentation

◆ classify()

FPClassTest ConstantFPRange::classify ( ) const

Return the FPClassTest which will return true for the value.

Definition at line 334 of file ConstantFPRange.cpp.

References assert(), llvm::APFloat::classify(), 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 141 of file ConstantFPRange.h.

◆ containsQNaN()

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

Definition at line 142 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual().

◆ containsSNaN()

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

Definition at line 143 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual().

◆ dump()

LLVM_DUMP_METHOD void ConstantFPRange::dump ( ) const

Allow printing from a debugger easily.

Definition at line 374 of file ConstantFPRange.cpp.

References llvm::dbgs(), 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()

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

Create empty constant range with the given semantics.

Definition at line 68 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()

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

Create full constant range with the given semantics.

Definition at line 73 of file ConstantFPRange.h.

◆ getLower()

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

Return the lower value for this range.

Definition at line 136 of file ConstantFPRange.h.

Referenced by extendZeroIfEqual(), and setNaNField().

◆ getMayBeNaN()

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

Create a range which may contain NaNs.

Definition at line 90 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 makeAllowedFCmpRegion(), and makeSatisfyingFCmpRegion().

◆ getNonNaN() [1/2]

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

Create a range which doesn't contain NaNs.

Definition at line 84 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 147 of file ConstantFPRange.h.

Referenced by contains(), intersectWith(), 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.

References llvm::APFloat::isNegative().

◆ 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().

◆ getUpper()

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

Return the upper value for this range.

Definition at line 139 of file ConstantFPRange.h.

References llvm::Upper.

Referenced by extendZeroIfEqual(), and setNaNField().

◆ 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 378 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.

References llvm::APFloat::isNegInfinity(), and llvm::APFloat::isPosInfinity().

Referenced by 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.

References llvm::APFloat::isNegInfinity(), and llvm::APFloat::isPosInfinity().

Referenced by print().

◆ isNaNOnly()

bool ConstantFPRange::isNaNOnly ( ) const

Definition at line 33 of file ConstantFPRange.cpp.

References llvm::APFloat::isNegInfinity(), and llvm::APFloat::isPosInfinity().

Referenced by classify(), 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 169 of file ConstantFPRange.h.

◆ 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.

◆ 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().

◆ operator!=()

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

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

Definition at line 181 of file ConstantFPRange.h.

References llvm::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 llvm::APFloat::bitwiseIsEqual().

◆ print()

void ConstantFPRange::print ( raw_ostream OS) const

Print out the bounds to a stream.

Definition at line 350 of file ConstantFPRange.cpp.

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

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

◆ 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 388 of file ConstantFPRange.cpp.

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


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