[Mlir-commits] [mlir] 07801f7 - [mlir][memref]Add conversion support for memref.extract_aligned_pointer_as_index to LLVM
Nicolas Vasilache
llvmlistbot at llvm.org
Thu Sep 29 02:35:09 PDT 2022
Author: Nicolas Vasilache
Date: 2022-09-29T02:35:00-07:00
New Revision: 07801f713e3ab95c09887b547a263fd615d799f3
URL: https://github.com/llvm/llvm-project/commit/07801f713e3ab95c09887b547a263fd615d799f3
DIFF: https://github.com/llvm/llvm-project/commit/07801f713e3ab95c09887b547a263fd615d799f3.diff
LOG: [mlir][memref]Add conversion support for memref.extract_aligned_pointer_as_index to LLVM
Reviewed By: pifon2a
Differential Revision: https://reviews.llvm.org/D134834
Added:
Modified:
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index c691c07f9bc4d..efeb2552646a6 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -2070,6 +2070,25 @@ struct AtomicRMWOpLowering : public LoadStoreOpLowering<memref::AtomicRMWOp> {
}
};
+/// Unpack the pointer returned by a memref.extract_aligned_pointer_as_index.
+class ConvertExtractAlignedPointerAsIndex
+ : public ConvertOpToLLVMPattern<memref::ExtractAlignedPointerAsIndexOp> {
+public:
+ using ConvertOpToLLVMPattern<
+ memref::ExtractAlignedPointerAsIndexOp>::ConvertOpToLLVMPattern;
+
+ LogicalResult
+ matchAndRewrite(memref::ExtractAlignedPointerAsIndexOp extractOp,
+ OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ MemRefDescriptor desc(adaptor.getSource());
+ rewriter.replaceOpWithNewOp<LLVM::PtrToIntOp>(
+ extractOp, getTypeConverter()->getIndexType(),
+ desc.alignedPtr(rewriter, extractOp->getLoc()));
+ return success();
+ }
+};
+
} // namespace
void mlir::populateMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
@@ -2080,6 +2099,7 @@ void mlir::populateMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
AllocaScopeOpLowering,
AtomicRMWOpLowering,
AssumeAlignmentOpLowering,
+ ConvertExtractAlignedPointerAsIndex,
DimOpLowering,
GenericAtomicRMWOpLowering,
GlobalMemrefOpLowering,
diff --git a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
index ce6eb620671c2..07979b116abed 100644
--- a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
+++ b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
@@ -1143,3 +1143,16 @@ func.func @memref_copy_unranked() {
// CHECK: llvm.call @memrefCopy([[SIZE]], [[ALLOCA2]], [[ALLOCA3]]) : (i64, !llvm.ptr<struct<(i64, ptr<i8>)>>, !llvm.ptr<struct<(i64, ptr<i8>)>>) -> ()
return
}
+
+// -----
+
+// CHECK-LABEL: func @extract_aligned_pointer_as_index
+func.func @extract_aligned_pointer_as_index(%m: memref<?xf32>) -> index {
+ %0 = memref.extract_aligned_pointer_as_index %m: memref<?xf32> -> index
+ // CHECK: %[[E:.*]] = llvm.extractvalue %{{.*}}[1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<1 x i64>, array<1 x i64>)>
+ // CHECK: %[[I64:.*]] = llvm.ptrtoint %[[E]] : !llvm.ptr<f32> to i64
+ // CHECK: %[[R:.*]] = builtin.unrealized_conversion_cast %[[I64]] : i64 to index
+
+ // CHECK: return %[[R:.*]] : index
+ return %0: index
+}
More information about the Mlir-commits
mailing list