[Mlir-commits] [mlir] [MLIR] support dynamic indexing in `VectorEmulateNarrowTypes` (PR #114169)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 30 10:29:30 PDT 2024
================
@@ -149,6 +150,61 @@ static Value insertSubvectorInto(RewriterBase &rewriter, Location loc,
dest, offsets, strides);
}
+static void dynamicallyExtractElementsToVector(
+ RewriterBase &rewriter, Location loc, TypedValue<VectorType> srcVec,
+ Value destVec, OpFoldResult srcOffsetVar, int64_t loopSize) {
+ /*
+ // Create affine maps for the lower and upper bounds
+ AffineMap lowerBoundMap = AffineMap::getConstantMap(0, rewriter.getContext());
+ AffineMap upperBoundMap =
+ AffineMap::getConstantMap(loopSize, rewriter.getContext());
+
+ auto forLoop = rewriter.create<affine::AffineForOp>(
+ loc, ValueRange{}, lowerBoundMap, ValueRange{}, upperBoundMap, 1,
+ ArrayRef<Value>(destVec));
+
+ OpBuilder builder =
+ OpBuilder::atBlockEnd(forLoop.getBody(), rewriter.getListener());
+
+ auto iv = forLoop.getInductionVar();
+
+ auto loopDestVec = forLoop.getRegionIterArgs()[0];
+ auto extractLoc = builder.create<arith::AddIOp>(
+ loc, rewriter.getIndexType(), srcOffsetVar.dyn_cast<Value>(), iv);
+ auto extractElemOp = builder.create<vector::ExtractElementOp>(
+ loc, elemType, srcVec, extractLoc);
+ auto insertElemOp = builder.create<vector::InsertElementOp>(
+ loc, extractElemOp, loopDestVec, iv);
+ builder.create<affine::AffineYieldOp>(loc,
+ ValueRange{insertElemOp->getResult(0)});
+ return forLoop->getResult(0);
+ */
+ for (int i = 0; i < loopSize; ++i) {
+ Value extractLoc;
+ if (i == 0) {
+ extractLoc = srcOffsetVar.dyn_cast<Value>();
+ } else {
+ extractLoc = rewriter.create<arith::AddIOp>(
+ loc, rewriter.getIndexType(), srcOffsetVar.dyn_cast<Value>(),
+ rewriter.create<arith::ConstantIndexOp>(loc, i));
+ }
+ auto extractOp =
+ rewriter.create<vector::ExtractOp>(loc, srcVec, extractLoc);
+ rewriter.create<vector::InsertOp>(loc, extractOp, destVec, i);
+ }
+}
+
+static TypedValue<VectorType>
----------------
lialan wrote:
updated
https://github.com/llvm/llvm-project/pull/114169
More information about the Mlir-commits
mailing list