@@ -15,79 +15,6 @@ class BufferScopePass<string name>
1515 : PassBase<name, "::mlir::bufferization::BufferScopePassBase">;
1616
1717
18- def BufferDeallocation : BufferScopePass<"buffer-deallocation"> {
19- let summary = "Adds all required dealloc operations for all allocations in "
20- "the input program";
21- let description = [{
22- This pass implements an algorithm to automatically introduce all required
23- deallocation operations for all buffers in the input program. This ensures
24- that the resulting program does not have any memory leaks.
25-
26-
27- Input
28-
29- ```mlir
30- #map0 = affine_map<(d0) -> (d0)>
31- module {
32- func.func @condBranch(%arg0: i1, %arg1: memref<2xf32>, %arg2: memref<2xf32>) {
33- cf.cond_br %arg0, ^bb1, ^bb2
34- ^bb1:
35- cf.br ^bb3(%arg1 : memref<2xf32>)
36- ^bb2:
37- %0 = memref.alloc() : memref<2xf32>
38- linalg.generic {
39- indexing_maps = [#map0, #map0],
40- iterator_types = ["parallel"]} %arg1, %0 {
41- ^bb0(%gen1_arg0: f32, %gen1_arg1: f32):
42- %tmp1 = exp %gen1_arg0 : f32
43- linalg.yield %tmp1 : f32
44- }: memref<2xf32>, memref<2xf32>
45- cf.br ^bb3(%0 : memref<2xf32>)
46- ^bb3(%1: memref<2xf32>):
47- "memref.copy"(%1, %arg2) : (memref<2xf32>, memref<2xf32>) -> ()
48- return
49- }
50- }
51-
52- ```
53-
54- Output
55-
56- ```mlir
57- #map0 = affine_map<(d0) -> (d0)>
58- module {
59- func.func @condBranch(%arg0: i1, %arg1: memref<2xf32>, %arg2: memref<2xf32>) {
60- cf.cond_br %arg0, ^bb1, ^bb2
61- ^bb1: // pred: ^bb0
62- %0 = memref.alloc() : memref<2xf32>
63- memref.copy(%arg1, %0) : memref<2xf32>, memref<2xf32>
64- cf.br ^bb3(%0 : memref<2xf32>)
65- ^bb2: // pred: ^bb0
66- %1 = memref.alloc() : memref<2xf32>
67- linalg.generic {
68- indexing_maps = [#map0, #map0],
69- iterator_types = ["parallel"]} %arg1, %1 {
70- ^bb0(%arg3: f32, %arg4: f32):
71- %4 = exp %arg3 : f32
72- linalg.yield %4 : f32
73- }: memref<2xf32>, memref<2xf32>
74- %2 = memref.alloc() : memref<2xf32>
75- memref.copy(%1, %2) : memref<2xf32>, memref<2xf32>
76- dealloc %1 : memref<2xf32>
77- cf.br ^bb3(%2 : memref<2xf32>)
78- ^bb3(%3: memref<2xf32>): // 2 preds: ^bb1, ^bb2
79- memref.copy(%3, %arg2) : memref<2xf32>, memref<2xf32>
80- dealloc %3 : memref<2xf32>
81- return
82- }
83-
84- }
85- ```
86-
87- }];
88- let constructor = "mlir::bufferization::createBufferDeallocationPass()";
89- }
90-
9118def OwnershipBasedBufferDeallocation : BufferScopePass<
9219 "ownership-based-buffer-deallocation"> {
9320 let summary = "Adds all required dealloc operations for all allocations in "
0 commit comments