[Mlir-commits] [mlir] 91c320e - [mlir] Add check for ViewLikeOpInterface that creates additional aliases.

Julian Gross llvmlistbot at llvm.org
Fri Jul 3 07:42:56 PDT 2020


Author: Julian Gross
Date: 2020-07-03T16:38:21+02:00
New Revision: 91c320e9d852120f011028e15ff0e25cdf762aad

URL: https://github.com/llvm/llvm-project/commit/91c320e9d852120f011028e15ff0e25cdf762aad
DIFF: https://github.com/llvm/llvm-project/commit/91c320e9d852120f011028e15ff0e25cdf762aad.diff

LOG: [mlir] Add check for ViewLikeOpInterface that creates additional aliases.

ViewLikeOpInterfaces introduce new aliases that need to be added to the alias
list. This is necessary to place deallocs in the right positions.

Differential Revision: https://reviews.llvm.org/D83044

Added: 
    

Modified: 
    mlir/lib/Transforms/BufferPlacement.cpp
    mlir/test/Transforms/buffer-placement.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/BufferPlacement.cpp b/mlir/lib/Transforms/BufferPlacement.cpp
index 577d52188351..71d397b47ea2 100644
--- a/mlir/lib/Transforms/BufferPlacement.cpp
+++ b/mlir/lib/Transforms/BufferPlacement.cpp
@@ -142,6 +142,12 @@ class BufferPlacementAliasAnalysis {
         this->aliases[std::get<0>(entry)].insert(std::get<1>(entry));
     };
 
+    // Add additional aliases created by view changes to the alias list.
+    op->walk([&](ViewLikeOpInterface viewInterface) {
+      aliases[viewInterface.getViewSource()].insert(
+          viewInterface.getOperation()->getResult(0));
+    });
+
     // Query all branch interfaces to link block argument aliases.
     op->walk([&](BranchOpInterface branchInterface) {
       Block *parentBlock = branchInterface.getOperation()->getBlock();

diff  --git a/mlir/test/Transforms/buffer-placement.mlir b/mlir/test/Transforms/buffer-placement.mlir
index 225a186caeb0..c3bce4ea5458 100644
--- a/mlir/test/Transforms/buffer-placement.mlir
+++ b/mlir/test/Transforms/buffer-placement.mlir
@@ -914,3 +914,22 @@ func @inner_region_control_flow_div(
 // CHECK-NEXT: test.region_if_yield %[[ALLOC8]]
 //      CHECK: dealloc %[[ALLOC0]]
 // CHECK-NEXT: return %[[ALLOC1]]
+
+// -----
+
+// CHECK-LABEL: func @subview
+func @subview(%arg0 : index, %arg1 : index, %arg2 : memref<?x?xf32>) {
+  %0 = alloc() : memref<64x4xf32, offset: 0, strides: [4, 1]>
+  %1 = subview %0[%arg0, %arg1][%arg0, %arg1][%arg0, %arg1] :
+    memref<64x4xf32, offset: 0, strides: [4, 1]>
+  to memref<?x?xf32, offset: ?, strides: [?, ?]>
+  "linalg.copy"(%1, %arg2) :
+    (memref<?x?xf32, offset: ?, strides: [?, ?]>, memref<?x?xf32>) -> ()
+  return
+}
+
+// CHECK-NEXT: %[[ALLOC:.*]] = alloc()
+// CHECK-NEXT: subview
+// CHECK-NEXT: linalg.copy
+// CHECK-NEXT: dealloc %[[ALLOC]]
+// CHECK-NEXT: return


        


More information about the Mlir-commits mailing list