-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Use llvm::stable_sort (NFC) #141186
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_20250522_llvm_stable_sort_mlir
May 23, 2025
Merged
[mlir] Use llvm::stable_sort (NFC) #141186
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_20250522_llvm_stable_sort_mlir
May 23, 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-mlir @llvm/pr-subscribers-mlir-sparse Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/141186.diff 6 Files Affected:
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
index 3a77ce347b1c0..84129edee3753 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
@@ -404,7 +404,7 @@ void LoopEmitter::categorizeIterators(
spIters.push_back(it);
}
- std::stable_sort(spIters.begin(), spIters.end(), [](auto lhs, auto rhs) {
+ llvm::stable_sort(spIters, [](auto lhs, auto rhs) {
// AffineUnRed > Affine > Slice > Trivial
return static_cast<uint8_t>(lhs->kind) > static_cast<uint8_t>(rhs->kind);
});
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 79697be2b45ea..3a0f81d240336 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -979,7 +979,7 @@ struct ParallelDiagnosticHandlerImpl : public llvm::PrettyStackTraceEntry {
// Stable sort all of the diagnostics that were emitted. This creates a
// deterministic ordering for the diagnostics based upon which order id they
// were emitted for.
- std::stable_sort(diagnostics.begin(), diagnostics.end());
+ llvm::stable_sort(diagnostics);
// Emit each diagnostic to the context again.
for (ThreadDiagnostic &diag : diagnostics)
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index 5939d0d00d328..ae3f22dec9f2c 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -2346,10 +2346,10 @@ void PDLByteCode::match(Operation *op, PatternRewriter &rewriter,
assert(succeeded(executeResult) && "unexpected matcher execution failure");
// Order the found matches by benefit.
- std::stable_sort(matches.begin(), matches.end(),
- [](const MatchResult &lhs, const MatchResult &rhs) {
- return lhs.benefit > rhs.benefit;
- });
+ llvm::stable_sort(matches,
+ [](const MatchResult &lhs, const MatchResult &rhs) {
+ return lhs.benefit > rhs.benefit;
+ });
}
LogicalResult PDLByteCode::rewrite(PatternRewriter &rewriter,
diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index ea43f8a147d47..4a12183492fd4 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -103,7 +103,7 @@ void PatternApplicator::applyCostModel(CostModel model) {
// Sort patterns with highest benefit first, and remove those that are
// impossible to match.
- std::stable_sort(list.begin(), list.end(), cmp);
+ llvm::stable_sort(list, cmp);
while (!list.empty() && benefits[list.back()].isImpossibleToMatch()) {
LLVM_DEBUG(logImpossibleToMatch(*list.back()));
list.pop_back();
diff --git a/mlir/lib/Transforms/Utils/CommutativityUtils.cpp b/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
index 5ba6e4747cb57..8b132b5e484bb 100644
--- a/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
+++ b/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
@@ -297,8 +297,7 @@ class SortCommutativeOperands : public RewritePattern {
}
// Sort the operands.
- std::stable_sort(commOperands.begin(), commOperands.end(),
- commutativeOperandComparator);
+ llvm::stable_sort(commOperands, commutativeOperandComparator);
SmallVector<Value, 2> sortedOperands;
for (const std::unique_ptr<CommutativeOperand> &commOperand : commOperands)
sortedOperands.push_back(commOperand->operand);
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index bd11bbe58a3f6..02657b500ebfa 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2520,19 +2520,19 @@ unsigned OperationLegalizer::applyCostModelToPatterns(
return minDepth;
// Sort the patterns by those likely to be the most beneficial.
- std::stable_sort(patternsByDepth.begin(), patternsByDepth.end(),
- [](const std::pair<const Pattern *, unsigned> &lhs,
- const std::pair<const Pattern *, unsigned> &rhs) {
- // First sort by the smaller pattern legalization
- // depth.
- if (lhs.second != rhs.second)
- return lhs.second < rhs.second;
-
- // Then sort by the larger pattern benefit.
- auto lhsBenefit = lhs.first->getBenefit();
- auto rhsBenefit = rhs.first->getBenefit();
- return lhsBenefit > rhsBenefit;
- });
+ llvm::stable_sort(patternsByDepth,
+ [](const std::pair<const Pattern *, unsigned> &lhs,
+ const std::pair<const Pattern *, unsigned> &rhs) {
+ // First sort by the smaller pattern legalization
+ // depth.
+ if (lhs.second != rhs.second)
+ return lhs.second < rhs.second;
+
+ // Then sort by the larger pattern benefit.
+ auto lhsBenefit = lhs.first->getBenefit();
+ auto rhsBenefit = rhs.first->getBenefit();
+ return lhsBenefit > rhsBenefit;
+ });
// Update the legalization pattern to use the new sorted list.
patterns.clear();
|
@llvm/pr-subscribers-mlir-core Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/141186.diff 6 Files Affected:
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
index 3a77ce347b1c0..84129edee3753 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp
@@ -404,7 +404,7 @@ void LoopEmitter::categorizeIterators(
spIters.push_back(it);
}
- std::stable_sort(spIters.begin(), spIters.end(), [](auto lhs, auto rhs) {
+ llvm::stable_sort(spIters, [](auto lhs, auto rhs) {
// AffineUnRed > Affine > Slice > Trivial
return static_cast<uint8_t>(lhs->kind) > static_cast<uint8_t>(rhs->kind);
});
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 79697be2b45ea..3a0f81d240336 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -979,7 +979,7 @@ struct ParallelDiagnosticHandlerImpl : public llvm::PrettyStackTraceEntry {
// Stable sort all of the diagnostics that were emitted. This creates a
// deterministic ordering for the diagnostics based upon which order id they
// were emitted for.
- std::stable_sort(diagnostics.begin(), diagnostics.end());
+ llvm::stable_sort(diagnostics);
// Emit each diagnostic to the context again.
for (ThreadDiagnostic &diag : diagnostics)
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index 5939d0d00d328..ae3f22dec9f2c 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -2346,10 +2346,10 @@ void PDLByteCode::match(Operation *op, PatternRewriter &rewriter,
assert(succeeded(executeResult) && "unexpected matcher execution failure");
// Order the found matches by benefit.
- std::stable_sort(matches.begin(), matches.end(),
- [](const MatchResult &lhs, const MatchResult &rhs) {
- return lhs.benefit > rhs.benefit;
- });
+ llvm::stable_sort(matches,
+ [](const MatchResult &lhs, const MatchResult &rhs) {
+ return lhs.benefit > rhs.benefit;
+ });
}
LogicalResult PDLByteCode::rewrite(PatternRewriter &rewriter,
diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index ea43f8a147d47..4a12183492fd4 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -103,7 +103,7 @@ void PatternApplicator::applyCostModel(CostModel model) {
// Sort patterns with highest benefit first, and remove those that are
// impossible to match.
- std::stable_sort(list.begin(), list.end(), cmp);
+ llvm::stable_sort(list, cmp);
while (!list.empty() && benefits[list.back()].isImpossibleToMatch()) {
LLVM_DEBUG(logImpossibleToMatch(*list.back()));
list.pop_back();
diff --git a/mlir/lib/Transforms/Utils/CommutativityUtils.cpp b/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
index 5ba6e4747cb57..8b132b5e484bb 100644
--- a/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
+++ b/mlir/lib/Transforms/Utils/CommutativityUtils.cpp
@@ -297,8 +297,7 @@ class SortCommutativeOperands : public RewritePattern {
}
// Sort the operands.
- std::stable_sort(commOperands.begin(), commOperands.end(),
- commutativeOperandComparator);
+ llvm::stable_sort(commOperands, commutativeOperandComparator);
SmallVector<Value, 2> sortedOperands;
for (const std::unique_ptr<CommutativeOperand> &commOperand : commOperands)
sortedOperands.push_back(commOperand->operand);
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index bd11bbe58a3f6..02657b500ebfa 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2520,19 +2520,19 @@ unsigned OperationLegalizer::applyCostModelToPatterns(
return minDepth;
// Sort the patterns by those likely to be the most beneficial.
- std::stable_sort(patternsByDepth.begin(), patternsByDepth.end(),
- [](const std::pair<const Pattern *, unsigned> &lhs,
- const std::pair<const Pattern *, unsigned> &rhs) {
- // First sort by the smaller pattern legalization
- // depth.
- if (lhs.second != rhs.second)
- return lhs.second < rhs.second;
-
- // Then sort by the larger pattern benefit.
- auto lhsBenefit = lhs.first->getBenefit();
- auto rhsBenefit = rhs.first->getBenefit();
- return lhsBenefit > rhsBenefit;
- });
+ llvm::stable_sort(patternsByDepth,
+ [](const std::pair<const Pattern *, unsigned> &lhs,
+ const std::pair<const Pattern *, unsigned> &rhs) {
+ // First sort by the smaller pattern legalization
+ // depth.
+ if (lhs.second != rhs.second)
+ return lhs.second < rhs.second;
+
+ // Then sort by the larger pattern benefit.
+ auto lhsBenefit = lhs.first->getBenefit();
+ auto rhsBenefit = rhs.first->getBenefit();
+ return lhsBenefit > rhsBenefit;
+ });
// Update the legalization pattern to use the new sorted list.
patterns.clear();
|
matthias-springer
approved these changes
May 23, 2025
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Jun 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.