[Mlir-commits] [mlir] b2f5004 - Revert "[mlir][bufferize] Insert memref.cast ops during finalizing pass"

Matthias Springer llvmlistbot at llvm.org
Thu Jan 27 03:49:45 PST 2022


Author: Matthias Springer
Date: 2022-01-27T20:48:58+09:00
New Revision: b2f50042590577b25184ab0f7d3461d167e6bd9e

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

LOG: Revert "[mlir][bufferize] Insert memref.cast ops during finalizing pass"

This reverts commit 1043107ce5e2dee38f6a9bf459549a75f78a83b2.

This commit caused a breakage in `finalizing-bufferize.mlir`.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h
    mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
    mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
    mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h b/mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h
index 2a1edf8d9e099..2cbfc901f239b 100644
--- a/mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h
+++ b/mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h
@@ -20,18 +20,6 @@
 
 #include "mlir/Dialect/Bufferization/IR/BufferizationOpsDialect.h.inc"
 
-namespace mlir {
-class RewritePatternSet;
-class MLIRContext;
-
-namespace bufferization {
-/// Populate patterns for folding to_memref and to_tensor ops.
-/// Note: to_memref(to_tensor(x)) without type changes are handled by a folder.
-void populateBufferizationOpFoldingPatterns(RewritePatternSet &patterns,
-                                            MLIRContext *context);
-} // namespace bufferization
-} // namespace mlir
-
 //===----------------------------------------------------------------------===//
 // Bufferization Dialect Operations
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index 28a8e5d1ea982..f1ec7bbdead24 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -240,8 +240,7 @@ static LogicalResult foldToMemrefToTensorPair(RewriterBase &rewriter,
       if (resultType.getShape()[i] != ShapedType::kDynamicSize)
         continue;
       auto index = rewriter.createOrFold<arith::ConstantIndexOp>(loc, i);
-      Value size =
-          rewriter.create<memref::DimOp>(loc, memrefToTensor.memref(), index);
+      Value size = rewriter.create<tensor::DimOp>(loc, memrefToTensor, index);
       dynamicOperands.push_back(size);
     }
     // TODO: Use alloc/memcpy callback from BufferizationOptions if called via
@@ -310,11 +309,6 @@ void ToMemrefOp::getCanonicalizationPatterns(RewritePatternSet &results,
       context);
 }
 
-void bufferization::populateBufferizationOpFoldingPatterns(
-    RewritePatternSet &patterns, MLIRContext *context) {
-  patterns.add<TensorLoadToMemref>(context);
-}
-
 LogicalResult ToMemrefOp::bufferize(RewriterBase &rewriter,
                                     const BufferizationState &state) {
   // Fold to_memref(to_tensor(x)) to x. Insert a cast if necessary.

diff  --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index d31c3532509e7..2b2d7cceeabb4 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -92,7 +92,6 @@ void mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns(
     BufferizeTypeConverter &typeConverter, RewritePatternSet &patterns) {
   patterns.add<BufferizeToTensorOp, BufferizeToMemrefOp>(typeConverter,
                                                          patterns.getContext());
-  populateBufferizationOpFoldingPatterns(patterns, patterns.getContext());
 }
 
 namespace {

diff  --git a/mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir b/mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir
index 66e1ccfe5c763..fac685ae7e725 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir
@@ -1,11 +1,11 @@
 // RUN: mlir-opt %s -finalizing-bufferize -split-input-file -verify-diagnostics | FileCheck %s
 
-// CHECK-LABEL: func @eliminate_materializations(
-//  CHECK-SAME:     %[[ARG:.*]]: memref<f32>) -> memref<f32> {
+// CHECK-LABEL:   func @eliminate_materializations(
+// CHECK-SAME:                                     %[[ARG:.*]]: memref<f32>) -> memref<f32> {
+// CHECK:           return %[[ARG]] : memref<f32>
 func @eliminate_materializations(%arg0: memref<f32>) -> memref<f32> {
   %0 = bufferization.to_tensor %arg0 : memref<f32>
   %1 = bufferization.to_memref %0 : memref<f32>
-  // CHECK: return %[[ARG]] : memref<f32>
   return %1 : memref<f32>
 }
 
@@ -26,37 +26,3 @@ func @unable_to_convert_lone_tensor_load(%arg0: memref<f32>) {
   "test.sink"(%0) : (tensor<f32>) -> ()
   return
 }
-
-// -----
-
-// CHECK: #[[$MAP1:.*]] = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)>
-#map1 = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)>
-
-// CHECK-LABEL: func @insert_memref_cast(
-//  CHECK-SAME:     %[[arg0:.*]]: memref<?xf32>
-func @insert_memref_cast(%arg0: memref<?xf32>) -> memref<?xf32, #map1> {
-  %0 = bufferization.to_tensor %arg0 : memref<?xf32>
-  %1 = bufferization.to_memref %0 : memref<?xf32, #map1>
-  // CHECK: %[[r:.*]] = memref.cast %[[arg0]] : memref<?xf32> to memref<?xf32, #[[$MAP1]]>
-  // CHECK: return %[[r]]
-  return %1 : memref<?xf32, #map1>
-}
-
-// -----
-
-// CHECK: #[[$MAP2:.*]] = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)>
-#map2 = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)>
-
-// CHECK-LABEL: func @insert_buffer_copy(
-//  CHECK-SAME:     %[[arg0:.*]]: memref<?xf32, #[[$MAP2]]>
-func @insert_buffer_copy(%arg0: memref<?xf32, #map2>) -> memref<?xf32> {
-  // CHECK: %[[c0:.*]] = arith.constant 0 : index
-  // CHECK: %[[dim0:.*]] = memref.dim %[[arg0]], %[[c0]]
-  // CHECK: %[[alloc:.*]] = memref.alloc(%[[dim0]]) : memref<?xf32>
-  // CHECK: memref.copy %[[arg0]], %[[alloc]]
-  %0 = bufferization.to_tensor %arg0 : memref<?xf32, #map2>
-  %1 = bufferization.to_memref %0 : memref<?xf32>
-
-  // CHECK: return %[[alloc]]
-  return %1 : memref<?xf32>
-}


        


More information about the Mlir-commits mailing list