LLVM API Documentation

Public Member Functions | Static Public Member Functions
llvm::ConstantRange Class Reference

#include <ConstantRange.h>

List of all members.

Public Member Functions

 ConstantRange (uint32_t BitWidth, bool isFullSet=true)
 ConstantRange (const APInt &Value)
 ConstantRange (const APInt &Lower, const APInt &Upper)
 Initialize a range of values explicitly. This will assert out if Lower==Upper and Lower != Min or Max value for its type. It will also assert out if the two APInt's are not the same bit width.
const APIntgetLower () const
const APIntgetUpper () const
uint32_t getBitWidth () const
bool isFullSet () const
bool isEmptySet () const
bool isWrappedSet () const
bool isSignWrappedSet () const
bool contains (const APInt &Val) const
bool contains (const ConstantRange &CR) const
const APIntgetSingleElement () const
bool isSingleElement () const
APInt getSetSize () const
APInt getUnsignedMax () const
APInt getUnsignedMin () const
APInt getSignedMax () const
APInt getSignedMin () const
bool operator== (const ConstantRange &CR) const
bool operator!= (const ConstantRange &CR) const
ConstantRange subtract (const APInt &CI) const
ConstantRange difference (const ConstantRange &CR) const
 Subtract the specified range from this range (aka relative complement of the sets).
ConstantRange intersectWith (const ConstantRange &CR) const
ConstantRange unionWith (const ConstantRange &CR) const
ConstantRange zeroExtend (uint32_t BitWidth) const
ConstantRange signExtend (uint32_t BitWidth) const
ConstantRange truncate (uint32_t BitWidth) const
ConstantRange zextOrTrunc (uint32_t BitWidth) const
ConstantRange sextOrTrunc (uint32_t BitWidth) const
ConstantRange add (const ConstantRange &Other) const
ConstantRange sub (const ConstantRange &Other) const
ConstantRange multiply (const ConstantRange &Other) const
ConstantRange smax (const ConstantRange &Other) const
ConstantRange umax (const ConstantRange &Other) const
ConstantRange udiv (const ConstantRange &Other) const
ConstantRange binaryAnd (const ConstantRange &Other) const
ConstantRange binaryOr (const ConstantRange &Other) const
ConstantRange shl (const ConstantRange &Other) const
ConstantRange lshr (const ConstantRange &Other) const
ConstantRange inverse () const
void print (raw_ostream &OS) const
void dump () const

Static Public Member Functions

static ConstantRange makeICmpRegion (unsigned Pred, const ConstantRange &Other)

Detailed Description

ConstantRange - This class represents an range of values.

Definition at line 42 of file ConstantRange.h.


Constructor & Destructor Documentation

ConstantRange::ConstantRange ( uint32_t  BitWidth,
bool  Full = true 
) [explicit]

Initialize a full (the default) or empty set for the specified bit width.

Initialize a full (the default) or empty set for the specified type.

Definition at line 32 of file ConstantRange.cpp.

References llvm::APInt::getMaxValue(), and llvm::APInt::getMinValue().

Referenced by add(), binaryAnd(), binaryOr(), intersectWith(), inverse(), lshr(), makeICmpRegion(), multiply(), shl(), signExtend(), smax(), sub(), subtract(), truncate(), udiv(), umax(), unionWith(), and zeroExtend().

ConstantRange::ConstantRange ( const APInt V)

Initialize a range to hold the single specified value.

Definition at line 41 of file ConstantRange.cpp.

ConstantRange::ConstantRange ( const APInt Lower,
const APInt Upper 
)

Initialize a range of values explicitly. This will assert out if Lower==Upper and Lower != Min or Max value for its type. It will also assert out if the two APInt's are not the same bit width.

Definition at line 43 of file ConstantRange.cpp.

References llvm::APInt::getBitWidth(), llvm::APInt::isMaxValue(), and llvm::APInt::isMinValue().


Member Function Documentation

ConstantRange ConstantRange::add ( const ConstantRange Other) const

add - 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 536 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getLower(), getSetSize(), getUpper(), isEmptySet(), isFullSet(), llvm::APInt::ult(), and llvm::X.

Referenced by llvm::ScalarEvolution::getSignedRange(), and llvm::ScalarEvolution::getUnsignedRange().

ConstantRange ConstantRange::binaryAnd ( const ConstantRange Other) const

