From c82e92bca89f3b9740e8c66afae0298965c3183a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 17 Apr 2019 07:58:05 +0000 Subject: [PATCH] Change some llvm::{lower,upper}_bound to llvm::bsearch. NFC llvm-svn: 358564 --- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h | 11 ++++--- llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp | 6 ++-- llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp | 4 +-- llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp | 10 +++---- llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp | 7 ++--- llvm/tools/llvm-objdump/llvm-objdump.cpp | 41 ++++++++++++-------------- 6 files changed, 34 insertions(+), 45 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h index c083ecc..d9467ee 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -462,12 +462,11 @@ public: DWARFDie getDIEForOffset(uint32_t Offset) { extractDIEsIfNeeded(false); assert(!DieArray.empty()); - auto it = llvm::lower_bound( - DieArray, Offset, [](const DWARFDebugInfoEntry &LHS, uint32_t Offset) { - return LHS.getOffset() < Offset; - }); - if (it != DieArray.end() && it->getOffset() == Offset) - return DWARFDie(this, &*it); + auto It = llvm::bsearch(DieArray, [=](const DWARFDebugInfoEntry &LHS) { + return Offset <= LHS.getOffset(); + }); + if (It != DieArray.end() && It->getOffset() == Offset) + return DWARFDie(this, &*It); return DWARFDie(); } diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp index 5dca699..1760917 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp @@ -506,10 +506,8 @@ LegalizerInfo::findAction(const SizeAndActionsVec &Vec, const uint32_t Size) { // Find the last element in Vec that has a bitsize equal to or smaller than // the requested bit size. // That is the element just before the first element that is bigger than Size. - auto VecIt = llvm::upper_bound( - Vec, Size, [](const uint32_t Size, const SizeAndAction lhs) -> bool { - return Size < lhs.first; - }); + auto VecIt = llvm::bsearch( + Vec, [=](const SizeAndAction &A) { return Size < A.first; }); assert(VecIt != Vec.begin() && "Does Vec not start with size 1?"); --VecIt; int VecIdx = VecIt - Vec.begin(); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp index a283136..010b010 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp @@ -115,9 +115,7 @@ void DWARFDebugAranges::construct() { uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const { RangeCollIterator It = - llvm::upper_bound(Aranges, Address, [](uint64_t LHS, Range RHS) { - return LHS < RHS.HighPC(); - }); + llvm::bsearch(Aranges, [=](Range RHS) { return Address < RHS.HighPC(); }); if (It != Aranges.end() && It->LowPC <= Address) return It->CUOffset; return -1U; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp index 7c80b3b..e0d6221 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -57,9 +57,8 @@ void DWARFDebugLoc::LocationList::dump(raw_ostream &OS, bool IsLittleEndian, DWARFDebugLoc::LocationList const * DWARFDebugLoc::getLocationListAtOffset(uint64_t Offset) const { - auto It = llvm::lower_bound( - Locations, Offset, - [](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; }); + auto It = llvm::bsearch( + Locations, [=](const LocationList &L) { return Offset <= L.Offset; }); if (It != Locations.end() && It->Offset == Offset) return &(*It); return nullptr; @@ -213,9 +212,8 @@ void DWARFDebugLoclists::parse(DataExtractor data, unsigned Version) { DWARFDebugLoclists::LocationList const * DWARFDebugLoclists::getLocationListAtOffset(uint64_t Offset) const { - auto It = llvm::lower_bound( - Locations, Offset, - [](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; }); + auto It = llvm::bsearch( + Locations, [=](const LocationList &L) { return Offset <= L.Offset; }); if (It != Locations.end() && It->Offset == Offset) return &(*It); return nullptr; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp index 8225a26..cff5c28 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp @@ -172,10 +172,9 @@ DWARFUnitIndex::getFromOffset(uint32_t Offset) const { E2->Contributions[InfoColumn].Offset; }); } - auto I = - llvm::upper_bound(OffsetLookup, Offset, [&](uint32_t Offset, Entry *E2) { - return Offset < E2->Contributions[InfoColumn].Offset; - }); + auto I = llvm::bsearch(OffsetLookup, [&](Entry *E2) { + return Offset < E2->Contributions[InfoColumn].Offset; + }); if (I == OffsetLookup.begin()) return nullptr; --I; diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 9568d34..db8bfe3 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1045,10 +1045,9 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, error(ExportEntry.getExportRVA(RVA)); uint64_t VA = COFFObj->getImageBase() + RVA; - auto Sec = llvm::upper_bound( - SectionAddresses, VA, - [](uint64_t LHS, const std::pair &RHS) { - return LHS < RHS.first; + auto Sec = llvm::bsearch( + SectionAddresses, [VA](const std::pair &RHS) { + return VA < RHS.first; }); if (Sec != SectionAddresses.begin()) { --Sec; @@ -1302,35 +1301,33 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, // N.B. We don't walk the relocations in the relocatable case yet. auto *TargetSectionSymbols = &Symbols; if (!Obj->isRelocatableObject()) { - auto SectionAddress = llvm::upper_bound( - SectionAddresses, Target, - [](uint64_t LHS, const std::pair &RHS) { - return LHS < RHS.first; + auto It = llvm::bsearch( + SectionAddresses, + [=](const std::pair &RHS) { + return Target < RHS.first; }); - if (SectionAddress != SectionAddresses.begin()) { - --SectionAddress; - TargetSectionSymbols = &AllSymbols[SectionAddress->second]; + if (It != SectionAddresses.begin()) { + --It; + TargetSectionSymbols = &AllSymbols[It->second]; } else { TargetSectionSymbols = &AbsoluteSymbols; } } - // Find the first symbol in the section whose offset is less than + // Find the last symbol in the section whose offset is less than // or equal to the target. If there isn't a section that contains // the target, find the nearest preceding absolute symbol. - auto TargetSym = llvm::upper_bound( - *TargetSectionSymbols, Target, - [](uint64_t LHS, - const std::tuple &RHS) { - return LHS < std::get<0>(RHS); + auto TargetSym = llvm::bsearch( + *TargetSectionSymbols, + [=](const std::tuple &RHS) { + return Target < std::get<0>(RHS); }); if (TargetSym == TargetSectionSymbols->begin()) { TargetSectionSymbols = &AbsoluteSymbols; - TargetSym = llvm::upper_bound( - AbsoluteSymbols, Target, - [](uint64_t LHS, - const std::tuple &RHS) { - return LHS < std::get<0>(RHS); + TargetSym = llvm::bsearch( + AbsoluteSymbols, + [=](const std::tuple &RHS) { + return Target < std::get<0>(RHS); }); } if (TargetSym != TargetSectionSymbols->begin()) { -- 2.7.4