[llvm] f1e2771 - [LiveInterval] Simplify with partition_point. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 19:25:31 PDT 2022


Author: Fangrui Song
Date: 2022-06-27T19:25:26-07:00
New Revision: f1e27716cf218d9923235f5f28e663a8da83ce89

URL: https://github.com/llvm/llvm-project/commit/f1e27716cf218d9923235f5f28e663a8da83ce89
DIFF: https://github.com/llvm/llvm-project/commit/f1e27716cf218d9923235f5f28e663a8da83ce89.diff

LOG: [LiveInterval] Simplify with partition_point. NFC

Added: 
    

Modified: 
    llvm/lib/CodeGen/LiveInterval.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LiveInterval.cpp b/llvm/lib/CodeGen/LiveInterval.cpp
index 9ded0fb6ae0a8..9378aaeb181c1 100644
--- a/llvm/lib/CodeGen/LiveInterval.cpp
+++ b/llvm/lib/CodeGen/LiveInterval.cpp
@@ -348,23 +348,8 @@ class CalcLiveRangeUtilSet : public CalcLiveRangeUtilSetBase {
 //===----------------------------------------------------------------------===//
 
 LiveRange::iterator LiveRange::find(SlotIndex Pos) {
-  // This algorithm is basically std::upper_bound.
-  // Unfortunately, std::upper_bound cannot be used with mixed types until we
-  // adopt C++0x. Many libraries can do it, but not all.
-  if (empty() || Pos >= endIndex())
-    return end();
-  iterator I = begin();
-  size_t Len = size();
-  do {
-    size_t Mid = Len >> 1;
-    if (Pos < I[Mid].end) {
-      Len = Mid;
-    } else {
-      I += Mid + 1;
-      Len -= Mid + 1;
-    }
-  } while (Len);
-  return I;
+  return llvm::partition_point(*this,
+                               [&](const Segment &X) { return X.end <= Pos; });
 }
 
 VNInfo *LiveRange::createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc) {


        


More information about the llvm-commits mailing list