[Mlir-commits] [mlir] 547b9af - [mlir][linalg][bufferize][NFC] Add explicit inplaceable attrs to test cases

Matthias Springer llvmlistbot at llvm.org
Fri Jan 7 07:28:12 PST 2022


Author: Matthias Springer
Date: 2022-01-08T00:25:15+09:00
New Revision: 547b9afc54ba79e1c7cb8ba21371eec5a25d8b9c

URL: https://github.com/llvm/llvm-project/commit/547b9afc54ba79e1c7cb8ba21371eec5a25d8b9c
DIFF: https://github.com/llvm/llvm-project/commit/547b9afc54ba79e1c7cb8ba21371eec5a25d8b9c.diff

LOG: [mlir][linalg][bufferize][NFC] Add explicit inplaceable attrs to test cases

This is in preparation of fixing CallOp bufferization. Add explicit linalg.inplaceable attrs to all bbArgs, except for the ones where inplaceability should be decided by the analysis.

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp
    mlir/test/Dialect/Linalg/comprehensive-module-bufferize-analysis.mlir
    mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp
index 5cac342296f82..d66ccae62ec09 100644
--- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp
+++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp
@@ -767,6 +767,13 @@ struct FuncOpInterface
     const ModuleBufferizationState &moduleState =
         getModuleBufferizationState(state);
 
+    // "linalg.inplaceable" overrides other writability decisions. This is
+    // currently used for testing only.
+    if (BoolAttr inplaceAttr = funcOp.getArgAttrOfType<BoolAttr>(
+            bbArg.getArgNumber(),
+            BufferizableOpInterface::kInplaceableAttrName))
+      return inplaceAttr.getValue();
+
     // In a first approximation:
     // =========================
     // If the function is called, we can allocate on the caller side which lets
@@ -775,13 +782,6 @@ struct FuncOpInterface
     if (moduleState.callerMap.find(funcOp) != moduleState.callerMap.end())
       return true;
 
-    // Set the function arguments marked with inplaceable to be known as
-    // bufferizing to a writeable memory.
-    BoolAttr inplaceAttr = funcOp.getArgAttrOfType<BoolAttr>(
-        bbArg.getArgNumber(), BufferizableOpInterface::kInplaceableAttrName);
-    if (inplaceAttr && inplaceAttr.getValue())
-      return true;
-
     // All other function arguments are not writable.
     return false;
   }

diff  --git a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize-analysis.mlir b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize-analysis.mlir
index 8705cd1f1b1e0..00eb163fab851 100644
--- a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize-analysis.mlir
+++ b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize-analysis.mlir
@@ -12,7 +12,8 @@
 // -----
 
 // CHECK-LABEL: func @extract_slice_fun