binaryAnd - return a new range representing the possible values resulting from a binary-and of a value in this range by a value in Other.

Definition at line 653 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), llvm::APInt::getNullValue(), getUnsignedMax(), llvm::APInt::isAllOnesValue(), isEmptySet(), and llvm::APIntOps::umin().

ConstantRange ConstantRange::binaryOr ( const ConstantRange Other) const

binaryOr - return a new range representing the possible values resulting from a binary-or of a value in this range by a value in Other.

Definition at line 666 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), llvm::APInt::getNullValue(), getUnsignedMin(), isEmptySet(), llvm::APInt::isMinValue(), and umax().

bool ConstantRange::contains ( const APInt V) const
bool ConstantRange::contains ( const ConstantRange Other) const

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

contains - Return true if the argument is a subset of this range. Two equal sets contain each other. The empty set contained by all other sets.

Definition at line 224 of file ConstantRange.cpp.

References getLower(), getUpper(), isEmptySet(), isFullSet(), isWrappedSet(), and llvm::APInt::ule().

ConstantRange ConstantRange::difference ( const ConstantRange CR) const

Subtract the specified range from this range (aka relative complement of the sets).

Definition at line 254 of file ConstantRange.cpp.

References intersectWith(), and inverse().

Referenced by getEdgeValueLocal().

void ConstantRange::dump ( ) const

dump - Allow printing from a debugger easily...

Definition at line 729 of file ConstantRange.cpp.

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

uint32_t llvm::ConstantRange::getBitWidth ( ) const [inline]
const APInt& llvm::ConstantRange::getLower ( ) const [inline]
APInt ConstantRange::getSetSize ( ) const

getSetSize - Return the number of elements in this set.

Definition at line 145 of file ConstantRange.cpp.

References getBitWidth(), isEmptySet(), isFullSet(), llvm::APInt::setBit(), and llvm::APInt::zext().

Referenced by add(), GatherConstantCompares(), intersectWith(), and sub().

APInt ConstantRange::getSignedMax ( ) const
APInt ConstantRange::getSignedMin ( ) const
const APInt* llvm::ConstantRange::getSingleElement ( ) const [inline]

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

Definition at line 111 of file ConstantRange.h.

Referenced by llvm::LazyValueInfo::getConstant(), llvm::LazyValueInfo::getConstantOnEdge(), and isSingleElement().

APInt ConstantRange::getUnsignedMax ( ) const
APInt ConstantRange::getUnsignedMin ( ) const
const APInt& llvm::ConstantRange::getUpper ( ) const [inline]
ConstantRange ConstantRange::intersectWith ( const ConstantRange CR) const

intersectWith - Return the range that results from the intersection of this range with another range. The resultant range is guaranteed to include all elements contained in both input ranges, and to have the smallest possible set size that does so. Because there may be two intersections with the same set size, A.intersectWith(B) might not be equal to B.intersectWith(A).

Definition at line 263 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getSetSize(), intersectWith(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::APInt::ule(), and llvm::APInt::ult().

Referenced by canBeMerged(), difference(), llvm::InstCombiner::FoldAndOfICmps(), and intersectWith().

ConstantRange ConstantRange::inverse ( ) const

inverse - Return a new range that is the logical not of the current set.

Definition at line 708 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), isEmptySet(), and isFullSet().

Referenced by difference(), GatherConstantCompares(), getEdgeValueLocal(), llvm::LazyValueInfo::getPredicateOnEdge(), and SimplifyICmpInst().

bool ConstantRange::isEmptySet ( ) const
bool ConstantRange::isFullSet ( ) const
bool ConstantRange::isSignWrappedSet ( ) const

isSignWrappedSet - Return true if this set wraps around the INT_MIN of its bitwidth, for example: i8 [120, 140).

Definition at line 138 of file ConstantRange.cpp.

References contains(), getBitWidth(), llvm::APInt::getSignedMaxValue(), and llvm::APInt::getSignedMinValue().

Referenced by signExtend().

bool llvm::ConstantRange::isSingleElement ( ) const [inline]

isSingleElement - Return true if this set contains exactly one member.

Definition at line 119 of file ConstantRange.h.

References getSingleElement().

Referenced by llvm::LazyValueInfo::getPredicateOnEdge(), and makeICmpRegion().

bool ConstantRange::isWrappedSet ( ) const

