9#ifndef LLVM_ANALYSIS_VALUELATTICE_H
10#define LLVM_ANALYSIS_VALUELATTICE_H
27 enum ValueLatticeElementTy {
71 constantrange_including_undef,
78 ValueLatticeElementTy Tag : 8;
80 unsigned NumRangeExtensions : 8;
99 case constantrange_including_undef:
101 Range.~ConstantRange();
150 : Tag(
Other.Tag), NumRangeExtensions(0) {
153 case constantrange_including_undef:
155 NumRangeExtensions =
Other.NumRangeExtensions;
169 : Tag(
Other.Tag), NumRangeExtensions(0) {
172 case constantrange_including_undef:
174 NumRangeExtensions =
Other.NumRangeExtensions;
207 assert(!isa<UndefValue>(
C) &&
"!= undef is not supported");
212 bool MayIncludeUndef =
false) {
240 return Tag == constantrange_including_undef;
247 return Tag == constantrange || (Tag == constantrange_including_undef &&
268 "Cannot get the constant-range of a non-constant-range!");
274 return cast<ConstantInt>(
getConstant())->getValue();
287 return ConstantRange::getEmpty(BW);
288 return ConstantRange::getFull(BW);
314 if (isa<UndefValue>(V))
334 assert(V &&
"Marking constant with NULL");
339 if (isa<UndefValue>(V))
366 ValueLatticeElementTy OldTag = Tag;
367 ValueLatticeElementTy NewTag =
369 ? constantrange_including_undef
374 return Tag != OldTag;
378 if (Opts.CheckWiden && ++NumRangeExtensions > Opts.MaxWidenSteps)
382 "Existing range must be a subset of NewR");
383 Range = std::move(NewR);
389 "Constant must be subset of new range");
391 NumRangeExtensions = 0;
403 if (
RHS.isOverdefined()) {
412 if (
RHS.isConstant())
414 if (
RHS.isConstantRange())
416 Opts.setMayIncludeUndef());
421 assert(!
RHS.isUnknown() &&
"Unknow RHS should be handled earlier");
436 RHS.asConstantRange(L.getBitWidth(),
true));
439 Opts.setMayIncludeUndef(
RHS.isConstantRangeIncludingUndef()));
455 Tag = constantrange_including_undef;
456 return OldTag != Tag;
461 RHS.asConstantRange(L.getBitWidth(),
true));
464 Opts.setMayIncludeUndef(
RHS.isConstantRangeIncludingUndef()));
495static_assert(
sizeof(ValueLatticeElement) <= 40,
496 "size of ValueLatticeElement changed unexpectedly");
498raw_ostream &
operator<<(raw_ostream &
OS,
const ValueLatticeElement &Val);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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 isSingleElement() const
Return true if this set contains exactly one member.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
This is an important base class in LLVM.
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.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
This class represents lattice values for constants.
bool markNotConstant(Constant *V)
static ValueLatticeElement getRange(ConstantRange CR, bool MayIncludeUndef=false)
bool isOverdefined() const
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
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.
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.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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).