71 lines · plain
1// RUN: mlir-opt --transform-interpreter=entry-point=all %s | FileCheck %s --check-prefixes=CHECK,ALL2// RUN: mlir-opt --transform-interpreter=entry-point=small %s | FileCheck %s --check-prefixes=CHECK,SMALL3 4func.func private @callee(memref<*xf32>)5 6// CHECK-LABEL: @large_alloc7func.func @large_alloc() {8 // SMALL: memref.alloc()9 // ALL: memref.alloca10 %0 = memref.alloc() : memref<100x100xf32>11 %1 = memref.cast %0 : memref<100x100xf32> to memref<*xf32>12 call @callee(%1) : (memref<*xf32>) -> ()13 // SMALL: memref.dealloc14 // ALL-NOT: memref.dealloc15 memref.dealloc %0 : memref<100x100xf32>16 return17}18 19// CHECK-LABEL: @small_alloc20func.func @small_alloc() {21 // CHECK: memref.alloca22 %0 = memref.alloc() : memref<2x2xf32>23 %1 = memref.cast %0 : memref<2x2xf32> to memref<*xf32>24 call @callee(%1) : (memref<*xf32>) -> ()25 // CHECK-NOT: memref.dealloc26 memref.dealloc %0 : memref<2x2xf32>27 return28}29 30// CHECK-LABEL: @no_dealloc31func.func @no_dealloc() {32 // CHECK: memref.alloc()33 %0 = memref.alloc() : memref<2x2xf32>34 %1 = memref.cast %0 : memref<2x2xf32> to memref<*xf32>35 call @callee(%1) : (memref<*xf32>) -> ()36 return37}38 39// CHECK-LABEL: @mismatching_scope40func.func @mismatching_scope() {41 // CHECK: memref.alloc()42 %0 = memref.alloc() : memref<2x2xf32>43 %1 = memref.cast %0 : memref<2x2xf32> to memref<*xf32>44 call @callee(%1) : (memref<*xf32>) -> ()45 scf.execute_region {46 memref.dealloc %0 : memref<2x2xf32>47 scf.yield48 }49 return50}51 52module attributes {transform.with_named_sequence} {53 transform.named_sequence @all(%arg0: !transform.any_op {transform.readonly}) {54 %0 = transform.structured.match ops{["func.func"]} in %arg0 : (!transform.any_op) -> !transform.any_op55 transform.apply_patterns to %0 {56 transform.apply_patterns.memref.alloc_to_alloca57 } : !transform.any_op58 transform.yield59 }60}61 62module attributes {transform.with_named_sequence} {63 transform.named_sequence @small(%arg0: !transform.any_op {transform.readonly}) {64 %0 = transform.structured.match ops{["func.func"]} in %arg0 : (!transform.any_op) -> !transform.any_op65 transform.apply_patterns to %0 {66 transform.apply_patterns.memref.alloc_to_alloca size_limit(32)67 } : !transform.any_op68 transform.yield69 }70}71