llvm.org GIT mirror llvm / 97e04d1
LiveInterval.h: add LiveRange::findIndexesLiveAt function - return a list of SlotIndexes the LiveRange live at. Differential revision: https://reviews.llvm.org/D62411 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363593 91177308-0d34-0410-b5e6-96231b3b80d8 Valery Pykhtin a month ago
1 changed file(s) with 38 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
604604 /// activated in the constructor of the live range.
605605 void flushSegmentSet();
606606
607 /// Stores indexes from the input index sequence R at which this LiveRange
608 /// is live to the output O iterator.
609 /// R is a range of _ascending sorted_ _random_ access iterators
610 /// to the input indexes. Indexes stored at O are ascending sorted so it
611 /// can be used directly in the subsequent search (for example for
612 /// subranges). Returns true if found at least one index.
613 template
614 bool findIndexesLiveAt(Range &&R, OutputIt O) const {
615 assert(std::is_sorted(R.begin(), R.end()));
616 auto Idx = R.begin(), EndIdx = R.end();
617 auto Seg = segments.begin(), EndSeg = segments.end();
618 bool Found = false;
619 while (Idx != EndIdx && Seg != EndSeg) {
620 // if the Seg is lower find first segment that is above Idx using binary
621 // search
622 if (Seg->end <= *Idx) {
623 Seg = std::upper_bound(++Seg, EndSeg, *Idx,
624 [=](typename std::remove_reference::type V,
625 const typename std::remove_reference::type &S) {
626 return V < S.end;
627 });
628 if (Seg == EndSeg)
629 break;
630 }
631 auto NotLessStart = std::lower_bound(Idx, EndIdx, Seg->start);
632 if (NotLessStart == EndIdx)
633 break;
634 auto NotLessEnd = std::lower_bound(NotLessStart, EndIdx, Seg->end);
635 if (NotLessEnd != NotLessStart) {
636 Found = true;
637 O = std::copy(NotLessStart, NotLessEnd, O);
638 }
639 Idx = NotLessEnd;
640 ++Seg;
641 }
642 return Found;
643 }
644
607645 void print(raw_ostream &OS) const;
608646 void dump() const;
609647