1// RUN: mlir-opt %s -tensor-constant-bufferize -split-input-file 2 3// CHECK-LABEL: module { 4// We check the debug name too since we put some effort into making that readable. 5// The name isn't load-bearing though. 6// CHECK: global_memref "private" constant @__constant_3x4xf32 : memref<3x4xf32> = dense<7.000000e+00> 7// CHECK: @basic 8func @basic() -> tensor<3x4xf32> { 9 // CHECK: %[[MEMREF:.*]] = get_global_memref @__constant_3x4xf32 : memref<3x4xf32> 10 // CHECK: %[[TENSOR:.*]] = tensor_load %[[MEMREF]] 11 %0 = constant dense<7.0> : tensor<3x4xf32> 12 // CHECK: return %[[TENSOR]] 13 return %0 : tensor<3x4xf32> 14} 15 16// CHECK: } 17 18// ----- 19 20// CHECK-LABEL: module { 21 22// Only one global is created. 23// CHECK: global_memref 24// CHECK-NOT: global_memref 25func @duplicate_constants() -> (tensor<3x4xf32>, tensor<3x4xf32>) { 26 %0 = constant dense<7.0> : tensor<3x4xf32> 27 %1 = constant dense<7.0> : tensor<3x4xf32> 28 return %0, %1 : tensor<3x4xf32>, tensor<3x4xf32> 29} 30 31// CHECK: } 32 33// ----- 34 35// CHECK-LABEL: module { 36 37// Two globals are created. 38// CHECK: global_memref 39// CHECK: global_memref 40// CHECK-NOT: global_memref 41func @multiple_constants() -> (tensor<3x4xf32>, tensor<3x4xf32>) { 42 %0 = constant dense<7.0> : tensor<3x4xf32> 43 %1 = constant dense<8.0> : tensor<3x4xf32> 44 return %0, %1 : tensor<3x4xf32>, tensor<3x4xf32> 45} 46 47// CHECK: } 48 49// ----- 50 51// CHECK-LABEL: module { 52// We don't convert non-tensor globals. 53// CHECK-NOT: global_memref 54func @non_tensor() { 55 %0 = constant 7 : i32 56 return 57} 58 59// CHECK: } 60