From cd088ba7e61a6132659d066918a1175861c9afe7 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 5 Jan 2021 21:15:59 -0800 Subject: [PATCH] [llvm] Use llvm::lower_bound and llvm::upper_bound (NFC) --- llvm/include/llvm/MC/MCSubtargetInfo.h | 2 +- llvm/include/llvm/ProfileData/InstrProf.h | 14 ++++++-------- llvm/include/llvm/Support/BinaryItemStream.h | 3 +-- llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | 2 +- llvm/lib/DWARFLinker/DWARFLinker.cpp | 5 ++--- .../DebugInfo/CodeView/LazyRandomTypeCollection.cpp | 8 ++++---- llvm/lib/DebugInfo/PDB/UDTLayout.cpp | 8 ++++---- llvm/lib/Object/ELF.cpp | 9 ++++----- llvm/lib/Support/TargetParser.cpp | 8 ++++---- llvm/lib/Target/AArch64/AArch64StackTagging.cpp | 7 ++++--- llvm/tools/llvm-exegesis/lib/Target.cpp | 3 +-- llvm/tools/llvm-profgen/ProfiledBinary.h | 2 +- llvm/tools/llvm-xray/xray-stacks.cpp | 6 ++---- llvm/utils/TableGen/RegisterInfoEmitter.cpp | 18 ++++++++---------- 14 files changed, 43 insertions(+), 52 deletions(-) diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h b/llvm/include/llvm/MC/MCSubtargetInfo.h index 901b11e..2c1072d8 100644 --- a/llvm/include/llvm/MC/MCSubtargetInfo.h +++ b/llvm/include/llvm/MC/MCSubtargetInfo.h @@ -222,7 +222,7 @@ public: /// Check whether the CPU string is valid. bool isCPUStringValid(StringRef CPU) const { - auto Found = std::lower_bound(ProcDesc.begin(), ProcDesc.end(), CPU); + auto Found = llvm::lower_bound(ProcDesc, CPU); return Found != ProcDesc.end() && StringRef(Found->Key) == CPU; } diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index 899abf5..9c16c35 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -562,10 +562,9 @@ StringRef InstrProfSymtab::getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash) { StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) { finalizeSymtab(); - auto Result = - std::lower_bound(MD5NameMap.begin(), MD5NameMap.end(), FuncMD5Hash, - [](const std::pair &LHS, - uint64_t RHS) { return LHS.first < RHS; }); + auto Result = llvm::lower_bound(MD5NameMap, FuncMD5Hash, + [](const std::pair &LHS, + uint64_t RHS) { return LHS.first < RHS; }); if (Result != MD5NameMap.end() && Result->first == FuncMD5Hash) return Result->second; return StringRef(); @@ -573,10 +572,9 @@ StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) { Function* InstrProfSymtab::getFunction(uint64_t FuncMD5Hash) { finalizeSymtab(); - auto Result = - std::lower_bound(MD5FuncMap.begin(), MD5FuncMap.end(), FuncMD5Hash, - [](const std::pair &LHS, - uint64_t RHS) { return LHS.first < RHS; }); + auto Result = llvm::lower_bound(MD5FuncMap, FuncMD5Hash, + [](const std::pair &LHS, + uint64_t RHS) { return LHS.first < RHS; }); if (Result != MD5FuncMap.end() && Result->first == FuncMD5Hash) return Result->second; return nullptr; diff --git a/llvm/include/llvm/Support/BinaryItemStream.h b/llvm/include/llvm/Support/BinaryItemStream.h index 4cd66ad..4d27013 100644 --- a/llvm/include/llvm/Support/BinaryItemStream.h +++ b/llvm/include/llvm/Support/BinaryItemStream.h @@ -88,8 +88,7 @@ private: if (Offset >= getLength()) return make_error(stream_error_code::stream_too_short); ++Offset; - auto Iter = - std::lower_bound(ItemEndOffsets.begin(), ItemEndOffsets.end(), Offset); + auto Iter = llvm::lower_bound(ItemEndOffsets, Offset); size_t Idx = std::distance(ItemEndOffsets.begin(), Iter); assert(Idx < Items.size() && "binary search for offset failed"); return Idx; diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp index 9f2629c..57fefc1 100644 --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -1016,7 +1016,7 @@ SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache, NonLocalDepEntry Val = Cache.back(); Cache.pop_back(); MemoryDependenceResults::NonLocalDepInfo::iterator Entry = - std::upper_bound(Cache.begin(), Cache.end(), Val); + llvm::upper_bound(Cache, Val); Cache.insert(Entry, Val); } break; diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp index bcda340..7acf902 100644 --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -52,9 +52,8 @@ static uint64_t getDebugInfoSize(DWARFContext &Dwarf) { /// Similar to DWARFUnitSection::getUnitForOffset(), but returning our /// CompileUnit object instead. static CompileUnit *getUnitForOffset(const UnitListTy &Units, uint64_t Offset) { - auto CU = std::upper_bound( - Units.begin(), Units.end(), Offset, - [](uint64_t LHS, const std::unique_ptr &RHS) { + auto CU = llvm::upper_bound( + Units, Offset, [](uint64_t LHS, const std::unique_ptr &RHS) { return LHS < RHS->getOrigUnit().getNextUnitOffset(); }); return CU != Units.end() ? CU->get() : nullptr; diff --git a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp index bf98e97..c0fc3e0 100644 --- a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp +++ b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp @@ -172,10 +172,10 @@ Error LazyRandomTypeCollection::visitRangeForType(TypeIndex TI) { if (PartialOffsets.empty()) return fullScanForType(TI); - auto Next = std::upper_bound(PartialOffsets.begin(), PartialOffsets.end(), TI, - [](TypeIndex Value, const TypeIndexOffset &IO) { - return Value < IO.Type; - }); + auto Next = llvm::upper_bound(PartialOffsets, TI, + [](TypeIndex Value, const TypeIndexOffset &IO) { + return Value < IO.Type; + }); assert(Next != PartialOffsets.begin()); auto Prev = std::prev(Next); diff --git a/llvm/lib/DebugInfo/PDB/UDTLayout.cpp b/llvm/lib/DebugInfo/PDB/UDTLayout.cpp index a8e1d0a..55854bb 100644 --- a/llvm/lib/DebugInfo/PDB/UDTLayout.cpp +++ b/llvm/lib/DebugInfo/PDB/UDTLayout.cpp @@ -289,10 +289,10 @@ void UDTLayoutBase::addChildToLayout(std::unique_ptr Child) { UsedBytes |= ChildBytes; if (ChildBytes.count() > 0) { - auto Loc = std::upper_bound(LayoutItems.begin(), LayoutItems.end(), Begin, - [](uint32_t Off, const LayoutItemBase *Item) { - return (Off < Item->getOffsetInParent()); - }); + auto Loc = llvm::upper_bound( + LayoutItems, Begin, [](uint32_t Off, const LayoutItemBase *Item) { + return (Off < Item->getOffsetInParent()); + }); LayoutItems.insert(Loc, Child.get()); } diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index 28a6914..264f115 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -589,11 +589,10 @@ ELFFile::toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler) const { llvm::stable_sort(LoadSegments, SortPred); } - const Elf_Phdr *const *I = - std::upper_bound(LoadSegments.begin(), LoadSegments.end(), VAddr, - [](uint64_t VAddr, const Elf_Phdr_Impl *Phdr) { - return VAddr < Phdr->p_vaddr; - }); + const Elf_Phdr *const *I = llvm::upper_bound( + LoadSegments, VAddr, [](uint64_t VAddr, const Elf_Phdr_Impl *Phdr) { + return VAddr < Phdr->p_vaddr; + }); if (I == LoadSegments.begin()) return createError("virtual address is not in any segment: 0x" + diff --git a/llvm/lib/Support/TargetParser.cpp b/llvm/lib/Support/TargetParser.cpp index 9c737f1..3ccdc55 100644 --- a/llvm/lib/Support/TargetParser.cpp +++ b/llvm/lib/Support/TargetParser.cpp @@ -117,10 +117,10 @@ constexpr GPUInfo AMDGCNGPUs[] = { const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef Table) { GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE }; - auto I = std::lower_bound(Table.begin(), Table.end(), Search, - [](const GPUInfo &A, const GPUInfo &B) { - return A.Kind < B.Kind; - }); + auto I = + llvm::lower_bound(Table, Search, [](const GPUInfo &A, const GPUInfo &B) { + return A.Kind < B.Kind; + }); if (I == Table.end()) return nullptr; diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp index c8ec7ef..ab49e0c 100644 --- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp +++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp @@ -107,9 +107,10 @@ public: SetTagZeroFn(SetTagZeroFn), StgpFn(StgpFn) {} bool addRange(uint64_t Start, uint64_t End, Instruction *Inst) { - auto I = std::lower_bound( - Ranges.begin(), Ranges.end(), Start, - [](const Range &LHS, uint64_t RHS) { return LHS.End <= RHS; }); + auto I = + llvm::lower_bound(Ranges, Start, [](const Range &LHS, uint64_t RHS) { + return LHS.End <= RHS; + }); if (I != Ranges.end() && End > I->Start) { // Overlap - bail. return false; diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp index 85180a1..2945c1e 100644 --- a/llvm/tools/llvm-exegesis/lib/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/Target.cpp @@ -132,8 +132,7 @@ const PfmCountersInfo &ExegesisTarget::getPfmCounters(StringRef CpuName) const { "CpuPfmCounters table is not sorted"); // Find entry - auto Found = - std::lower_bound(CpuPfmCounters.begin(), CpuPfmCounters.end(), CpuName); + auto Found = llvm::lower_bound(CpuPfmCounters, CpuName); if (Found == CpuPfmCounters.end() || StringRef(Found->CpuName) != CpuName) { // Use the default. if (CpuPfmCounters.begin() != CpuPfmCounters.end() && diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h index 646e79f..add1a22 100644 --- a/llvm/tools/llvm-profgen/ProfiledBinary.h +++ b/llvm/tools/llvm-profgen/ProfiledBinary.h @@ -203,7 +203,7 @@ public: // using lower bound operation uint32_t getIndexForAddr(uint64_t Address) const { uint64_t Offset = virtualAddrToOffset(Address); - auto Low = std::lower_bound(CodeAddrs.begin(), CodeAddrs.end(), Offset); + auto Low = llvm::lower_bound(CodeAddrs, Offset); return Low - CodeAddrs.begin(); } diff --git a/llvm/tools/llvm-xray/xray-stacks.cpp b/llvm/tools/llvm-xray/xray-stacks.cpp index 185a324..b317ae6 100644 --- a/llvm/tools/llvm-xray/xray-stacks.cpp +++ b/llvm/tools/llvm-xray/xray-stacks.cpp @@ -640,10 +640,8 @@ public: { auto E = std::make_pair(Top, Top->ExtraData.TerminalDurations.size()); - TopStacksByCount.insert(std::lower_bound(TopStacksByCount.begin(), - TopStacksByCount.end(), E, - greater_second), - E); + TopStacksByCount.insert( + llvm::lower_bound(TopStacksByCount, E, greater_second), E); if (TopStacksByCount.size() == 11) TopStacksByCount.pop_back(); } diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp index 38809b4..69e9bc6 100644 --- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp +++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp @@ -462,18 +462,16 @@ void RegisterInfoEmitter::EmitRegMappingTables( DefInit *DI = cast(V->getValue()); Record *Alias = DI->getDef(); - const auto &AliasIter = - std::lower_bound(DwarfRegNums.begin(), DwarfRegNums.end(), Alias, - [](const DwarfRegNumsMapPair &A, const Record *B) { - return LessRecordRegister()(A.first, B); - }); + const auto &AliasIter = llvm::lower_bound( + DwarfRegNums, Alias, [](const DwarfRegNumsMapPair &A, const Record *B) { + return LessRecordRegister()(A.first, B); + }); assert(AliasIter != DwarfRegNums.end() && AliasIter->first == Alias && "Expected Alias to be present in map"); - const auto &RegIter = - std::lower_bound(DwarfRegNums.begin(), DwarfRegNums.end(), Reg, - [](const DwarfRegNumsMapPair &A, const Record *B) { - return LessRecordRegister()(A.first, B); - }); + const auto &RegIter = llvm::lower_bound( + DwarfRegNums, Reg, [](const DwarfRegNumsMapPair &A, const Record *B) { + return LessRecordRegister()(A.first, B); + }); assert(RegIter != DwarfRegNums.end() && RegIter->first == Reg && "Expected Reg to be present in map"); RegIter->second = AliasIter->second; -- 2.7.4