[Mlir-commits] [mlir] [mlir][vector] Add `vector.from_elements` op (PR #95938)
Guray Ozen
llvmlistbot at llvm.org
Tue Jun 18 09:55:10 PDT 2024
================
@@ -1836,6 +1836,34 @@ struct VectorDeinterleaveOpLowering
}
};
+/// Conversion pattern for a `vector.from_elements`.
+struct VectorFromElementsLowering
+ : public ConvertOpToLLVMPattern<vector::FromElementsOp> {
+ using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::FromElementsOp fromElementsOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ Location loc = fromElementsOp.getLoc();
+ VectorType vectorType = fromElementsOp.getType();
+ // TODO: Multi-dimensional vectors lower to !llvm.array<... x vector<>>.
+ // Such ops should be handled in the same way as vector.insert.
+ if (vectorType.getRank() > 1)
+ return rewriter.notifyMatchFailure(fromElementsOp,
+ "rank > 1 vectors are not supported");
+ Type llvmType = typeConverter->convertType(vectorType);
+ Value result = rewriter.create<LLVM::UndefOp>(loc, llvmType);
+ for (auto it : llvm::enumerate(adaptor.getElements())) {
+ result = rewriter.create<LLVM::InsertElementOp>(
+ loc, result, it.value(),
+ rewriter.create<LLVM::ConstantOp>(
+ loc, rewriter.getI64IntegerAttr(it.index())));
----------------
grypp wrote:
Can't we pass i32 or the op forces us to pass i64
https://github.com/llvm/llvm-project/pull/95938
More information about the Mlir-commits
mailing list