20 #ifndef LLVM_CODEGEN_LIVEINTERVAL_H 21 #define LLVM_CODEGEN_LIVEINTERVAL_H 45 class MachineRegisterInfo;
98 : EarlyVal(EarlyVal), LateVal(LateVal), EndPoint(EndPoint), Kill(Kill)
123 return isDeadDef() ? nullptr : LateVal;
135 return EarlyVal == LateVal ? nullptr : LateVal;
170 : start(S), end(E), valno(V) {
171 assert(S < E &&
"Cannot create empty or backwards segment");
176 return start <= I && I <
end;
181 assert((S < E) &&
"Backwards interval?");
182 return (start <= S && S < end) && (start < E && E <=
end);
186 return std::tie(start, end) < std::tie(Other.
start, Other.
end);
189 return start == Other.
start && end == Other.
end;
193 return !(*
this ==
Other);
238 "Copying of LiveRanges with active SegmentSets is not supported");
239 assign(Other, Allocator);
248 "Copying of LiveRanges with active SegmentSets is not supported");
251 createValueCopy(VNI, Allocator);
264 if (Pos >= endIndex())
266 while (I->end <= Pos) ++
I;
272 if (Pos >= endIndex())
274 while (I->end <= Pos) ++
I;
297 return segments.
size();
309 return valnos[ValNo];
312 return valnos[ValNo];
317 return VNI && VNI->
id < getNumValNums() && VNI == getValNumInfo(VNI->
id);
343 new (VNInfoAllocator)
VNInfo((
unsigned)valnos.
size(), *orig);
350 void RenumberValues();
370 void MergeValueInAsValue(
const LiveRange &RHS,
377 assert(!
empty() &&
"Call to beginIndex() on empty range.");
378 return segments.
front().start;
384 assert(!
empty() &&
"Call to endIndex() on empty range.");
385 return segments.
back().end;
389 return index >= endIndex();
394 return r !=
end() && r->start <= index;
401 return I ==
end() ? nullptr : &*
I;
408 return I ==
end() ? nullptr : &*
I;
414 return I ==
end() ? nullptr : I->valno;
422 return I ==
end() ? nullptr : I->valno;
429 return I !=
end() && I->start <= Idx ?
I :
end();
434 return I !=
end() && I->start <= Idx ?
I :
end();
442 return overlapsFrom(other, other.
begin());
466 bool covers(
const LiveRange &Other)
const;
501 const int *ValNoAssignments,
502 const int *RHSValNoAssignments,
517 bool RemoveDeadValNo =
false);
520 removeSegment(S.
start, S.
end, RemoveDeadValNo);
526 return segments.
erase(I);
542 VNInfo *EarlyVal =
nullptr;
543 VNInfo *LateVal =
nullptr;
573 void removeValNo(
VNInfo *ValNo);
578 for (
const Segment &S : segments)
591 const SlotIndex &thisIndex = beginIndex();
593 return thisIndex < otherIndex;
602 return Begin <= Idx && Idx < End;
610 void flushSegmentSet();
618 template <
typename Range,
typename OutputIt>
620 assert(std::is_sorted(R.begin(), R.end()));
621 auto Idx = R.begin(), EndIdx = R.end();
622 auto Seg = segments.
begin(), EndSeg = segments.
end();
624 while (Idx != EndIdx && Seg != EndSeg) {
627 if (Seg->end <= *Idx) {
629 [=](
typename std::remove_reference<decltype(*Idx)>::
type V,
630 const typename std::remove_reference<decltype(*Seg)>::
type &S) {
637 if (NotLessStart == EndIdx)
640 if (NotLessEnd != NotLessStart) {
642 O =
std::copy(NotLessStart, NotLessEnd, O);
668 void addSegmentToSet(
Segment S);
669 void markValNoForDeletion(
VNInfo *V);
697 :
LiveRange(Other, Allocator), LaneMask(LaneMask) {}
734 return P != Other.operator->();
737 return P == Other.operator->();
765 return make_range(subrange_begin(), subrange_end());
769 return make_range(subrange_begin(), subrange_end());
777 appendSubRange(Range);
787 appendSubRange(Range);
793 return SubRanges !=
nullptr;
797 void clearSubRanges();
801 void removeEmptySubRanges();
805 unsigned getSize()
const;
867 unsigned ComposeSubRegIdx = 0);
870 const SlotIndex &thisIndex = beginIndex();
872 return std::tie(thisIndex, reg) < std::tie(otherIndex, other.
reg);
889 void appendSubRange(
SubRange *Range) {
890 Range->
Next = SubRanges;
961 if (LR != lr && isDirty())
1016 #endif // LLVM_CODEGEN_LIVEINTERVAL_H std::set< Segment > SegmentSet
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
const_iterator end(StringRef path)
Get end iterator over path.
A common definition of LaneBitmask for use in TableGen and CodeGen.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
VNInfo(unsigned i, SlotIndex d)
VNInfo constructor.
typename SuperClass::const_iterator const_iterator
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex def
The index of the defining instruction.
This class represents lattice values for constants.
const_subrange_iterator subrange_begin() const
Segment * getSegmentContaining(SlotIndex Idx)
Return the live segment that contains the specified index, or null if there is none.
VNInfoList::iterator vni_iterator
Segments::iterator iterator
SubRange(LaneBitmask LaneMask)
Constructs a new SubRange object.
void push_back(const T &Elt)
bool isUndefIn(ArrayRef< SlotIndex > Undefs, SlotIndex Begin, SlotIndex End) const
Returns true if there is an explicit "undef" between Begin End.
LiveInterval - This class represents the liveness of a register, or stack slot.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position...
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
LiveRangeUpdater(LiveRange *lr=nullptr)
Create a LiveRangeUpdater for adding segments to LR.
bool isDeadDef() const
Return true if this instruction has a dead def.
LiveInterval(unsigned Reg, float Weight)
A live range for subregisters.
bool isValid() const
Returns true if this is a valid index.
This represents a simple continuous liveness interval for a value.
unsigned const TargetRegisterInfo * TRI
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 * valueOut() const
Return the value leaving the instruction, if any.
VNInfo - Value Number Information.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
const_iterator find(SlotIndex Pos) const
This class represents the liveness of a register, stack slot, etc.
bool isUnused() const
Returns true if this value is unused.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
bool findIndexesLiveAt(Range &&R, OutputIt O) const
Stores indexes from the input index sequence R at which this LiveRange is live to the output O iterat...
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
bool operator<(const Segment &Other) const
A helper class for register coalescers.
iterator_range< subrange_iterator > subranges()
Result of a LiveRange query.
const_iterator end() const
SingleLinkedListIterator< T > & operator++()
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
unsigned getEqClass(const VNInfo *VNI) const
getEqClass - Classify creates equivalence classes numbered 0..N.
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
bool contains(SlotIndex I) const
Return true if the index is covered by this segment.
const_iterator advanceTo(const_iterator I, SlotIndex Pos) const
LiveQueryResult(VNInfo *EarlyVal, VNInfo *LateVal, SlotIndex EndPoint, bool Kill)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool operator<(const LiveRange &other) const
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.
bool isKill() const
Return true if the live-in value is killed by this instruction.
bool isZeroLength(SlotIndexes *Indexes) const
Returns true if the live range is zero length, i.e.
void print(raw_ostream &OS) const
void copyFrom(VNInfo &src)
Copy from the parameter into this VNInfo.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
bool containsOneValue() const
iterator_range< const_subrange_iterator > subranges() const
BumpPtrAllocator Allocator
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
SubRange(LaneBitmask LaneMask, const LiveRange &Other, BumpPtrAllocator &Allocator)
Constructs a new SubRange object by copying liveness from Other.
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
SubRange * createSubRange(BumpPtrAllocator &Allocator, LaneBitmask LaneMask)
Creates a new empty subregister live range.
void removeSegment(Segment S, bool RemoveDeadValNo=false)
unsigned const MachineRegisterInfo * MRI
VNInfoList::const_iterator const_vni_iterator
bool expiredAt(SlotIndex index) const
void print(raw_ostream &OS) const
Allocate memory in an ever growing pool, as if by bump-pointer.
bool liveAt(SlotIndex index) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LiveRange(bool UseSegmentSet=false)
Constructs a new LiveRange object.
bool containsValue(const VNInfo *VNI) const
containsValue - Returns true if VNI belongs to this range.
void setDest(LiveRange *lr)
Select a different destination live range.
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)
bool operator<(const LiveInterval &other) const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
iterator removeSegment(iterator I)
Remove segment pointed to by iterator I from this range.
iterator erase(const_iterator CI)
void print(raw_ostream &) const
const_vni_iterator vni_begin() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
VNInfo(unsigned i, const VNInfo &orig)
VNInfo constructor, copies values from orig, except for the value number.
SlotIndex endPoint() const
Return the end point of the last live range segment to interact with the instruction, if any.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
const_iterator FindSegmentContaining(SlotIndex Idx) const
unsigned id
The ID number of this value.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
ConnectedVNInfoEqClasses(LiveIntervals &lis)
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Segments::const_iterator const_iterator
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
bool isDirty() const
Return true if the LR is currently in an invalid state, and flush() needs to be called.
const_iterator begin() const
bool operator==(const SingleLinkedListIterator< T > &Other)
std::unique_ptr< SegmentSet > segmentSet
void markNotSpillable()
markNotSpillable - Mark interval as not spillable
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
A range adaptor for a pair of iterators.
bool hasAtLeastOneValue() const
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
LiveRange * getDest() const
Get the current destination live range.
typename SuperClass::iterator iterator
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool operator==(const Segment &Other) const
unsigned getNumValNums() const
bool overlaps(const LiveRange &other) const
overlaps - Return true if the intersection of the two live ranges is not empty.
void assign(const LiveRange &Other, BumpPtrAllocator &Allocator)
Copies values numbers and live segments from Other into this range.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
LLVM_NODISCARD bool empty() const
static void createDeadDef(SlotIndexes &Indexes, VNInfo::Allocator &Alloc, LiveRange &LR, const MachineOperand &MO)
bool operator!=(const Segment &Other) const
bool operator!=(const SingleLinkedListIterator< T > &Other)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
Helper class for performant LiveRange bulk updates.
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)
bool isSpillable() const
isSpillable - Can this interval be spilled?
const VNInfo * getValNumInfo(unsigned ValNo) const
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
bool isLocal(SlotIndex Start, SlotIndex End) const
True iff this segment is a single segment that lies between the specified boundaries, exclusively.
const_subrange_iterator subrange_end() const
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()
print Print MemDeps of function
iterator FindSegmentContaining(SlotIndex Idx)
Return an iterator to the segment that contains the specified index, or end() if there is none...
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
subrange_iterator subrange_begin()
OutputIt copy(R &&Range, OutputIt Out)
void print(raw_ostream &OS) const
const_vni_iterator vni_end() const
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
VNInfo * createValueCopy(const VNInfo *orig, VNInfo::Allocator &VNInfoAllocator)
Create a copy of the given value.
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
bool containsInterval(SlotIndex S, SlotIndex E) const
Return true if the given interval, [S, E), is covered by this segment.