LLVM
8.0.1
|
This class represents a range of values. More...
#include "llvm/IR/ConstantRange.h"
Public Member Functions | |
ConstantRange (uint32_t BitWidth, bool isFullSet=true) | |
Initialize a full (the default) or empty set for the specified bit width. More... | |
ConstantRange (APInt Value) | |
Initialize a range to hold the single specified value. More... | |
ConstantRange (APInt Lower, APInt Upper) | |
Initialize a range of values explicitly. More... | |
bool | getEquivalentICmp (CmpInst::Predicate &Pred, APInt &RHS) const |
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this. More... | |
const APInt & | getLower () const |
Return the lower value for this range. More... | |
const APInt & | getUpper () const |
Return the upper value for this range. More... | |
uint32_t | getBitWidth () const |
Get the bit width of this ConstantRange. More... | |
bool | isFullSet () const |
Return true if this set contains all of the elements possible for this data-type. More... | |
bool | isEmptySet () const |
Return true if this set contains no members. More... | |
bool | isWrappedSet () const |
Return true if this set wraps around the top of the range. More... | |
bool | isSignWrappedSet () const |
Return true if this set wraps around the INT_MIN of its bitwidth. More... | |
bool | contains (const APInt &Val) const |
Return true if the specified value is in the set. More... | |
bool | contains (const ConstantRange &CR) const |
Return true if the other range is a subset of this one. More... | |
const APInt * | getSingleElement () const |
If this set contains a single element, return it, otherwise return null. More... | |
const APInt * | getSingleMissingElement () const |
If this set contains all but a single element, return it, otherwise return null. More... | |
bool | isSingleElement () const |
Return true if this set contains exactly one member. More... | |
APInt | getSetSize () const |
Return the number of elements in this set. More... | |
bool | isSizeStrictlySmallerThan (const ConstantRange &CR) const |
Compare set size of this range with the range CR. More... | |
bool | isSizeLargerThan (uint64_t MaxSize) const |
APInt | getUnsignedMax () const |
Return the largest unsigned value contained in the ConstantRange. More... | |
APInt | getUnsignedMin () const |
Return the smallest unsigned value contained in the ConstantRange. More... | |
APInt | getSignedMax () const |
Return the largest signed value contained in the ConstantRange. More... | |
APInt | getSignedMin () const |
Return the smallest signed value contained in the ConstantRange. More... | |
bool | operator== (const ConstantRange &CR) const |
Return true if this range is equal to another range. More... | |
bool | operator!= (const ConstantRange &CR) const |
ConstantRange | subtract (const APInt &CI) const |
Subtract the specified constant from the endpoints of this constant range. More... | |
ConstantRange | difference (const ConstantRange &CR) const |
Subtract the specified range from this range (aka relative complement of the sets). More... | |
ConstantRange | intersectWith (const ConstantRange &CR) const |
Return the range that results from the intersection of this range with another range. More... | |
ConstantRange | unionWith (const ConstantRange &CR) const |
Return the range that results from the union of this range with another range. More... | |
ConstantRange | castOp (Instruction::CastOps CastOp, uint32_t BitWidth) const |
Return a new range representing the possible values resulting from an application of the specified cast operator to this range. More... | |
ConstantRange | zeroExtend (uint32_t BitWidth) const |
Return a new range in the specified integer type, which must be strictly larger than the current type. More... | |
ConstantRange | signExtend (uint32_t BitWidth) const |
Return a new range in the specified integer type, which must be strictly larger than the current type. More... | |
ConstantRange | truncate (uint32_t BitWidth) const |
Return a new range in the specified integer type, which must be strictly smaller than the current type. More... | |
ConstantRange | zextOrTrunc (uint32_t BitWidth) const |
Make this range have the bit width given by BitWidth . More... | |
ConstantRange | sextOrTrunc (uint32_t BitWidth) const |
Make this range have the bit width given by BitWidth . More... | |
ConstantRange | binaryOp (Instruction::BinaryOps BinOp, const ConstantRange &Other) const |
Return a new range representing the possible values resulting from an application of the specified binary operator to an left hand side of this range and a right hand side of Other . More... | |
ConstantRange | add (const ConstantRange &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 . More... | |
ConstantRange | addWithNoSignedWrap (const APInt &Other) const |
Return a new range representing the possible values resulting from a known NSW addition of a value in this range and Other constant. More... | |
ConstantRange | sub (const ConstantRange &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 . More... | |
ConstantRange | multiply (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a multiplication of a value in this range and a value in Other , treating both this and Other as unsigned ranges. More... | |
ConstantRange | smax (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a signed maximum of a value in this range and a value in Other . More... | |
ConstantRange | umax (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from an unsigned maximum of a value in this range and a value in Other . More... | |
ConstantRange | smin (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a signed minimum of a value in this range and a value in Other . More... | |
ConstantRange | umin (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from an unsigned minimum of a value in this range and a value in Other . More... | |
ConstantRange | udiv (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from an unsigned division of a value in this range and a value in Other . More... | |
ConstantRange | binaryAnd (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a binary-and of a value in this range by a value in Other . More... | |
ConstantRange | binaryOr (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a binary-or of a value in this range by a value in Other . More... | |
ConstantRange | shl (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a left shift of a value in this range by a value in Other . More... | |
ConstantRange | lshr (const ConstantRange &Other) const |
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 . More... | |
ConstantRange | ashr (const ConstantRange &Other) const |
Return a new range representing the possible values resulting from a arithmetic right shift of a value in this range and a value in Other . More... | |
ConstantRange | inverse () const |
Return a new range that is the logical not of the current set. More... | |
void | print (raw_ostream &OS) const |
Print out the bounds to a stream. More... | |
void | dump () const |
Allow printing from a debugger easily. More... | |
Static Public Member Functions | |
static ConstantRange | makeAllowedICmpRegion (CmpInst::Predicate Pred, const ConstantRange &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. More... | |
static ConstantRange | makeSatisfyingICmpRegion (CmpInst::Predicate Pred, const ConstantRange &Other) |
Produce the largest range such that all values in the returned range satisfy the given predicate with all values contained within Other. More... | |
static ConstantRange | makeExactICmpRegion (CmpInst::Predicate Pred, const APInt &Other) |
Produce the exact range such that all values in the returned range satisfy the given predicate with any value contained within Other. More... | |
static ConstantRange | makeGuaranteedNoWrapRegion (Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind) |
Return the largest range containing all X such that "X BinOpC Y" is guaranteed not to wrap (overflow) for all Y in Other. More... | |
This class represents a range of values.
Definition at line 47 of file ConstantRange.h.
Initialize a full (the default) or empty set for the specified bit width.
Definition at line 42 of file ConstantRange.cpp.
References llvm::Upper.
Referenced by add(), addWithNoSignedWrap(), ashr(), binaryAnd(), binaryOp(), binaryOr(), castOp(), llvm::getConstantRangeFromMetadata(), intersectWith(), inverse(), lshr(), makeAllowedICmpRegion(), makeGuaranteedNoWrapRegion(), multiply(), shl(), signExtend(), smax(), smin(), sub(), subtract(), truncate(), udiv(), umax(), umin(), unionWith(), and zeroExtend().
ConstantRange::ConstantRange | ( | APInt | Value | ) |
Initialize a range to hold the single specified value.
Definition at line 46 of file ConstantRange.cpp.
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 49 of file ConstantRange.cpp.
References assert(), llvm::APInt::getBitWidth(), and llvm::LegalizeActions::Lower.
ConstantRange ConstantRange::add | ( | const ConstantRange & | 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 761 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getLower(), getUpper(), isEmptySet(), isFullSet(), isSizeStrictlySmallerThan(), and X.
Referenced by binaryOp(), llvm::JumpThreadingPass::ComputeValueKnownInPredecessorsImpl(), llvm::StackSafetyInfo::FunctionInfo::FunctionInfo(), GetRangeFromMetadata(), and IsKnownPredicateViaMinOrMax().
ConstantRange ConstantRange::addWithNoSignedWrap | ( | const APInt & | Other | ) | const |
Return a new range representing the possible values resulting from a known NSW addition of a value in this range and Other
constant.
Definition at line 780 of file ConstantRange.cpp.
References llvm::MCID::Add, ConstantRange(), intersectWith(), makeGuaranteedNoWrapRegion(), and llvm::OverflowingBinaryOperator::NoSignedWrap.
ConstantRange ConstantRange::ashr | ( | const ConstantRange & | Other | ) | const |
Return a new range representing the possible values resulting from a arithmetic right shift of a value in this range and a value in Other
.
Definition at line 1009 of file ConstantRange.cpp.
References llvm::APInt::ashr(), ConstantRange(), getBitWidth(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::APInt::isNegative(), llvm::APInt::isNonNegative(), and llvm::max().
Referenced by binaryOp().
ConstantRange ConstantRange::binaryAnd | ( | const ConstantRange & | Other | ) | const |
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 949 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), llvm::APInt::getNullValue(), getUnsignedMax(), llvm::APInt::isAllOnesValue(), isEmptySet(), umin(), and llvm::APIntOps::umin().
Referenced by binaryOp().
ConstantRange ConstantRange::binaryOp | ( | Instruction::BinaryOps | BinOp, |
const ConstantRange & | Other | ||
) | const |
Return a new range representing the possible values resulting from an application of the specified binary operator to an left hand side of this range and a right hand side of Other
.
Definition at line 723 of file ConstantRange.cpp.
References llvm::MCID::Add, add(), ashr(), assert(), binaryAnd(), binaryOr(), ConstantRange(), getBitWidth(), llvm::Instruction::isBinaryOp(), lshr(), multiply(), shl(), sub(), and udiv().
Referenced by isObjectDereferencedInBlock().
ConstantRange ConstantRange::binaryOr | ( | const ConstantRange & | Other | ) | const |
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 962 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), llvm::APInt::getNullValue(), getUnsignedMin(), isEmptySet(), llvm::APInt::isNullValue(), umax(), and llvm::APIntOps::umax().
Referenced by binaryOp().
ConstantRange ConstantRange::castOp | ( | Instruction::CastOps | CastOp, |
uint32_t | BitWidth | ||
) | const |
Return a new range representing the possible values resulting from an application of the specified cast operator to this range.
BitWidth
is the target bitwidth of the cast. For casts which don't change bitwidth, it must be the same as the source bitwidth. For casts which do change bitwidth, the bitwidth must be consistent with the requested cast and source bitwidth.
Definition at line 573 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm_unreachable, llvm::APInt::sextOrSelf(), signExtend(), truncate(), zeroExtend(), and llvm::APInt::zextOrSelf().
Referenced by isObjectDereferencedInBlock().
Return true if the specified value is in the set.
Definition at line 389 of file ConstantRange.cpp.
References isFullSet(), isWrappedSet(), llvm::LegalizeActions::Lower, and llvm::APInt::ult().
Referenced by llvm::JumpThreadingPass::ComputeValueKnownInPredecessorsImpl(), llvm::copyRangeMetadata(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getPredicateResult(), getRangeForAffineARHelper(), llvm::ScalarEvolution::getSignExtendExpr(), llvm::ScalarEvolution::getZeroExtendExpr(), IsKnownPredicateViaMinOrMax(), llvm::ScalarEvolution::isLoopInvariantPredicate(), isSignWrappedSet(), processAdd(), simplifyICmpWithAbsNabs(), simplifyICmpWithConstant(), SolveQuadraticAddRecRange(), and willNotOverflow().
bool ConstantRange::contains | ( | const ConstantRange & | CR | ) | const |
Return true if the other range is a subset of this one.
Definition at line 398 of file ConstantRange.cpp.
References getLower(), getUpper(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::LegalizeActions::Lower, 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 424 of file ConstantRange.cpp.
References intersectWith(), and inverse().
Referenced by getEdgeValueLocal(), isImpliedCondMatchingImmOperands(), and processUGT_ADDCST_ADD().
LLVM_DUMP_METHOD void ConstantRange::dump | ( | ) | const |
Allow printing from a debugger easily.
Definition at line 1080 of file ConstantRange.cpp.
References llvm::dbgs(), and print().
|
inline |
Get the bit width of this ConstantRange.
Definition at line 132 of file ConstantRange.h.
References contains(), and llvm::APInt::getBitWidth().
Referenced by add(), ashr(), binaryAnd(), binaryOp(), binaryOr(), castOp(), getEquivalentICmp(), getRangeForAffineARHelper(), getSetSize(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), intersectWith(), inverse(), isSignWrappedSet(), isSizeLargerThan(), isSizeStrictlySmallerThan(), lshr(), makeAllowedICmpRegion(), makeGuaranteedNoWrapRegion(), mapBinOpcode(), multiply(), sextOrTrunc(), shl(), signExtend(), smax(), smin(), sub(), subtract(), truncate(), udiv(), umax(), umin(), unionWith(), zeroExtend(), and zextOrTrunc().
bool ConstantRange::getEquivalentICmp | ( | CmpInst::Predicate & | Pred, |
APInt & | RHS | ||
) | const |
Set up Pred
and RHS
such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
Return true if successful.
Definition at line 145 of file ConstantRange.cpp.
References assert(), getBitWidth(), getLower(), getSingleElement(), getSingleMissingElement(), getUpper(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, isEmptySet(), isFullSet(), llvm::APInt::isMinSignedValue(), makeExactICmpRegion(), and Success.
Referenced by llvm::ScalarEvolution::SimplifyICmpOperands().
Return the lower value for this range.
Definition at line 126 of file ConstantRange.h.
References llvm::Lower.
Referenced by add(), contains(), GetConstantInt(), getEquivalentICmp(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getRangeForAffineARHelper(), getSignedMin(), getUnsignedMin(), isContiguous(), makeAllowedICmpRegion(), mapBinOpcode(), llvm::operator<<(), SolveQuadraticAddRecRange(), sub(), tryMergeRange(), and udiv().
APInt ConstantRange::getSetSize | ( | ) | const |
Return the number of elements in this set.
Definition at line 336 of file ConstantRange.cpp.
References getBitWidth(), llvm::APInt::getOneBitSet(), isFullSet(), and llvm::LegalizeActions::Lower.
APInt ConstantRange::getSignedMax | ( | ) | const |
Return the largest signed value contained in the ConstantRange.
Definition at line 377 of file ConstantRange.cpp.
References getBitWidth(), llvm::APInt::getSignedMaxValue(), getUpper(), isFullSet(), and llvm::LegalizeActions::Lower.
Referenced by ashr(), getRangeForAffineARHelper(), hasSingleUsesFromRoot(), makeAllowedICmpRegion(), makeGuaranteedNoWrapRegion(), multiply(), smax(), and smin().
APInt ConstantRange::getSignedMin | ( | ) | const |
Return the smallest signed value contained in the ConstantRange.
Definition at line 383 of file ConstantRange.cpp.
References getBitWidth(), getLower(), llvm::APInt::getSignedMinValue(), getUpper(), isFullSet(), llvm::APInt::isMinSignedValue(), and llvm::LegalizeActions::Lower.
Referenced by ashr(), getRangeForAffineARHelper(), hasSingleUsesFromRoot(), makeAllowedICmpRegion(), makeGuaranteedNoWrapRegion(), multiply(), smax(), and smin().
If this set contains a single element, return it, otherwise return null.
Definition at line 156 of file ConstantRange.h.
References llvm::Lower.
Referenced by llvm::ValueLatticeElement::asConstantInteger(), llvm::LazyValueInfo::getConstant(), llvm::LazyValueInfo::getConstantOnEdge(), getEquivalentICmp(), makeGuaranteedNoWrapRegion(), and processUGT_ADDCST_ADD().
If this set contains all but a single element, return it, otherwise return null.
Definition at line 164 of file ConstantRange.h.
References llvm::Upper.
Referenced by getEquivalentICmp().
APInt ConstantRange::getUnsignedMax | ( | ) | const |
Return the largest unsigned value contained in the ConstantRange.
Definition at line 365 of file ConstantRange.cpp.
References getBitWidth(), llvm::APInt::getMaxValue(), getUpper(), isFullSet(), and isWrappedSet().
Referenced by llvm::SCEVAAResult::alias(), ashr(), binaryAnd(), hasSingleUsesFromRoot(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), lshr(), makeAllowedICmpRegion(), makeGuaranteedNoWrapRegion(), multiply(), mustBeFiniteCountedLoop(), processUDivOrURem(), shl(), udiv(), umax(), and umin().
APInt ConstantRange::getUnsignedMin | ( | ) | const |
Return the smallest unsigned value contained in the ConstantRange.
Definition at line 371 of file ConstantRange.cpp.
References getBitWidth(), getLower(), llvm::APInt::getMinValue(), getUpper(), isFullSet(), and isWrappedSet().
Referenced by llvm::SCEVAAResult::alias(), ashr(), binaryOr(), GetLoopInvariantInsertPosition(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), lshr(), makeAllowedICmpRegion(), multiply(), shl(), udiv(), umax(), and umin().
Return the upper value for this range.
Definition at line 129 of file ConstantRange.h.
References llvm::Upper.
Referenced by add(), contains(), GetConstantInt(), getEquivalentICmp(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getRangeForAffineARHelper(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), isContiguous(), makeAllowedICmpRegion(), mapBinOpcode(), multiply(), llvm::operator<<(), SolveQuadraticAddRecRange(), sub(), tryMergeRange(), and udiv().
ConstantRange ConstantRange::intersectWith | ( | const ConstantRange & | CR | ) | const |
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 428 of file ConstantRange.cpp.
References assert(), ConstantRange(), getBitWidth(), intersectWith(), isEmptySet(), isFullSet(), isSizeStrictlySmallerThan(), isWrappedSet(), llvm::LegalizeActions::Lower, llvm::APInt::ule(), and llvm::APInt::ult().
Referenced by addWithNoSignedWrap(), canBeMerged(), difference(), GetRangeFromMetadata(), intersect(), intersectWith(), isContiguous(), isImpliedCondMatchingImmOperands(), processUGT_ADDCST_ADD(), simplifyICmpWithConstant(), and visitIVCast().
ConstantRange ConstantRange::inverse | ( | ) | const |
Return a new range that is the logical not of the current set.
Definition at line 1062 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), isEmptySet(), isFullSet(), and llvm::LegalizeActions::Lower.
Referenced by llvm::JumpThreadingPass::ComputeValueKnownInPredecessorsImpl(), difference(), GetConstantInt(), getPredicateResult(), makeGuaranteedNoWrapRegion(), makeSatisfyingICmpRegion(), and simplifyICmpWithConstant().
bool ConstantRange::isEmptySet | ( | ) | const |
Return true if this set contains no members.
Definition at line 323 of file ConstantRange.cpp.
References llvm::LegalizeActions::Lower.
Referenced by add(), llvm::ValueLatticeElement::asConstantInteger(), ashr(), binaryAnd(), binaryOr(), canBeMerged(), contains(), llvm::StackSafetyInfo::FunctionInfo::FunctionInfo(), GetConstantInt(), getEquivalentICmp(), intersectWith(), inverse(), isContiguous(), isImpliedCondMatchingImmOperands(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), lshr(), makeAllowedICmpRegion(), multiply(), print(), processAdd(), processUGT_ADDCST_ADD(), shl(), signExtend(), llvm::ScalarEvolution::SimplifyICmpOperands(), simplifyICmpWithConstant(), smax(), smin(), sub(), truncate(), udiv(), umax(), umin(), unionWith(), willNotOverflow(), and zeroExtend().
bool ConstantRange::isFullSet | ( | ) | const |
Return true if this set contains all of the elements possible for this data-type.
Definition at line 319 of file ConstantRange.cpp.
References llvm::LegalizeActions::Lower.
Referenced by add(), contains(), getEquivalentICmp(), llvm::MDNode::getMostGenericRange(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getRangeForAffineARHelper(), GetRangeFromMetadata(), getSetSize(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), intersectWith(), inverse(), isContiguous(), isSizeLargerThan(), isSizeStrictlySmallerThan(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), mapBinOpcode(), llvm::ValueLatticeElement::mergeIn(), print(), signExtend(), llvm::ScalarEvolution::SimplifyICmpOperands(), simplifyICmpWithConstant(), sub(), truncate(), udiv(), unionWith(), and zeroExtend().
bool ConstantRange::isSignWrappedSet | ( | ) | const |
Return true if this set wraps around the INT_MIN of its bitwidth.
For example: i8 [120, 140).
Definition at line 331 of file ConstantRange.cpp.
References contains(), getBitWidth(), llvm::APInt::getSignedMaxValue(), and llvm::APInt::getSignedMinValue().
Referenced by mapBinOpcode(), and signExtend().
|
inline |
Return true if this set contains exactly one member.
Definition at line 171 of file ConstantRange.h.
Referenced by getPredicateResult(), hasSingleValue(), and makeAllowedICmpRegion().
bool ConstantRange::isSizeLargerThan | ( | uint64_t | MaxSize | ) | const |
Definition at line 355 of file ConstantRange.cpp.
References assert(), getBitWidth(), llvm::APInt::getMaxValue(), isFullSet(), llvm::LegalizeActions::Lower, and llvm::APInt::ugt().
Referenced by GetConstantInt().
bool ConstantRange::isSizeStrictlySmallerThan | ( | const ConstantRange & | CR | ) | const |
Compare set size of this range with the range CR.
Definition at line 345 of file ConstantRange.cpp.
References assert(), getBitWidth(), isFullSet(), and llvm::LegalizeActions::Lower.
Referenced by add(), intersectWith(), multiply(), and sub().
bool ConstantRange::isWrappedSet | ( | ) | const |
Return true if this set wraps around the top of the range.
For example: [100, 8).
Definition at line 327 of file ConstantRange.cpp.
References llvm::LegalizeActions::Lower.
Referenced by contains(), getUnsignedMax(), getUnsignedMin(), intersectWith(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), multiply(), truncate(), unionWith(), and zeroExtend().
ConstantRange ConstantRange::lshr | ( | const ConstantRange & | Other | ) | const |
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 996 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::APInt::lshr(), and llvm::max().
Referenced by binaryOp().
|
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 : icmp op x y is true }'. If the exact answer is not representable as a ConstantRange, the return value will be a proper superset of the above.
Example: Pred = ult and Other = i8 [2, 5) returns Result = [0, 4)
Definition at line 57 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(), llvm_unreachable, and llvm::RISCVFenceField::W.
Referenced by GetConstantInt(), getValueFromICmpCondition(), isImpliedCondMatchingImmOperands(), IsKnownPredicateViaMinOrMax(), makeExactICmpRegion(), makeSatisfyingICmpRegion(), processUGT_ADDCST_ADD(), and truncateIVUse().
|
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 the exact answer when the superset of 'union over all y in Other is exactly same as the subset of intersection over all y in Other. { x : icmp op x y is true}'.
Example: Pred = ult and Other = i8 3 returns [0, 3)
Definition at line 133 of file ConstantRange.cpp.
References assert(), makeAllowedICmpRegion(), and makeSatisfyingICmpRegion().
Referenced by llvm::JumpThreadingPass::ComputeValueKnownInPredecessorsImpl(), foldICmpShlOne(), llvm::ScalarEvolution::forgetValue(), getEquivalentICmp(), getPredicateResult(), isImpliedCondMatchingImmOperands(), processUGT_ADDCST_ADD(), simplifyAndOrOfICmpsWithConstants(), llvm::ScalarEvolution::SimplifyICmpOperands(), simplifyICmpWithAbsNabs(), and simplifyICmpWithConstant().
|
static |
Return the largest range containing all X such that "X BinOpC Y" is guaranteed not to wrap (overflow) for all Y in Other.
NB! The returned set does not contain all possible values of X for which "X BinOpC Y" does not wrap – some viable values of X may be missing, so you cannot use this to constrain X's range. E.g. in the fourth example, "(-2) + 1" is both nsw and nuw (so the "X" could be -2), but (-2) is not in the set returned.
Examples: typedef OverflowingBinaryOperator OBO; #define MGNR makeGuaranteedNoWrapRegion MGNR(Add, [i8 1, 2), OBO::NoSignedWrap) == [-128, 127) MGNR(Add, [i8 1, 2), OBO::NoUnsignedWrap) == [0, -1) MGNR(Add, [i8 0, 1), OBO::NoUnsignedWrap) == Full Set MGNR(Add, [i8 1, 2), OBO::NoUnsignedWrap | OBO::NoSignedWrap) == [0,INT_MAX) MGNR(Add, [i8 -1, 6), OBO::NoSignedWrap) == [INT_MIN+1, INT_MAX-4) MGNR(Sub, [i8 1, 2), OBO::NoSignedWrap) == [-127, 128) MGNR(Sub, [i8 1, 2), OBO::NoUnsignedWrap) == [1, 0) MGNR(Sub, [i8 1, 2), OBO::NoUnsignedWrap | OBO::NoSignedWrap) == [1,INT_MAX)
Definition at line 180 of file ConstantRange.cpp.
References llvm::MCID::Add, assert(), C, ConstantRange(), llvm::APInt::DOWN, getBitWidth(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), llvm::APInt::getNullValue(), getSignedMax(), llvm::APInt::getSignedMaxValue(), getSignedMin(), llvm::APInt::getSignedMinValue(), getSingleElement(), getUnsignedMax(), inverse(), llvm::Instruction::isBinaryOp(), llvm::APInt::isNegative(), llvm::APInt::isStrictlyPositive(), llvm::LegalizeActions::Lower, llvm::APIntOps::RoundingSDiv(), llvm::APIntOps::RoundingUDiv(), llvm::APInt::sextOrSelf(), unionWith(), Unsigned, llvm::APInt::UP, and llvm::APInt::zextOrSelf().
Referenced by addWithNoSignedWrap(), processAdd(), PushDefUseChildren(), StrengthenNoWrapFlags(), and willNotOverflow().
|
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 : icmp op x y is true }'. If the exact answer is not representable as a ConstantRange, the return value will be a proper subset of the above.
Example: Pred = ult and Other = i8 [2, 5) returns [0, 2)
Definition at line 123 of file ConstantRange.cpp.
References llvm::CmpInst::getInversePredicate(), inverse(), and makeAllowedICmpRegion().
Referenced by llvm::ValueLatticeElement::getCompare(), IsKnownPredicateViaMinOrMax(), llvm::ScalarEvolution::isLoopInvariantPredicate(), makeExactICmpRegion(), and SimplifyICmpInst().
ConstantRange ConstantRange::multiply | ( | const ConstantRange & | Other | ) | const |
Return a new range representing the possible values resulting from a multiplication of a value in this range and a value in Other
, treating both this and Other
as unsigned ranges.
Definition at line 814 of file ConstantRange.cpp.
References A, B, llvm::MCID::Compare, ConstantRange(), getBitWidth(), getSignedMax(), getSignedMin(), getUnsignedMax(), getUnsignedMin(), getUpper(), isEmptySet(), llvm::APInt::isMinSignedValue(), llvm::APInt::isNonNegative(), isSizeStrictlySmallerThan(), isWrappedSet(), llvm::max(), llvm::APInt::sext(), llvm::APInt::slt(), truncate(), and llvm::APInt::zext().
Referenced by binaryOp(), and GetRangeFromMetadata().
|
inline |
Definition at line 198 of file ConstantRange.h.
References llvm::ARM_AM::add, llvm::dump(), llvm::operator==(), print(), llvm::APIntOps::smax(), llvm::APIntOps::smin(), llvm::ARM_AM::sub, llvm::APIntOps::umax(), and llvm::APIntOps::umin().
|
inline |
Return true if this range is equal to another range.
Definition at line 195 of file ConstantRange.h.
void ConstantRange::print | ( | raw_ostream & | OS | ) | const |
Print out the bounds to a stream.
Definition at line 1070 of file ConstantRange.cpp.
References isEmptySet(), isFullSet(), and llvm::LegalizeActions::Lower.
Referenced by dump(), llvm::operator<<(), and llvm::ScalarEvolution::print().
ConstantRange ConstantRange::sextOrTrunc | ( | uint32_t | BitWidth | ) | const |
Make this range have the bit width given by BitWidth
.
The value is sign extended, truncated, or left alone to make it that width.
Definition at line 714 of file ConstantRange.cpp.
References getBitWidth(), signExtend(), and truncate().
Referenced by llvm::ScalarEvolution::getSignExtendExpr().
ConstantRange ConstantRange::shl | ( | const ConstantRange & | Other | ) | const |
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 975 of file ConstantRange.cpp.
References ConstantRange(), llvm::APInt::countLeadingZeros(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::max(), and llvm::APInt::uge().
Referenced by binaryOp().
ConstantRange ConstantRange::signExtend | ( | uint32_t | BitWidth | ) | const |
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.
Definition at line 633 of file ConstantRange.cpp.
References assert(), ConstantRange(), getBitWidth(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), isEmptySet(), isFullSet(), llvm::APInt::isMinSignedValue(), isSignWrappedSet(), llvm::LegalizeActions::Lower, llvm::APInt::sext(), and llvm::APInt::zext().
Referenced by castOp(), GetRangeFromMetadata(), llvm::ScalarEvolution::getSignExtendExpr(), and sextOrTrunc().
ConstantRange ConstantRange::smax | ( | const ConstantRange & | Other | ) | const |
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 868 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getSignedMax(), getSignedMin(), isEmptySet(), and llvm::APIntOps::smax().
Referenced by GetRangeFromMetadata(), and isObjectDereferencedInBlock().
ConstantRange ConstantRange::smin | ( | const ConstantRange & | Other | ) | const |
Return a new range representing the possible values resulting from a signed minimum of a value in this range and a value in Other
.
Definition at line 894 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getSignedMax(), getSignedMin(), isEmptySet(), and llvm::APIntOps::smin().
Referenced by isObjectDereferencedInBlock().
ConstantRange ConstantRange::sub | ( | const ConstantRange & | 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 794 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getLower(), getUpper(), isEmptySet(), isFullSet(), isSizeStrictlySmallerThan(), and X.
Referenced by binaryOp().
ConstantRange ConstantRange::subtract | ( | const APInt & | CI | ) | const |
Subtract the specified constant from the endpoints of this constant range.
Definition at line 416 of file ConstantRange.cpp.
References assert(), ConstantRange(), getBitWidth(), llvm::APInt::getBitWidth(), and llvm::LegalizeActions::Lower.
Referenced by foldICmpShlOne(), GetConstantInt(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), and getValueFromICmpCondition().
ConstantRange ConstantRange::truncate | ( | uint32_t | BitWidth | ) | const |
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.
Definition at line 651 of file ConstantRange.cpp.
References assert(), llvm::APInt::clearBit(), ConstantRange(), llvm::APInt::countTrailingOnes(), llvm::APInt::getActiveBits(), llvm::APInt::getBitsSetFrom(), getBitWidth(), llvm::APInt::getMaxValue(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::LegalizeActions::Lower, llvm::APInt::setAllBits(), llvm::APInt::trunc(), llvm::APInt::ult(), and unionWith().
Referenced by castOp(), GetRangeFromMetadata(), llvm::ScalarEvolution::getSignExtendExpr(), llvm::ScalarEvolution::getZeroExtendExpr(), multiply(), sextOrTrunc(), and zextOrTrunc().
ConstantRange ConstantRange::udiv | ( | const ConstantRange & | Other | ) | const |
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 920 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getLower(), getUnsignedMax(), getUnsignedMin(), getUpper(), isEmptySet(), isFullSet(), llvm::APInt::isNullValue(), llvm::LegalizeActions::Lower, and llvm::APInt::udiv().
Referenced by binaryOp(), and GetRangeFromMetadata().
ConstantRange ConstantRange::umax | ( | const ConstantRange & | Other | ) | const |
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 881 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), and llvm::APIntOps::umax().
Referenced by binaryOr(), GetRangeFromMetadata(), and isObjectDereferencedInBlock().
ConstantRange ConstantRange::umin | ( | const ConstantRange & | Other | ) | const |
Return a new range representing the possible values resulting from an unsigned minimum of a value in this range and a value in Other
.
Definition at line 907 of file ConstantRange.cpp.
References ConstantRange(), getBitWidth(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), and llvm::APIntOps::umin().
Referenced by binaryAnd(), and isObjectDereferencedInBlock().
ConstantRange ConstantRange::unionWith | ( | const ConstantRange & | CR | ) | const |
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 502 of file ConstantRange.cpp.
References assert(), ConstantRange(), getBitWidth(), isEmptySet(), isFullSet(), llvm::APInt::isNullValue(), isWrappedSet(), llvm::LegalizeActions::Lower, llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ule(), llvm::APInt::ult(), and unionWith().
Referenced by getEdgeValueLocal(), getRangeForAffineARHelper(), GetRangeFromMetadata(), makeGuaranteedNoWrapRegion(), mapBinOpcode(), llvm::ValueLatticeElement::mergeIn(), processUDivOrURem(), truncate(), tryMergeRange(), and unionWith().
ConstantRange ConstantRange::zeroExtend | ( | uint32_t | BitWidth | ) | const |
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.
Definition at line 616 of file ConstantRange.cpp.
References assert(), ConstantRange(), getBitWidth(), llvm::APInt::getOneBitSet(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::LegalizeActions::Lower, and llvm::APInt::zext().
Referenced by castOp(), GetRangeFromMetadata(), llvm::ScalarEvolution::getZeroExtendExpr(), and zextOrTrunc().
ConstantRange ConstantRange::zextOrTrunc | ( | uint32_t | BitWidth | ) | const |
Make this range have the bit width given by BitWidth
.
The value is zero extended, truncated, or left alone to make it that width.
Definition at line 705 of file ConstantRange.cpp.
References getBitWidth(), truncate(), and zeroExtend().
Referenced by llvm::StackSafetyInfo::FunctionInfo::FunctionInfo(), and llvm::ScalarEvolution::getZeroExtendExpr().