[Mlir-commits] [mlir] [mlir][EmitC] Convert MemRef::DeallocOp (PR #194591)

Gil Rapaport llvmlistbot at llvm.org
Fri May 29 00:27:47 PDT 2026


================
@@ -1,72 +1,113 @@
-// RUN: mlir-opt -convert-memref-to-emitc="lower-to-cpp=true" %s -split-input-file | FileCheck %s --check-prefix=CPP
-// RUN: mlir-opt -convert-memref-to-emitc="lower-to-cpp=false" %s -split-input-file | FileCheck %s --check-prefix=NOCPP
+// RUN: mlir-opt -convert-memref-to-emitc="lower-to-cpp=true" %s | FileCheck %s --check-prefix=CPP
+// RUN: mlir-opt -convert-memref-to-emitc="lower-to-cpp=false" %s | FileCheck %s --check-prefix=NOCPP
 
-func.func @alloc() {
+/// Tests for converting `memref.alloc` and `memref.dealloc`.
+/// At the moment, `memref.dealloc` lowering only accepts the pointer-backed form
+/// produced by the current `memref.alloc` lowering, so alloc and dealloc tests
+/// are kept together.
+
+func.func @alloc_and_dealloc() {
   %alloc = memref.alloc() : memref<999xi32>
+  memref.dealloc %alloc : memref<999xi32>
   return
 }
 
-// CPP:      module {
-// CPP-NEXT:   emitc.include <"cstdlib">
-// CPP-LABEL:  alloc()
-// CPP-NEXT:   %[[ALLOC:.*]] = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t 
-// CPP-NEXT:   %[[ALLOC_SIZE:.*]] = "emitc.constant"() <{value = 999 : index}> : () -> index
-// CPP-NEXT:   %[[ALLOC_TOTAL_SIZE:.*]] = emitc.mul %[[ALLOC]], %[[ALLOC_SIZE]] : (!emitc.size_t, index) -> !emitc.size_t
-// CPP-NEXT:   %[[ALLOC_PTR:.*]] = emitc.call_opaque "malloc"(%[[ALLOC_TOTAL_SIZE]]) : (!emitc.size_t) -> !emitc.ptr<!emitc.opaque<"void">>
-// CPP-NEXT:   %[[ALLOC_CAST:.*]] = emitc.cast %[[ALLOC_PTR]] : !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<i32>
-// CPP-NEXT:   return
+// CPP:        emitc.include <"cstdlib">
+// CPP-LABEL:  alloc_and_dealloc
+// CPP:          %[[ALLOC:.*]] = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t
+// CPP:          %[[ALLOC_SIZE:.*]] = "emitc.constant"() <{value = 999 : index}> : () -> index
+// CPP:          %[[ALLOC_TOTAL_SIZE:.*]] = emitc.mul %[[ALLOC]], %[[ALLOC_SIZE]]
+// CPP-SAME:       : (!emitc.size_t, index) -> !emitc.size_t
+// CPP:          %[[ALLOC_PTR:.*]] = emitc.call_opaque "malloc"(%[[ALLOC_TOTAL_SIZE]])
+// CPP-SAME:       : (!emitc.size_t) -> !emitc.ptr<!emitc.opaque<"void">>
+// CPP:          %[[ALLOC_CAST:.*]] = emitc.cast %[[ALLOC_PTR]]
+// CPP-SAME:       : !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<i32>
+// CPP:          %[[FREE_PTR:.*]] = emitc.cast %[[ALLOC_CAST]]
+// CPP-SAME:       : !emitc.ptr<i32> to !emitc.ptr<!emitc.opaque<"void">>
+// CPP:          emitc.call_opaque "free"(%[[FREE_PTR]]) : (!emitc.ptr<!emitc.opaque<"void">>) -> ()
+// CPP:          return
----------------
aniragil wrote:

[Multiple locations]
Please keep the new check lines as close as possible to the original to minimize the diff to what the PR actually changes.
I'd also drop the '-SAME' splits unless there's a strict 80-column limit on lit tests I'm not aware of(?). I usually see '-SAME' used on lists (function args, loop induction vars, etc.) where it improves readability. Here it kind of does the opposite.

https://github.com/llvm/llvm-project/pull/194591


More information about the Mlir-commits mailing list