Since the recent MemRef refactoring that centralizes the lowering of complex MemRef operations outside of the conversion framework, the MemRefToLLVM pass doesn't directly convert these complex operations. Instead, to fully convert the whole MemRef dialect space, MemRefToLLVM needs to run after `expand-strided-metadata`. Make this more obvious by changing the name of the pass and the option associated with it from `convert-memref-to-llvm` to `finalize-memref-to-llvm`. The word "finalize" conveys that this pass needs to run after something else and that something else is documented in its tablegen description. This is a follow-up patch related to the conversation at: https://discourse.llvm.org/t/psa-you-need-to-run-expand-strided-metadata-before-memref-to-llvm-now/66956/14 Differential Revision: https://reviews.llvm.org/D142463
58 lines
2.2 KiB
MLIR
58 lines
2.2 KiB
MLIR
// RUN: mlir-opt %s -convert-scf-to-cf -convert-vector-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts |\
|
|
// RUN: mlir-cpu-runner -e entry -entry-point-result=void \
|
|
// RUN: -shared-libs=%mlir_lib_dir/libmlir_c_runner_utils%shlibext
|
|
// RUN: mlir-opt %s -convert-scf-to-cf -convert-vector-to-llvm -finalize-memref-to-llvm='use-aligned-alloc=1' -convert-func-to-llvm -arith-expand -reconcile-unrealized-casts |\
|
|
// RUN: mlir-cpu-runner -e entry -entry-point-result=void \
|
|
// RUN: -shared-libs=%mlir_lib_dir/libmlir_c_runner_utils%shlibext | FileCheck %s
|
|
|
|
func.func @entry() {
|
|
// Set up memory.
|
|
%c0 = arith.constant 0: index
|
|
%c1 = arith.constant 1: index
|
|
%c8 = arith.constant 8: index
|
|
%A = memref.alloc() : memref<8xf32>
|
|
scf.for %i = %c0 to %c8 step %c1 {
|
|
%i32 = arith.index_cast %i : index to i32
|
|
%fi = arith.sitofp %i32 : i32 to f32
|
|
memref.store %fi, %A[%i] : memref<8xf32>
|
|
}
|
|
|
|
%d0 = arith.constant -1.0 : f32
|
|
%Av = vector.transfer_read %A[%c0], %d0: memref<8xf32>, vector<8xf32>
|
|
vector.print %Av : vector<8xf32>
|
|
// CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7 )
|
|
|
|
// Realloc with static sizes.
|
|
%B = memref.realloc %A : memref<8xf32> to memref<10xf32>
|
|
|
|
%c10 = arith.constant 10: index
|
|
scf.for %i = %c8 to %c10 step %c1 {
|
|
%i32 = arith.index_cast %i : index to i32
|
|
%fi = arith.sitofp %i32 : i32 to f32
|
|
memref.store %fi, %B[%i] : memref<10xf32>
|
|
}
|
|
|
|
%Bv = vector.transfer_read %B[%c0], %d0: memref<10xf32>, vector<10xf32>
|
|
vector.print %Bv : vector<10xf32>
|
|
// CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 )
|
|
|
|
// Realloc with dynamic sizes.
|
|
%Bd = memref.cast %B : memref<10xf32> to memref<?xf32>
|
|
%c13 = arith.constant 13: index
|
|
%Cd = memref.realloc %Bd(%c13) : memref<?xf32> to memref<?xf32>
|
|
%C = memref.cast %Cd : memref<?xf32> to memref<13xf32>
|
|
|
|
scf.for %i = %c10 to %c13 step %c1 {
|
|
%i32 = arith.index_cast %i : index to i32
|
|
%fi = arith.sitofp %i32 : i32 to f32
|
|
memref.store %fi, %C[%i] : memref<13xf32>
|
|
}
|
|
|
|
%Cv = vector.transfer_read %C[%c0], %d0: memref<13xf32>, vector<13xf32>
|
|
vector.print %Cv : vector<13xf32>
|
|
// CHECK: ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 )
|
|
|
|
memref.dealloc %C : memref<13xf32>
|
|
return
|
|
}
|