isWrappedSet - Return true if this set wraps around the top of the range, for example: [100, 8)

Definition at line 131 of file ConstantRange.cpp.

References llvm::APInt::ugt().

Referenced by contains(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), intersectWith(), truncate(), unionWith(), and zeroExtend().

ConstantRange ConstantRange::lshr ( const ConstantRange Other) const

lshr - Return a new range representing the possible values resulting from a logical right shift of a value in this range and a value in Other.

Definition at line 696 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), and llvm::APInt::lshr().

ConstantRange ConstantRange::makeICmpRegion ( unsigned  Pred,
const ConstantRange Other 
) [static]

makeICmpRegion - Produce the smallest range that contains all values that might satisfy the comparison specified by Pred when compared to any value contained within Other.

Solves for range X in 'for all x in X, there exists a y in Y such that icmp op x, y is true'. Every value that might make the comparison true is included in the resulting range.

Definition at line 51 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getLower(), llvm::APInt::getMinValue(), llvm::APInt::getNullValue(), getSignedMax(), getSignedMin(), llvm::APInt::getSignedMinValue(), getUnsignedMax(), getUnsignedMin(), getUpper(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, isEmptySet(), isSingleElement(), and llvm_unreachable.

Referenced by llvm::InstCombiner::FoldAndOfICmps(), GatherConstantCompares(), and getEdgeValueLocal().

ConstantRange ConstantRange::multiply ( const ConstantRange Other) const

multiply - Return a new range representing the possible values resulting from a multiplication of a value in this range and a value in Other. TODO: This isn't fully implemented yet.

Definition at line 578 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), truncate(), and llvm::APInt::zext().

Referenced by llvm::ScalarEvolution::getSignedRange(), and llvm::ScalarEvolution::getUnsignedRange().

bool llvm::ConstantRange::operator!= ( const ConstantRange CR) const [inline]

Definition at line 150 of file ConstantRange.h.

References operator==().

bool llvm::ConstantRange::operator== ( const ConstantRange CR) const [inline]

operator== - Return true if this range is equal to another range.

Definition at line 147 of file ConstantRange.h.

Referenced by operator!=().

void ConstantRange::print ( raw_ostream OS) const

print - Print out the bounds to a stream...

Definition at line 718 of file ConstantRange.cpp.

References isEmptySet(), and isFullSet().

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

ConstantRange ConstantRange::sextOrTrunc ( uint32_t  DstTySize) const

sextOrTrunc - make this range have the bit width given by BitWidth. The value is sign extended, truncated, or left alone to make it that width.

sextOrTrunc - make this range have the bit width given by DstTySize. The value is sign extended, truncated, or left alone to make it that width.

Definition at line 526 of file ConstantRange.cpp.

References getBitWidth(), signExtend(), and truncate().

Referenced by llvm::ScalarEvolution::getSignedRange(), llvm::ScalarEvolution::getSignExtendExpr(), and llvm::ScalarEvolution::getUnsignedRange().

ConstantRange ConstantRange::shl ( const ConstantRange Other) const

shl - Return a new range representing the possible values resulting from a left shift of a value in this range by a value in Other. TODO: This isn't fully implemented yet.

Definition at line 679 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::APInt::shl(), and llvm::APInt::ugt().

Referenced by zeroExtend().

ConstantRange ConstantRange::signExtend ( uint32_t  DstTySize) const

signExtend - Return a new range in the specified integer type, which must be strictly larger than the current type. The returned range will correspond to the possible range of values if the source range had been sign extended to BitWidth.

signExtend - Return a new range in the specified integer type, which must be strictly larger than the current type. The returned range will correspond to the possible range of values as if the source range had been sign extended.

Definition at line 445 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), isEmptySet(), isFullSet(), isSignWrappedSet(), and llvm::APInt::sext().

Referenced by llvm::ScalarEvolution::getSignedRange(), llvm::ScalarEvolution::getSignExtendExpr(), llvm::ScalarEvolution::getUnsignedRange(), and sextOrTrunc().

ConstantRange ConstantRange::smax ( const ConstantRange Other) const

smax - Return a new range representing the possible values resulting from a signed maximum of a value in this range and a value in Other.

Definition at line 598 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getSignedMax(), getSignedMin(), and isEmptySet().

