]> granicus.if.org Git - llvm/commitdiff
SlotIndexes: simplify IdxMBBPair operators
authorFangrui Song <maskray@google.com>
Sun, 23 Jun 2019 13:16:03 +0000 (13:16 +0000)
committerFangrui Song <maskray@google.com>
Sun, 23 Jun 2019 13:16:03 +0000 (13:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364152 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SlotIndexes.h
lib/CodeGen/SlotIndexes.cpp

index 63461d61bf3485532a53d095270f1f6206da9e1e..76d5ff34d84465476b419722a501af1530e2ca19 100644 (file)
@@ -308,20 +308,6 @@ class raw_ostream;
 
   using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
 
-  inline bool operator<(SlotIndex V, const IdxMBBPair &IM) {
-    return V < IM.first;
-  }
-
-  inline bool operator<(const IdxMBBPair &IM, SlotIndex V) {
-    return IM.first < V;
-  }
-
-  struct Idx2MBBCompare {
-    bool operator()(const IdxMBBPair &LHS, const IdxMBBPair &RHS) const {
-      return LHS.first < RHS.first;
-    }
-  };
-
   /// SlotIndexes pass.
   ///
   /// This pass assigns indexes to each instruction.
@@ -513,7 +499,8 @@ class raw_ostream;
     /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
     /// equal to \p To.
     MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const {
-      return std::lower_bound(I, idx2MBBMap.end(), To);
+      return llvm::bsearch(I, idx2MBBMap.end(),
+                           [=](const IdxMBBPair &IM) { return To <= IM.first; });
     }
 
     /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
@@ -677,7 +664,7 @@ class raw_ostream;
       idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));
 
       renumberIndexes(newItr);
-      llvm::sort(idx2MBBMap, Idx2MBBCompare());
+      llvm::sort(idx2MBBMap, less_first());
     }
 
     /// Free the resources that were required to maintain a SlotIndex.
index a55e74c4c063cc944a495f6a2ee36db957a6840d..ce00fa9a1361427c741fe8214325bb1306365fc2 100644 (file)
@@ -94,7 +94,7 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
   }
 
   // Sort the Idx2MBBMap
-  llvm::sort(idx2MBBMap, Idx2MBBCompare());
+  llvm::sort(idx2MBBMap, less_first());
 
   LLVM_DEBUG(mf->print(dbgs(), this));