[Mlir-commits] [mlir] 880b33a - [mlir][vector][contract] Add comments and rename helper hooks (NFC) (#237708)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Nov 2 00:53:56 PST 2026
Author: Andrzej WarzyĆski
Date: 2026-11-02T08:53:52Z
New Revision: 880b33a6c8e7e2fd9a0e6d9c131b3b2780a8e77e
URL: https://github.com/llvm/llvm-project/commit/880b33a6c8e7e2fd9a0e6d9c131b3b2780a8e77e
DIFF: https://github.com/llvm/llvm-project/commit/880b33a6c8e7e2fd9a0e6d9c131b3b2780a8e77e.diff
LOG: [mlir][vector][contract] Add comments and rename helper hooks (NFC) (#237708)
* Renames `getDimMap` to `getDimPairForIterTy` to make its purpose
clearer.
* Adds a `ContractionOp` argument to the updated helpers to make it
explicit that they only apply to that op.
* Reduces code duplication.
Added:
Modified:
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 7945ca3ea79634..15f588017eb8d1 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -1264,16 +1264,22 @@ static int64_t getResultIndex(AffineMap map, AffineExpr targetExpr) {
return -1;
}
+// For every contraction `dim` for which:
+// * the corresponding iteratory type matches `targetIteratorType`,
+// returns a pair: <lhsIdx, rhsIdx>, where:
+// * {lhs|rhs}Idx is the index of `dim` in the (result of) indexing map for
+// {lhs|rhs}.
static std::vector<std::pair<int64_t, int64_t>>
-getDimMap(ArrayRef<AffineMap> indexingMaps, ArrayAttr iteratorTypes,
- IteratorType targetIteratorType, MLIRContext *context) {
+getDimPairForIterTy(ContractionOp *contract, IteratorType targetIteratorType) {
+ SmallVector<AffineMap, 4> indexingMaps(contract->getIndexingMapsArray());
+ ArrayAttr iteratorTypes = contract->getIteratorTypes();
std::vector<std::pair<int64_t, int64_t>> dimMap;
for (const auto &it : llvm::enumerate(iteratorTypes)) {
auto iteratorType = llvm::cast<IteratorTypeAttr>(it.value()).getValue();
if (iteratorType != targetIteratorType)
continue;
// Search lhs/rhs map results for 'targetExpr'.
- auto targetExpr = getAffineDimExpr(it.index(), context);
+ auto targetExpr = getAffineDimExpr(it.index(), contract->getContext());
int64_t lhsDim = getResultIndex(indexingMaps[0], targetExpr);
int64_t rhsDim = getResultIndex(indexingMaps[1], targetExpr);
if (lhsDim >= 0 && rhsDim >= 0)
@@ -1282,6 +1288,14 @@ getDimMap(ArrayRef<AffineMap> indexingMaps, ArrayAttr iteratorTypes,
return dimMap;
}
+std::vector<std::pair<int64_t, int64_t>> ContractionOp::getContractingDimMap() {
+ return getDimPairForIterTy(this, IteratorType::reduction);
+}
+
+std::vector<std::pair<int64_t, int64_t>> ContractionOp::getBatchDimMap() {
+ return getDimPairForIterTy(this, IteratorType::parallel);
+}
+
void ContractionOp::getIterationBounds(
SmallVectorImpl<int64_t> &iterationBounds) {
auto lhsShape = getLhsType().getShape();
@@ -1320,18 +1334,6 @@ void ContractionOp::getIterationIndexMap(
}
}
-std::vector<std::pair<int64_t, int64_t>> ContractionOp::getContractingDimMap() {
- SmallVector<AffineMap, 4> indexingMaps(getIndexingMapsArray());
- return getDimMap(indexingMaps, getIteratorTypes(), IteratorType::reduction,
- getContext());
-}
-
-std::vector<std::pair<int64_t, int64_t>> ContractionOp::getBatchDimMap() {
- SmallVector<AffineMap, 4> indexingMaps(getIndexingMapsArray());
- return getDimMap(indexingMaps, getIteratorTypes(), IteratorType::parallel,
- getContext());
-}
-
std::optional<SmallVector<int64_t, 4>>
ContractionOp::getIterationShapeToUnroll() {
SmallVector<int64_t, 4> shape;
More information about the Mlir-commits
mailing list