From: Valery Pykhtin Date: Mon, 17 Jun 2019 18:23:39 +0000 (+0000) Subject: LiveInterval.h: add LiveRange::findIndexesLiveAt function - return a list of SlotInde... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97e04d1cf3037b97457707f05203c27d71fcb93c;p=llvm 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 --- diff --git a/include/llvm/CodeGen/LiveInterval.h b/include/llvm/CodeGen/LiveInterval.h index 2cead89c1f1..8bb88165d3e 100644 --- a/include/llvm/CodeGen/LiveInterval.h +++ b/include/llvm/CodeGen/LiveInterval.h @@ -605,6 +605,44 @@ namespace llvm { /// activated in the constructor of the live range. void flushSegmentSet(); + /// Stores indexes from the input index sequence R at which this LiveRange + /// is live to the output O iterator. + /// R is a range of _ascending sorted_ _random_ access iterators + /// to the input indexes. Indexes stored at O are ascending sorted so it + /// can be used directly in the subsequent search (for example for + /// subranges). Returns true if found at least one index. + template + bool findIndexesLiveAt(Range &&R, OutputIt O) const { + assert(std::is_sorted(R.begin(), R.end())); + auto Idx = R.begin(), EndIdx = R.end(); + auto Seg = segments.begin(), EndSeg = segments.end(); + bool Found = false; + while (Idx != EndIdx && Seg != EndSeg) { + // if the Seg is lower find first segment that is above Idx using binary + // search + if (Seg->end <= *Idx) { + Seg = std::upper_bound(++Seg, EndSeg, *Idx, + [=](typename std::remove_reference::type V, + const typename std::remove_reference::type &S) { + return V < S.end; + }); + if (Seg == EndSeg) + break; + } + auto NotLessStart = std::lower_bound(Idx, EndIdx, Seg->start); + if (NotLessStart == EndIdx) + break; + auto NotLessEnd = std::lower_bound(NotLessStart, EndIdx, Seg->end); + if (NotLessEnd != NotLessStart) { + Found = true; + O = std::copy(NotLessStart, NotLessEnd, O); + } + Idx = NotLessEnd; + ++Seg; + } + return Found; + } + void print(raw_ostream &OS) const; void dump() const;