[Mlir-commits] [mlir] [MLIR] support dynamic indexing in `VectorEmulateNarrowTypes` (PR #114169)
Han-Chung Wang
llvmlistbot at llvm.org
Mon Nov 4 11:13:19 PST 2024
================
@@ -129,26 +128,80 @@ static FailureOr<Operation *> getCompressedMaskOp(OpBuilder &rewriter,
return newMask;
}
+/// Extracts 1-D subvector from a 1-D vector. It is a wrapper function for
+/// emitting `vector.extract_strided_slice`.
static Value extractSubvectorFrom(RewriterBase &rewriter, Location loc,
- VectorType extractType, Value vector,
+ VectorType extractType, Value source,
int64_t frontOffset, int64_t subvecSize) {
+ auto vectorType = dyn_cast<VectorType>(source.getType());
+ assert(vectorType && vectorType.getRank() == 1 &&
+ extractType.getRank() == 1 &&
+ "expected 1-D source and destination types");
auto offsets = rewriter.getI64ArrayAttr({frontOffset});
auto sizes = rewriter.getI64ArrayAttr({subvecSize});
auto strides = rewriter.getI64ArrayAttr({1});
return rewriter
- .create<vector::ExtractStridedSliceOp>(loc, extractType, vector, offsets,
+ .create<vector::ExtractStridedSliceOp>(loc, extractType, source, offsets,
sizes, strides)
->getResult(0);
}
+/// Inserts 1-D subvector into a 1-D vector by overwriting the elements starting
+/// at `offset`. it is a wrapper function for emitting
+/// `vector.insert_strided_slice`.
static Value insertSubvectorInto(RewriterBase &rewriter, Location loc,
Value src, Value dest, int64_t offset) {
+ auto srcType = dyn_cast<VectorType>(src.getType());
+ auto destType = dyn_cast<VectorType>(dest.getType());
+ assert(srcType && srcType.getRank() == 1 && destType &&
+ destType.getRank() == 1 &&
+ "expected source and dest to be vector type");
auto offsets = rewriter.getI64ArrayAttr({offset});
auto strides = rewriter.getI64ArrayAttr({1});
return rewriter.create<vector::InsertStridedSliceOp>(loc, dest.getType(), src,
dest, offsets, strides);
}
+/// Extracts a 1-D subvector from a 1-D `source` vector, with index at `offset`
+/// and size `numElementsToExtract`, and inserts into the `dest` vector. This
+/// Function emits multiple `vector.extract` and `vector.insert` ops, so only
----------------
hanhanW wrote:
style nit: function
```suggestion
/// function emits multiple `vector.extract` and `vector.insert` ops, so only
```
https://github.com/llvm/llvm-project/pull/114169
More information about the Mlir-commits
mailing list