}
};
+/// 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,
AssumeAlignmentOpLowering,
ConvertExtractAlignedPointerAsIndex,
DimOpLowering,
+ ExtractStridedMetadataOpLowering,
GenericAtomicRMWOpLowering,
GlobalMemrefOpLowering,
GetGlobalMemrefOpLowering,
// 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
+}