[Mlir-commits] [mlir] fd5cda3 - [mlir][vector][NFC] Minor VectorTransferOpInterface cleanup
Matthias Springer
llvmlistbot at llvm.org
Fri Jul 14 06:46:21 PDT 2023
Author: Matthias Springer
Date: 2023-07-14T15:41:21+02:00
New Revision: fd5cda3393fb0285c47a05ed920e9dee24c70f21
URL: https://github.com/llvm/llvm-project/commit/fd5cda3393fb0285c47a05ed920e9dee24c70f21
DIFF: https://github.com/llvm/llvm-project/commit/fd5cda3393fb0285c47a05ed920e9dee24c70f21.diff
LOG: [mlir][vector][NFC] Minor VectorTransferOpInterface cleanup
* Rename functions with underscore to camel case.
* Return C++ bools of "in_bounds" values instead of an `ArrayAttr`.
Differential Revision: https://reviews.llvm.org/D155277
Added:
Modified:
mlir/include/mlir/Interfaces/VectorInterfaces.td
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Interfaces/VectorInterfaces.td b/mlir/include/mlir/Interfaces/VectorInterfaces.td
index 8e56d926fc3ebf..346a409a3f3e0e 100644
--- a/mlir/include/mlir/Interfaces/VectorInterfaces.td
+++ b/mlir/include/mlir/Interfaces/VectorInterfaces.td
@@ -107,7 +107,7 @@ def VectorTransferOpInterface : OpInterface<"VectorTransferOpInterface"> {
InterfaceMethod<
/*desc=*/"Return the permutation map.",
/*retTy=*/"::mlir::AffineMap",
- /*methodName=*/"permutation_map",
+ /*methodName=*/"getPermutationMap",
/*args=*/(ins),
/*methodBody=*/"return $_op.getPermutationMap();"
/*defaultImplementation=*/
@@ -140,12 +140,17 @@ def VectorTransferOpInterface : OpInterface<"VectorTransferOpInterface"> {
}]
>,
InterfaceMethod<
- /*desc=*/"Return the `in_bounds` boolean ArrayAttr.",
- /*retTy=*/"::std::optional<::mlir::ArrayAttr>",
- /*methodName=*/"in_bounds",
+ /*desc=*/"Return a vector of all in_bounds values as booleans.",
+ /*retTy=*/"::llvm::SmallVector<bool>",
+ /*methodName=*/"getInBoundsValues",
/*args=*/(ins),
- /*methodBody=*/"return $_op.getInBounds();"
- /*defaultImplementation=*/
+ /*methodBody=*/"",
+ /*defaultImplementation=*/[{
+ ::llvm::SmallVector<bool> inBounds;
+ for (int64_t i = 0, e = $_op.getTransferRank(); i < e; ++i)
+ inBounds.push_back($_op.isDimInBounds(i));
+ return inBounds;
+ }]
>,
InterfaceMethod<
/*desc=*/"Return the ShapedType.",
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 623d75407963f2..b64aec164bdca7 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -3481,18 +3481,10 @@ verifyTransferOp(VectorTransferOpInterface op, ShapedType shapedType,
static void printTransferAttrs(OpAsmPrinter &p, VectorTransferOpInterface op) {
SmallVector<StringRef, 3> elidedAttrs;
elidedAttrs.push_back(TransferReadOp::getOperandSegmentSizeAttr());
- if (op.permutation_map().isMinorIdentity())
+ if (op.getPermutationMap().isMinorIdentity())
elidedAttrs.push_back(op.getPermutationMapAttrStrName());
- bool elideInBounds = true;
- if (auto inBounds = op.in_bounds()) {
- for (auto attr : *inBounds) {
- if (llvm::cast<BoolAttr>(attr).getValue()) {
- elideInBounds = false;
- break;
- }
- }
- }
- if (elideInBounds)
+ // Elide in_bounds attribute if all dims are out-of-bounds.
+ if (llvm::none_of(op.getInBoundsValues(), [](bool b) { return b; }))
elidedAttrs.push_back(op.getInBoundsAttrStrName());
p.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
}
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
index 1d240374f8a8f7..7a21863c4d9e98 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
@@ -42,7 +42,7 @@ using namespace mlir::vector;
/// is in-bounds.
static Value createInBoundsCond(RewriterBase &b,
VectorTransferOpInterface xferOp) {
- assert(xferOp.permutation_map().isMinorIdentity() &&
+ assert(xferOp.getPermutationMap().isMinorIdentity() &&
"Expected minor identity map");
Value inBoundsCond;
xferOp.zipResultAndIndexing([&](int64_t resultIdx, int64_t indicesIdx) {
@@ -105,7 +105,7 @@ static Value createInBoundsCond(RewriterBase &b,
/// where `alloc` is a top of the function alloca'ed buffer of one vector.
///
/// Preconditions:
-/// 1. `xferOp.permutation_map()` must be a minor identity map
+/// 1. `xferOp.getPermutationMap()` must be a minor identity map
/// 2. the rank of the `xferOp.memref()` and the rank of the `xferOp.vector()`
/// must be equal. This will be relaxed in the future but requires
/// rank-reducing subviews.
@@ -116,7 +116,7 @@ splitFullAndPartialTransferPrecondition(VectorTransferOpInterface xferOp) {
return failure();
// TODO: expand support to these 2 cases.
- if (!xferOp.permutation_map().isMinorIdentity())
+ if (!xferOp.getPermutationMap().isMinorIdentity())
return failure();
// Must have some out-of-bounds dimension to be a candidate for splitting.
if (!xferOp.hasOutOfBoundsDim())
@@ -512,7 +512,7 @@ static Operation *getAutomaticAllocationScope(Operation *op) {
/// where `alloc` is a top of the function alloca'ed buffer of one vector.
///
/// Preconditions:
-/// 1. `xferOp.permutation_map()` must be a minor identity map
+/// 1. `xferOp.getPermutationMap()` must be a minor identity map
/// 2. the rank of the `xferOp.source()` and the rank of the `xferOp.vector()`
/// must be equal. This will be relaxed in the future but requires
/// rank-reducing subviews.
More information about the Mlir-commits
mailing list