[Mlir-commits] [mlir] [mlir] Use llvm::stable_sort (NFC) (PR #141186)
Kazu Hirata
llvmlistbot at llvm.org
Thu May 22 19:19:25 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/141186
None
>From 11ec2fc1dd434ed64b7145be3d222e720ba7a9ae Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 21 May 2025 20:17:09 -0700
Subject: [PATCH] [mlir] Use llvm::stable_sort (NFC)
---
.../Transforms/Utils/LoopEmitter.cpp | 2 +-
mlir/lib/IR/Diagnostics.cpp | 2 +-
mlir/lib/Rewrite/ByteCode.cpp | 8 +++---
mlir/lib/Rewrite/PatternApplicator.cpp | 2 +-
.../Transforms/Utils/CommutativityUtils.cpp | 3 +--
.../Transforms/Utils/DialectConversion.cpp | 26 +++++++++----------
6 files changed, 21 insertions(+), 22 deletions(-)
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();
More information about the Mlir-commits
mailing list