[Mlir-commits] [mlir] [mlir][EmitC] Convert MemRef::DeallocOp (PR #194591)
Gil Rapaport
llvmlistbot at llvm.org
Wed Jun 3 01:09:59 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:
There's still difference in lines this PR isn't changing (the missing `module`, the removed `-NEXT` and some whitespaces). Sorry for the nitpick, but it obfuscates what the PR actually modifies in these lits ...
https://github.com/llvm/llvm-project/pull/194591
More information about the Mlir-commits
mailing list