[Mlir-commits] [mlir] 85e38e5 - [MLIR][Tensor] Use the existing helper function `applyPermutationToVector` (NFC)
Lorenzo Chelini
llvmlistbot at llvm.org
Tue Nov 22 02:34:50 PST 2022
Author: Lorenzo Chelini
Date: 2022-11-22T11:34:44+01:00
New Revision: 85e38e5292a3bea538fbdce04c2301c8bf3d7408
URL: https://github.com/llvm/llvm-project/commit/85e38e5292a3bea538fbdce04c2301c8bf3d7408
DIFF: https://github.com/llvm/llvm-project/commit/85e38e5292a3bea538fbdce04c2301c8bf3d7408.diff
LOG: [MLIR][Tensor] Use the existing helper function `applyPermutationToVector` (NFC)
Avoid duplicate code by using an existing helper function to interchange
a vector based on a permutation. Address comments emerged after landing
D138119.
Reviewed By: nicolasvasilache
Differential Revision: https://reviews.llvm.org/D138480
Added:
Modified:
mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index 95dbd77c4abc2..c5d7e42493af4 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -10,6 +10,7 @@
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
+#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/BlockAndValueMapping.h"
@@ -3200,19 +3201,6 @@ LogicalResult PackOp::verify() {
return success();
}
-/// Returns a vector that interchanges `elements` starting at offset `offset`
-/// based on the indexes in `interchangeVector`.
-template <typename T>
-SmallVector<T> interchange(ArrayRef<T> elements,
- ArrayRef<int64_t> interchangeVector,
- int offset = 0) {
- SmallVector<T> vec = llvm::to_vector(elements);
- for (auto en : llvm::enumerate(interchangeVector))
- vec[en.index() + offset] = elements[en.value() + offset];
-
- return vec;
-}
-
/// Get the expected packed type based on source type, tile factors, position of
/// the inner tiles and permutation of the outer tiled loop.
ShapedType PackOp::inferPackedType(ShapedType sourceType,
@@ -3231,7 +3219,8 @@ ShapedType PackOp::inferPackedType(ShapedType sourceType,
innerTileSizes[tiledDim.index()]);
}
- resultShape = interchange<int64_t>(resultShape, outerDimsPerm);
+ if (!outerDimsPerm.empty())
+ applyPermutationToVector(resultShape, outerDimsPerm);
// Append the inner tile dimensions.
resultShape.append(innerTileSizes.begin(), innerTileSizes.end());
More information about the Mlir-commits
mailing list