From 32e092ad46bb527debb97a6b5bc683bd543b88a7 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 21 Jun 2019 05:40:31 +0000 Subject: [PATCH] Simplify std::lower_bound with llvm::{bsearch,lower_bound}. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364006 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ProfileSummaryInfo.cpp | 7 +++---- lib/CodeGen/LiveIntervals.cpp | 6 ++---- lib/CodeGen/MachinePipeliner.cpp | 15 ++++++--------- lib/DebugInfo/DWARF/DWARFDebugFrame.cpp | 7 +++---- lib/IR/DataLayout.cpp | 9 +++------ lib/IR/Function.cpp | 6 +++--- lib/MC/MCSubtargetInfo.cpp | 2 +- lib/ProfileData/InstrProf.cpp | 6 +++--- lib/Support/SourceMgr.cpp | 11 +++-------- lib/Target/ARM/ARMConstantIslandPass.cpp | 8 ++------ lib/Target/ARM/ARMExpandPseudoInsts.cpp | 3 +-- lib/Target/Hexagon/HexagonGenInsert.cpp | 4 ++-- lib/Target/Mips/Mips16ISelLowering.cpp | 3 +-- lib/Target/Mips/MipsConstantIslandPass.cpp | 8 ++------ lib/Target/X86/X86EvexToVex.cpp | 2 +- lib/Target/X86/X86FloatingPoint.cpp | 2 +- lib/Target/X86/X86ISelLowering.cpp | 6 ++---- lib/Target/X86/X86InstrFMA3Info.cpp | 8 +++----- lib/Target/X86/X86InstrFoldTables.cpp | 6 ++---- lib/TextAPI/MachO/InterfaceFile.cpp | 17 ++++++++--------- lib/Transforms/Coroutines/CoroFrame.cpp | 2 +- lib/Transforms/Scalar/JumpThreading.cpp | 3 +-- lib/Transforms/Scalar/MemCpyOptimizer.cpp | 4 ++-- lib/Transforms/Scalar/Reassociate.cpp | 2 +- tools/dsymutil/DwarfLinker.cpp | 12 +++++------- tools/llvm-xray/xray-stacks.cpp | 6 ++---- 26 files changed, 64 insertions(+), 101 deletions(-) diff --git a/lib/Analysis/ProfileSummaryInfo.cpp b/lib/Analysis/ProfileSummaryInfo.cpp index 682f15d054d..52e015b5bb3 100644 --- a/lib/Analysis/ProfileSummaryInfo.cpp +++ b/lib/Analysis/ProfileSummaryInfo.cpp @@ -60,10 +60,9 @@ static cl::opt ProfileSummaryColdCount( // Find the summary entry for a desired percentile of counts. static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS, uint64_t Percentile) { - auto Compare = [](const ProfileSummaryEntry &Entry, uint64_t Percentile) { - return Entry.Cutoff < Percentile; - }; - auto It = std::lower_bound(DS.begin(), DS.end(), Percentile, Compare); + auto It = llvm::bsearch(DS, [=](const ProfileSummaryEntry &Entry) { + return Percentile <= Entry.Cutoff; + }); // The required percentile has to be <= one of the percentiles in the // detailed summary. if (It == DS.end()) diff --git a/lib/CodeGen/LiveIntervals.cpp b/lib/CodeGen/LiveIntervals.cpp index 8706bdb09fc..aa85569063b 100644 --- a/lib/CodeGen/LiveIntervals.cpp +++ b/lib/CodeGen/LiveIntervals.cpp @@ -900,8 +900,7 @@ bool LiveIntervals::checkRegMaskInterference(LiveInterval &LI, // We are going to enumerate all the register mask slots contained in LI. // Start with a binary search of RegMaskSlots to find a starting point. - ArrayRef::iterator SlotI = - std::lower_bound(Slots.begin(), Slots.end(), LiveI->start); + ArrayRef::iterator SlotI = llvm::lower_bound(Slots, LiveI->start); ArrayRef::iterator SlotE = Slots.end(); // No slots in range, LI begins after the last call. @@ -1370,8 +1369,7 @@ private: void updateRegMaskSlots() { SmallVectorImpl::iterator RI = - std::lower_bound(LIS.RegMaskSlots.begin(), LIS.RegMaskSlots.end(), - OldIdx); + llvm::lower_bound(LIS.RegMaskSlots, OldIdx); assert(RI != LIS.RegMaskSlots.end() && *RI == OldIdx.getRegSlot() && "No RegMask at OldIdx."); *RI = NewIdx.getRegSlot(); diff --git a/lib/CodeGen/MachinePipeliner.cpp b/lib/CodeGen/MachinePipeliner.cpp index 87ece444fec..570ed4aadab 100644 --- a/lib/CodeGen/MachinePipeliner.cpp +++ b/lib/CodeGen/MachinePipeliner.cpp @@ -3726,9 +3726,8 @@ void SwingSchedulerDAG::checkValidNodeOrder(const NodeSetType &Circuits) const { for (SDep &PredEdge : SU->Preds) { SUnit *PredSU = PredEdge.getSUnit(); - unsigned PredIndex = - std::get<1>(*std::lower_bound(Indices.begin(), Indices.end(), - std::make_pair(PredSU, 0), CompareKey)); + unsigned PredIndex = std::get<1>( + *llvm::lower_bound(Indices, std::make_pair(PredSU, 0), CompareKey)); if (!PredSU->getInstr()->isPHI() && PredIndex < Index) { PredBefore = true; Pred = PredSU; @@ -3743,9 +3742,8 @@ void SwingSchedulerDAG::checkValidNodeOrder(const NodeSetType &Circuits) const { // return Indices.end(). if (SuccSU->isBoundaryNode()) continue; - unsigned SuccIndex = - std::get<1>(*std::lower_bound(Indices.begin(), Indices.end(), - std::make_pair(SuccSU, 0), CompareKey)); + unsigned SuccIndex = std::get<1>( + *llvm::lower_bound(Indices, std::make_pair(SuccSU, 0), CompareKey)); if (!SuccSU->getInstr()->isPHI() && SuccIndex < Index) { SuccBefore = true; Succ = SuccSU; @@ -3756,9 +3754,8 @@ void SwingSchedulerDAG::checkValidNodeOrder(const NodeSetType &Circuits) const { if (PredBefore && SuccBefore && !SU->getInstr()->isPHI()) { // instructions in circuits are allowed to be scheduled // after both a successor and predecessor. - bool InCircuit = std::any_of( - Circuits.begin(), Circuits.end(), - [SU](const NodeSet &Circuit) { return Circuit.count(SU); }); + bool InCircuit = llvm::any_of( + Circuits, [SU](const NodeSet &Circuit) { return Circuit.count(SU); }); if (InCircuit) LLVM_DEBUG(dbgs() << "In a circuit, predecessor ";); else { diff --git a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp index bf256d1a427..65a6b57ddb5 100644 --- a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp @@ -532,10 +532,9 @@ void DWARFDebugFrame::parse(DWARFDataExtractor Data) { } FrameEntry *DWARFDebugFrame::getEntryAtOffset(uint64_t Offset) const { - auto It = - std::lower_bound(Entries.begin(), Entries.end(), Offset, - [](const std::unique_ptr &E, - uint64_t Offset) { return E->getOffset() < Offset; }); + auto It = llvm::bsearch(Entries, [=](const std::unique_ptr &E) { + return Offset <= E->getOffset(); + }); if (It != Entries.end() && (*It)->getOffset() == Offset) return It->get(); return nullptr; diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index 943f5381c64..b8c130a54e9 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -463,12 +463,9 @@ DataLayout::AlignmentsTy::iterator DataLayout::findAlignmentLowerBound(AlignTypeEnum AlignType, uint32_t BitWidth) { auto Pair = std::make_pair((unsigned)AlignType, BitWidth); - return std::lower_bound(Alignments.begin(), Alignments.end(), Pair, - [](const LayoutAlignElem &LHS, - const std::pair &RHS) { - return std::tie(LHS.AlignType, LHS.TypeBitWidth) < - std::tie(RHS.first, RHS.second); - }); + return llvm::bsearch(Alignments, [=](const LayoutAlignElem &E) { + return Pair <= std::make_pair(E.AlignType, E.TypeBitWidth); + }); } void diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index 770524feace..6a276b18023 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -533,9 +533,9 @@ static ArrayRef findTargetSubtable(StringRef Name) { // Drop "llvm." and take the first dotted component. That will be the target // if this is target specific. StringRef Target = Name.drop_front(5).split('.').first; - auto It = std::lower_bound(Targets.begin(), Targets.end(), Target, - [](const IntrinsicTargetInfo &TI, - StringRef Target) { return TI.Name < Target; }); + auto It = llvm::bsearch(Targets, [=](const IntrinsicTargetInfo &TI) { + return Target <= TI.Name; + }); // We've either found the target or just fall back to the generic set, which // is always first. const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0]; diff --git a/lib/MC/MCSubtargetInfo.cpp b/lib/MC/MCSubtargetInfo.cpp index 9b0272cab0b..5fd48d9e101 100644 --- a/lib/MC/MCSubtargetInfo.cpp +++ b/lib/MC/MCSubtargetInfo.cpp @@ -24,7 +24,7 @@ using namespace llvm; template static const T *Find(StringRef S, ArrayRef A) { // Binary search the array - auto F = std::lower_bound(A.begin(), A.end(), S); + auto F = llvm::lower_bound(A, S); // If not found then return NULL if (F == A.end() || StringRef(F->Key) != S) return nullptr; // Return the found array item diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 582049eabfb..c0b067a490e 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -364,9 +364,9 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) { uint64_t InstrProfSymtab::getFunctionHashFromAddress(uint64_t Address) { finalizeSymtab(); auto Result = - std::lower_bound(AddrToMD5Map.begin(), AddrToMD5Map.end(), Address, - [](const std::pair &LHS, - uint64_t RHS) { return LHS.first < RHS; }); + llvm::bsearch(AddrToMD5Map, [=](std::pair A) { + return Address <= A.first; + }); // Raw function pointer collected by value profiler may be from // external functions that are not instrumented. They won't have // mapping data to be used by the deserializer. Force the value to diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index 401f6aec4ca..2a241f18c36 100644 --- a/lib/Support/SourceMgr.cpp +++ b/lib/Support/SourceMgr.cpp @@ -95,14 +95,9 @@ unsigned SourceMgr::SrcBuffer::getLineNumber(const char *Ptr) const { assert(PtrDiff >= 0 && static_cast(PtrDiff) <= std::numeric_limits::max()); T PtrOffset = static_cast(PtrDiff); - // std::lower_bound returns the first EOL offset that's not-less-than - // PtrOffset, meaning the EOL that _ends the line_ that PtrOffset is on - // (including if PtrOffset refers to the EOL itself). If there's no such - // EOL, returns end(). - auto EOL = std::lower_bound(Offsets->begin(), Offsets->end(), PtrOffset); - - // Lines count from 1, so add 1 to the distance from the 0th line. - return (1 + (EOL - Offsets->begin())); + // llvm::lower_bound gives the number of EOL before PtrOffset. Add 1 to get + // the line number. + return llvm::lower_bound(*Offsets, PtrOffset) - Offsets->begin() + 1; } SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other) diff --git a/lib/Target/ARM/ARMConstantIslandPass.cpp b/lib/Target/ARM/ARMConstantIslandPass.cpp index 20154bacbd3..60e5d7bf609 100644 --- a/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -875,9 +875,7 @@ void ARMConstantIslands::updateForInsertedWaterBlock(MachineBasicBlock *NewBB) { // Next, update WaterList. Specifically, we need to add NewMBB as having // available water after it. - water_iterator IP = - std::lower_bound(WaterList.begin(), WaterList.end(), NewBB, - CompareMBBNumbers); + water_iterator IP = llvm::lower_bound(WaterList, NewBB, CompareMBBNumbers); WaterList.insert(IP, NewBB); } @@ -928,9 +926,7 @@ MachineBasicBlock *ARMConstantIslands::splitBlockBeforeInstr(MachineInstr *MI) { // available water after it (but not if it's already there, which happens // when splitting before a conditional branch that is followed by an // unconditional branch - in that case we want to insert NewBB). - water_iterator IP = - std::lower_bound(WaterList.begin(), WaterList.end(), OrigBB, - CompareMBBNumbers); + water_iterator IP = llvm::lower_bound(WaterList, OrigBB, CompareMBBNumbers); MachineBasicBlock* WaterBB = *IP; if (WaterBB == OrigBB) WaterList.insert(std::next(IP), NewBB); diff --git a/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/lib/Target/ARM/ARMExpandPseudoInsts.cpp index a27f7f157de..b32ba3eeea1 100644 --- a/lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ b/lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -423,8 +423,7 @@ static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) { } #endif - auto I = std::lower_bound(std::begin(NEONLdStTable), - std::end(NEONLdStTable), Opcode); + auto I = llvm::lower_bound(NEONLdStTable, Opcode); if (I != std::end(NEONLdStTable) && I->PseudoOpc == Opcode) return I; return nullptr; diff --git a/lib/Target/Hexagon/HexagonGenInsert.cpp b/lib/Target/Hexagon/HexagonGenInsert.cpp index 725cfe04df3..81025c1c532 100644 --- a/lib/Target/Hexagon/HexagonGenInsert.cpp +++ b/lib/Target/Hexagon/HexagonGenInsert.cpp @@ -436,7 +436,7 @@ namespace { } // end anonymous namespace void OrderedRegisterList::insert(unsigned VR) { - iterator L = std::lower_bound(Seq.begin(), Seq.end(), VR, Ord); + iterator L = llvm::lower_bound(Seq, VR, Ord); if (L == Seq.end()) Seq.push_back(VR); else @@ -449,7 +449,7 @@ void OrderedRegisterList::insert(unsigned VR) { } void OrderedRegisterList::remove(unsigned VR) { - iterator L = std::lower_bound(Seq.begin(), Seq.end(), VR, Ord); + iterator L = llvm::lower_bound(Seq, VR, Ord); if (L != Seq.end()) Seq.erase(L); } diff --git a/lib/Target/Mips/Mips16ISelLowering.cpp b/lib/Target/Mips/Mips16ISelLowering.cpp index 45162efb512..6d8e5aef2a3 100644 --- a/lib/Target/Mips/Mips16ISelLowering.cpp +++ b/lib/Target/Mips/Mips16ISelLowering.cpp @@ -459,8 +459,7 @@ getOpndList(SmallVectorImpl &Ops, } // one more look at list of intrinsics const Mips16IntrinsicHelperType *Helper = - std::lower_bound(std::begin(Mips16IntrinsicHelper), - std::end(Mips16IntrinsicHelper), IntrinsicFind); + llvm::lower_bound(Mips16IntrinsicHelper, IntrinsicFind); if (Helper != std::end(Mips16IntrinsicHelper) && *Helper == IntrinsicFind) { Mips16HelperFunction = Helper->Helper; diff --git a/lib/Target/Mips/MipsConstantIslandPass.cpp b/lib/Target/Mips/MipsConstantIslandPass.cpp index c10d9c38f50..eea28df7eda 100644 --- a/lib/Target/Mips/MipsConstantIslandPass.cpp +++ b/lib/Target/Mips/MipsConstantIslandPass.cpp @@ -841,9 +841,7 @@ void MipsConstantIslands::updateForInsertedWaterBlock // Next, update WaterList. Specifically, we need to add NewMBB as having // available water after it. - water_iterator IP = - std::lower_bound(WaterList.begin(), WaterList.end(), NewBB, - CompareMBBNumbers); + water_iterator IP = llvm::lower_bound(WaterList, NewBB, CompareMBBNumbers); WaterList.insert(IP, NewBB); } @@ -893,9 +891,7 @@ MipsConstantIslands::splitBlockBeforeInstr(MachineInstr &MI) { // available water after it (but not if it's already there, which happens // when splitting before a conditional branch that is followed by an // unconditional branch - in that case we want to insert NewBB). - water_iterator IP = - std::lower_bound(WaterList.begin(), WaterList.end(), OrigBB, - CompareMBBNumbers); + water_iterator IP = llvm::lower_bound(WaterList, OrigBB, CompareMBBNumbers); MachineBasicBlock* WaterBB = *IP; if (WaterBB == OrigBB) WaterList.insert(std::next(IP), NewBB); diff --git a/lib/Target/X86/X86EvexToVex.cpp b/lib/Target/X86/X86EvexToVex.cpp index 21ae1f1896b..58680f1815b 100644 --- a/lib/Target/X86/X86EvexToVex.cpp +++ b/lib/Target/X86/X86EvexToVex.cpp @@ -252,7 +252,7 @@ bool EvexToVexInstPass::CompressEvexToVexImpl(MachineInstr &MI) const { (Desc.TSFlags & X86II::VEX_L) ? makeArrayRef(X86EvexToVex256CompressTable) : makeArrayRef(X86EvexToVex128CompressTable); - auto I = std::lower_bound(Table.begin(), Table.end(), MI.getOpcode()); + auto I = llvm::lower_bound(Table, MI.getOpcode()); if (I == Table.end() || I->EvexOpcode != MI.getOpcode()) return false; diff --git a/lib/Target/X86/X86FloatingPoint.cpp b/lib/Target/X86/X86FloatingPoint.cpp index f82ad190fc8..074cf21d03f 100644 --- a/lib/Target/X86/X86FloatingPoint.cpp +++ b/lib/Target/X86/X86FloatingPoint.cpp @@ -596,7 +596,7 @@ namespace { } static int Lookup(ArrayRef Table, unsigned Opcode) { - const TableEntry *I = std::lower_bound(Table.begin(), Table.end(), Opcode); + const TableEntry *I = llvm::lower_bound(Table, Opcode); if (I != Table.end() && I->from == Opcode) return I->to; return -1; diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index a4d06f068bb..301bd5724f1 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -13099,11 +13099,9 @@ static SDValue lowerV8I16GeneralSingleInputShuffle( copy_if(HiMask, std::back_inserter(HiInputs), [](int M) { return M >= 0; }); array_pod_sort(HiInputs.begin(), HiInputs.end()); HiInputs.erase(std::unique(HiInputs.begin(), HiInputs.end()), HiInputs.end()); - int NumLToL = - std::lower_bound(LoInputs.begin(), LoInputs.end(), 4) - LoInputs.begin(); + int NumLToL = llvm::lower_bound(LoInputs, 4) - LoInputs.begin(); int NumHToL = LoInputs.size() - NumLToL; - int NumLToH = - std::lower_bound(HiInputs.begin(), HiInputs.end(), 4) - HiInputs.begin(); + int NumLToH = llvm::lower_bound(HiInputs, 4) - HiInputs.begin(); int NumHToH = HiInputs.size() - NumLToH; MutableArrayRef LToLInputs(LoInputs.data(), NumLToL); MutableArrayRef LToHInputs(HiInputs.data(), NumLToH); diff --git a/lib/Target/X86/X86InstrFMA3Info.cpp b/lib/Target/X86/X86InstrFMA3Info.cpp index f917b06a52e..77dc75386fc 100644 --- a/lib/Target/X86/X86InstrFMA3Info.cpp +++ b/lib/Target/X86/X86InstrFMA3Info.cpp @@ -158,11 +158,9 @@ const X86InstrFMA3Group *llvm::getFMA3Group(unsigned Opcode, uint64_t TSFlags) { // FMA 231 instructions have an opcode of 0xB6-0xBF unsigned FormIndex = ((BaseOpcode - 0x90) >> 4) & 0x3; - auto I = std::lower_bound(Table.begin(), Table.end(), Opcode, - [FormIndex](const X86InstrFMA3Group &Group, - unsigned Opcode) { - return Group.Opcodes[FormIndex] < Opcode; - }); + auto I = llvm::bsearch(Table, [=](const X86InstrFMA3Group &Group) { + return Opcode <= Group.Opcodes[FormIndex]; + }); assert(I != Table.end() && I->Opcodes[FormIndex] == Opcode && "Couldn't find FMA3 opcode!"); return I; diff --git a/lib/Target/X86/X86InstrFoldTables.cpp b/lib/Target/X86/X86InstrFoldTables.cpp index 4b24dd1058e..b1eb6396bc5 100644 --- a/lib/Target/X86/X86InstrFoldTables.cpp +++ b/lib/Target/X86/X86InstrFoldTables.cpp @@ -5288,9 +5288,7 @@ lookupFoldTableImpl(ArrayRef Table, unsigned RegOp) { } #endif - const X86MemoryFoldTableEntry *Data = std::lower_bound(Table.begin(), - Table.end(), - RegOp); + const X86MemoryFoldTableEntry *Data = llvm::lower_bound(Table, RegOp); if (Data != Table.end() && Data->KeyOp == RegOp && !(Data->Flags & TB_NO_FORWARD)) return Data; @@ -5377,7 +5375,7 @@ static ManagedStatic MemUnfoldTable; const X86MemoryFoldTableEntry * llvm::lookupUnfoldTable(unsigned MemOp) { auto &Table = MemUnfoldTable->Table; - auto I = std::lower_bound(Table.begin(), Table.end(), MemOp); + auto I = llvm::lower_bound(Table, MemOp); if (I != Table.end() && I->KeyOp == MemOp) return &*I; return nullptr; diff --git a/lib/TextAPI/MachO/InterfaceFile.cpp b/lib/TextAPI/MachO/InterfaceFile.cpp index 323f1b61fcd..f1851014e70 100644 --- a/lib/TextAPI/MachO/InterfaceFile.cpp +++ b/lib/TextAPI/MachO/InterfaceFile.cpp @@ -21,11 +21,9 @@ namespace MachO { namespace detail { template typename C::iterator addEntry(C &Container, StringRef InstallName) { - auto I = - std::lower_bound(std::begin(Container), std::end(Container), InstallName, - [](const InterfaceFileRef &LHS, const StringRef &RHS) { - return LHS.getInstallName() < RHS; - }); + auto I = llvm::bsearch(Container, [=](const InterfaceFileRef &O) { + return InstallName <= O.getInstallName(); + }); if ((I != std::end(Container)) && !(InstallName < I->getInstallName())) return I; @@ -46,11 +44,12 @@ void InterfaceFile::addReexportedLibrary(StringRef InstallName, } void InterfaceFile::addUUID(Architecture Arch, StringRef UUID) { - auto I = std::lower_bound(UUIDs.begin(), UUIDs.end(), Arch, - [](const std::pair &LHS, - Architecture RHS) { return LHS.first < RHS; }); + auto I = + llvm::bsearch(UUIDs, [=](const std::pair &O) { + return Arch <= O.first; + }); - if ((I != UUIDs.end()) && !(Arch < I->first)) { + if (I != UUIDs.end() && Arch == I->first) { I->second = UUID; return; } diff --git a/lib/Transforms/Coroutines/CoroFrame.cpp b/lib/Transforms/Coroutines/CoroFrame.cpp index 98f6ca24f97..174430da171 100644 --- a/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/lib/Transforms/Coroutines/CoroFrame.cpp @@ -52,7 +52,7 @@ public: } size_t blockToIndex(BasicBlock *BB) const { - auto *I = std::lower_bound(V.begin(), V.end(), BB); + auto *I = llvm::lower_bound(V, BB); assert(I != V.end() && *I == BB && "BasicBlockNumberng: Unknown block"); return I - V.begin(); } diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 7cb955d03ff..c80cdd08224 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -1480,8 +1480,7 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LoadI) { for (pred_iterator PI = PB; PI != PE; ++PI) { BasicBlock *P = *PI; AvailablePredsTy::iterator I = - std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(), - std::make_pair(P, (Value*)nullptr)); + llvm::lower_bound(AvailablePreds, std::make_pair(P, (Value *)nullptr)); assert(I != AvailablePreds.end() && I->first == P && "Didn't find entry for predecessor!"); diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index eeeef58384d..cf852111283 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -278,8 +278,8 @@ void MemsetRanges::addRange(int64_t Start, int64_t Size, Value *Ptr, unsigned Alignment, Instruction *Inst) { int64_t End = Start+Size; - range_iterator I = std::lower_bound(Ranges.begin(), Ranges.end(), Start, - [](const MemsetRange &LHS, int64_t RHS) { return LHS.End < RHS; }); + range_iterator I = llvm::bsearch( + Ranges, [=](const MemsetRange &O) { return Start <= O.End; }); // We now know that I == E, in which case we didn't find anything to merge // with, or that Start <= I->End. If End < I->Start or I == E, then we need diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 1c06ffce17e..fa8c9e2a5fe 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -1826,7 +1826,7 @@ Value *ReassociatePass::OptimizeMul(BinaryOperator *I, return V; ValueEntry NewEntry = ValueEntry(getRank(V), V); - Ops.insert(std::lower_bound(Ops.begin(), Ops.end(), NewEntry), NewEntry); + Ops.insert(llvm::lower_bound(Ops, NewEntry), NewEntry); return nullptr; } diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index be8bcc648ad..dc568678c82 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -1766,18 +1766,16 @@ static void insertLineSequence(std::vector &Seq, return; } - auto InsertPoint = std::lower_bound( - Rows.begin(), Rows.end(), Seq.front(), - [](const DWARFDebugLine::Row &LHS, const DWARFDebugLine::Row &RHS) { - return LHS.Address < RHS.Address; - }); + object::SectionedAddress Front = Seq.front().Address; + auto InsertPoint = llvm::bsearch( + Rows, [=](const DWARFDebugLine::Row &O) { return !(O.Address < Front); }); // FIXME: this only removes the unneeded end_sequence if the // sequences have been inserted in order. Using a global sort like // described in patchLineTableForUnit() and delaying the end_sequene // elimination to emitLineTableForUnit() we can get rid of all of them. - if (InsertPoint != Rows.end() && - InsertPoint->Address == Seq.front().Address && InsertPoint->EndSequence) { + if (InsertPoint != Rows.end() && InsertPoint->Address == Front && + InsertPoint->EndSequence) { *InsertPoint = Seq.front(); Rows.insert(InsertPoint + 1, Seq.begin() + 1, Seq.end()); } else { diff --git a/tools/llvm-xray/xray-stacks.cpp b/tools/llvm-xray/xray-stacks.cpp index 66933d059cf..bcfc5cb1f1b 100644 --- a/tools/llvm-xray/xray-stacks.cpp +++ b/tools/llvm-xray/xray-stacks.cpp @@ -633,10 +633,8 @@ public: Top->ExtraData.TerminalDurations.end(), 0uLL); { auto E = std::make_pair(Top, TopSum); - TopStacksBySum.insert(std::lower_bound(TopStacksBySum.begin(), - TopStacksBySum.end(), E, - greater_second), - E); + TopStacksBySum.insert( + llvm::lower_bound(TopStacksBySum, E, greater_second), E); if (TopStacksBySum.size() == 11) TopStacksBySum.pop_back(); } -- 2.11.0