[PATCH] D136304: [mlir][MemRefToLLVM] Lower extract_strided_metadata
Quentin Colombet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 14:34:33 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55d08a867056: [mlir][MemRefToLLVM] Lower extract_strided_metadata (authored by qcolombet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136304/new/
https://reviews.llvm.org/D136304
Files:
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
Index: mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
===================================================================
--- mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
+++ mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
@@ -1162,3 +1162,26 @@
// CHECK: return %[[R:.*]] : index
return %0: index
}
+
+// -----
+
+// CHECK-LABEL: func @extract_strided_metadata(
+// CHECK-SAME: %[[ARG:.*]]: memref
+// CHECK: %[[MEM_DESC:.*]] = builtin.unrealized_conversion_cast %[[ARG]] : memref<?x?xf32, strided<[?, ?], offset: ?>> to !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[BASE:.*]] = llvm.extractvalue %[[MEM_DESC]][0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[OFFSET:.*]] = llvm.extractvalue %[[MEM_DESC]][2] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[SIZE0:.*]] = llvm.extractvalue %[[MEM_DESC]][3, 0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[SIZE1:.*]] = llvm.extractvalue %[[MEM_DESC]][3, 1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[STRIDE0:.*]] = llvm.extractvalue %[[MEM_DESC]][4, 0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+// CHECK: %[[STRIDE1:.*]] = llvm.extractvalue %[[MEM_DESC]][4, 1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+func.func @extract_strided_metadata(
+ %ref: memref<?x?xf32, strided<[?,?], offset: ?>>) {
+
+ %base, %offset, %sizes:2, %strides:2 =
+ memref.extract_strided_metadata %ref : memref<?x?xf32, strided<[?,?], offset: ?>>
+ -> memref<f32>, index,
+ index, index,
+ index, index
+
+ return
+}
Index: mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
===================================================================
--- mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -2098,6 +2098,50 @@
}
};
+/// Materialize the MemRef descriptor represented by the results of
+/// ExtractStridedMetadataOp.
+class ExtractStridedMetadataOpLowering
+ : public ConvertOpToLLVMPattern<memref::ExtractStridedMetadataOp> {
+public:
+ using ConvertOpToLLVMPattern<
+ memref::ExtractStridedMetadataOp>::ConvertOpToLLVMPattern;
+
+ LogicalResult
+ matchAndRewrite(memref::ExtractStridedMetadataOp extractStridedMetadataOp,
+ OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+
+ if (!LLVM::isCompatibleType(adaptor.getOperands().front().getType()))
+ return failure();
+
+ // Create the descriptor.
+ MemRefDescriptor sourceMemRef(adaptor.getOperands().front());
+ Location loc = extractStridedMetadataOp.getLoc();
+ Value source = extractStridedMetadataOp.getSource();
+
+ auto sourceMemRefType = source.getType().cast<MemRefType>();
+ int64_t rank = sourceMemRefType.getRank();
+ SmallVector<Value> results;
+ results.reserve(2 + rank * 2);
+
+ // Base buffer.
+ results.push_back(sourceMemRef.allocatedPtr(rewriter, loc));
+
+ // Offset.
+ results.push_back(sourceMemRef.offset(rewriter, loc));
+
+ // Sizes.
+ for (unsigned i = 0; i < rank; ++i)
+ results.push_back(sourceMemRef.size(rewriter, loc, i));
+ // Strides.
+ for (unsigned i = 0; i < rank; ++i)
+ results.push_back(sourceMemRef.stride(rewriter, loc, i));
+
+ rewriter.replaceOp(extractStridedMetadataOp, results);
+ return success();
+ }
+};
+
} // namespace
void mlir::populateMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
@@ -2110,6 +2154,7 @@
AssumeAlignmentOpLowering,
ConvertExtractAlignedPointerAsIndex,
DimOpLowering,
+ ExtractStridedMetadataOpLowering,
GenericAtomicRMWOpLowering,
GlobalMemrefOpLowering,
GetGlobalMemrefOpLowering,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136304.470938.patch
Type: text/x-patch
Size: 3932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221026/df2fbe8f/attachment-0001.bin>
More information about the llvm-commits
mailing list