Use llvm::less_second (NFC)

This commit is contained in:
Kazu Hirata 2022-06-04 22:48:32 -07:00
parent 9a8e65de8c
commit e0039b8d6a
10 changed files with 11 additions and 48 deletions

View File

@ -205,12 +205,6 @@ class UnexploredFirstPriorityQueue : public WorkList {
using QueuePriority = std::pair<int, unsigned long>; using QueuePriority = std::pair<int, unsigned long>;
using QueueItem = std::pair<WorkListUnit, QueuePriority>; using QueueItem = std::pair<WorkListUnit, QueuePriority>;
struct ExplorationComparator {
bool operator() (const QueueItem &LHS, const QueueItem &RHS) {
return LHS.second < RHS.second;
}
};
// Number of inserted nodes, used to emulate DFS ordering in the priority // Number of inserted nodes, used to emulate DFS ordering in the priority
// queue when insertions are equal. // queue when insertions are equal.
unsigned long Counter = 0; unsigned long Counter = 0;
@ -219,7 +213,7 @@ class UnexploredFirstPriorityQueue : public WorkList {
VisitedTimesMap NumReached; VisitedTimesMap NumReached;
// The top item is the largest one. // The top item is the largest one.
llvm::PriorityQueue<QueueItem, std::vector<QueueItem>, ExplorationComparator> llvm::PriorityQueue<QueueItem, std::vector<QueueItem>, llvm::less_second>
queue; queue;
public: public:
@ -267,12 +261,6 @@ class UnexploredFirstPriorityLocationQueue : public WorkList {
using QueuePriority = std::pair<int, unsigned long>; using QueuePriority = std::pair<int, unsigned long>;
using QueueItem = std::pair<WorkListUnit, QueuePriority>; using QueueItem = std::pair<WorkListUnit, QueuePriority>;
struct ExplorationComparator {
bool operator() (const QueueItem &LHS, const QueueItem &RHS) {
return LHS.second < RHS.second;
}
};
// Number of inserted nodes, used to emulate DFS ordering in the priority // Number of inserted nodes, used to emulate DFS ordering in the priority
// queue when insertions are equal. // queue when insertions are equal.
unsigned long Counter = 0; unsigned long Counter = 0;
@ -281,7 +269,7 @@ class UnexploredFirstPriorityLocationQueue : public WorkList {
VisitedTimesMap NumReached; VisitedTimesMap NumReached;
// The top item is the largest one. // The top item is the largest one.
llvm::PriorityQueue<QueueItem, std::vector<QueueItem>, ExplorationComparator> llvm::PriorityQueue<QueueItem, std::vector<QueueItem>, llvm::less_second>
queue; queue;
public: public:

View File

@ -257,9 +257,7 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
return LU->getOperandNo() > RU->getOperandNo(); return LU->getOperandNo() > RU->getOperandNo();
}); });
if (llvm::is_sorted(List, [](const Entry &L, const Entry &R) { if (llvm::is_sorted(List, llvm::less_second()))
return L.second < R.second;
}))
// Order is already correct. // Order is already correct.
return; return;

View File

@ -521,11 +521,7 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
for (auto E : COrDtors) for (auto E : COrDtors)
InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority)); InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
llvm::sort(InitsOrDeInits, llvm::sort(InitsOrDeInits, llvm::less_second());
[](const std::pair<Function *, unsigned> &LHS,
const std::pair<Function *, unsigned> &RHS) {
return LHS.second < RHS.second;
});
auto *InitOrDeInitFuncEntryBlock = auto *InitOrDeInitFuncEntryBlock =
BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc); BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);

View File

@ -223,9 +223,7 @@ predictValueUseListOrder(const Value *V, unsigned ID, const OrderMap &OM) {
return LU->getOperandNo() > RU->getOperandNo(); return LU->getOperandNo() > RU->getOperandNo();
}); });
if (llvm::is_sorted(List, [](const Entry &L, const Entry &R) { if (llvm::is_sorted(List, llvm::less_second()))
return L.second < R.second;
}))
// Order is already correct. // Order is already correct.
return {}; return {};

