forked from OSchip/llvm-project
[mlir] Conversion of ViewOp with memory space to LLVM.
Handle the case where the ViewOp takes in a memref that has an memory space. Reviewed By: ftynse, bondhugula, nicolasvasilache Differential Revision: https://reviews.llvm.org/D85048
This commit is contained in:
parent
a3d427d30c
commit
fab4b59961
|
@ -2960,8 +2960,10 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<ViewOp> {
|
||||||
|
|
||||||
// Field 1: Copy the allocated pointer, used for malloc/free.
|
// Field 1: Copy the allocated pointer, used for malloc/free.
|
||||||
Value allocatedPtr = sourceMemRef.allocatedPtr(rewriter, loc);
|
Value allocatedPtr = sourceMemRef.allocatedPtr(rewriter, loc);
|
||||||
|
auto srcMemRefType = viewOp.source().getType().cast<MemRefType>();
|
||||||
Value bitcastPtr = rewriter.create<LLVM::BitcastOp>(
|
Value bitcastPtr = rewriter.create<LLVM::BitcastOp>(
|
||||||
loc, targetElementTy.getPointerTo(), allocatedPtr);
|
loc, targetElementTy.getPointerTo(srcMemRefType.getMemorySpace()),
|
||||||
|
allocatedPtr);
|
||||||
targetMemRef.setAllocatedPtr(rewriter, loc, bitcastPtr);
|
targetMemRef.setAllocatedPtr(rewriter, loc, bitcastPtr);
|
||||||
|
|
||||||
// Field 2: Copy the actual aligned pointer to payload.
|
// Field 2: Copy the actual aligned pointer to payload.
|
||||||
|
@ -2969,7 +2971,8 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<ViewOp> {
|
||||||
alignedPtr = rewriter.create<LLVM::GEPOp>(loc, alignedPtr.getType(),
|
alignedPtr = rewriter.create<LLVM::GEPOp>(loc, alignedPtr.getType(),
|
||||||
alignedPtr, adaptor.byte_shift());
|
alignedPtr, adaptor.byte_shift());
|
||||||
bitcastPtr = rewriter.create<LLVM::BitcastOp>(
|
bitcastPtr = rewriter.create<LLVM::BitcastOp>(
|
||||||
loc, targetElementTy.getPointerTo(), alignedPtr);
|
loc, targetElementTy.getPointerTo(srcMemRefType.getMemorySpace()),
|
||||||
|
alignedPtr);
|
||||||
targetMemRef.setAlignedPtr(rewriter, loc, bitcastPtr);
|
targetMemRef.setAlignedPtr(rewriter, loc, bitcastPtr);
|
||||||
|
|
||||||
// Field 3: The offset in the resulting type must be 0. This is because of
|
// Field 3: The offset in the resulting type must be 0. This is because of
|
||||||
|
|
|
@ -824,6 +824,28 @@ func @view(%arg0 : index, %arg1 : index, %arg2 : index) {
|
||||||
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[4, 0] : !llvm.struct<(ptr<float>, ptr<float>, i64, array<2 x i64>, array<2 x i64>)>
|
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[4, 0] : !llvm.struct<(ptr<float>, ptr<float>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
%5 = view %0[%arg2][] : memref<2048xi8> to memref<64x4xf32>
|
%5 = view %0[%arg2][] : memref<2048xi8> to memref<64x4xf32>
|
||||||
|
|
||||||
|
// Test view memory space.
|
||||||
|
// CHECK: llvm.mlir.constant(2048 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.mlir.undef : !llvm.struct<(ptr<i8, 4>, ptr<i8, 4>, i64, array<1 x i64>, array<1 x i64>)>
|
||||||
|
%6 = alloc() : memref<2048xi8, 4>
|
||||||
|
|
||||||
|
// CHECK: llvm.mlir.undef : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: %[[BASE_PTR_4:.*]] = llvm.extractvalue %{{.*}}[1] : !llvm.struct<(ptr<i8, 4>, ptr<i8, 4>, i64, array<1 x i64>, array<1 x i64>)>
|
||||||
|
// CHECK: %[[SHIFTED_BASE_PTR_4:.*]] = llvm.getelementptr %[[BASE_PTR_4]][%[[ARG2]]] : (!llvm.ptr<i8, 4>, !llvm.i64) -> !llvm.ptr<i8, 4>
|
||||||
|
// CHECK: %[[CAST_SHIFTED_BASE_PTR_4:.*]] = llvm.bitcast %[[SHIFTED_BASE_PTR_4]] : !llvm.ptr<i8, 4> to !llvm.ptr<float, 4>
|
||||||
|
// CHECK: llvm.insertvalue %[[CAST_SHIFTED_BASE_PTR_4]], %{{.*}}[1] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: %[[C0_4:.*]] = llvm.mlir.constant(0 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.insertvalue %[[C0_4]], %{{.*}}[2] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: llvm.mlir.constant(4 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[3, 1] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: llvm.mlir.constant(1 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[4, 1] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: llvm.mlir.constant(64 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[3, 0] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
// CHECK: llvm.mlir.constant(4 : index) : !llvm.i64
|
||||||
|
// CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[4, 0] : !llvm.struct<(ptr<float, 4>, ptr<float, 4>, i64, array<2 x i64>, array<2 x i64>)>
|
||||||
|
%7 = view %6[%arg2][] : memref<2048xi8, 4> to memref<64x4xf32, 4>
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue