[Mlir-commits] [mlir] 6b30fb7 - [mlir] Rename ShapeTypeConversion to ShapeBufferize

Sean Silva llvmlistbot at llvm.org
Wed Oct 14 12:41:32 PDT 2020


Author: Sean Silva
Date: 2020-10-14T12:39:16-07:00
New Revision: 6b30fb7653948fec80ca0cea19d8691495c96c28

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

LOG: [mlir] Rename ShapeTypeConversion to ShapeBufferize

Once we have tensor_to_memref ops suitable for type materializations,
this pass can be split into a generic type conversion pattern.

Part of the refactor discussed in:
https://llvm.discourse.group/t/what-is-the-strategy-for-tensor-memref-conversion-bufferization/1938/17

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

Added: 
    mlir/lib/Dialect/Shape/Transforms/Bufferize.cpp
    mlir/test/Dialect/Shape/bufferize.mlir

Modified: 
    mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
    mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
    mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt

Removed: 
    mlir/lib/Dialect/Shape/Transforms/ShapeTypeConversion.cpp
    mlir/test/Dialect/Shape/shape-type-conversion.mlir


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
index 81f64dc3ccb3..0d1635fd90c6 100644
--- a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
@@ -43,9 +43,12 @@ std::unique_ptr<FunctionPass> createRemoveShapeConstraintsPass();
 void populateShapeTypeConversionPatterns(
     MLIRContext *ctx, BufferAssignmentTypeConverter &converter,
     OwningRewritePatternList &patterns);
-// Collects a set of patterns to replace tensors as inputs and outputs to shape
-// operations with buffers. This only modifies the shape operations.
-std::unique_ptr<FunctionPass> createShapeTensorToMemrefPass();
+// Bufferizes shape dialect ops.
+//
+// Note that most shape dialect ops must be converted to std before
+// bufferization happens, as they are intended to be bufferized at the std
+// level.
+std::unique_ptr<FunctionPass> createShapeBufferizePass();
 
 //===----------------------------------------------------------------------===//
 // Registration

diff  --git a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
index e3b6a476a9f5..c4ccdbd0c2d3 100644
--- a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
@@ -22,8 +22,8 @@ def ShapeToShapeLowering : FunctionPass<"shape-to-shape-lowering"> {
 }
 
 // TODO: Generalize this to allow any type conversions desired.
-def ShapeTensorToMemref : FunctionPass<"shape-tensor-to-memref"> {
-  let summary = "Replace tensors involving shape operations with memrefs";
-  let constructor = "mlir::createShapeTensorToMemrefPass()";
+def ShapeBufferize : FunctionPass<"shape-bufferize"> {
+  let summary = "Bufferize the shape dialect.";
+  let constructor = "mlir::createShapeBufferizePass()";
 }
 #endif // MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES

diff  --git a/mlir/lib/Dialect/Shape/Transforms/ShapeTypeConversion.cpp b/mlir/lib/Dialect/Shape/Transforms/Bufferize.cpp
similarity index 84%
rename from mlir/lib/Dialect/Shape/Transforms/ShapeTypeConversion.cpp
rename to mlir/lib/Dialect/Shape/Transforms/Bufferize.cpp
index 83e432855f6e..4eb29f7002a0 100644
--- a/mlir/lib/Dialect/Shape/Transforms/ShapeTypeConversion.cpp
+++ b/mlir/lib/Dialect/Shape/Transforms/Bufferize.cpp
@@ -1,16 +1,12 @@
-//====----- ShapeTypeConversion.cpp - Shape Type Conversions ----*- C++-*--===//
+//====----- Bufferize.cpp - Bufferization of shape ops  ---------*- C++-*--===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-//
-// This file defines patterns to convert types of inputs and outputs to shape
-// operations to be memrefs instead of tensors.
-//
-//===----------------------------------------------------------------------===//
 
+#include "mlir/Transforms/Bufferize.h"
 #include "PassDetail.h"
 #include "mlir/Dialect/Shape/IR/Shape.h"
 #include "mlir/Dialect/Shape/Transforms/Passes.h"
@@ -18,7 +14,6 @@
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/StandardTypes.h"
 #include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/Bufferize.h"
 
 using namespace mlir;
 using namespace mlir::shape;
@@ -53,8 +48,7 @@ class TypeConversionAssumingOpConverter
   }
 };
 
-struct ShapeTensorToMemrefPass
-    : public ShapeTensorToMemrefBase<ShapeTensorToMemrefPass> {
+struct ShapeBufferizePass : public ShapeBufferizeBase<ShapeBufferizePass> {
   void runOnFunction() override {
     MLIRContext &ctx = getContext();
 
@@ -87,9 +81,9 @@ void mlir::populateShapeTypeConversionPatterns(
 }
 
 //===----------------------------------------------------------------------===//
-// ShapeTensorToMemrefPass construction
+// ShapeBufferizePass construction
 //===----------------------------------------------------------------------===//
 
-std::unique_ptr<FunctionPass> mlir::createShapeTensorToMemrefPass() {
-  return std::make_unique<ShapeTensorToMemrefPass>();
+std::unique_ptr<FunctionPass> mlir::createShapeBufferizePass() {
+  return std::make_unique<ShapeBufferizePass>();
 }

diff  --git a/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
index 9df40a0fb740..ce413f57d989 100644
--- a/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_mlir_dialect_library(MLIRShapeOpsTransforms
+  Bufferize.cpp
   RemoveShapeConstraints.cpp
-  ShapeTypeConversion.cpp
   ShapeToShapeLowering.cpp
 
   ADDITIONAL_HEADER_DIRS

diff  --git a/mlir/test/Dialect/Shape/shape-type-conversion.mlir b/mlir/test/Dialect/Shape/bufferize.mlir
similarity index 84%
rename from mlir/test/Dialect/Shape/shape-type-conversion.mlir
rename to mlir/test/Dialect/Shape/bufferize.mlir
index 52bc6658a821..7393de101466 100644
--- a/mlir/test/Dialect/Shape/shape-type-conversion.mlir
+++ b/mlir/test/Dialect/Shape/bufferize.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -shape-tensor-to-memref <%s | FileCheck %s
+// RUN: mlir-opt -split-input-file -shape-bufferize <%s | FileCheck %s
 
 // -----
 // Check that shape.assuming returns a memref.
@@ -14,5 +14,3 @@ func @shape_assuming_returns_memref() {
   "test.sink"(%1) : (tensor<2xf16>) -> ()
   return
 }
-
-


        


More information about the Mlir-commits mailing list