Use llvm::lower_bound (NFC)

This commit is contained in:
Kazu Hirata 2022-09-03 11:17:37 -07:00
parent 3850edd9e0
commit 89f1433225
16 changed files with 30 additions and 36 deletions

View File

@ -336,8 +336,8 @@ void FrameOptimizerPass::performShrinkWrapping(const RegAnalysis &RA,
std::vector<std::pair<uint64_t, const BinaryFunction *>> Top10Funcs; std::vector<std::pair<uint64_t, const BinaryFunction *>> Top10Funcs;
auto LogFunc = [&](BinaryFunction &BF) { auto LogFunc = [&](BinaryFunction &BF) {
auto Lower = std::lower_bound( auto Lower = llvm::lower_bound(
Top10Funcs.begin(), Top10Funcs.end(), BF.getKnownExecutionCount(), Top10Funcs, BF.getKnownExecutionCount(),
[](const std::pair<uint64_t, const BinaryFunction *> &Elmt, [](const std::pair<uint64_t, const BinaryFunction *> &Elmt,
uint64_t Value) { return Elmt.first > Value; }); uint64_t Value) { return Elmt.first > Value; });
if (Lower == Top10Funcs.end() && Top10Funcs.size() >= 10) if (Lower == Top10Funcs.end() && Top10Funcs.size() >= 10)

View File

@ -68,10 +68,9 @@ std::string ConfusableIdentifierCheck::skeleton(StringRef Name) {
} }
StringRef Key(Prev, Curr - Prev); StringRef Key(Prev, Curr - Prev);
auto Where = std::lower_bound(std::begin(ConfusableEntries), auto Where = llvm::lower_bound(ConfusableEntries, CodePoint,
std::end(ConfusableEntries), CodePoint, [](decltype(ConfusableEntries[0]) x,
[](decltype(ConfusableEntries[0]) x, UTF32 y) { return x.codepoint < y; });
UTF32 y) { return x.codepoint < y; });
if (Where == std::end(ConfusableEntries) || CodePoint != Where->codepoint) { if (Where == std::end(ConfusableEntries) || CodePoint != Where->codepoint) {
Skeleton.append(Prev, Curr); Skeleton.append(Prev, Curr);
} else { } else {

View File

@ -18924,8 +18924,7 @@ getIntrinsicForHexagonNonClangBuiltin(unsigned BuiltinID) {
static const bool SortOnce = (llvm::sort(Infos, CmpInfo), true); static const bool SortOnce = (llvm::sort(Infos, CmpInfo), true);
(void)SortOnce; (void)SortOnce;
const Info *F = std::lower_bound(std::begin(Infos), std::end(Infos), const Info *F = llvm::lower_bound(Infos, Info{BuiltinID, 0, 0}, CmpInfo);
Info{BuiltinID, 0, 0}, CmpInfo);
if (F == std::end(Infos) || F->BuiltinID != BuiltinID) if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
return {Intrinsic::not_intrinsic, 0}; return {Intrinsic::not_intrinsic, 0};

View File

@ -5542,9 +5542,10 @@ static bool ArmBuiltinAliasValid(unsigned BuiltinID, StringRef AliasName,
const char *IntrinNames) { const char *IntrinNames) {
if (AliasName.startswith("__arm_")) if (AliasName.startswith("__arm_"))
AliasName = AliasName.substr(6); AliasName = AliasName.substr(6);
const IntrinToName *It = std::lower_bound( const IntrinToName *It =
Map.begin(), Map.end(), BuiltinID, llvm::lower_bound(Map, BuiltinID, [](const IntrinToName &L, unsigned Id) {
[](const IntrinToName &L, unsigned Id) { return L.Id < Id; }); return L.Id < Id;
});
if (It == Map.end() || It->Id != BuiltinID) if (It == Map.end() || It->Id != BuiltinID)
return false; return false;
StringRef FullName(&IntrinNames[It->FullName]); StringRef FullName(&IntrinNames[It->FullName]);

View File

@ -1015,8 +1015,7 @@ static const IntrinsicHandler *findIntrinsicHandler(llvm::StringRef name) {
auto compare = [](const IntrinsicHandler &handler, llvm::StringRef name) { auto compare = [](const IntrinsicHandler &handler, llvm::StringRef name) {
return name.compare(handler.name) > 0; return name.compare(handler.name) > 0;
}; };
auto result = auto result = llvm::lower_bound(handlers, name, compare);
std::lower_bound(std::begin(handlers), std::end(handlers), name, compare);
return result != std::end(handlers) && result->name == name ? result return result != std::end(handlers) && result->name == name ? result
: nullptr; : nullptr;
} }

View File

@ -1094,8 +1094,7 @@ void TypeMerger::mergeTypesWithGHash() {
entries.size(), tableSize)); entries.size(), tableSize));
// Find out how many type and item indices there are. // Find out how many type and item indices there are.
auto mid = auto mid = llvm::lower_bound(entries, GHashCell(true, 0, 0));
std::lower_bound(entries.begin(), entries.end(), GHashCell(true, 0, 0));
assert((mid == entries.end() || mid->isItem()) && assert((mid == entries.end() || mid->isItem()) &&
(mid == entries.begin() || !std::prev(mid)->isItem()) && (mid == entries.begin() || !std::prev(mid)->isItem()) &&
"midpoint is not midpoint"); "midpoint is not midpoint");

View File

@ -618,11 +618,10 @@ public:
if (!m_entries.empty()) { if (!m_entries.empty()) {
typename Collection::const_iterator begin = m_entries.begin(); typename Collection::const_iterator begin = m_entries.begin();
typename Collection::const_iterator end = m_entries.end(); typename Collection::const_iterator end = m_entries.end();
typename Collection::const_iterator pos = typename Collection::const_iterator pos = llvm::lower_bound(
std::lower_bound(m_entries.begin(), end, addr, m_entries, addr, [](const Entry &lhs, B rhs_base) -> bool {
[](const Entry &lhs, B rhs_base) -> bool { return lhs.GetRangeEnd() <= rhs_base;
return lhs.GetRangeEnd() <= rhs_base; });
});
while (pos != begin && pos[-1].Contains(addr)) while (pos != begin && pos[-1].Contains(addr))
--pos; --pos;
@ -794,7 +793,7 @@ public:
typename Collection::iterator begin = m_entries.begin(); typename Collection::iterator begin = m_entries.begin();
typename Collection::iterator end = m_entries.end(); typename Collection::iterator end = m_entries.end();
typename Collection::iterator pos = 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) while (pos != begin && pos[-1].addr == addr)
--pos; --pos;

View File

@ -69,7 +69,7 @@ BreakpointLocationList::FindByID(lldb::break_id_t break_id) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex); std::lock_guard<std::recursive_mutex> guard(m_mutex);
collection::const_iterator end = m_locations.end(); collection::const_iterator end = m_locations.end();
collection::const_iterator pos = 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) if (pos != end && (*pos)->GetID() == break_id)
return *(pos); return *(pos);
else else

View File

@ -474,9 +474,8 @@ static llvm::Optional<PublicSym32> FindPublicSym(const SegmentOffset &addr,
SymbolStream &syms, SymbolStream &syms,
PublicsStream &publics) { PublicsStream &publics) {
llvm::FixedStreamArray<ulittle32_t> addr_map = publics.getAddressMap(); llvm::FixedStreamArray<ulittle32_t> addr_map = publics.getAddressMap();
auto iter = std::lower_bound( auto iter = llvm::lower_bound(
addr_map.begin(), addr_map.end(), addr, addr_map, addr, [&](const ulittle32_t &x, const SegmentOffset &y) {
[&](const ulittle32_t &x, const SegmentOffset &y) {
CVSymbol s1 = syms.readRecord(x); CVSymbol s1 = syms.readRecord(x);
lldbassert(s1.kind() == S_PUB32); lldbassert(s1.kind() == S_PUB32);
PublicSym32 p1; PublicSym32 p1;

View File

@ -516,7 +516,7 @@ bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
key.function_offset = function_offset; key.function_offset = function_offset;
std::vector<UnwindIndex>::const_iterator it; std::vector<UnwindIndex>::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()) { if (it == m_indexes.end()) {
return false; return false;
} }

View File

@ -225,6 +225,6 @@ llvm::Error Loader::LoadIndex() {
bool Loader::HasFile(StringRef file) { bool Loader::HasFile(StringRef file) {
assert(m_loaded); 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); return (it != m_files.end()) && (*it == file);
} }

View File

@ -161,8 +161,8 @@ SymbolFileLoader::GetPaths(const UUID *uuid) const {
if (!uuid) if (!uuid)
return {}; return {};
auto it = std::lower_bound(m_symbol_files.begin(), m_symbol_files.end(), auto it = llvm::lower_bound(m_symbol_files,
SymbolFileProvider::Entry(uuid->GetAsString())); SymbolFileProvider::Entry(uuid->GetAsString()));
if (it == m_symbol_files.end()) if (it == m_symbol_files.end())
return {}; return {};
return std::make_pair<FileSpec, FileSpec>(FileSpec(it->module_path), return std::make_pair<FileSpec, FileSpec>(FileSpec(it->module_path),

View File

@ -1430,8 +1430,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
// Try to lookup the instruction number, and find the machine value number // Try to lookup the instruction number, and find the machine value number
// that it defines. It could be an instruction, or a PHI. // that it defines. It could be an instruction, or a PHI.
auto InstrIt = DebugInstrNumToInstr.find(InstNo); auto InstrIt = DebugInstrNumToInstr.find(InstNo);
auto PHIIt = std::lower_bound(DebugPHINumToValue.begin(), auto PHIIt = llvm::lower_bound(DebugPHINumToValue, InstNo);
DebugPHINumToValue.end(), InstNo);
if (InstrIt != DebugInstrNumToInstr.end()) { if (InstrIt != DebugInstrNumToInstr.end()) {
const MachineInstr &TargetInstr = *InstrIt->second.first; const MachineInstr &TargetInstr = *InstrIt->second.first;
uint64_t BlockNo = TargetInstr.getParent()->getNumber(); uint64_t BlockNo = TargetInstr.getParent()->getNumber();

View File

@ -1482,8 +1482,8 @@ void JITDylib::dump(raw_ostream &OS) {
void JITDylib::MaterializingInfo::addQuery( void JITDylib::MaterializingInfo::addQuery(
std::shared_ptr<AsynchronousSymbolQuery> Q) { std::shared_ptr<AsynchronousSymbolQuery> Q) {
auto I = std::lower_bound( auto I = llvm::lower_bound(
PendingQueries.rbegin(), PendingQueries.rend(), Q->getRequiredState(), llvm::reverse(PendingQueries), Q->getRequiredState(),
[](const std::shared_ptr<AsynchronousSymbolQuery> &V, SymbolState S) { [](const std::shared_ptr<AsynchronousSymbolQuery> &V, SymbolState S) {
return V->getRequiredState() <= S; return V->getRequiredState() <= S;
}); });

View File

@ -445,8 +445,8 @@ nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount) {
return Name; return Name;
}; };
auto It = std::lower_bound( auto It = llvm::lower_bound(
Matches.begin(), Matches.end(), Distance, Matches, Distance,
[&](const MatchForCodepointName &a, std::size_t Distance) { [&](const MatchForCodepointName &a, std::size_t Distance) {
if (Distance == a.Distance) if (Distance == a.Distance)
return a.Name < GetName(); return a.Name < GetName();

View File

@ -435,7 +435,7 @@ void PerfScriptReader::updateBinaryAddress(const MMapEvent &Event) {
} else { } else {
// Verify segments are loaded consecutively. // Verify segments are loaded consecutively.
const auto &Offsets = Binary->getTextSegmentOffsets(); 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) { if (It != Offsets.end() && *It == Event.Offset) {
// The event is for loading a separate executable segment. // The event is for loading a separate executable segment.
auto I = std::distance(Offsets.begin(), It); auto I = std::distance(Offsets.begin(), It);