1// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | mlir-runner -e print_0d -entry-point-result=void -shared-libs=%mlir_runner_utils -shared-libs=%mlir_c_runner_utils | FileCheck %s --check-prefix=PRINT-0D 2// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | mlir-runner -e print_1d -entry-point-result=void -shared-libs=%mlir_runner_utils -shared-libs=%mlir_c_runner_utils | FileCheck %s --check-prefix=PRINT-1D 3// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | mlir-runner -e print_3d -entry-point-result=void -shared-libs=%mlir_runner_utils -shared-libs=%mlir_c_runner_utils | FileCheck %s --check-prefix=PRINT-3D 4// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | mlir-runner -e vector_splat_2d -entry-point-result=void -shared-libs=%mlir_runner_utils -shared-libs=%mlir_c_runner_utils | FileCheck %s --check-prefix=PRINT-VECTOR-SPLAT-2D 5 6func.func @print_0d() { 7 %f = arith.constant 2.00000e+00 : f32 8 %A = memref.alloc() : memref<f32> 9 memref.store %f, %A[]: memref<f32> 10 %U = memref.cast %A : memref<f32> to memref<*xf32> 11 call @printMemrefF32(%U): (memref<*xf32>) -> () 12 memref.dealloc %A : memref<f32> 13 return 14} 15// PRINT-0D: Unranked Memref base@ = {{.*}} rank = 0 offset = 0 sizes = [] strides = [] data = 16// PRINT-0D: [2] 17 18func.func @print_1d() { 19 %f = arith.constant 2.00000e+00 : f32 20 %A = memref.alloc() : memref<16xf32> 21 %B = memref.cast %A: memref<16xf32> to memref<?xf32> 22 linalg.fill ins(%f : f32) outs(%B : memref<?xf32>) 23 %U = memref.cast %B : memref<?xf32> to memref<*xf32> 24 call @printMemrefF32(%U): (memref<*xf32>) -> () 25 memref.dealloc %A : memref<16xf32> 26 return 27} 28// PRINT-1D: Unranked Memref base@ = {{.*}} rank = 1 offset = 0 sizes = [16] strides = [1] data = 29// PRINT-1D-NEXT: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] 30 31func.func @print_3d() { 32 %f = arith.constant 2.00000e+00 : f32 33 %f4 = arith.constant 4.00000e+00 : f32 34 %A = memref.alloc() : memref<3x4x5xf32> 35 %B = memref.cast %A: memref<3x4x5xf32> to memref<?x?x?xf32> 36 linalg.fill ins(%f : f32) outs(%B : memref<?x?x?xf32>) 37 38 %c2 = arith.constant 2 : index 39 memref.store %f4, %B[%c2, %c2, %c2]: memref<?x?x?xf32> 40 %U = memref.cast %B : memref<?x?x?xf32> to memref<*xf32> 41 call @printMemrefF32(%U): (memref<*xf32>) -> () 42 memref.dealloc %A : memref<3x4x5xf32> 43 return 44} 45// PRINT-3D: Unranked Memref base@ = {{.*}} rank = 3 offset = 0 sizes = [3, 4, 5] strides = [20, 5, 1] data = 46// PRINT-3D-COUNT-4: {{.*[[:space:]].*}}2, 2, 2, 2, 2 47// PRINT-3D-COUNT-4: {{.*[[:space:]].*}}2, 2, 2, 2, 2 48// PRINT-3D-COUNT-2: {{.*[[:space:]].*}}2, 2, 2, 2, 2 49// PRINT-3D-NEXT: 2, 2, 4, 2, 2 50// PRINT-3D-NEXT: 2, 2, 2, 2, 2 51 52func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface } 53 54!vector_type_C = vector<4x4xf32> 55!matrix_type_CC = memref<1x1x!vector_type_C> 56func.func @vector_splat_2d() { 57 %c0 = arith.constant 0 : index 58 %f10 = arith.constant 10.0 : f32 59 %vf10 = vector.splat %f10: !vector_type_C 60 %C = memref.alloc() : !matrix_type_CC 61 memref.store %vf10, %C[%c0, %c0]: !matrix_type_CC 62 63 %CC = memref.cast %C: !matrix_type_CC to memref<?x?x!vector_type_C> 64 call @printMemrefVector4x4xf32(%CC): (memref<?x?x!vector_type_C>) -> () 65 66 memref.dealloc %C : !matrix_type_CC 67 return 68} 69 70// PRINT-VECTOR-SPLAT-2D: Memref base@ = {{.*}} rank = 2 offset = 0 sizes = [1, 1] strides = [1, 1] data = 71// PRINT-VECTOR-SPLAT-2D-NEXT: [((10, 10, 10, 10), (10, 10, 10, 10), (10, 10, 10, 10), (10, 10, 10, 10))] 72 73func.func private @printMemrefVector4x4xf32(memref<?x?x!vector_type_C>) attributes { llvm.emit_c_interface } 74