Go to the documentation of this file.
9 #ifndef LLVM_ANALYSIS_VALUELATTICE_H
10 #define LLVM_ANALYSIS_VALUELATTICE_H
30 enum ValueLatticeElementTy {
74 constantrange_including_undef,
81 ValueLatticeElementTy Tag : 8;
83 unsigned NumRangeExtensions : 8;
102 case constantrange_including_undef:
104 Range.~ConstantRange();
153 : Tag(
Other.Tag), NumRangeExtensions(0) {
156 case constantrange_including_undef:
158 NumRangeExtensions =
Other.NumRangeExtensions;
172 : Tag(
Other.Tag), NumRangeExtensions(0) {
175 case constantrange_including_undef:
177 NumRangeExtensions =
Other.NumRangeExtensions;
205 if (isa<UndefValue>(
C))
213 assert(!isa<UndefValue>(
C) &&
"!= undef is not supported");
218 bool MayIncludeUndef =
false) {
246 return Tag == constantrange_including_undef;
253 return Tag == constantrange || (Tag == constantrange_including_undef &&
274 "Cannot get the constant-range of a non-constant-range!");
280 return cast<ConstantInt>(
getConstant())->getValue();
305 if (isa<UndefValue>(V))
325 assert(V &&
"Marking constant with NULL");
330 if (isa<UndefValue>(V))
357 ValueLatticeElementTy OldTag = Tag;
358 ValueLatticeElementTy NewTag =
360 ? constantrange_including_undef
365 return Tag != OldTag;
369 if (Opts.CheckWiden && ++NumRangeExtensions > Opts.MaxWidenSteps)
373 "Existing range must be a subset of NewR");
380 NumRangeExtensions = 0;
392 if (
RHS.isOverdefined()) {
401 if (
RHS.isConstant())
403 if (
RHS.isConstantRange())
405 Opts.setMayIncludeUndef());
410 assert(!
RHS.isUnknown() &&
"Unknow RHS should be handled earlier");
434 Tag = constantrange_including_undef;
435 return OldTag != Tag;
438 if (!
RHS.isConstantRange()) {
448 Opts.setMayIncludeUndef(
RHS.isConstantRangeIncludingUndef()));
478 const auto &OtherCR =
Other.getConstantRange();
479 if (CR.icmp(Pred, OtherCR))
491 static_assert(
sizeof(ValueLatticeElement) <= 40,
492 "size of ValueLatticeElement changed unexpectedly");
494 raw_ostream &
operator<<(raw_ostream &OS,
const ValueLatticeElement &Val);
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
static ValueLatticeElement getNot(Constant *C)
MergeOptions & setMaxWidenSteps(unsigned Steps=1)
const ConstantRange & getConstantRange(bool UndefAllowed=true) const
Returns the constant range for this value.
This is an optimization pass for GlobalISel generic memory operations.
unsigned MaxWidenSteps
The number of allowed widening steps (including setting the range initially).
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Constant * getConstant() const
Optional< APInt > asConstantInteger() const
Constant * getNotConstant() const
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isEquality() const
Return true if this predicate is either EQ or NE.
static ValueLatticeElement getOverdefined()
bool markNotConstant(Constant *V)
This is the shared class of boolean and integer constants.
Struct to control some aspects related to merging constant ranges.
bool isUnknownOrUndef() const
(vector float) vec_cmpeq(*A, *B) C
ValueLatticeElement & operator=(ValueLatticeElement &&Other)
bool isConstantRangeIncludingUndef() const
bool isSingleElement() const
Return true if this set contains exactly one member.
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
bool markConstantRange(ConstantRange NewR, MergeOptions Opts=MergeOptions())
Mark the object as constant range with NewR.
ValueLatticeElement(ValueLatticeElement &&Other)
bool markConstant(Constant *V, bool MayIncludeUndef=false)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
This is an important base class in LLVM.
ValueLatticeElement(const ValueLatticeElement &Other)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
bool MayIncludeUndef
The merge value may include undef.
ValueLatticeElement & operator=(const ValueLatticeElement &Other)
Constant * getCompare(CmpInst::Predicate Pred, Type *Ty, const ValueLatticeElement &Other) const
true, false or undef constants, or nullptr if the comparison cannot be evaluated.
unsigned getNumRangeExtensions() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
This class represents lattice values for constants.
bool isOverdefined() const
static ConstantInt * getFalse(LLVMContext &Context)
static ConstantInt * getTrue(LLVMContext &Context)
MergeOptions & setMayIncludeUndef(bool V=true)
MergeOptions(bool MayIncludeUndef, bool CheckWiden, unsigned MaxWidenSteps=1)
static ValueLatticeElement getRange(ConstantRange CR, bool MayIncludeUndef=false)
bool isNotConstant() const
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
bool CheckWiden
Handle repeatedly extending a range by going to overdefined after a number of steps.
This class represents a range of values.
bool mergeIn(const ValueLatticeElement &RHS, MergeOptions Opts=MergeOptions())
Updates this object to approximate both this object and RHS.
static ValueLatticeElement get(Constant *C)
bool isConstantRange(bool UndefAllowed=true) const
Returns true if this value is a constant range.
bool isEmptySet() const
Return true if this set contains no members.
MergeOptions & setCheckWiden(bool V=true)
void setNumRangeExtensions(unsigned N)
Optional< std::vector< StOtherPiece > > Other