Skip to content

Commit 18ecff4

Browse files
[llvm] Use llvm::stable_sort (NFC) (#140067)
1 parent 2661e99 commit 18ecff4

File tree

9 files changed

+44
-50
lines changed

9 files changed

+44
-50
lines changed

llvm/lib/CGData/StableFunctionMap.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,10 @@ void StableFunctionMap::finalize(bool SkipTrim) {
206206
auto &[StableHash, SFS] = *It;
207207

208208
// Group stable functions by ModuleIdentifier.
209-
std::stable_sort(SFS.begin(), SFS.end(),
210-
[&](const std::unique_ptr<StableFunctionEntry> &L,
211-
const std::unique_ptr<StableFunctionEntry> &R) {
212-
return *getNameForId(L->ModuleNameId) <
213-
*getNameForId(R->ModuleNameId);
214-
});
209+
llvm::stable_sort(SFS, [&](const std::unique_ptr<StableFunctionEntry> &L,
210+
const std::unique_ptr<StableFunctionEntry> &R) {
211+
return *getNameForId(L->ModuleNameId) < *getNameForId(R->ModuleNameId);
212+
});
215213

216214
// Consider the first function as the root function.
217215
auto &RSF = SFS[0];

llvm/lib/CGData/StableFunctionMapRecord.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ getStableFunctionEntries(const StableFunctionMap &SFM) {
5656
for (auto &Func : P.second)
5757
FuncEntries.emplace_back(Func.get());
5858

59-
std::stable_sort(
60-
FuncEntries.begin(), FuncEntries.end(), [&](auto &A, auto &B) {
59+
llvm::stable_sort(
60+
FuncEntries, [&](auto &A, auto &B) {
6161
return std::tuple(A->Hash, SFM.getNameForId(A->ModuleNameId),
6262
SFM.getNameForId(A->FunctionNameId)) <
6363
std::tuple(B->Hash, SFM.getNameForId(B->ModuleNameId),

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,10 +6071,9 @@ TargetLowering::ConstraintGroup TargetLowering::getConstraintPreferences(
60716071
Ret.emplace_back(Code, CType);
60726072
}
60736073

6074-
std::stable_sort(
6075-
Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
6076-
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
6077-
});
6074+
llvm::stable_sort(Ret, [](ConstraintPair a, ConstraintPair b) {
6075+
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
6076+
});
60786077

60796078
return Ret;
60806079
}

llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void LVRange::sort() {
139139
};
140140

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

145145
void LVRange::print(raw_ostream &OS, bool Full) const {

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ bool checkIntegrityScopesTree(LVScope *Root) {
6565
TraverseScope(Root);
6666
bool PassIntegrity = true;
6767
if (Duplicate.size()) {
68-
std::stable_sort(begin(Duplicate), end(Duplicate),
69-
[](const auto &l, const auto &r) {
70-
return std::get<0>(l)->getID() < std::get<0>(r)->getID();
71-
});
68+
llvm::stable_sort(Duplicate, [](const auto &l, const auto &r) {
69+
return std::get<0>(l)->getID() < std::get<0>(r)->getID();
70+
});
7271

7372
auto PrintIndex = [](unsigned Index) {
7473
if (Index)

llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ void LVScope::sort() {
679679
[&](LVScope *Parent, LVSortFunction SortFunction) {
680680
auto Traverse = [&](auto &Set, LVSortFunction SortFunction) {
681681
if (Set)
682-
std::stable_sort(Set->begin(), Set->end(), SortFunction);
682+
llvm::stable_sort(*Set, SortFunction);
683683
};
684684
Traverse(Parent->Types, SortFunction);
685685
Traverse(Parent->Symbols, SortFunction);
@@ -1627,8 +1627,7 @@ void LVScopeCompileUnit::printMatchedElements(raw_ostream &OS,
16271627
bool UseMatchedElements) {
16281628
LVSortFunction SortFunction = getSortFunction();
16291629
if (SortFunction)
1630-
std::stable_sort(MatchedElements.begin(), MatchedElements.end(),
1631-
SortFunction);
1630+
llvm::stable_sort(MatchedElements, SortFunction);
16321631

16331632
// Check the type of elements required to be printed. 'MatchedElements'
16341633
// contains generic elements (lines, scopes, symbols, types). If we have a

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16317,10 +16317,10 @@ static SDValue CombineBaseUpdate(SDNode *N,
1631716317
// Try to fold with other users. Non-constant updates are considered
1631816318
// first, and constant updates are sorted to not break a sequence of
1631916319
// strided accesses (if there is any).
16320-
std::stable_sort(BaseUpdates.begin(), BaseUpdates.end(),
16321-
[](const BaseUpdateUser &LHS, const BaseUpdateUser &RHS) {
16322-
return LHS.ConstInc < RHS.ConstInc;
16323-
});
16320+
llvm::stable_sort(BaseUpdates,
16321+
[](const BaseUpdateUser &LHS, const BaseUpdateUser &RHS) {
16322+
return LHS.ConstInc < RHS.ConstInc;
16323+
});
1632416324
for (BaseUpdateUser &User : BaseUpdates) {
1632516325
if (TryCombineBaseUpdate(Target, User, /*SimpleConstIncOnly=*/false, DCI))
1632616326
return SDValue();

llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void SystemZELFFrameLowering::orderFrameObjects(
139139
return ADensityCmp < BDensityCmp;
140140
return A.DPairCount * B.ObjectSize < B.DPairCount * A.ObjectSize;
141141
};
142-
std::stable_sort(SortingObjects.begin(), SortingObjects.end(), CmpD12);
142+
llvm::stable_sort(SortingObjects, CmpD12);
143143

144144
// Now modify the original list to represent the final order that
145145
// we want.

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,8 +1832,8 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
18321832
DenseMap<const FuncTy *, unsigned> FuncToIndex;
18331833
for (const auto &[Idx, CallCtxInfo] : enumerate(Calls))
18341834
FuncToIndex.insert({CallCtxInfo.Func, Idx});
1835-
std::stable_sort(
1836-
Calls.begin(), Calls.end(),
1835+
llvm::stable_sort(
1836+
Calls,
18371837
[&FuncToIndex](const CallContextInfo &A, const CallContextInfo &B) {
18381838
return A.StackIds.size() > B.StackIds.size() ||
18391839
(A.StackIds.size() == B.StackIds.size() &&
@@ -3688,27 +3688,27 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones(
36883688
const unsigned AllocTypeCloningPriority[] = {/*None*/ 3, /*NotCold*/ 4,
36893689
/*Cold*/ 1,
36903690
/*NotColdCold*/ 2};
3691-
std::stable_sort(Node->CallerEdges.begin(), Node->CallerEdges.end(),
3692-
[&](const std::shared_ptr<ContextEdge> &A,
3693-
const std::shared_ptr<ContextEdge> &B) {
3694-
// Nodes with non-empty context ids should be sorted before
3695-
// those with empty context ids.
3696-
if (A->ContextIds.empty())
3697-
// Either B ContextIds are non-empty (in which case we
3698-
// should return false because B < A), or B ContextIds
3699-
// are empty, in which case they are equal, and we should
3700-
// maintain the original relative ordering.
3701-
return false;
3702-
if (B->ContextIds.empty())
3703-
return true;
3704-
3705-
if (A->AllocTypes == B->AllocTypes)
3706-
// Use the first context id for each edge as a
3707-
// tie-breaker.
3708-
return *A->ContextIds.begin() < *B->ContextIds.begin();
3709-
return AllocTypeCloningPriority[A->AllocTypes] <
3710-
AllocTypeCloningPriority[B->AllocTypes];
3711-
});
3691+
llvm::stable_sort(Node->CallerEdges,
3692+
[&](const std::shared_ptr<ContextEdge> &A,
3693+
const std::shared_ptr<ContextEdge> &B) {
3694+
// Nodes with non-empty context ids should be sorted
3695+
// before those with empty context ids.
3696+
if (A->ContextIds.empty())
3697+
// Either B ContextIds are non-empty (in which case we
3698+
// should return false because B < A), or B ContextIds
3699+
// are empty, in which case they are equal, and we
3700+
// should maintain the original relative ordering.
3701+
return false;
3702+
if (B->ContextIds.empty())
3703+
return true;
3704+
3705+
if (A->AllocTypes == B->AllocTypes)
3706+
// Use the first context id for each edge as a
3707+
// tie-breaker.
3708+
return *A->ContextIds.begin() < *B->ContextIds.begin();
3709+
return AllocTypeCloningPriority[A->AllocTypes] <
3710+
AllocTypeCloningPriority[B->AllocTypes];
3711+
});
37123712

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

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

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

0 commit comments

Comments
 (0)