[Mlir-commits] [mlir] [mlir][NFC] Use range-based overload of `llvm::sort` (PR #150934)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jul 28 05:50:32 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Longsheng Mou (CoTinker)
<details>
<summary>Changes</summary>
Replace explicit begin/end iterator pairs with the range-based overload of `llvm::sort`, which simplifies the code and improves readability.
---
Full diff: https://github.com/llvm/llvm-project/pull/150934.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp (+10-10)
- (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+22-23)
``````````diff
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index f49d9a1eb96b5..73ae029056298 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -476,10 +476,10 @@ inferContractionDimsImpl(ArrayRef<AffineMap> indexingMaps,
SmallVector<unsigned, 2>(ac.begin(), ac.end()),
SmallVector<unsigned, 2>(bc.begin(), bc.end()),
SmallVector<unsigned, 2>(ra.begin(), ra.end())};
- llvm::sort(dimensions.batch.begin(), dimensions.batch.end());
- llvm::sort(dimensions.m.begin(), dimensions.m.end());
- llvm::sort(dimensions.n.begin(), dimensions.n.end());
- llvm::sort(dimensions.k.begin(), dimensions.k.end());
+ llvm::sort(dimensions.batch);
+ llvm::sort(dimensions.m);
+ llvm::sort(dimensions.n);
+ llvm::sort(dimensions.k);
return dimensions;
}
@@ -797,12 +797,12 @@ inferConvolutionDimsImpl(LinalgOp linalgOp,
SmallVector<unsigned, 2>(depth.begin(), depth.end()),
/*strides=*/SmallVector<int64_t, 2>{},
/*dilations=*/SmallVector<int64_t, 2>{}};
- llvm::sort(dimensions.batch.begin(), dimensions.batch.end());
- llvm::sort(dimensions.outputImage.begin(), dimensions.outputImage.end());
- llvm::sort(dimensions.outputChannel.begin(), dimensions.outputChannel.end());
- llvm::sort(dimensions.filterLoop.begin(), dimensions.filterLoop.end());
- llvm::sort(dimensions.inputChannel.begin(), dimensions.inputChannel.end());
- llvm::sort(dimensions.depth.begin(), dimensions.depth.end());
+ llvm::sort(dimensions.batch);
+ llvm::sort(dimensions.outputImage);
+ llvm::sort(dimensions.outputChannel);
+ llvm::sort(dimensions.filterLoop);
+ llvm::sort(dimensions.inputChannel);
+ llvm::sort(dimensions.depth);
// Use the op carried strides/dilations attribute if present.
auto nativeStrides = linalgOp->getAttrOfType<DenseIntElementsAttr>("strides");
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 9f18199c75b4b..49e1e55c686a6 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -3877,29 +3877,28 @@ static omp::MapInfoOp getFirstOrLastMappedMemberPtr(omp::MapInfoOp mapInfo,
llvm::SmallVector<size_t> indices(indexAttr.size());
std::iota(indices.begin(), indices.end(), 0);
- llvm::sort(indices.begin(), indices.end(),
- [&](const size_t a, const size_t b) {
- auto memberIndicesA = cast<ArrayAttr>(indexAttr[a]);
- auto memberIndicesB = cast<ArrayAttr>(indexAttr[b]);
- for (const auto it : llvm::zip(memberIndicesA, memberIndicesB)) {
- int64_t aIndex = cast<IntegerAttr>(std::get<0>(it)).getInt();
- int64_t bIndex = cast<IntegerAttr>(std::get<1>(it)).getInt();
-
- if (aIndex == bIndex)
- continue;
-
- if (aIndex < bIndex)
- return first;
-
- if (aIndex > bIndex)
- return !first;
- }
-
- // Iterated the up until the end of the smallest member and
- // they were found to be equal up to that point, so select
- // the member with the lowest index count, so the "parent"
- return memberIndicesA.size() < memberIndicesB.size();
- });
+ llvm::sort(indices, [&](const size_t a, const size_t b) {
+ auto memberIndicesA = cast<ArrayAttr>(indexAttr[a]);
+ auto memberIndicesB = cast<ArrayAttr>(indexAttr[b]);
+ for (const auto it : llvm::zip(memberIndicesA, memberIndicesB)) {
+ int64_t aIndex = cast<IntegerAttr>(std::get<0>(it)).getInt();
+ int64_t bIndex = cast<IntegerAttr>(std::get<1>(it)).getInt();
+
+ if (aIndex == bIndex)
+ continue;
+
+ if (aIndex < bIndex)
+ return first;
+
+ if (aIndex > bIndex)
+ return !first;
+ }
+
+ // Iterated the up until the end of the smallest member and
+ // they were found to be equal up to that point, so select
+ // the member with the lowest index count, so the "parent"
+ return memberIndicesA.size() < memberIndicesB.size();
+ });
return llvm::cast<omp::MapInfoOp>(
mapInfo.getMembers()[indices.front()].getDefiningOp());
``````````
</details>
https://github.com/llvm/llvm-project/pull/150934
More information about the Mlir-commits
mailing list