From 89f1433225b05b993b9b3f0b8c3a282ec070ac23 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 3 Sep 2022 11:17:37 -0700 Subject: [PATCH] Use llvm::lower_bound (NFC) --- bolt/lib/Passes/FrameOptimizer.cpp | 4 ++-- .../clang-tidy/misc/ConfusableIdentifierCheck.cpp | 7 +++---- clang/lib/CodeGen/CGBuiltin.cpp | 3 +-- clang/lib/Sema/SemaDeclAttr.cpp | 7 ++++--- flang/lib/Lower/IntrinsicCall.cpp | 3 +-- lld/COFF/DebugTypes.cpp | 3 +-- lldb/include/lldb/Utility/RangeMap.h | 11 +++++------ lldb/source/Breakpoint/BreakpointLocationList.cpp | 2 +- lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp | 5 ++--- lldb/source/Symbol/CompactUnwindInfo.cpp | 2 +- lldb/source/Utility/Reproducer.cpp | 2 +- lldb/source/Utility/ReproducerProvider.cpp | 4 ++-- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 3 +-- llvm/lib/ExecutionEngine/Orc/Core.cpp | 4 ++-- llvm/lib/Support/UnicodeNameToCodepoint.cpp | 4 ++-- llvm/tools/llvm-profgen/PerfReader.cpp | 2 +- 16 files changed, 30 insertions(+), 36 deletions(-) diff --git a/bolt/lib/Passes/FrameOptimizer.cpp b/bolt/lib/Passes/FrameOptimizer.cpp index bf6aede..dc17ca4 100644 --- a/bolt/lib/Passes/FrameOptimizer.cpp +++ b/bolt/lib/Passes/FrameOptimizer.cpp @@ -336,8 +336,8 @@ void FrameOptimizerPass::performShrinkWrapping(const RegAnalysis &RA, std::vector> Top10Funcs; auto LogFunc = [&](BinaryFunction &BF) { - auto Lower = std::lower_bound( - Top10Funcs.begin(), Top10Funcs.end(), BF.getKnownExecutionCount(), + auto Lower = llvm::lower_bound( + Top10Funcs, BF.getKnownExecutionCount(), [](const std::pair &Elmt, uint64_t Value) { return Elmt.first > Value; }); if (Lower == Top10Funcs.end() && Top10Funcs.size() >= 10) diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp index 556d761..aa8300c 100644 --- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp @@ -68,10 +68,9 @@ std::string ConfusableIdentifierCheck::skeleton(StringRef Name) { } StringRef Key(Prev, Curr - Prev); - auto Where = std::lower_bound(std::begin(ConfusableEntries), - std::end(ConfusableEntries), CodePoint, - [](decltype(ConfusableEntries[0]) x, - UTF32 y) { return x.codepoint < y; }); + auto Where = llvm::lower_bound(ConfusableEntries, CodePoint, + [](decltype(ConfusableEntries[0]) x, + UTF32 y) { return x.codepoint < y; }); if (Where == std::end(ConfusableEntries) || CodePoint != Where->codepoint) { Skeleton.append(Prev, Curr); } else { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 7bde3fd..5af3811 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18924,8 +18924,7 @@ getIntrinsicForHexagonNonClangBuiltin(unsigned BuiltinID) { static const bool SortOnce = (llvm::sort(Infos, CmpInfo), true); (void)SortOnce; - const Info *F = std::lower_bound(std::begin(Infos), std::end(Infos), - Info{BuiltinID, 0, 0}, CmpInfo); + const Info *F = llvm::lower_bound(Infos, Info{BuiltinID, 0, 0}, CmpInfo); if (F == std::end(Infos) || F->BuiltinID != BuiltinID) return {Intrinsic::not_intrinsic, 0}; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5b3d4ae..0e9b27f 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5542,9 +5542,10 @@ static bool ArmBuiltinAliasValid(unsigned BuiltinID, StringRef AliasName, const char *IntrinNames) { if (AliasName.startswith("__arm_")) AliasName = AliasName.substr(6); - const IntrinToName *It = std::lower_bound( - Map.begin(), Map.end(), BuiltinID, - [](const IntrinToName &L, unsigned Id) { return L.Id < Id; }); + const IntrinToName *It = + llvm::lower_bound(Map, BuiltinID, [](const IntrinToName &L, unsigned Id) { + return L.Id < Id; + }); if (It == Map.end() || It->Id != BuiltinID) return false; StringRef FullName(&IntrinNames[It->FullName]); diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp index 545c2d9..4335cb7 100644 --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -1015,8 +1015,7 @@ static const IntrinsicHandler *findIntrinsicHandler(llvm::StringRef name) { auto compare = [](const IntrinsicHandler &handler, llvm::StringRef name) { return name.compare(handler.name) > 0; }; - auto result = - std::lower_bound(std::begin(handlers), std::end(handlers), name, compare); + auto result = llvm::lower_bound(handlers, name, compare); return result != std::end(handlers) && result->name == name ? result : nullptr; } diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp index d75833d..31618cc 100644 --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -1094,8 +1094,7 @@ void TypeMerger::mergeTypesWithGHash() { entries.size(), tableSize)); // Find out how many type and item indices there are. - auto mid = - std::lower_bound(entries.begin(), entries.end(), GHashCell(true, 0, 0)); + auto mid = llvm::lower_bound(entries, GHashCell(true, 0, 0)); assert((mid == entries.end() || mid->isItem()) && (mid == entries.begin() || !std::prev(mid)->isItem()) && "midpoint is not midpoint"); diff --git a/lldb/include/lldb/Utility/RangeMap.h b/lldb/include/lldb/Utility/RangeMap.h index 54c8664..49b7eeb 100644 --- a/lldb/include/lldb/Utility/RangeMap.h +++ b/lldb/include/lldb/Utility/RangeMap.h @@ -618,11 +618,10 @@ public: if (!m_entries.empty()) { typename Collection::const_iterator begin = m_entries.begin(); typename Collection::const_iterator end = m_entries.end(); - typename Collection::const_iterator pos = - std::lower_bound(m_entries.begin(), end, addr, - [](const Entry &lhs, B rhs_base) -> bool { - return lhs.GetRangeEnd() <= rhs_base; - }); + typename Collection::const_iterator pos = llvm::lower_bound( + m_entries, addr, [](const Entry &lhs, B rhs_base) -> bool { + return lhs.GetRangeEnd() <= rhs_base; + }); while (pos != begin && pos[-1].Contains(addr)) --pos; @@ -794,7 +793,7 @@ public: typename Collection::iterator begin = m_entries.begin(); typename Collection::iterator end = m_entries.end(); typename Collection::iterator pos = - std::lower_bound(begin, end, entry, BaseLessThan); + llvm::lower_bound(m_entries, entry, BaseLessThan); while (pos != begin && pos[-1].addr == addr) --pos; diff --git a/lldb/source/Breakpoint/BreakpointLocationList.cpp b/lldb/source/Breakpoint/BreakpointLocationList.cpp index 46f6627..8688f88 100644 --- a/lldb/source/Breakpoint/BreakpointLocationList.cpp +++ b/lldb/source/Breakpoint/BreakpointLocationList.cpp @@ -69,7 +69,7 @@ BreakpointLocationList::FindByID(lldb::break_id_t break_id) const { std::lock_guard guard(m_mutex); collection::const_iterator end = m_locations.end(); collection::const_iterator pos = - std::lower_bound(m_locations.begin(), end, break_id, Compare); + llvm::lower_bound(m_locations, break_id, Compare); if (pos != end && (*pos)->GetID() == break_id) return *(pos); else diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp index 21b1cb2..11a8738 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -474,9 +474,8 @@ static llvm::Optional FindPublicSym(const SegmentOffset &addr, SymbolStream &syms, PublicsStream &publics) { llvm::FixedStreamArray addr_map = publics.getAddressMap(); - auto iter = std::lower_bound( - addr_map.begin(), addr_map.end(), addr, - [&](const ulittle32_t &x, const SegmentOffset &y) { + auto iter = llvm::lower_bound( + addr_map, addr, [&](const ulittle32_t &x, const SegmentOffset &y) { CVSymbol s1 = syms.readRecord(x); lldbassert(s1.kind() == S_PUB32); PublicSym32 p1; diff --git a/lldb/source/Symbol/CompactUnwindInfo.cpp b/lldb/source/Symbol/CompactUnwindInfo.cpp index ce59752..822ac7b 100644 --- a/lldb/source/Symbol/CompactUnwindInfo.cpp +++ b/lldb/source/Symbol/CompactUnwindInfo.cpp @@ -516,7 +516,7 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction( key.function_offset = function_offset; std::vector::const_iterator it; - it = std::lower_bound(m_indexes.begin(), m_indexes.end(), key); + it = llvm::lower_bound(m_indexes, key); if (it == m_indexes.end()) { return false; } diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp index 3641c93..6274632 100644 --- a/lldb/source/Utility/Reproducer.cpp +++ b/lldb/source/Utility/Reproducer.cpp @@ -225,6 +225,6 @@ llvm::Error Loader::LoadIndex() { bool Loader::HasFile(StringRef file) { assert(m_loaded); - auto it = std::lower_bound(m_files.begin(), m_files.end(), file.str()); + auto it = llvm::lower_bound(m_files, file.str()); return (it != m_files.end()) && (*it == file); } diff --git a/lldb/source/Utility/ReproducerProvider.cpp b/lldb/source/Utility/ReproducerProvider.cpp index 44f24e4..fef225f 100644 --- a/lldb/source/Utility/ReproducerProvider.cpp +++ b/lldb/source/Utility/ReproducerProvider.cpp @@ -161,8 +161,8 @@ SymbolFileLoader::GetPaths(const UUID *uuid) const { if (!uuid) return {}; - auto it = std::lower_bound(m_symbol_files.begin(), m_symbol_files.end(), - SymbolFileProvider::Entry(uuid->GetAsString())); + auto it = llvm::lower_bound(m_symbol_files, + SymbolFileProvider::Entry(uuid->GetAsString())); if (it == m_symbol_files.end()) return {}; return std::make_pair(FileSpec(it->module_path), diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index 87ccfc1..f6a55db 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -1430,8 +1430,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI, // Try to lookup the instruction number, and find the machine value number // that it defines. It could be an instruction, or a PHI. auto InstrIt = DebugInstrNumToInstr.find(InstNo); - auto PHIIt = std::lower_bound(DebugPHINumToValue.begin(), - DebugPHINumToValue.end(), InstNo); + auto PHIIt = llvm::lower_bound(DebugPHINumToValue, InstNo); if (InstrIt != DebugInstrNumToInstr.end()) { const MachineInstr &TargetInstr = *InstrIt->second.first; uint64_t BlockNo = TargetInstr.getParent()->getNumber(); diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 8169568..228a50a 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -1482,8 +1482,8 @@ void JITDylib::dump(raw_ostream &OS) { void JITDylib::MaterializingInfo::addQuery( std::shared_ptr Q) { - auto I = std::lower_bound( - PendingQueries.rbegin(), PendingQueries.rend(), Q->getRequiredState(), + auto I = llvm::lower_bound( + llvm::reverse(PendingQueries), Q->getRequiredState(), [](const std::shared_ptr &V, SymbolState S) { return V->getRequiredState() <= S; }); diff --git a/llvm/lib/Support/UnicodeNameToCodepoint.cpp b/llvm/lib/Support/UnicodeNameToCodepoint.cpp index 1e8aebf..095abd8 100644 --- a/llvm/lib/Support/UnicodeNameToCodepoint.cpp +++ b/llvm/lib/Support/UnicodeNameToCodepoint.cpp @@ -445,8 +445,8 @@ nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount) { return Name; }; - auto It = std::lower_bound( - Matches.begin(), Matches.end(), Distance, + auto It = llvm::lower_bound( + Matches, Distance, [&](const MatchForCodepointName &a, std::size_t Distance) { if (Distance == a.Distance) return a.Name < GetName(); diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp index 613e530..3d83c68 100644 --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -435,7 +435,7 @@ void PerfScriptReader::updateBinaryAddress(const MMapEvent &Event) { } else { // Verify segments are loaded consecutively. const auto &Offsets = Binary->getTextSegmentOffsets(); - auto It = std::lower_bound(Offsets.begin(), Offsets.end(), Event.Offset); + auto It = llvm::lower_bound(Offsets, Event.Offset); if (It != Offsets.end() && *It == Event.Offset) { // The event is for loading a separate executable segment. auto I = std::distance(Offsets.begin(), It); -- 2.7.4