Skip to content

Commit 91c320e

Browse files
committed
[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
1 parent b954cb4 commit 91c320e

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎mlir/lib/Transforms/BufferPlacement.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ class BufferPlacementAliasAnalysis {
142142
this->aliases[std::get<0>(entry)].insert(std::get<1>(entry));
143143
};
144144

145+
// Add additional aliases created by view changes to the alias list.
146+
op->walk([&](ViewLikeOpInterface viewInterface) {
147+
aliases[viewInterface.getViewSource()].insert(
148+
viewInterface.getOperation()->getResult(0));
149+
});
150+
145151
// Query all branch interfaces to link block argument aliases.
146152
op->walk([&](BranchOpInterface branchInterface) {
147153
Block *parentBlock = branchInterface.getOperation()->getBlock();

‎mlir/test/Transforms/buffer-placement.mlir‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,22 @@ func @inner_region_control_flow_div(
914914
// CHECK-NEXT: test.region_if_yield %[[ALLOC8]]
915915
// CHECK: dealloc %[[ALLOC0]]
916916
// CHECK-NEXT: return %[[ALLOC1]]
917+
918+
// -----
919+
920+
// CHECK-LABEL: func @subview
921+
func @subview(%arg0 : index, %arg1 : index, %arg2 : memref<?x?xf32>) {
922+
%0 = alloc() : memref<64x4xf32, offset: 0, strides: [4, 1]>
923+
%1 = subview %0[%arg0, %arg1][%arg0, %arg1][%arg0, %arg1] :
924+
memref<64x4xf32, offset: 0, strides: [4, 1]>
925+
to memref<?x?xf32, offset: ?, strides: [?, ?]>
926+
"linalg.copy"(%1, %arg2) :
927+
(memref<?x?xf32, offset: ?, strides: [?, ?]>, memref<?x?xf32>) -> ()
928+
return
929+
}
930+
931+
// CHECK-NEXT: %[[ALLOC:.*]] = alloc()
932+
// CHECK-NEXT: subview
933+
// CHECK-NEXT: linalg.copy
934+
// CHECK-NEXT: dealloc %[[ALLOC]]
935+
// CHECK-NEXT: return

0 commit comments

Comments
 (0)