View File

@ -282,9 +282,7 @@ void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
// Copy out uses since UseMap will get touched below. // Copy out uses since UseMap will get touched below.
using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>; using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end()); SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
llvm::sort(Uses, [](const UseTy &L, const UseTy &R) { llvm::sort(Uses, llvm::less_second());
return L.second.second < R.second.second;
});
for (const auto &Pair : Uses) { for (const auto &Pair : Uses) {
// Check that this Ref hasn't disappeared after RAUW (when updating a // Check that this Ref hasn't disappeared after RAUW (when updating a
// previous Ref). // previous Ref).

View File

@ -778,10 +778,7 @@ bool AMDGPUPromoteAllocaImpl::hasSufficientLocalMem(const Function &F) {
// //
// FIXME: We should really do something to fix the addresses to a more optimal // FIXME: We should really do something to fix the addresses to a more optimal
// value instead // value instead
llvm::sort(AllocatedSizes, [](std::pair<uint64_t, Align> LHS, llvm::sort(AllocatedSizes, llvm::less_second());
std::pair<uint64_t, Align> RHS) {
return LHS.second < RHS.second;
});
// Check how much local memory is being used by global objects // Check how much local memory is being used by global objects
CurrentLocalMemUsage = 0; CurrentLocalMemUsage = 0;

View File

@ -2131,8 +2131,7 @@ SDValue WebAssemblyTargetLowering::LowerBUILD_VECTOR(SDValue Op,
auto GetMostCommon = [](auto &Counts) { auto GetMostCommon = [](auto &Counts) {
auto CommonIt = auto CommonIt =
std::max_element(Counts.begin(), Counts.end(), std::max_element(Counts.begin(), Counts.end(), llvm::less_second());
[](auto A, auto B) { return A.second < B.second; });
assert(CommonIt != Counts.end() && "Unexpected all-undef build_vector"); assert(CommonIt != Counts.end() && "Unexpected all-undef build_vector");
return *CommonIt; return *CommonIt;
}; };

View File

@ -2200,11 +2200,7 @@ bool LowerTypeTestsModule::lower() {
} }
Sets.emplace_back(I, MaxUniqueId); Sets.emplace_back(I, MaxUniqueId);
} }
llvm::sort(Sets, llvm::sort(Sets, llvm::less_second());
[](const std::pair<GlobalClassesTy::iterator, unsigned> &S1,
const std::pair<GlobalClassesTy::iterator, unsigned> &S2) {
return S1.second < S2.second;
});
// For each disjoint set we found... // For each disjoint set we found...
for (const auto &S : Sets) { for (const auto &S : Sets) {

View File

@ -658,12 +658,7 @@ Optional<SinkingInstructionCandidate> GVNSink::analyzeInstructionForSinking(
VNums[N]++; VNums[N]++;
} }
unsigned VNumToSink = unsigned VNumToSink =
std::max_element(VNums.begin(), VNums.end(), std::max_element(VNums.begin(), VNums.end(), llvm::less_second())->first;
[](const std::pair<uint32_t, unsigned> &I,
const std::pair<uint32_t, unsigned> &J) {
return I.second < J.second;
})
->first;
if (VNums[VNumToSink] == 1) if (VNums[VNumToSink] == 1)
// Can't sink anything! // Can't sink anything!

View File

@ -1559,10 +1559,8 @@ findMostPopularDest(BasicBlock *BB,
DestPopularity[PredToDest.second]++; DestPopularity[PredToDest.second]++;
// Find the most popular dest. // Find the most popular dest.
using VT = decltype(DestPopularity)::value_type;
auto MostPopular = std::max_element( auto MostPopular = std::max_element(
DestPopularity.begin(), DestPopularity.end(), DestPopularity.begin(), DestPopularity.end(), llvm::less_second());
[](const VT &L, const VT &R) { return L.second < R.second; });
// Okay, we have finally picked the most popular destination. // Okay, we have finally picked the most popular destination.
return MostPopular->first; return MostPopular->first;