9#ifndef LLVM_ANALYSIS_VALUELATTICE_H
10#define LLVM_ANALYSIS_VALUELATTICE_H
28 enum ValueLatticeElementTy {
72 constantrange_including_undef,
79 ValueLatticeElementTy Tag : 8;
81 unsigned NumRangeExtensions : 8;
86 bool MayHaveDifferentProvenance =
false;
105 case constantrange_including_undef:
107 Range.~ConstantRange();
156 : Tag(
Other.Tag), NumRangeExtensions(0),
157 MayHaveDifferentProvenance(
Other.MayHaveDifferentProvenance) {
160 case constantrange_including_undef:
161 new (&Range) ConstantRange(Other.Range);
162 NumRangeExtensions = Other.NumRangeExtensions;
166 ConstVal = Other.ConstVal;
176 : Tag(
Other.Tag), NumRangeExtensions(0),
177 MayHaveDifferentProvenance(
Other.MayHaveDifferentProvenance) {
180 case constantrange_including_undef:
181 new (&Range) ConstantRange(std::move(Other.Range));
182 NumRangeExtensions = Other.NumRangeExtensions;
186 ConstVal = Other.ConstVal;
220 bool MayIncludeUndef =
false) {
248 return Tag == constantrange_including_undef;
255 return Tag == constantrange || (Tag == constantrange_including_undef &&
256 (UndefAllowed ||
Range.isSingleElement()));
276 "Cannot get the constant-range of a non-constant-range!");
295 return ConstantRange::getEmpty(BW);
296 return ConstantRange::getFull(BW);
300 assert(Ty->isIntOrIntVectorTy() &&
"Must be integer type");
342 assert(V &&
"Marking constant with NULL");
374 ValueLatticeElementTy OldTag = Tag;
375 ValueLatticeElementTy NewTag =
377 ? constantrange_including_undef
382 return Tag != OldTag;
386 if (Opts.CheckWiden && ++NumRangeExtensions > Opts.MaxWidenSteps)
390 "Existing range must be a subset of NewR");
391 Range = std::move(NewR);
397 "Constant must be subset of new range");
399 NumRangeExtensions = 0;
411 if (
RHS.isOverdefined()) {
420 if (
RHS.isConstant())
422 if (
RHS.isConstantRange())
424 Opts.setMayIncludeUndef());
429 assert(!
RHS.isUnknown() &&
"Unknow RHS should be handled earlier");
438 bool Current = MayHaveDifferentProvenance;
439 MayHaveDifferentProvenance |=
RHS.mayHaveDifferentProvenance();
440 return MayHaveDifferentProvenance != Current;
449 RHS.asConstantRange(L.getBitWidth(),
true));
452 Opts.setMayIncludeUndef(
RHS.isConstantRangeIncludingUndef()));
468 Tag = constantrange_including_undef;
469 return OldTag != Tag;
474 RHS.asConstantRange(L.getBitWidth(),
true));
477 Opts.setMayIncludeUndef(
RHS.isConstantRangeIncludingUndef()));
512static_assert(
sizeof(ValueLatticeElement) <= 40,
513 "size of ValueLatticeElement changed unexpectedly");
516 const ValueLatticeElement &Val);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static SymbolRef::Type getType(const Symbol *Sym)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
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 APInt &Val) const
Return true if the specified value is in the set.
This is an important base class in LLVM.
LLVM_ABI ConstantRange toConstantRange() const
Convert constant to an approximate constant range.
A parsed version of the target data layout string in and methods for querying it.
The instances of the Type class are immutable: once they are created, they are never changed.
This class represents lattice values for constants.
bool markNotConstant(Constant *V)
static ValueLatticeElement getRange(ConstantRange CR, bool MayIncludeUndef=false)
bool isOverdefined() const
void setMayHaveDifferentProvenance(bool V)
LLVM_ABI Constant * getCompare(CmpInst::Predicate Pred, Type *Ty, const ValueLatticeElement &Other, const DataLayout &DL) const
true, false or undef constants, or nullptr if the comparison cannot be evaluated.
bool isConstantRangeIncludingUndef() const
ValueLatticeElement(const ValueLatticeElement &Other)
static ValueLatticeElement getNot(Constant *C)
ConstantRange asConstantRange(unsigned BW, bool UndefAllowed=false) const
bool isNotConstant() const
std::optional< APInt > asConstantInteger() const
ValueLatticeElement & operator=(const ValueLatticeElement &Other)
ValueLatticeElement(ValueLatticeElement &&Other)
void setNumRangeExtensions(unsigned N)
const ConstantRange & getConstantRange(bool UndefAllowed=true) const
Returns the constant range for this value.
bool isConstantRange(bool UndefAllowed=true) const
Returns true if this value is a constant range.
static ValueLatticeElement get(Constant *C)
unsigned getNumRangeExtensions() const
Constant * getNotConstant() const
LLVM_ABI ValueLatticeElement intersect(const ValueLatticeElement &Other) const
Combine two sets of facts about the same value into a single set of facts.
bool isUnknownOrUndef() const
ConstantRange asConstantRange(Type *Ty, bool UndefAllowed=false) const
Constant * getConstant() const
bool mergeIn(const ValueLatticeElement &RHS, MergeOptions Opts=MergeOptions())
Updates this object to approximate both this object and RHS.
bool mayHaveDifferentProvenance() const
ValueLatticeElement & operator=(ValueLatticeElement &&Other)
bool markConstant(Constant *V, bool MayIncludeUndef=false)
static ValueLatticeElement getOverdefined()
bool markConstantRange(ConstantRange NewR, MergeOptions Opts=MergeOptions())
Mark the object as constant range with NewR.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Struct to control some aspects related to merging constant ranges.
bool MayIncludeUndef
The merge value may include undef.
MergeOptions & setMayIncludeUndef(bool V=true)
bool CheckWiden
Handle repeatedly extending a range by going to overdefined after a number of steps.
MergeOptions & setMaxWidenSteps(unsigned Steps=1)
MergeOptions & setCheckWiden(bool V=true)
MergeOptions(bool MayIncludeUndef, bool CheckWiden, unsigned MaxWidenSteps=1)
unsigned MaxWidenSteps
The number of allowed widening steps (including setting the range initially).