Skip to content

[llvm] Use llvm::stable_sort (NFC) #140067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions llvm/lib/CGData/StableFunctionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,10 @@ void StableFunctionMap::finalize(bool SkipTrim) {
auto &[StableHash, SFS] = *It;

// Group stable functions by ModuleIdentifier.
std::stable_sort(SFS.begin(), SFS.end(),
[&](const std::unique_ptr<StableFunctionEntry> &L,
const std::unique_ptr<StableFunctionEntry> &R) {
return *getNameForId(L->ModuleNameId) <
*getNameForId(R->ModuleNameId);
});
llvm::stable_sort(SFS, [&](const std::unique_ptr<StableFunctionEntry> &L,
const std::unique_ptr<StableFunctionEntry> &R) {
return *getNameForId(L->ModuleNameId) < *getNameForId(R->ModuleNameId);
});

// Consider the first function as the root function.
auto &RSF = SFS[0];
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CGData/StableFunctionMapRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ getStableFunctionEntries(const StableFunctionMap &SFM) {
for (auto &Func : P.second)
FuncEntries.emplace_back(Func.get());

std::stable_sort(
FuncEntries.begin(), FuncEntries.end(), [&](auto &A, auto &B) {
llvm::stable_sort(
FuncEntries, [&](auto &A, auto &B) {
return std::tuple(A->Hash, SFM.getNameForId(A->ModuleNameId),
SFM.getNameForId(A->FunctionNameId)) <
std::tuple(B->Hash, SFM.getNameForId(B->ModuleNameId),
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6071,10 +6071,9 @@ TargetLowering::ConstraintGroup TargetLowering::getConstraintPreferences(
Ret.emplace_back(Code, CType);
}

std::stable_sort(
Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
});
llvm::stable_sort(Ret, [](ConstraintPair a, ConstraintPair b) {
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
});

return Ret;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void LVRange::sort() {
};

// Sort the ranges using low address and range size.
std::stable_sort(RangeEntries.begin(), RangeEntries.end(), CompareRangeEntry);
llvm::stable_sort(RangeEntries, CompareRangeEntry);
}

void LVRange::print(raw_ostream &OS, bool Full) const {
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ bool checkIntegrityScopesTree(LVScope *Root) {
TraverseScope(Root);
bool PassIntegrity = true;
if (Duplicate.size()) {
std::stable_sort(begin(Duplicate), end(Duplicate),
[](const auto &l, const auto &r) {
return std::get<0>(l)->getID() < std::get<0>(r)->getID();
});
llvm::stable_sort(Duplicate, [](const auto &l, const auto &r) {
return std::get<0>(l)->getID() < std::get<0>(r)->getID();
});

auto PrintIndex = [](unsigned Index) {
if (Index)
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ void LVScope::sort() {
[&](LVScope *Parent, LVSortFunction SortFunction) {
auto Traverse = [&](auto &Set, LVSortFunction SortFunction) {
if (Set)
std::stable_sort(Set->begin(), Set->end(), SortFunction);
llvm::stable_sort(*Set, SortFunction);
};
Traverse(Parent->Types, SortFunction);
Traverse(Parent->Symbols, SortFunction);
Expand Down Expand Up @@ -1627,8 +1627,7 @@ void LVScopeCompileUnit::printMatchedElements(raw_ostream &OS,
bool UseMatchedElements) {
LVSortFunction SortFunction = getSortFunction();
if (SortFunction)
std::stable_sort(MatchedElements.begin(), MatchedElements.end(),
SortFunction);
llvm::stable_sort(MatchedElements, SortFunction);

// Check the type of elements required to be printed. 'MatchedElements'
// contains generic elements (lines, scopes, symbols, types). If we have a
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16317,10 +16317,10 @@ static SDValue CombineBaseUpdate(SDNode *N,
// Try to fold with other users. Non-constant updates are considered
// first, and constant updates are sorted to not break a sequence of
// strided accesses (if there is any).
std::stable_sort(BaseUpdates.begin(), BaseUpdates.end(),
[](const BaseUpdateUser &LHS, const BaseUpdateUser &RHS) {
return LHS.ConstInc < RHS.ConstInc;
});
llvm::stable_sort(BaseUpdates,
[](const BaseUpdateUser &LHS, const BaseUpdateUser &RHS) {
return LHS.ConstInc < RHS.ConstInc;
});
for (BaseUpdateUser &User : BaseUpdates) {
if (TryCombineBaseUpdate(Target, User, /*SimpleConstIncOnly=*/false, DCI))
return SDValue();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void SystemZELFFrameLowering::orderFrameObjects(
return ADensityCmp < BDensityCmp;
return A.DPairCount * B.ObjectSize < B.DPairCount * A.ObjectSize;
};
std::stable_sort(SortingObjects.begin(), SortingObjects.end(), CmpD12);
llvm::stable_sort(SortingObjects, CmpD12);

// Now modify the original list to represent the final order that
// we want.
Expand Down
49 changes: 24 additions & 25 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,8 +1832,8 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
DenseMap<const FuncTy *, unsigned> FuncToIndex;
for (const auto &[Idx, CallCtxInfo] : enumerate(Calls))
FuncToIndex.insert({CallCtxInfo.Func, Idx});
std::stable_sort(
Calls.begin(), Calls.end(),
llvm::stable_sort(
Calls,
[&FuncToIndex](const CallContextInfo &A, const CallContextInfo &B) {
return A.StackIds.size() > B.StackIds.size() ||
(A.StackIds.size() == B.StackIds.size() &&
Expand Down Expand Up @@ -3688,27 +3688,27 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones(
const unsigned AllocTypeCloningPriority[] = {/*None*/ 3, /*NotCold*/ 4,
/*Cold*/ 1,
/*NotColdCold*/ 2};
std::stable_sort(Node->CallerEdges.begin(), Node->CallerEdges.end(),
[&](const std::shared_ptr<ContextEdge> &A,
const std::shared_ptr<ContextEdge> &B) {
// Nodes with non-empty context ids should be sorted before
// those with empty context ids.
if (A->ContextIds.empty())
// Either B ContextIds are non-empty (in which case we
// should return false because B < A), or B ContextIds
// are empty, in which case they are equal, and we should
// maintain the original relative ordering.
return false;
if (B->ContextIds.empty())
return true;

if (A->AllocTypes == B->AllocTypes)
// Use the first context id for each edge as a
// tie-breaker.
return *A->ContextIds.begin() < *B->ContextIds.begin();
return AllocTypeCloningPriority[A->AllocTypes] <
AllocTypeCloningPriority[B->AllocTypes];
});
llvm::stable_sort(Node->CallerEdges,
[&](const std::shared_ptr<ContextEdge> &A,
const std::shared_ptr<ContextEdge> &B) {
// Nodes with non-empty context ids should be sorted
// before those with empty context ids.
if (A->ContextIds.empty())
// Either B ContextIds are non-empty (in which case we
// should return false because B < A), or B ContextIds
// are empty, in which case they are equal, and we
// should maintain the original relative ordering.
return false;
if (B->ContextIds.empty())
return true;

if (A->AllocTypes == B->AllocTypes)
// Use the first context id for each edge as a
// tie-breaker.
return *A->ContextIds.begin() < *B->ContextIds.begin();
return AllocTypeCloningPriority[A->AllocTypes] <
AllocTypeCloningPriority[B->AllocTypes];
});

assert(Node->AllocTypes != (uint8_t)AllocationType::None);

Expand Down Expand Up @@ -4180,8 +4180,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::mergeNodeCalleeClones(
// their caller edge counts, putting the original non-clone node first in
// cases of a tie. This simplifies finding an existing node to use as the
// merge node.
std::stable_sort(CalleeEdges.begin(), CalleeEdges.end(),
CalleeCallerEdgeLessThan);
llvm::stable_sort(CalleeEdges, CalleeCallerEdgeLessThan);

/// Find other callers of the given set of callee edges that can
/// share the same callee merge node. See the comments at this method
Expand Down