[Mlir-commits] [mlir] [MLIR] support dynamic indexing in `VectorEmulateNarrowTypes` (PR #114169)
Han-Chung Wang
llvmlistbot at llvm.org
Mon Nov 4 13:19:29 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
+/// use it when `offset` cannot be folded into a constant value.
+static Value dynamicallyExtractSubVector(RewriterBase &rewriter, Location loc,
+ TypedValue<VectorType> source,
+ Value dest, OpFoldResult offset,
+ int64_t numElementsToExtract) {
+ for (int i = 0; i < numElementsToExtract; ++i) {
+ Value extractLoc =
+ (i == 0) ? offset.dyn_cast<Value>()
+ : rewriter.create<arith::AddIOp>(
+ loc, rewriter.getIndexType(), offset.dyn_cast<Value>(),
+ rewriter.create<arith::ConstantIndexOp>(loc, i));
+ auto extractOp =
+ rewriter.create<vector::ExtractOp>(loc, source, extractLoc);
+ dest = rewriter.create<vector::InsertOp>(loc, extractOp, dest, i);
+ }
+ return dest;
+}
+
+/// Returns the op sequence for an emulated sub-byte data type vector load.
+/// specifically, use `emulatedElemType` for loading a vector of `origElemType`.
+/// The load location is given by `base` and `linearizedIndices`, and the
+/// load size is given by `numEmulatedElementsToLoad`.
+static TypedValue<VectorType>
+emulatedVectorLoad(ConversionPatternRewriter &rewriter, Location loc,
----------------
hanhanW wrote:
SGTM
https://github.com/llvm/llvm-project/pull/114169
More information about the Mlir-commits
mailing list