-func @extract_slice_fun(%A : tensor<?xf32>, %B : tensor<?xf32> {linalg.inplaceable = true})
+func @extract_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = false},
+                        %B : tensor<?xf32> {linalg.inplaceable = true})
   -> (tensor<4xf32>, tensor<8xf32>)
 {
   // tensor.extract_slice is not used in a write, it is not compelled to
@@ -33,10 +34,9 @@ func @extract_slice_fun(%A : tensor<?xf32>, %B : tensor<?xf32> {linalg.inplaceab
 // -----
 
 // CHECK-LABEL: func @insert_slice_fun
-func @insert_slice_fun(
-    %A : tensor<?xf32>,
-    %B : tensor<?xf32> {linalg.inplaceable = true},
-    %C : tensor<4xf32>)
+func @insert_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = false},
+                       %B : tensor<?xf32> {linalg.inplaceable = true},
+                       %C : tensor<4xf32> {linalg.inplaceable = false})
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   // must bufferize out of place.
@@ -57,9 +57,8 @@ func @insert_slice_fun(
 // -----
 
 // CHECK-LABEL: func @conflict_on_B
-func @conflict_on_B(
-    %A : tensor<4x4xf32> {linalg.inplaceable = true},
-    %B : tensor<4x4xf32> {linalg.inplaceable = true})
+func @conflict_on_B(%A : tensor<4x4xf32> {linalg.inplaceable = true},
+                    %B : tensor<4x4xf32> {linalg.inplaceable = true})
   -> (tensor<4x4xf32>, tensor<4x4xf32>, tensor<4x4xf32>)
 {
   // matmul output operand interferes with input operand.
@@ -96,7 +95,8 @@ func @conflict_on_B(
 
 // CHECK-LABEL: func @extract_slice_extract_slice
 func @extract_slice_extract_slice(
-    %A : tensor<?xf32> {linalg.inplaceable = true}, %B : tensor<?xf32>)
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %B : tensor<?xf32> {linalg.inplaceable = false})
   -> (tensor<2xf32>, tensor<2xf32>)
 {
   // tensor.extract_slice is not used in a write, it is not compelled to
@@ -125,7 +125,9 @@ func @insert_slice_insert_slice(
     %A : tensor<?xf32> {linalg.inplaceable = true},
     %A2 : tensor<4xf32> {linalg.inplaceable = true},
     %A3 : tensor<2xf32> {linalg.inplaceable = true},
-    %B : tensor<?xf32>, %B2 : tensor<4xf32>, %B3 : tensor<2xf32>)
+    %B : tensor<?xf32> {linalg.inplaceable = false},
+    %B2 : tensor<4xf32> {linalg.inplaceable = false},
+    %B3 : tensor<2xf32> {linalg.inplaceable = false})
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   // CHECK: {__inplace_results_attr__ = ["true"]}
@@ -150,7 +152,8 @@ func @insert_slice_insert_slice(
 // CHECK-LABEL: func @extract_slice_nonmatching_insert_slice
 func @extract_slice_nonmatching_insert_slice(
     %A : tensor<?xf32> {linalg.inplaceable = true},
-    %B : tensor<?xf32>, %idx: index)
+    %B : tensor<?xf32> {linalg.inplaceable = false},
+    %idx: index)
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   // %r1 bufferizes inplace because %A is inplaceable.
@@ -188,7 +191,7 @@ func @extract_slice_nonmatching_insert_slice(
 // CHECK-LABEL: func @extract_slice_matching_insert_slice
 func @extract_slice_matching_insert_slice(
     %A : tensor<?xf32> {linalg.inplaceable = true},
-    %B : tensor<?xf32>)
+    %B : tensor<?xf32> {linalg.inplaceable = false})
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   // %r1 bufferizes inplace because %A is inplaceable.
@@ -225,7 +228,9 @@ func @extract_slice_matching_insert_slice(
 
 // CHECK-LABEL: @read_of_matching_insert_slice_source
 func @read_of_matching_insert_slice_source(
-    %A : tensor<?xf32> {linalg.inplaceable = true}, %idx : index, %idx2 : index)
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %idx : index,
+    %idx2 : index)
   -> (tensor<?xf32>, vector<5xf32>)
 {
   %cst = arith.constant 0.0 : f32
@@ -254,7 +259,9 @@ func @read_of_matching_insert_slice_source(
 
 // CHECK-LABEL: @read_of_matching_insert_slice_source_interleaved
 func @read_of_matching_insert_slice_source_interleaved(
-    %A : tensor<?xf32> {linalg.inplaceable = true}, %idx : index, %idx2 : index,
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %idx : index,
+    %idx2 : index,
     %idx3 : index)
   -> (tensor<?xf32>, vector<5xf32>)
 {
@@ -296,8 +303,8 @@ func @read_of_matching_insert_slice_source_interleaved(
 
 // CHECK-LABEL: func @extract_slice_linalg_readonly_use
 func @extract_slice_linalg_readonly_use(
-    %A : tensor<?x?xf32>,
-    %B : tensor<4x4xf32>,
+    %A : tensor<?x?xf32> {linalg.inplaceable = false},
+    %B : tensor<4x4xf32> {linalg.inplaceable = false},
     %C : tensor<4x4xf32> {linalg.inplaceable = true})
   ->  (tensor<4x4xf32>, tensor<4x4xf32>)
 {
@@ -330,8 +337,8 @@ func @extract_slice_linalg_readonly_use(
 
 // CHECK-LABEL: func @extract_slice_to_linalg_write_use
 func @extract_slice_to_linalg_write_use(
-    %A : tensor<4x4xf32>,
-    %B : tensor<?x?xf32>,
+    %A : tensor<4x4xf32> {linalg.inplaceable = false},
+    %B : tensor<?x?xf32> {linalg.inplaceable = false},
     %C : tensor<?x?xf32> {linalg.inplaceable = true})
   ->  (tensor<4x4xf32>, tensor<4x4xf32>)
 {
@@ -370,9 +377,15 @@ func @extract_slice_to_linalg_write_use(
 
 // CHECK-LABEL: func @insert_slice_double_extract_slice
 func @insert_slice_double_extract_slice(
-    %s1: index, %s2: index, %s3: index, %s4: index, %A: tensor<8x6xf32>,
-    %B: tensor<6x6xf32>, %C: tensor<30x20xf32> {linalg.inplaceable = true})
-        -> tensor<30x20xf32> {
+    %s1: index,
+    %s2: index,
+    %s3: index,
+    %s4: index,
+    %A: tensor<8x6xf32> {linalg.inplaceable = false},
+    %B: tensor<6x6xf32> {linalg.inplaceable = false},
+    %C: tensor<30x20xf32> {linalg.inplaceable = true})
+  -> tensor<30x20xf32>
+{
   //      CHECK: tensor.extract_slice
   // CHECK-SAME: {__inplace_results_attr__ = ["true"]}
   %15 = tensor.extract_slice %C[%s3, %s4] [%s1, %s2] [1, 1] : tensor<30x20xf32> to tensor<?x?xf32>
@@ -402,8 +415,8 @@ func @insert_slice_double_extract_slice(
 
 // CHECK-LABEL: func @extract_slice_to_linalg_write_use
 func @extract_slice_to_linalg_write_use(
-    %A : tensor<4x4xf32>,
-    %B : tensor<?x?xf32>,
+    %A : tensor<4x4xf32> {linalg.inplaceable = false},
+    %B : tensor<?x?xf32> {linalg.inplaceable = false},
     %C : tensor<?x?xf32> {linalg.inplaceable = true})
   ->  (tensor<4x4xf32>, tensor<4x4xf32>)
 {
@@ -444,7 +457,7 @@ func @extract_slice_to_linalg_write_use(
 
 // CHECK-LABEL: func @nested_extract_slice_and_insert
 func @nested_extract_slice_and_insert(
-    %A : tensor<?x?xf32>,
+    %A : tensor<?x?xf32> {linalg.inplaceable = false},
     %B : tensor<?x?xf32> {linalg.inplaceable = true},
     %C : tensor<?x?xf32> {linalg.inplaceable = true},
     %idx : index,
@@ -535,9 +548,12 @@ func @nested_extract_slice_and_insert(
 // -----
 
 // CHECK-LABEL: func @scf_for_yield_only
-func @scf_for_yield_only(%A : tensor<?xf32>,
-                         %B : tensor<?xf32> {linalg.inplaceable = true},
-                         %lb : index, %ub : index, %step : index)
+func @scf_for_yield_only(
+    %A : tensor<?xf32> {linalg.inplaceable = false},
+    %B : tensor<?xf32> {linalg.inplaceable = true},
+    %lb : index,
+    %ub : index,
+    %step : index)
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   //      CHECK: scf.for
@@ -562,10 +578,13 @@ func @scf_for_yield_only(%A : tensor<?xf32>,
 // -----
 
 // CHECK-LABEL: func @scf_for_with_tensor.insert_slice
-func @scf_for_with_tensor.insert_slice(%A : tensor<?xf32>,
-              %B : tensor<?xf32> {linalg.inplaceable = true},
-              %C : tensor<4xf32>,
-              %lb : index, %ub : index, %step : index)
+func @scf_for_with_tensor.insert_slice(
+    %A : tensor<?xf32> {linalg.inplaceable = false},
+    %B : tensor<?xf32> {linalg.inplaceable = true},
+    %C : tensor<4xf32> {linalg.inplaceable = false},
+    %lb : index,
+    %ub : index,
+    %step : index)
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   //      CHECK: scf.for
@@ -597,9 +616,12 @@ func @scf_for_with_tensor.insert_slice(%A : tensor<?xf32>,
 func private @some_use(tensor<?xf32>) -> ()
 
 // CHECK-LABEL: func @scf_for_deps
-func @scf_for_deps(%A : tensor<?xf32> {linalg.inplaceable = true},
-                   %B : tensor<?xf32> {linalg.inplaceable = true},
-                   %lb : index, %ub : index, %step : index)
+func @scf_for_deps(
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %B : tensor<?xf32> {linalg.inplaceable = true},
+    %lb : index,
+    %ub : index,
+    %step : index)
   -> (tensor<?xf32>, tensor<?xf32>)
 {
   // %r0 must be out of place because one use of %t in the subsequent production

diff  --git a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir
index 08835d429f98e..4d6341501682c 100644
--- a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir
+++ b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir
@@ -6,7 +6,10 @@
 // RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=91" -split-input-file -o /dev/null
 
 // CHECK-LABEL: func @transfer_read(%{{.*}}: memref<?xf32, #map>) -> vector<4xf32> {
-func @transfer_read(%A : tensor<?xf32>) -> (vector<4xf32>) {
+func @transfer_read(
+    %A : tensor<?xf32> {linalg.inplaceable = false})
+  -> (vector<4xf32>)
+{
   %c0 = arith.constant 0 : index
   %f0 = arith.constant 0.0 : f32
 
@@ -23,7 +26,10 @@ func @transfer_read(%A : tensor<?xf32>) -> (vector<4xf32>) {
 
 // CHECK-LABEL: func @fill_inplace(
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
-func @fill_inplace(%A : tensor<?xf32> {linalg.inplaceable = true}) -> tensor<?xf32> {
+func @fill_inplace(
+    %A : tensor<?xf32> {linalg.inplaceable = true})
+  -> tensor<?xf32>
+{
   //     CHECK: %[[F0:.*]] = arith.constant 0.000000e+00 : f32
   %f0 = arith.constant 0.0 : f32
 
@@ -40,7 +46,7 @@ func @fill_inplace(%A : tensor<?xf32> {linalg.inplaceable = true}) -> tensor<?xf
 // -----
 
 // CHECK-LABEL: func @tensor_extract(%{{.*}}: memref<?xf32, #{{.*}}>) -> f32 {
-func @tensor_extract(%A : tensor<?xf32>) -> (f32) {
+func @tensor_extract(%A : tensor<?xf32> {linalg.inplaceable = false}) -> (f32) {
   %c0 = arith.constant 0 : index
 
 //       CHECK: %[[RES:.*]] = memref.load {{.*}} : memref<?xf32, #{{.*}}>
@@ -57,7 +63,10 @@ func @tensor_extract(%A : tensor<?xf32>) -> (f32) {
 /// No linalg.inplaceable flag, must allocate.
 // CHECK-LABEL: func @not_inplace(
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>) -> memref<?xf32> {
-func @not_inplace(%A : tensor<?xf32>) -> tensor<?xf32> {
+func @not_inplace(
+    %A : tensor<?xf32> {linalg.inplaceable = false})
+  -> tensor<?xf32>
+{
   //     CHECK: %[[F0:.*]] = arith.constant 0.000000e+00 : f32
   %f0 = arith.constant 0.0 : f32
 
@@ -77,7 +86,10 @@ func @not_inplace(%A : tensor<?xf32>) -> tensor<?xf32> {
 
 // CHECK-LABEL: func @not_inplace
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?x?xf32, #[[$map_2d_dyn]]>) {
-func @not_inplace(%A : tensor<?x?xf32> {linalg.inplaceable = true}) -> tensor<?x?xf32> {
+func @not_inplace(
+    %A : tensor<?x?xf32> {linalg.inplaceable = true})
+  -> tensor<?x?xf32>
+{
   %f0 = arith.constant 0.0 : f32
 
   /// Cross-op multiple uses of %A, the first op which has interfering reads must alloc.
@@ -161,9 +173,9 @@ func @vec_not_inplace(%A : tensor<?xf32> {linalg.inplaceable = true}, %vec : vec
 //  CHECK-SAME:   %[[A1:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>,
 //  CHECK-SAME:   %[[t0:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>,
 //  CHECK-SAME:   %[[t1:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>
-func @insert_slice_fun(%A0 : tensor<?xf32>,
+func @insert_slice_fun(%A0 : tensor<?xf32> {linalg.inplaceable = false},
                        %A1 : tensor<?xf32> {linalg.inplaceable = true},
-                       %t0 : tensor<4xf32>,
+                       %t0 : tensor<4xf32> {linalg.inplaceable = false},
                        %t1 : tensor<4xf32> {linalg.inplaceable = true})
   ->  (tensor<?xf32>, tensor<?xf32>, tensor<?xf32>, tensor<?xf32>)
 {
@@ -208,7 +220,9 @@ func @insert_slice_fun(%A0 : tensor<?xf32>,
 // CHECK-LABEL: func @insert_slice_fun
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
 //  CHECK-SAME:   %[[t:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>
-func @insert_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = true}, %t : tensor<4xf32>)
+func @insert_slice_fun(
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %t : tensor<4xf32> {linalg.inplaceable = false})
   -> tensor<?xf32>
 {
   %f0 = arith.constant 0.0 : f32
@@ -234,7 +248,9 @@ func @insert_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = true}, %t : tens
 // CHECK-LABEL: func @insert_slice_fun
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
 //  CHECK-SAME:   %[[t:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>
-func @insert_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = true}, %t : tensor<4xf32>)
+func @insert_slice_fun(
+    %A : tensor<?xf32> {linalg.inplaceable = true},
+    %t : tensor<4xf32> {linalg.inplaceable = false})
   -> tensor<?xf32>
 {
   %f0 = arith.constant 0.0 : f32
@@ -260,7 +276,9 @@ func @insert_slice_fun(%A : tensor<?xf32> {linalg.inplaceable = true}, %t : tens
 // CHECK-LABEL: func @insert_slice_fun_not_inplace
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
 //  CHECK-SAME:   %[[t:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>
-func @insert_slice_fun_not_inplace(%A : tensor<?xf32>, %t : tensor<4xf32>)
+func @insert_slice_fun_not_inplace(
+    %A : tensor<?xf32> {linalg.inplaceable = false},
+    %t : tensor<4xf32> {linalg.inplaceable = false})
   -> tensor<?xf32>
 {
   //      CHECK: %[[ALLOC:.*]] = memref.alloc(%{{.*}}) {alignment = 128 : i64} : memref<?xf32>
@@ -285,7 +303,7 @@ func @insert_slice_fun_not_inplace(%A : tensor<?xf32>, %t : tensor<4xf32>)
 // CHECK-LABEL: func @scf_for_yield_only
 //  CHECK-SAME:   %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
 //  CHECK-SAME:   %[[t:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
-func @scf_for_yield_only(%A : tensor<?xf32>,
+func @scf_for_yield_only(%A : tensor<?xf32> {linalg.inplaceable = false},
                          %B : tensor<?xf32> {linalg.inplaceable = true},
                          %lb : index, %ub : index, %step : index)
   -> (tensor<?xf32>, tensor<?xf32>)
@@ -340,9 +358,9 @@ func @nested_scf_for(%A : tensor<?xf32> {linalg.inplaceable = true},
 //  CHECK-SAME:   %[[B:[a-zA-Z0-9]*]]: memref<?xf32, #[[$map_1d_dyn]]>
 //  CHECK-SAME:   %[[C:[a-zA-Z0-9]*]]: memref<4xf32, #[[$map_1d_dyn]]>
 func @scf_for_with_tensor.insert_slice(
-   %A : tensor<?xf32>,
+   %A : tensor<?xf32> {linalg.inplaceable = false},
    %B : tensor<?xf32> {linalg.inplaceable = true},
-   %C : tensor<4xf32>,
+   %C : tensor<4xf32> {linalg.inplaceable = false},
    %lb : index, %ub : index, %step : index)
   -> (tensor<?xf32>, tensor<?xf32>)
 {
@@ -567,8 +585,13 @@ func private @some_use(memref<?xf32>)
 // CHECK-SAME:    %[[A:[a-zA-Z0-9]*]]: memref<?xf32, #[[$DYN_1D_MAP]]>
 // CHECK-SAME:    %[[B:[a-zA-Z0-9]*]]: memref<?xf32, #[[$DYN_1D_MAP]]>
 // CHECK-SAME:    %[[c:[a-zA-Z0-9]*]]: memref<f32, #[[$DYN_0D_MAP]]>
-func @tiled_dot(%A: tensor<?xf32>, %B: tensor<?xf32>, %c: tensor<f32> {linalg.inplaceable = true},
-                %effecting: memref<?xf32>) -> tensor<f32> {
+func @tiled_dot(
+    %A: tensor<?xf32> {linalg.inplaceable = false},
+    %B: tensor<?xf32> {linalg.inplaceable = false},
+    %c: tensor<f32> {linalg.inplaceable = true},
+    %effecting: memref<?xf32>)
+  -> tensor<f32>
+{
   %c3 = arith.constant 3 : index
   %c0 = arith.constant 0 : index
 
@@ -719,9 +742,9 @@ func @callee(%A : tensor<?xf32> {linalg.buffer_layout = affine_map<(i)[s0, s1] -
 // CHECK-SAME:   %[[A:[0-9a-zA-Z]*]]: memref<?xf32>
 // CHECK-SAME:   %[[B:[0-9a-zA-Z]*]]: memref<?xf32>
 // CHECK-SAME:   %[[C:[0-9a-zA-Z]*]]: memref<?xf32, #[[$DYNAMIC]]>
-func @entry(%A : tensor<?xf32> {linalg.buffer_layout = affine_map<(i)[s0, s1] -> (i)>},
-            %B : tensor<?xf32> {linalg.buffer_layout = affine_map<(i)[s0, s1] -> (i)>},
-            %C : tensor<?xf32>) {
+func @entry(%A : tensor<?xf32> {linalg.buffer_layout = affine_map<(i)[s0, s1] -> (i)>, linalg.inplaceable = false},
+            %B : tensor<?xf32> {linalg.buffer_layout = affine_map<(i)[s0, s1] -> (i)>, linalg.inplaceable = false},
+            %C : tensor<?xf32> {linalg.inplaceable = false}) {
 // CHECK-NEXT: %[[CASTED_B:.*]] = memref.cast %[[B]] : memref<?xf32> to memref<?xf32, #[[$DYNAMIC]]>
 // CHECK-NEXT: call @callee(%[[A]], %[[CASTED_B]], %[[C]])
   call @callee(%A, %B, %C) : (tensor<?xf32>, tensor<?xf32>, tensor<?xf32>) -> ()
@@ -809,7 +832,7 @@ func @matmul(
 //       CHECK:   %[[cast:.*]] = memref.cast %[[alloc]]
 func @tensor_cast_not_in_place(
     %A : tensor<?xf32> {linalg.inplaceable = true},
-    %B : tensor<?xf32>, %idx: index)
+    %B : tensor<?xf32> {linalg.inplaceable = false}, %idx: index)
   -> (tensor<?xf32>)
 {
   %r0 = tensor.cast %A : tensor<?xf32> to tensor<4xf32>
@@ -827,7 +850,11 @@ func @tensor_cast_not_in_place(
 /// errors in the def-use chains.
 
 // CHECK-LABEL: func @dominance_violation_bug_1
-func @dominance_violation_bug_1(%A : tensor<?x?xf32>, %idx : index) -> tensor<?x?xf32> {
+func @dominance_violation_bug_1(
+    %A : tensor<?x?xf32> {linalg.inplaceable = false},
+    %idx : index)
+  -> tensor<?x?xf32>
+{
   %f0 = arith.constant 0.0 : f32
 
   %sA = tensor.extract_slice %A[0, 0][%idx, %idx][1, 1] : tensor<?x?xf32> to tensor<?x?xf32>
@@ -958,7 +985,11 @@ func @scf_if_inside_scf_for(%t1: tensor<?xf32> {linalg.inplaceable = true},
 
 // CHECK-LABEL: func @scf_if_non_equiv_yields(
 //  CHECK-SAME:     %[[cond:.*]]: i1, %[[A:.*]]: memref<{{.*}}>, %[[B:.*]]: memref<{{.*}}>) -> memref<{{.*}}>
-func @scf_if_non_equiv_yields(%b : i1, %A : tensor<4xf32>, %B : tensor<4xf32>) -> tensor<4xf32>
+func @scf_if_non_equiv_yields(
+    %b : i1,
+    %A : tensor<4xf32> {linalg.inplaceable = false},
+    %B : tensor<4xf32> {linalg.inplaceable = false})
+  -> tensor<4xf32>
 {
   // CHECK: %[[r:.*]] = select %[[cond]], %[[A]], %[[B]]
   %r = scf.if %b -> (tensor<4xf32>) {
@@ -1092,7 +1123,9 @@ func @empty_func() -> () {
 
 // -----
 
-func @gather_like(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?xi32>,
+func @gather_like(
+    %arg0 : tensor<?x?xf32> {linalg.inplaceable = false},
+    %arg1 : tensor<?xi32> {linalg.inplaceable = false},
     %arg2 : tensor<?x?xf32> {linalg.inplaceable = true}) -> tensor<?x?xf32> {
   %0 = linalg.generic {
       indexing_maps = [affine_map<(d0, d1) -> (d0)>,
@@ -1101,9 +1134,9 @@ func @gather_like(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?xi32>,
       ins(%arg1 : tensor<?xi32>) outs(%arg2 : tensor<?x?xf32>) {
       ^bb0(%arg3: i32, %arg4 : f32):
         %iv1 = linalg.index 1 : index
-	%1 = arith.index_cast %arg3: i32 to index
-	%2 = tensor.extract %arg0[%1, %iv1] : tensor<?x?xf32>
-	linalg.yield %2 : f32
+        %1 = arith.index_cast %arg3: i32 to index
+        %2 = tensor.extract %arg0[%1, %iv1] : tensor<?x?xf32>
+        linalg.yield %2 : f32
       } -> tensor<?x?xf32>
   return %0 : tensor<?x?xf32>
 }
@@ -1124,7 +1157,8 @@ func @gather_like(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?xi32>,
 //  CHECK-SAME:     %[[t1:.*]]: memref<?x?xf32, #{{.*}}>, %[[t2:.*]]: memref<?xf32, #{{.*}}>, %[[t3:.*]]: memref<?x?xf32, #{{.*}}>
 func @linalg_op_bufferizes_inplace_with_input(
     %t1: tensor<?x?xf32> {linalg.inplaceable = true},
-    %t2: tensor<?xf32>, %t3: tensor<?x?xf32>,
+    %t2: tensor<?xf32> {linalg.inplaceable = false},
+    %t3: tensor<?x?xf32> {linalg.inplaceable = false},
     %s1: index, %s2: index, %cst: f32) -> tensor<?x?xf32> {
   // CHECK: linalg.generic {{.*}} ins(%[[t1]], %[[t2]] : {{.*}}) outs(%[[t1]] : {{.*}})
   %r = linalg.generic {
@@ -1146,7 +1180,9 @@ func @linalg_op_bufferizes_inplace_with_input(
 // CHECK-LABEL: func @linalg_op_bufferizes_out_of_place_with_input
 //  CHECK-SAME:     %[[t1:.*]]: memref<?x?xf32, #{{.*}}>, %[[t2:.*]]: memref<?xf32, #{{.*}}>, %[[t3:.*]]: memref<?x?xf32, #{{.*}}>
 func @linalg_op_bufferizes_out_of_place_with_input(
-    %t1: tensor<?x?xf32>, %t2: tensor<?xf32>, %t3: tensor<?x?xf32>,
+    %t1: tensor<?x?xf32> {linalg.inplaceable = false},
+    %t2: tensor<?xf32> {linalg.inplaceable = false},
+    %t3: tensor<?x?xf32> {linalg.inplaceable = false},
     %s1: index, %s2: index, %cst: f32) -> tensor<?x?xf32> {
   // CHECK: %[[alloc:.*]] = memref.alloc
   // CHECK: linalg.copy(%[[t1]], %[[alloc]])
@@ -1172,7 +1208,8 @@ func @linalg_op_bufferizes_out_of_place_with_input(
 //  CHECK-SAME:     %[[t1:.*]]: memref<?x?xf32, #{{.*}}>, %[[t2:.*]]: memref<?xf32, #{{.*}}>, %[[t3:.*]]: memref<?x?xf32, #{{.*}}>
 func @linalg_op_output_cannot_alias_with_input(
     %t1: tensor<?x?xf32> {linalg.inplaceable = true},
-    %t2: tensor<?xf32>, %t3: tensor<?x?xf32> {linalg.inplaceable = true},
+    %t2: tensor<?xf32> {linalg.inplaceable = false},
+    %t3: tensor<?x?xf32> {linalg.inplaceable = true},
     %s1: index, %s2: index, %cst: f32) -> tensor<?x?xf32> {
   // CHECK: linalg.generic {{.*}} ins(%[[t1]], %[[t2]] : {{.*}}) outs(%[[t3]] : {{.*}})
   %r = linalg.generic {


        


More information about the Mlir-commits mailing list