[llvm][clang][bolt][NFC] Use llvm::less_first() when applicable

One could reuse this functor instead of rolling out your own version.
There were a couple other cases where the code was similar, but not
quite the same, such as it might have an assertion in the lambda or other
constructs. Thus, I've not touched any of those, as it might change the
behavior in some way.

As per https://discourse.llvm.org/t/submitting-simple-nfc-patches/62640/3?u=steakhal
Chris Lattner
> LLVM intentionally has a “yes, you can apply common sense judgement to
> things” policy when it comes to code review. If you are doing mechanical
> patches (e.g. adopting less_first) that apply to the entire monorepo,
> then you don’t need everyone in the monorepo to sign off on it. Having
> some +1 validation from someone is useful, but you don’t need everyone
> whose code you touch to weigh in.

Differential Revision: https://reviews.llvm.org/D126068
This commit is contained in:
Balazs Benics 2022-05-27 11:15:23 +02:00
parent f13050eca3
commit 3988bd1398
11 changed files with 20 additions and 62 deletions

View File

@ -91,14 +91,9 @@ LongJmpPass::createNewStub(BinaryBasicBlock &SourceBB, const MCSymbol *TgtSym,
// Register this in stubs maps // Register this in stubs maps
auto registerInMap = [&](StubGroupsTy &Map) { auto registerInMap = [&](StubGroupsTy &Map) {
StubGroupTy &StubGroup = Map[TgtSym]; StubGroupTy &StubGroup = Map[TgtSym];
StubGroup.insert( StubGroup.insert(std::lower_bound(StubGroup.begin(), StubGroup.end(),
std::lower_bound(
StubGroup.begin(), StubGroup.end(),
std::make_pair(AtAddress, nullptr), std::make_pair(AtAddress, nullptr),
[&](const std::pair<uint64_t, BinaryBasicBlock *> &LHS, llvm::less_first()),
const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
return LHS.first < RHS.first;
}),
std::make_pair(AtAddress, StubBB.get())); std::make_pair(AtAddress, StubBB.get()));
}; };
@ -129,12 +124,9 @@ BinaryBasicBlock *LongJmpPass::lookupStubFromGroup(
const StubGroupTy &Candidates = CandidatesIter->second; const StubGroupTy &Candidates = CandidatesIter->second;
if (Candidates.empty()) if (Candidates.empty())
return nullptr; return nullptr;
auto Cand = std::lower_bound( auto Cand =
Candidates.begin(), Candidates.end(), std::make_pair(DotAddress, nullptr), std::lower_bound(Candidates.begin(), Candidates.end(),
[&](const std::pair<uint64_t, BinaryBasicBlock *> &LHS, std::make_pair(DotAddress, nullptr), llvm::less_first());
const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
return LHS.first < RHS.first;
});
if (Cand == Candidates.end()) if (Cand == Candidates.end())
return nullptr; return nullptr;
if (Cand != Candidates.begin()) { if (Cand != Candidates.begin()) {
@ -259,11 +251,7 @@ void LongJmpPass::updateStubGroups() {
for (auto &KeyVal : StubGroups) { for (auto &KeyVal : StubGroups) {
for (StubTy &Elem : KeyVal.second) for (StubTy &Elem : KeyVal.second)
Elem.first = BBAddresses[Elem.second]; Elem.first = BBAddresses[Elem.second];
std::sort(KeyVal.second.begin(), KeyVal.second.end(), std::sort(KeyVal.second.begin(), KeyVal.second.end(), llvm::less_first());
[&](const std::pair<uint64_t, BinaryBasicBlock *> &LHS,
const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
return LHS.first < RHS.first;
});
} }
}; };

View File

@ -413,11 +413,7 @@ static std::error_code collectModuleHeaderIncludes(
// Sort header paths and make the header inclusion order deterministic // Sort header paths and make the header inclusion order deterministic
// across different OSs and filesystems. // across different OSs and filesystems.
llvm::sort(Headers.begin(), Headers.end(), []( llvm::sort(Headers.begin(), Headers.end(), llvm::less_first());
const std::pair<std::string, const FileEntry *> &LHS,
const std::pair<std::string, const FileEntry *> &RHS) {
return LHS.first < RHS.first;
});
for (auto &H : Headers) { for (auto &H : Headers) {
// Include this header as part of the umbrella directory. // Include this header as part of the umbrella directory.
Module->addTopHeader(H.second); Module->addTopHeader(H.second);

View File

@ -5430,8 +5430,7 @@ static void DiagnoseBaseOrMemInitializerOrder(
return; return;
// Sort based on the ideal order, first in the pair. // Sort based on the ideal order, first in the pair.
llvm::sort(CorrelatedInitOrder, llvm::sort(CorrelatedInitOrder, llvm::less_first());
[](auto &LHS, auto &RHS) { return LHS.first < RHS.first; });
// Introduce a new scope as SemaDiagnosticBuilder needs to be destroyed to // Introduce a new scope as SemaDiagnosticBuilder needs to be destroyed to
// emit the diagnostic before we can try adding notes. // emit the diagnostic before we can try adding notes.

View File

@ -717,9 +717,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
std::make_pair(Names[i]->getName(), Exprs[i])); std::make_pair(Names[i]->getName(), Exprs[i]));
// Sort NamedOperandList. // Sort NamedOperandList.
std::stable_sort(NamedOperandList.begin(), NamedOperandList.end(), std::stable_sort(NamedOperandList.begin(), NamedOperandList.end(),
[](const NamedOperand &LHS, const NamedOperand &RHS) { llvm::less_first());
return LHS.first < RHS.first;
});
// Find adjacent duplicate operand. // Find adjacent duplicate operand.
SmallVector<NamedOperand, 4>::iterator Found = SmallVector<NamedOperand, 4>::iterator Found =
std::adjacent_find(begin(NamedOperandList), end(NamedOperandList), std::adjacent_find(begin(NamedOperandList), end(NamedOperandList),

View File

@ -101,10 +101,7 @@ OPTIONS:
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
}; };
llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS, llvm::sort(PrintableOptions, llvm::less_first());
const OptionAndDescriptionTy &RHS) {
return LHS.first < RHS.first;
});
for (const auto &Pair : PrintableOptions) { for (const auto &Pair : PrintableOptions) {
AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2, AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,

View File

@ -299,9 +299,7 @@ STRING_LOCATION_STDPAIR(MethodDecl, getTypeSpecStartLoc())
auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors); auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors);
llvm::sort(ExpectedRanges, [](const auto &LHS, const auto &RHS) { llvm::sort(ExpectedRanges, llvm::less_first());
return LHS.first < RHS.first;
});
// clang-format off // clang-format off
EXPECT_EQ( EXPECT_EQ(

View File

@ -339,11 +339,7 @@ public:
/// Sort the lookup set by pointer value. This sort is fast but sensitive to /// Sort the lookup set by pointer value. This sort is fast but sensitive to
/// allocation order and so should not be used where a consistent order is /// allocation order and so should not be used where a consistent order is
/// required. /// required.
void sortByAddress() { void sortByAddress() { llvm::sort(Symbols, llvm::less_first()); }
llvm::sort(Symbols, [](const value_type &LHS, const value_type &RHS) {
return LHS.first < RHS.first;
});
}
/// Sort the lookup set lexicographically. This sort is slow but the order /// Sort the lookup set lexicographically. This sort is slow but the order
/// is unaffected by allocation order. /// is unaffected by allocation order.

View File

@ -1018,11 +1018,7 @@ AttributeList::get(LLVMContext &C,
if (Attrs.empty()) if (Attrs.empty())
return {}; return {};
assert(llvm::is_sorted(Attrs, assert(llvm::is_sorted(Attrs, llvm::less_first()) &&
[](const std::pair<unsigned, Attribute> &LHS,
const std::pair<unsigned, Attribute> &RHS) {
return LHS.first < RHS.first;
}) &&
"Misordered Attributes list!"); "Misordered Attributes list!");
assert(llvm::all_of(Attrs, assert(llvm::all_of(Attrs,
[](const std::pair<unsigned, Attribute> &Pair) { [](const std::pair<unsigned, Attribute> &Pair) {
@ -1055,11 +1051,7 @@ AttributeList::get(LLVMContext &C,
if (Attrs.empty()) if (Attrs.empty())
return {}; return {};
assert(llvm::is_sorted(Attrs, assert(llvm::is_sorted(Attrs, llvm::less_first()) &&
[](const std::pair<unsigned, AttributeSet> &LHS,
const std::pair<unsigned, AttributeSet> &RHS) {
return LHS.first < RHS.first;
}) &&
"Misordered Attributes list!"); "Misordered Attributes list!");
assert(llvm::none_of(Attrs, assert(llvm::none_of(Attrs,
[](const std::pair<unsigned, AttributeSet> &Pair) { [](const std::pair<unsigned, AttributeSet> &Pair) {

View File

@ -634,9 +634,7 @@ void MachOWriter::writeTail() {
} }
} }
llvm::sort(Queue, [](const WriteOperation &LHS, const WriteOperation &RHS) { llvm::sort(Queue, llvm::less_first());
return LHS.first < RHS.first;
});
for (auto WriteOp : Queue) for (auto WriteOp : Queue)
(this->*WriteOp.second)(); (this->*WriteOp.second)();

View File

@ -62,9 +62,7 @@ void DebugMapObject::print(raw_ostream &OS) const {
Entries.reserve(Symbols.getNumItems()); Entries.reserve(Symbols.getNumItems());
for (const auto &Sym : Symbols) for (const auto &Sym : Symbols)
Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue())); Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue()));
llvm::sort(Entries, [](const Entry &LHS, const Entry &RHS) { llvm::sort(Entries, llvm::less_first());
return LHS.first < RHS.first;
});
for (const auto &Sym : Entries) { for (const auto &Sym : Entries) {
if (Sym.second.ObjectAddress) if (Sym.second.ObjectAddress)
OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress)); OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));

View File

@ -158,10 +158,8 @@ AttributeList convertAttributeRefVecToAttributeList(
V.first, convertAttributeRefToAttributeSet(C, V.second)); V.first, convertAttributeRefToAttributeSet(C, V.second));
}); });
sort(SetVec, [](const std::pair<unsigned, AttributeSet> &LHS, // All values are unique.
const std::pair<unsigned, AttributeSet> &RHS) { sort(SetVec, llvm::less_first());
return LHS.first < RHS.first; // All values are unique.
});
return AttributeList::get(C, SetVec); return AttributeList::get(C, SetVec);
} }