xref: /llvm-project/mlir/test/Dialect/SparseTensor/codegen_sparse_alloc.mlir (revision 3dc621124fedab11b2877114c104551c63649f1c)
17b86f7c5SPeiming Liu// RUN: mlir-opt %s --sparse-tensor-codegen --canonicalize --cse | FileCheck %s
27b86f7c5SPeiming Liu
3e2e429d9SYinying Li#CSR = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : dense, d1 : compressed)}>
4*3dc62112SYinying Li#COO = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton)}>
57b86f7c5SPeiming Liu
67b86f7c5SPeiming Liu// CHECK-LABEL:   func.func @sparse_alloc_copy_CSR(
77b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_0:.*0]]: memref<?xindex>,
87b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_1:.*1]]: memref<?xindex>,
97b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_2:.*2]]: memref<?xf32>,
107b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_3:.*]]: !sparse_tensor.storage_specifier<#{{.*}}>) -> (memref<?xindex>, memref<?xindex>, memref<?xf32>, !sparse_tensor.storage_specifier<#{{.*}}>) {
117b86f7c5SPeiming Liu// CHECK:           %[[VAL_4:.*]] = arith.constant 0 : index
127b86f7c5SPeiming Liu// CHECK:           %[[VAL_5:.*]] = memref.dim %[[VAL_0]], %[[VAL_4]] : memref<?xindex>
137b86f7c5SPeiming Liu// CHECK:           %[[VAL_6:.*]] = memref.alloc(%[[VAL_5]]) : memref<?xindex>
147b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_0]], %[[VAL_6]] : memref<?xindex> to memref<?xindex>
157b86f7c5SPeiming Liu// CHECK:           %[[VAL_7:.*]] = memref.dim %[[VAL_1]], %[[VAL_4]] : memref<?xindex>
167b86f7c5SPeiming Liu// CHECK:           %[[VAL_8:.*]] = memref.alloc(%[[VAL_7]]) : memref<?xindex>
177b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_1]], %[[VAL_8]] : memref<?xindex> to memref<?xindex>
187b86f7c5SPeiming Liu// CHECK:           %[[VAL_9:.*]] = memref.dim %[[VAL_2]], %[[VAL_4]] : memref<?xf32>
197b86f7c5SPeiming Liu// CHECK:           %[[VAL_10:.*]] = memref.alloc(%[[VAL_9]]) : memref<?xf32>
207b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_2]], %[[VAL_10]] : memref<?xf32> to memref<?xf32>
217b86f7c5SPeiming Liufunc.func @sparse_alloc_copy_CSR(%arg0: tensor<2x2xf32, #CSR>) -> tensor<2x2xf32, #CSR> {
227b86f7c5SPeiming Liu  %0 = bufferization.alloc_tensor() copy(%arg0) : tensor<2x2xf32, #CSR>
237b86f7c5SPeiming Liu  "test.sink"(%0) : (tensor<2x2xf32, #CSR>) -> ()
247b86f7c5SPeiming Liu}
257b86f7c5SPeiming Liu
267b86f7c5SPeiming Liu// CHECK-LABEL:   func.func @sparse_alloc_copy_COO(
277b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_0:.*0]]: memref<?xindex>,
287b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_1:.*1]]: memref<?xindex>,
297b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_2:.*2]]: memref<?xf32>,
307b86f7c5SPeiming Liu// CHECK-SAME:      %[[VAL_3:.*]]: !sparse_tensor.storage_specifier<#{{.*}}>) -> (memref<?xindex>, memref<?xindex>, memref<?xf32>, !sparse_tensor.storage_specifier<#{{.*}}>) {
317b86f7c5SPeiming Liu// CHECK:           %[[VAL_4:.*]] = arith.constant 0 : index
327b86f7c5SPeiming Liu// CHECK:           %[[VAL_5:.*]] = memref.dim %[[VAL_0]], %[[VAL_4]] : memref<?xindex>
337b86f7c5SPeiming Liu// CHECK:           %[[VAL_6:.*]] = memref.alloc(%[[VAL_5]]) : memref<?xindex>
347b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_0]], %[[VAL_6]] : memref<?xindex> to memref<?xindex>
357b86f7c5SPeiming Liu// CHECK:           %[[VAL_7:.*]] = memref.dim %[[VAL_1]], %[[VAL_4]] : memref<?xindex>
367b86f7c5SPeiming Liu// CHECK:           %[[VAL_8:.*]] = memref.alloc(%[[VAL_7]]) : memref<?xindex>
377b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_1]], %[[VAL_8]] : memref<?xindex> to memref<?xindex>
387b86f7c5SPeiming Liu// CHECK:           %[[VAL_9:.*]] = memref.dim %[[VAL_2]], %[[VAL_4]] : memref<?xf32>
397b86f7c5SPeiming Liu// CHECK:           %[[VAL_10:.*]] = memref.alloc(%[[VAL_9]]) : memref<?xf32>
407b86f7c5SPeiming Liu// CHECK:           memref.copy %[[VAL_2]], %[[VAL_10]] : memref<?xf32> to memref<?xf32>
417b86f7c5SPeiming Liufunc.func @sparse_alloc_copy_COO(%arg0: tensor<2x2xf32, #COO>) -> tensor<2x2xf32, #COO> {
427b86f7c5SPeiming Liu  %0 = bufferization.alloc_tensor() copy(%arg0) : tensor<2x2xf32, #COO>
437b86f7c5SPeiming Liu  "test.sink"(%0) : (tensor<2x2xf32, #COO>) -> ()
447b86f7c5SPeiming Liu}
45