21 #ifndef LLVM_CODEGEN_LIVEINTERVAL_H
22 #define LLVM_CODEGEN_LIVEINTERVAL_H
36 class MachineRegisterInfo;
37 class TargetRegisterInfo;
39 template <
typename T,
unsigned Small>
class SmallPtrSet;
95 : EarlyVal(EarlyVal), LateVal(LateVal), EndPoint(EndPoint), Kill(Kill)
132 return EarlyVal == LateVal ?
nullptr : LateVal;
168 assert(S < E &&
"Cannot create empty or backwards segment");
178 assert((S < E) &&
"Backwards interval?");
229 "Copying of LiveRanges with active SegmentSets is not supported");
250 while (I->end <= Pos) ++
I;
258 while (I->end <= Pos) ++
I;
361 assert(!
empty() &&
"Call to beginIndex() on empty range.");
368 assert(!
empty() &&
"Call to endIndex() on empty range.");
378 return r !=
end() && r->start <= index;
385 return I ==
end() ?
nullptr : &*
I;
392 return I ==
end() ?
nullptr : &*
I;
398 return I ==
end() ?
nullptr : I->valno;
406 return I ==
end() ?
nullptr : I->valno;
413 return I !=
end() && I->start <= Idx ? I :
end();
418 return I !=
end() && I->start <= Idx ? I :
end();
485 const int *ValNoAssignments,
486 const int *RHSValNoAssignments,
501 bool RemoveDeadValNo =
false);
526 VNInfo *EarlyVal =
nullptr;
527 VNInfo *LateVal =
nullptr;
577 return thisIndex < otherIndex;
586 return Begin <= Idx && Idx <
End;
610 void append(
const LiveRange::Segment S);
614 void addSegmentToSet(
Segment S);
615 void markValNoForDeletion(
VNInfo *V);
639 :
Next(nullptr), LaneMask(LaneMask) {
645 :
LiveRange(Other, Allocator),
Next(nullptr), LaneMask(LaneMask) {
660 : SubRanges(nullptr),
reg(Reg),
weight(Weight) {}
681 return P != Other.operator->();
684 return P == Other.operator->();
723 appendSubRange(Range);
733 appendSubRange(Range);
739 return SubRanges !=
nullptr;
773 return std::tie(thisIndex,
reg) < std::tie(otherIndex, other.
reg);
785 void verify(
const MachineRegisterInfo *
MRI =
nullptr)
const;
790 void appendSubRange(SubRange *Range) {
791 Range->Next = SubRanges;
796 void freeSubRange(SubRange *S);
810 raw_ostream &
operator<<(raw_ostream &OS,
const LiveRange::Segment &S);
void add(LiveRange::Segment)
Add a segment to LR and coalesce when possible, just like LR.addSegment().
void RenumberValues()
RenumberValues - Renumber all values in order of appearance and remove unused values.
void push_back(const T &Elt)
const_vni_iterator vni_end() const
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
void flush()
Flush the updater state to LR so it is valid and contains all added segments.
const_subrange_iterator subrange_begin() const
Segments::iterator iterator
VNInfo(unsigned i, SlotIndex d)
VNInfo constructor.
SlotIndex def
The index of the defining instruction.
bool contains(SlotIndex I) const
Return true if the index is covered by this segment.
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
void MergeValueInAsValue(const LiveRange &RHS, const VNInfo *RHSValNo, VNInfo *LHSValNo)
MergeValueInAsValue - Merge all of the segments of a specific val# in RHS into this live range as the...
Segment * getSegmentContaining(SlotIndex Idx)
Return the live segment that contains the specified index, or null if there is none.
SubRange(LaneBitmask LaneMask)
Constructs a new SubRange object.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool isSpillable() const
isSpillable - Can this interval be spilled?
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position...
bool isLocal(SlotIndex Start, SlotIndex End) const
True iff this segment is a single segment that lies between the specified boundaries, exclusively.
bool isLiveAtIndexes(ArrayRef< SlotIndex > Slots) const
LiveRangeUpdater(LiveRange *lr=nullptr)
Create a LiveRangeUpdater for adding segments to LR.
bool isKill() const
Return true if the live-in value is killed by this instruction.
LiveInterval(unsigned Reg, float Weight)
A live range for subregisters.
This represents a simple continuous liveness interval for a value.
bool containsInterval(SlotIndex S, SlotIndex E) const
Return true if the given interval, [S, E), is covered by this segment.
SlotIndex endPoint() const
Return the end point of the last live range segment to interact with the instruction, if any.
bool operator<(const LiveInterval &other) const
void markUnused()
Mark this value as unused.
SubRange * createSubRangeFrom(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, const LiveRange &CopyFrom)
Like createSubRange() but the new range is filled with a copy of the liveness information in CopyFrom...
VNInfo - Value Number Information.
unsigned getNumValNums() const
void flushSegmentSet()
Flush segment set into the regular segment vector.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void Distribute(LiveInterval &LI, LiveInterval *LIV[], MachineRegisterInfo &MRI)
Distribute values in LI into a separate LiveIntervals for each connected component.
This class represents the liveness of a register, stack slot, etc.
bool isDirty() const
Return true if the LR is currently in an invalid state, and flush() needs to be called.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
const_iterator FindSegmentContaining(SlotIndex Idx) const
bool operator<(const LiveRange &other) const
A Use represents the edge between a Value definition and its users.
A helper class for register coalescers.
iterator_range< subrange_iterator > subranges()
Result of a LiveRange query.
SingleLinkedListIterator< T > & operator++()
Reg
All possible values of the reg field in the ModR/M byte.
bool operator<(const Segment &Other) const
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
unsigned getSize() const
getSize - Returns the sum of sizes of all the LiveRange's.
LLVM_NODISCARD bool empty() const
void print(raw_ostream &OS) const
bool isUnused() const
Returns true if this value is unused.
void MergeSegmentsInAsValue(const LiveRange &RHS, VNInfo *LHSValNo)
Merge all of the live segments of a specific val# in RHS into this live range as the specified value ...
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
LiveQueryResult(VNInfo *EarlyVal, VNInfo *LateVal, SlotIndex EndPoint, bool Kill)
VNInfo * MergeValueNumberInto(VNInfo *V1, VNInfo *V2)
MergeValueNumberInto - This method is called when two value numbers are found to be equivalent...
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const float huge_valf
Use this rather than HUGE_VALF; the latter causes warnings on MSVC.
LiveRange(const LiveRange &Other, BumpPtrAllocator &Allocator)
Constructs a new LiveRange object by copying segments and valnos from another LiveRange.
iterator_range< const_subrange_iterator > subranges() const
bool expiredAt(SlotIndex index) const
VNInfoList::const_iterator const_vni_iterator
const VNInfo * getValNumInfo(unsigned ValNo) const
const_iterator advanceTo(const_iterator I, SlotIndex Pos) const
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void copyFrom(VNInfo &src)
Copy from the parameter into this VNInfo.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool isDeadDef() const
Return true if this instruction has a dead def.
void removeValNo(VNInfo *ValNo)
removeValNo - Remove all the segments defined by the specified value#.
SubRange(LaneBitmask LaneMask, const LiveRange &Other, BumpPtrAllocator &Allocator)
Constructs a new SubRange object by copying liveness from Other.
bool hasAtLeastOneValue() const
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
bool isValid() const
Returns true if this is a valid index.
SubRange * createSubRange(BumpPtrAllocator &Allocator, LaneBitmask LaneMask)
Creates a new empty subregister live range.
void removeSegment(Segment S, bool RemoveDeadValNo=false)
unsigned const MachineRegisterInfo * MRI
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Allocate memory in an ever growing pool, as if by bump-pointer.
std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Use)
Attempt to extend a value defined after StartIdx to include Use.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
LiveRange(bool UseSegmentSet=false)
Constructs a new LiveRange object.
void setDest(LiveRange *lr)
Select a different destination live range.
const_iterator begin() const
bool overlaps(const LiveRange &other) const
overlaps - Return true if the intersection of the two live ranges is not empty.
Greedy Register Allocator
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
void add(SlotIndex Start, SlotIndex End, VNInfo *VNI)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
void append(const LiveRange::Segment S)
Append a segment to the list of segments.
void verify() const
Walk the range and assert if any invariants fail to hold.
SmallVector< Segment, 2 > Segments
iterator removeSegment(iterator I)
Remove segment pointed to by iterator I from this range.
LiveRange * getDest() const
Get the current destination live range.
iterator erase(const_iterator CI)
bool liveAt(SlotIndex index) const
VNInfoList::iterator vni_iterator
VNInfo(unsigned i, const VNInfo &orig)
VNInfo constructor, copies values from orig, except for the value number.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
bool containsValue(const VNInfo *VNI) const
containsValue - Returns true if VNI belongs to this range.
bool operator==(const Segment &Other) const
iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
bool isUndefIn(ArrayRef< SlotIndex > Undefs, SlotIndex Begin, SlotIndex End) const
Returns true if there is an explicit "undef" between Begin End.
unsigned id
The ID number of this value.
void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified segment from this range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
ConnectedVNInfoEqClasses(LiveIntervals &lis)
const_vni_iterator vni_begin() const
Segments::const_iterator const_iterator
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
BumpPtrAllocator Allocator
SingleLinkedListIterator< SubRange > subrange_iterator
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
bool operator==(const SingleLinkedListIterator< T > &Other)
std::unique_ptr< SegmentSet > segmentSet
void markNotSpillable()
markNotSpillable - Mark interval as not spillable
SingleLinkedListIterator< const SubRange > const_subrange_iterator
SmallVector< VNInfo *, 2 > VNInfoList
void clearSubRanges()
Removes all subregister liveness information.
void print(raw_ostream &OS) const
A range adaptor for a pair of iterators.
bool isZeroLength(SlotIndexes *Indexes) const
Returns true if the live range is zero length, i.e.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
bool containsOneValue() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
void print(raw_ostream &OS) const
void print(raw_ostream &) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
createDeadDef - Make sure the range has a value defined at Def.
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
const_subrange_iterator subrange_end() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool operator!=(const SingleLinkedListIterator< T > &Other)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Helper class for performant LiveRange bulk updates.
std::set< Segment > SegmentSet
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
SingleLinkedListIterator< T > operator++(int)
Segment(SlotIndex S, SlotIndex E, VNInfo *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
subrange_iterator subrange_end()
void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
void join(LiveRange &Other, const int *ValNoAssignments, const int *RHSValNoAssignments, SmallVectorImpl< VNInfo * > &NewVNInfo)
join - Join two live ranges (this, and other) together.
iterator FindSegmentContaining(SlotIndex Idx)
Return an iterator to the segment that contains the specified index, or end() if there is none...
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
unsigned getEqClass(const VNInfo *VNI) const
getEqClass - Classify creates equivalence classes numbered 0..N.
const_iterator find(SlotIndex Pos) const
bool hasSubRanges() const
Returns true if subregister liveness information is available.
subrange_iterator subrange_begin()
SlotIndex - An opaque wrapper around machine indexes.
bool overlapsFrom(const LiveRange &Other, const_iterator I) const
overlapsFrom - Return true if the intersection of the two live ranges is not empty.
bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range...
const_iterator end() const
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
VNInfo * createValueCopy(const VNInfo *orig, VNInfo::Allocator &VNInfoAllocator)
Create a copy of the given value.