[PATCH] D80333: [mlir] NFC - Add a builder to vector.transpose
Nicolas Vasilache via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 21 02:40:56 PDT 2020
nicolasvasilache updated this revision to Diff 265462.
nicolasvasilache added a comment.
Update.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80333/new/
https://reviews.llvm.org/D80333
Files:
mlir/include/mlir/Dialect/Vector/EDSC/Intrinsics.h
mlir/include/mlir/Dialect/Vector/VectorOps.td
mlir/include/mlir/EDSC/Builders.h
mlir/lib/Dialect/Vector/VectorOps.cpp
Index: mlir/lib/Dialect/Vector/VectorOps.cpp
===================================================================
--- mlir/lib/Dialect/Vector/VectorOps.cpp
+++ mlir/lib/Dialect/Vector/VectorOps.cpp
@@ -1713,6 +1713,18 @@
// TransposeOp
//===----------------------------------------------------------------------===//
+void vector::TransposeOp::build(OpBuilder &builder, OperationState &result,
+ Value vector, ArrayRef<int64_t> transp) {
+ VectorType vt = vector.getType().cast<VectorType>();
+ SmallVector<int64_t, 4> transposedShape(vt.getRank());
+ for (unsigned i = 0; i < transp.size(); ++i)
+ transposedShape[i] = vt.getShape()[transp[i]];
+
+ result.addOperands(vector);
+ result.addTypes(VectorType::get(transposedShape, vt.getElementType()));
+ result.addAttribute(getTranspAttrName(), builder.getI64ArrayAttr(transp));
+}
+
// Eliminates transpose operations, which produce values identical to their
// input values. This happens when the dimensions of the input vector remain in
// their original order after the transpose operation.
Index: mlir/include/mlir/EDSC/Builders.h
===================================================================
--- mlir/include/mlir/EDSC/Builders.h
+++ mlir/include/mlir/EDSC/Builders.h
@@ -358,8 +358,23 @@
/// Emits a `load` when converting to a Value.
operator Value() const { return Load(value, indices); }
+ /// Returns the base memref.
Value getBase() const { return value; }
+ /// Returns the underlying memref.
+ MemRefType getMemRefType() const {
+ return value.getType().template cast<MemRefType>();
+ }
+
+ /// Returns the underlying MemRef elemental type cast as `T`.
+ template <typename T>
+ T getElementalTypeAs() const {
+ return value.getType()
+ .template cast<MemRefType>()
+ .getElementType()
+ .template cast<T>();
+ }
+
/// Arithmetic operator overloadings.
Value operator+(Value e);
Value operator-(Value e);
Index: mlir/include/mlir/Dialect/Vector/VectorOps.td
===================================================================
--- mlir/include/mlir/Dialect/Vector/VectorOps.td
+++ mlir/include/mlir/Dialect/Vector/VectorOps.td
@@ -1385,6 +1385,9 @@
[c, f] ]
```
}];
+ let builders = [OpBuilder<
+ "OpBuilder &builder, OperationState &result, Value vector, "
+ "ArrayRef<int64_t> transp">];
let extraClassDeclaration = [{
VectorType getVectorType() {
return vector().getType().cast<VectorType>();
@@ -1393,6 +1396,7 @@
return result().getType().cast<VectorType>();
}
void getTransp(SmallVectorImpl<int64_t> &results);
+ static StringRef getTranspAttrName() { return "transp"; }
}];
let assemblyFormat = [{
$vector `,` $transp attr-dict `:` type($vector) `to` type($result)
Index: mlir/include/mlir/Dialect/Vector/EDSC/Intrinsics.h
===================================================================
--- mlir/include/mlir/Dialect/Vector/EDSC/Intrinsics.h
+++ mlir/include/mlir/Dialect/Vector/EDSC/Intrinsics.h
@@ -20,9 +20,11 @@
using vector_fma = ValueBuilder<vector::FMAOp>;
using vector_extract = ValueBuilder<vector::ExtractOp>;
using vector_matmul = ValueBuilder<vector::MatmulOp>;
+using vector_outerproduct = ValueBuilder<vector::OuterProductOp>;
using vector_print = OperationBuilder<vector::PrintOp>;
using vector_transfer_read = ValueBuilder<vector::TransferReadOp>;
using vector_transfer_write = OperationBuilder<vector::TransferWriteOp>;
+using vector_transpose = ValueBuilder<vector::TransposeOp>;
using vector_type_cast = ValueBuilder<vector::TypeCastOp>;
using vector_insert = ValueBuilder<vector::InsertOp>;
using vector_fma = ValueBuilder<vector::FMAOp>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80333.265462.patch
Type: text/x-patch
Size: 3739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200521/8102ab9d/attachment-0001.bin>
More information about the llvm-commits
mailing list