[PATCH] D62411: LiveIntervals: add LiveRange::findIndexesLiveAt function - return a list of SlotIndexes the LiveRange live at.

Valery Pykhtin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 09:02:13 PDT 2019


vpykhtin updated this revision to Diff 201537.
vpykhtin added a comment.

- replaced output std::vector with template output iterator, return bool on found
- added is_sorted assert
- improved description


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62411/new/

https://reviews.llvm.org/D62411

Files:
  include/llvm/CodeGen/LiveInterval.h


Index: include/llvm/CodeGen/LiveInterval.h
===================================================================
--- include/llvm/CodeGen/LiveInterval.h
+++ include/llvm/CodeGen/LiveInterval.h
@@ -605,6 +605,33 @@
     /// 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 <typename Range, typename OutputIt>
+    bool findIndexesLiveAt(Range &&R, OutputIt O) const {
+      assert(std::is_sorted(R.begin(), R.end()));
+      auto I = R.begin(), E = R.end();
+      bool Found = false;
+      for (auto &S : segments) {
+        auto Lower = std::lower_bound(I, E, S.start);
+        if (Lower == E)
+          break;
+        auto Upper = std::upper_bound(Lower, E, S.end);
+        if (Upper != Lower) {
+          O = std::copy(Lower, Upper, O);
+          Found = true;
+        }
+        if (Upper == E)
+          break;
+        I = Upper;
+      }
+      return Found;
+    }
+
     void print(raw_ostream &OS) const;
     void dump() const;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62411.201537.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190527/1bd851cd/attachment.bin>


More information about the llvm-commits mailing list