Skip to content

[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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/IR/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/Rewrite/ByteCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Rewrite/PatternApplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Transforms/Utils/CommutativityUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions mlir/lib/Transforms/Utils/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading