Skip to content

Commit 78af0f3

Browse files
authored
[mlir][NFC] Use llvm::sort (#140261)
1 parent 8696d16 commit 78af0f3

File tree

8 files changed

+40
-44
lines changed

8 files changed

+40
-44
lines changed

mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ coalesceTileLiveRanges(DenseMap<Value, LiveRange> &initialLiveRanges) {
497497

498498
// Sort the new live ranges by starting point (ready for tile allocation).
499499
auto coalescedLiveRanges = uniqueLiveRanges.takeVector();
500-
std::sort(coalescedLiveRanges.begin(), coalescedLiveRanges.end(),
501-
[](LiveRange *a, LiveRange *b) { return *a < *b; });
500+
llvm::sort(coalescedLiveRanges,
501+
[](LiveRange *a, LiveRange *b) { return *a < *b; });
502502
return std::move(coalescedLiveRanges);
503503
}
504504

@@ -824,8 +824,8 @@ LogicalResult mlir::arm_sme::allocateSMETiles(FunctionOpInterface function,
824824
[&](LiveRange const &liveRange) { return !liveRange.empty(); });
825825
auto initialRanges = llvm::to_vector(llvm::map_range(
826826
nonEmpty, [](LiveRange const &liveRange) { return &liveRange; }));
827-
std::sort(initialRanges.begin(), initialRanges.end(),
828-
[](LiveRange const *a, LiveRange const *b) { return *a < *b; });
827+
llvm::sort(initialRanges,
828+
[](LiveRange const *a, LiveRange const *b) { return *a < *b; });
829829
llvm::errs() << "\n========== Initial Live Ranges:\n";
830830
dumpLiveRanges(operationToIndexMap, initialRanges, function);
831831
}

mlir/lib/Dialect/Bufferization/IR/BufferDeallocationOpInterface.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ void DeallocationState::getMemrefsToRetain(
177177
// liveOut has non-deterministic order because it was constructed by iterating
178178
// over a hash-set.
179179
SmallVector<Value> retainedByLiveness(liveOut.begin(), liveOut.end());
180-
std::sort(retainedByLiveness.begin(), retainedByLiveness.end(),
181-
ValueComparator());
180+
llvm::sort(retainedByLiveness, ValueComparator());
182181
toRetain.append(retainedByLiveness);
183182
}
184183

mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ computeTransposeBroadcast(AffineMap &map) {
103103

104104
// If dims are not monotonically increasing then transpose is present.
105105
SmallVector<int64_t> sortedResMap(minorResult);
106-
std::sort(sortedResMap.begin(), sortedResMap.end());
106+
llvm::sort(sortedResMap);
107107
bool hasTranspose = !std::equal(minorResult.begin(), minorResult.end(),
108108
sortedResMap.begin(), sortedResMap.end());
109109

mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenEnv.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ static bool isMaterializing(Value val) {
3131
/// Sorts the dependent loops such that it is ordered in the same sequence in
3232
/// which loops will be generated.
3333
static void sortDependentLoops(std::vector<LoopCoeffPair> &target) {
34-
std::sort(target.begin(), target.end(),
35-
[](const LoopCoeffPair &l, const LoopCoeffPair &r) {
36-
assert(std::addressof(l) == std::addressof(r) || l != r);
37-
return l.first < r.first;
38-
});
34+
llvm::sort(target, [](const LoopCoeffPair &l, const LoopCoeffPair &r) {
35+
assert(std::addressof(l) == std::addressof(r) || l != r);
36+
return l.first < r.first;
37+
});
3938
}
4039
//===----------------------------------------------------------------------===//
4140
// Code generation environment constructor and general methods

mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,26 +459,25 @@ void sparse_tensor::foreachInSparseConstant(
459459
}
460460

461461
// Sorts the sparse element attribute based on coordinates.
462-
std::sort(elems.begin(), elems.end(),
463-
[order](const ElementAttr &lhs, const ElementAttr &rhs) {
464-
if (std::addressof(lhs) == std::addressof(rhs))
465-
return false;
466-
467-
auto lhsCoords = llvm::map_to_vector(
468-
lhs.first, [](IntegerAttr i) { return i.getInt(); });
469-
auto rhsCoords = llvm::map_to_vector(
470-
rhs.first, [](IntegerAttr i) { return i.getInt(); });
471-
472-
SmallVector<int64_t, 4> lhsLvlCrds = order.compose(lhsCoords);
473-
SmallVector<int64_t, 4> rhsLvlCrds = order.compose(rhsCoords);
474-
// Sort the element based on the lvl coordinates.
475-
for (Level l = 0; l < order.getNumResults(); l++) {
476-
if (lhsLvlCrds[l] == rhsLvlCrds[l])
477-
continue;
478-
return lhsLvlCrds[l] < rhsLvlCrds[l];
479-
}
480-
llvm_unreachable("no equal coordinate in sparse element attr");
481-
});
462+
llvm::sort(elems, [order](const ElementAttr &lhs, const ElementAttr &rhs) {
463+
if (std::addressof(lhs) == std::addressof(rhs))
464+
return false;
465+
466+
auto lhsCoords = llvm::map_to_vector(
467+
lhs.first, [](IntegerAttr i) { return i.getInt(); });
468+
auto rhsCoords = llvm::map_to_vector(
469+
rhs.first, [](IntegerAttr i) { return i.getInt(); });
470+
471+
SmallVector<int64_t, 4> lhsLvlCrds = order.compose(lhsCoords);
472+
SmallVector<int64_t, 4> rhsLvlCrds = order.compose(rhsCoords);
473+
// Sort the element based on the lvl coordinates.
474+
for (Level l = 0; l < order.getNumResults(); l++) {
475+
if (lhsLvlCrds[l] == rhsLvlCrds[l])
476+
continue;
477+
return lhsLvlCrds[l] < rhsLvlCrds[l];
478+
}
479+
llvm_unreachable("no equal coordinate in sparse element attr");
480+
});
482481

483482
SmallVector<Value> cvs;
484483
cvs.reserve(dimRank);

mlir/lib/Dialect/Utils/StaticValueUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ getValuesSortedByKeyImpl(ArrayRef<K> keys, ArrayRef<V> values,
237237
return SmallVector<V>{values};
238238
assert(keys.size() == values.size() && "unexpected mismatching sizes");
239239
auto indices = llvm::to_vector(llvm::seq<int64_t>(0, values.size()));
240-
std::sort(indices.begin(), indices.end(),
241-
[&](int64_t i, int64_t j) { return compare(keys[i], keys[j]); });
240+
llvm::sort(indices,
241+
[&](int64_t i, int64_t j) { return compare(keys[i], keys[j]); });
242242
SmallVector<V> res;
243243
res.reserve(values.size());
244244
for (int64_t i = 0, e = indices.size(); i < e; ++i)

mlir/lib/Pass/Pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ LogicalResult OpToOpPassAdaptor::tryMergeInto(MLIRContext *ctx,
689689
}
690690
return false; // lhs(op-agnostic) > rhs(op-specific)
691691
};
692-
std::sort(rhs.mgrs.begin(), rhs.mgrs.end(), compareFn);
692+
llvm::sort(rhs.mgrs, compareFn);
693693
return success();
694694
}
695695

mlir/tools/mlir-tblgen/OpDocGen.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,14 @@ static bool emitDialectDoc(const RecordKeeper &records, raw_ostream &os) {
583583
// sections.
584584
// TODO: The sorting order could be revised, currently attempting to sort of
585585
// keep in alphabetical order.
586-
std::sort(dialectOps.begin(), dialectOps.end(),
587-
[](const OpDocGroup &lhs, const OpDocGroup &rhs) {
588-
auto getDesc = [](const OpDocGroup &arg) -> StringRef {
589-
if (!arg.summary.empty())
590-
return arg.summary;
591-
return arg.ops.front().getDef().getValueAsString("opName");
592-
};
593-
return getDesc(lhs).compare_insensitive(getDesc(rhs)) < 0;
594-
});
586+
llvm::sort(dialectOps, [](const OpDocGroup &lhs, const OpDocGroup &rhs) {
587+
auto getDesc = [](const OpDocGroup &arg) -> StringRef {
588+
if (!arg.summary.empty())
589+
return arg.summary;
590+
return arg.ops.front().getDef().getValueAsString("opName");
591+
};
592+
return getDesc(lhs).compare_insensitive(getDesc(rhs)) < 0;
593+
});
595594

596595
os << "<!-- Autogenerated by mlir-tblgen; don't manually edit -->\n";
597596
emitDialectDoc(*dialect, records.getInputFilename(), dialectAttrs,

0 commit comments

Comments
 (0)