Skip to content

Commit c82e92b

Browse files
committed
Change some llvm::{lower,upper}_bound to llvm::bsearch. NFC
llvm-svn: 358564
1 parent b0b65ca commit c82e92b

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,11 @@ class DWARFUnit {
462462
DWARFDie getDIEForOffset(uint32_t Offset) {
463463
extractDIEsIfNeeded(false);
464464
assert(!DieArray.empty());
465-
auto it = llvm::lower_bound(
466-
DieArray, Offset, [](const DWARFDebugInfoEntry &LHS, uint32_t Offset) {
467-
return LHS.getOffset() < Offset;
468-
});
469-
if (it != DieArray.end() && it->getOffset() == Offset)
470-
return DWARFDie(this, &*it);
465+
auto It = llvm::bsearch(DieArray, [=](const DWARFDebugInfoEntry &LHS) {
466+
return Offset <= LHS.getOffset();
467+
});
468+
if (It != DieArray.end() && It->getOffset() == Offset)
469+
return DWARFDie(this, &*It);
471470
return DWARFDie();
472471
}
473472

llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,8 @@ LegalizerInfo::findAction(const SizeAndActionsVec &Vec, const uint32_t Size) {
506506
// Find the last element in Vec that has a bitsize equal to or smaller than
507507
// the requested bit size.
508508
// That is the element just before the first element that is bigger than Size.
509-
auto VecIt = llvm::upper_bound(
510-
Vec, Size, [](const uint32_t Size, const SizeAndAction lhs) -> bool {
511-
return Size < lhs.first;
512-
});
509+
auto VecIt = llvm::bsearch(
510+
Vec, [=](const SizeAndAction &A) { return Size < A.first; });
513511
assert(VecIt != Vec.begin() && "Does Vec not start with size 1?");
514512
--VecIt;
515513
int VecIdx = VecIt - Vec.begin();

llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ void DWARFDebugAranges::construct() {
115115

116116
uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {
117117
RangeCollIterator It =
118-
llvm::upper_bound(Aranges, Address, [](uint64_t LHS, Range RHS) {
119-
return LHS < RHS.HighPC();
120-
});
118+
llvm::bsearch(Aranges, [=](Range RHS) { return Address < RHS.HighPC(); });
121119
if (It != Aranges.end() && It->LowPC <= Address)
122120
return It->CUOffset;
123121
return -1U;

llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ void DWARFDebugLoc::LocationList::dump(raw_ostream &OS, bool IsLittleEndian,
5757

5858
DWARFDebugLoc::LocationList const *
5959
DWARFDebugLoc::getLocationListAtOffset(uint64_t Offset) const {
60-
auto It = llvm::lower_bound(
61-
Locations, Offset,
62-
[](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; });
60+
auto It = llvm::bsearch(
61+
Locations, [=](const LocationList &L) { return Offset <= L.Offset; });
6362
if (It != Locations.end() && It->Offset == Offset)
6463
return &(*It);
6564
return nullptr;
@@ -213,9 +212,8 @@ void DWARFDebugLoclists::parse(DataExtractor data, unsigned Version) {
213212

214213
DWARFDebugLoclists::LocationList const *
215214
DWARFDebugLoclists::getLocationListAtOffset(uint64_t Offset) const {
216-
auto It = llvm::lower_bound(
217-
Locations, Offset,
218-
[](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; });
215+
auto It = llvm::bsearch(
216+
Locations, [=](const LocationList &L) { return Offset <= L.Offset; });
219217
if (It != Locations.end() && It->Offset == Offset)
220218
return &(*It);
221219
return nullptr;

llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ DWARFUnitIndex::getFromOffset(uint32_t Offset) const {
172172
E2->Contributions[InfoColumn].Offset;
173173
});
174174
}
175-
auto I =
176-
llvm::upper_bound(OffsetLookup, Offset, [&](uint32_t Offset, Entry *E2) {
177-
return Offset < E2->Contributions[InfoColumn].Offset;
178-
});
175+
auto I = llvm::bsearch(OffsetLookup, [&](Entry *E2) {
176+
return Offset < E2->Contributions[InfoColumn].Offset;
177+
});
179178
if (I == OffsetLookup.begin())
180179
return nullptr;
181180
--I;

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,9 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
10451045
error(ExportEntry.getExportRVA(RVA));
10461046

10471047
uint64_t VA = COFFObj->getImageBase() + RVA;
1048-
auto Sec = llvm::upper_bound(
1049-
SectionAddresses, VA,
1050-
[](uint64_t LHS, const std::pair<uint64_t, SectionRef> &RHS) {
1051-
return LHS < RHS.first;
1048+
auto Sec = llvm::bsearch(
1049+
SectionAddresses, [VA](const std::pair<uint64_t, SectionRef> &RHS) {
1050+
return VA < RHS.first;
10521051
});
10531052
if (Sec != SectionAddresses.begin()) {
10541053
--Sec;
@@ -1302,35 +1301,33 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
13021301
// N.B. We don't walk the relocations in the relocatable case yet.
13031302
auto *TargetSectionSymbols = &Symbols;
13041303
if (!Obj->isRelocatableObject()) {
1305-
auto SectionAddress = llvm::upper_bound(
1306-
SectionAddresses, Target,
1307-
[](uint64_t LHS, const std::pair<uint64_t, SectionRef> &RHS) {
1308-
return LHS < RHS.first;
1304+
auto It = llvm::bsearch(
1305+
SectionAddresses,
1306+
[=](const std::pair<uint64_t, SectionRef> &RHS) {
1307+
return Target < RHS.first;
13091308
});
1310-
if (SectionAddress != SectionAddresses.begin()) {
1311-
--SectionAddress;
1312-
TargetSectionSymbols = &AllSymbols[SectionAddress->second];
1309+
if (It != SectionAddresses.begin()) {
1310+
--It;
1311+
TargetSectionSymbols = &AllSymbols[It->second];
13131312
} else {
13141313
TargetSectionSymbols = &AbsoluteSymbols;
13151314
}
13161315
}
13171316

1318-
// Find the first symbol in the section whose offset is less than
1317+
// Find the last symbol in the section whose offset is less than
13191318
// or equal to the target. If there isn't a section that contains
13201319
// the target, find the nearest preceding absolute symbol.
1321-
auto TargetSym = llvm::upper_bound(
1322-
*TargetSectionSymbols, Target,
1323-
[](uint64_t LHS,
1324-
const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1325-
return LHS < std::get<0>(RHS);
1320+
auto TargetSym = llvm::bsearch(
1321+
*TargetSectionSymbols,
1322+
[=](const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1323+
return Target < std::get<0>(RHS);
13261324
});
13271325
if (TargetSym == TargetSectionSymbols->begin()) {
13281326
TargetSectionSymbols = &AbsoluteSymbols;
1329-
TargetSym = llvm::upper_bound(
1330-
AbsoluteSymbols, Target,
1331-
[](uint64_t LHS,
1332-
const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1333-
return LHS < std::get<0>(RHS);
1327+
TargetSym = llvm::bsearch(
1328+
AbsoluteSymbols,
1329+
[=](const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1330+
return Target < std::get<0>(RHS);
13341331
});
13351332
}
13361333
if (TargetSym != TargetSectionSymbols->begin()) {

0 commit comments

Comments
 (0)