Referenced by llvm::ScalarEvolution::getSignedRange(), and llvm::ScalarEvolution::getUnsignedRange().

ConstantRange ConstantRange::sub ( const ConstantRange Other) const

sub - 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 557 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getLower(), getSetSize(), getUpper(), isEmptySet(), isFullSet(), llvm::APInt::ult(), and llvm::X.

ConstantRange ConstantRange::subtract ( const APInt Val) const

subtract - Subtract the specified constant from the endpoints of this constant range.

Definition at line 244 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), and llvm::APInt::getBitWidth().

Referenced by getEdgeValueLocal(), and llvm::SCEVAddRecExpr::getNumIterationsInRange().

ConstantRange ConstantRange::truncate ( uint32_t  DstTySize) const

truncate - Return a new range in the specified integer type, which must be strictly smaller than the current type. The returned range will correspond to the possible range of values if the source range had been truncated to the specified type.

truncate - Return a new range in the specified integer type, which must be strictly smaller than the current type. The returned range will correspond to the possible range of values as if the source range had been truncated to the specified type.

Definition at line 462 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), llvm::APInt::getMaxValue(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::APInt::setBit(), llvm::APInt::trunc(), llvm::APInt::udivrem(), llvm::APInt::uge(), llvm::APInt::ule(), llvm::APInt::ult(), unionWith(), and llvm::APInt::zext().

Referenced by llvm::ScalarEvolution::getSignedRange(), llvm::ScalarEvolution::getSignExtendExpr(), llvm::ScalarEvolution::getUnsignedRange(), llvm::ScalarEvolution::getZeroExtendExpr(), multiply(), sextOrTrunc(), and zextOrTrunc().

ConstantRange ConstantRange::udiv ( const ConstantRange Other) const

udiv - Return a new range representing the possible values resulting from an unsigned division of a value in this range and a value in Other.

Definition at line 624 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getLower(), getUnsignedMax(), getUnsignedMin(), getUpper(), isEmptySet(), isFullSet(), and llvm::APInt::udiv().

Referenced by llvm::ScalarEvolution::getSignedRange(), and llvm::ScalarEvolution::getUnsignedRange().

ConstantRange ConstantRange::umax ( const ConstantRange Other) const

umax - Return a new range representing the possible values resulting from an unsigned maximum of a value in this range and a value in Other.

Definition at line 611 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), and isEmptySet().

Referenced by binaryOr(), llvm::ScalarEvolution::getSignedRange(), and llvm::ScalarEvolution::getUnsignedRange().

ConstantRange ConstantRange::unionWith ( const ConstantRange CR) const

unionWith - Return the 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. For example, [3, 9) union [12,15) is [3, 15), which includes 9, 10, and 11, which were not included in either set before.

Definition at line 344 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), if(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ule(), llvm::APInt::ult(), and unionWith().

Referenced by getEdgeValueLocal(), truncate(), tryMergeRange(), and unionWith().

ConstantRange ConstantRange::zeroExtend ( uint32_t  DstTySize) const

zeroExtend - Return a new range in the specified integer type, which must be strictly larger than the current type. The returned range will correspond to the possible range of values if the source range had been zero extended to BitWidth.

zeroExtend - Return a new range in the specified integer type, which must be strictly larger than the current type. The returned range will correspond to the possible range of values as if the source range had been zero extended.

Definition at line 425 of file ConstantRange.cpp.

References ConstantRange(), getBitWidth(), isEmptySet(), isFullSet(), isWrappedSet(), shl(), and llvm::APInt::zext().

Referenced by llvm::ScalarEvolution::getSignedRange(), llvm::ScalarEvolution::getUnsignedRange(), llvm::ScalarEvolution::getZeroExtendExpr(), and zextOrTrunc().

ConstantRange ConstantRange::zextOrTrunc ( uint32_t  DstTySize) const

zextOrTrunc - make this range have the bit width given by BitWidth. The value is zero extended, truncated, or left alone to make it that width.

zextOrTrunc - make this range have the bit width given by DstTySize. The value is zero extended, truncated, or left alone to make it that width.

Definition at line 515 of file ConstantRange.cpp.

References getBitWidth(), truncate(), and zeroExtend().

Referenced by llvm::ScalarEvolution::getSignedRange(), llvm::ScalarEvolution::getUnsignedRange(), and llvm::ScalarEvolution::getZeroExtendExpr().


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