-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_llvm_stable_sort_llvm
May 15, 2025
Merged
[llvm] Use llvm::stable_sort (NFC) #140067
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_llvm_stable_sort_llvm
May 15, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-debuginfo Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140067.diff 9 Files Affected:
diff --git a/llvm/lib/CGData/StableFunctionMap.cpp b/llvm/lib/CGData/StableFunctionMap.cpp
index 4afe77d78a4fe..87f1e76afb60b 100644
--- a/llvm/lib/CGData/StableFunctionMap.cpp
+++ b/llvm/lib/CGData/StableFunctionMap.cpp
@@ -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];
diff --git a/llvm/lib/CGData/StableFunctionMapRecord.cpp b/llvm/lib/CGData/StableFunctionMapRecord.cpp
index 8eb667a651ebe..e23b0e072c9a3 100644
--- a/llvm/lib/CGData/StableFunctionMapRecord.cpp
+++ b/llvm/lib/CGData/StableFunctionMapRecord.cpp
@@ -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),
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index a476b191abf62..f17d6a2787889 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -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;
}
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp
index b6003fcb8b93b..4dc4b588ad60d 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVRange.cpp
@@ -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 {
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
index c3f1d6843957f..328ced9f4eb66 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
@@ -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)
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
index 8bbaf93db0caa..e1ea5da4dc51a 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp
@@ -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);
@@ -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
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index fde7f04cc1747..c9d96f85dd370 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -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();
diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
index d24a94ab25ff3..4bef8ff9bbac1 100644
--- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
@@ -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.
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 4b2683dc6c2a7..5b4350845b726 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -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() &&
@@ -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);
@@ -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
|
arsenm
approved these changes
May 15, 2025
dwblaikie
approved these changes
May 15, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.