diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h --- a/mlir/include/mlir/Dialect/Linalg/Passes.h +++ b/mlir/include/mlir/Dialect/Linalg/Passes.h @@ -46,8 +46,7 @@ /// Create a pass to convert Linalg operations which work on tensors to use /// buffers instead. -std::unique_ptr> -createConvertLinalgOnTensorsToBuffersPass(); +std::unique_ptr> createLinalgBufferizePass(); /// Patterns for fusing linalg operation on tensors. void populateLinalgTensorOpsFusionPatterns(MLIRContext *context, diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -48,10 +48,9 @@ let dependentDialects = ["linalg::LinalgDialect", "scf::SCFDialect", "AffineDialect"]; } -def LinalgOnTensorsToBuffers : Pass<"convert-linalg-on-tensors-to-buffers", "ModuleOp"> { - let summary = "Convert the Linalg operations which work on tensor-type " - "operands or results to use buffers instead"; - let constructor = "mlir::createConvertLinalgOnTensorsToBuffersPass()"; +def LinalgBufferize : Pass<"linalg-bufferize", "ModuleOp"> { + let summary = "Bufferize the linalg dialect"; + let constructor = "mlir::createLinalgBufferizePass()"; let dependentDialects = ["linalg::LinalgDialect", "vector::VectorDialect"]; } diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -49,11 +49,10 @@ MLIRContext *context, SmallVectorImpl &patterns, ArrayRef tileSizes); -/// Populates the given list with patterns to convert Linalg operations on -/// tensors to buffers. -void populateConvertLinalgOnTensorsToBuffersPatterns( - MLIRContext *context, BufferAssignmentTypeConverter &converter, - OwningRewritePatternList &patterns); +/// Populates the given list with patterns to bufferize linalg ops. +void populateLinalgBufferizePatterns(MLIRContext *context, + BufferAssignmentTypeConverter &converter, + OwningRewritePatternList &patterns); /// Performs standalone tiling of a single LinalgOp by `tileSizes`. /// and permute the loop nest according to `interchangeVector` diff --git a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir --- a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir +++ b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -convert-linalg-on-tensors-to-buffers -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \ +// RUN: mlir-opt %s -linalg-bufferize -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \ // RUN: mlir-cpu-runner -e main -entry-point-result=void \ // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \ // RUN: | FileCheck %s diff --git a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir --- a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir +++ b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -convert-linalg-on-tensors-to-buffers -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \ +// RUN: mlir-opt %s -linalg-bufferize -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \ // RUN: mlir-cpu-runner -e main -entry-point-result=void \ // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \ // RUN: | FileCheck %s diff --git a/mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp rename from mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp rename to mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp @@ -1,16 +1,12 @@ -//===- TensorsToBuffers.cpp - Transformation from tensors to buffers ------===// +//===- Bufferize.cpp - Bufferization of linalg ops ------------------===// // // 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 implements the conversion from tensors to buffers on Linalg -// operations. -// -//===----------------------------------------------------------------------===// +#include "mlir/Transforms/Bufferize.h" #include "PassDetail.h" #include "mlir/Dialect/Linalg/IR/LinalgOps.h" #include "mlir/Dialect/Linalg/Passes.h" @@ -20,7 +16,6 @@ #include "mlir/IR/Function.h" #include "mlir/IR/Operation.h" #include "mlir/Pass/Pass.h" -#include "mlir/Transforms/Bufferize.h" using namespace ::mlir; using namespace ::mlir::linalg; @@ -295,8 +290,7 @@ /// Converts Linalg operations that work on tensor-type operands or results to /// work on buffers. -struct ConvertLinalgOnTensorsToBuffers - : public LinalgOnTensorsToBuffersBase { +struct LinalgBufferizePass : public LinalgBufferizeBase { void runOnOperation() override { MLIRContext &context = getContext(); ConversionTarget target(context); @@ -353,8 +347,7 @@ BufferAssignmentTypeConverter::AppendToArgumentsList); OwningRewritePatternList patterns; - populateConvertLinalgOnTensorsToBuffersPatterns(&context, converter, - patterns); + populateLinalgBufferizePatterns(&context, converter, patterns); populateWithBufferAssignmentOpConversionPatterns< mlir::ReturnOp, mlir::ReturnOp, linalg::CopyOp>(&context, converter, patterns); @@ -364,12 +357,10 @@ }; } // end anonymous namespace -std::unique_ptr> -mlir::createConvertLinalgOnTensorsToBuffersPass() { - return std::make_unique(); +std::unique_ptr> mlir::createLinalgBufferizePass() { + return std::make_unique(); } -void mlir::linalg::populateConvertLinalgOnTensorsToBuffersPatterns( - +void mlir::linalg::populateLinalgBufferizePatterns( MLIRContext *context, BufferAssignmentTypeConverter &converter, OwningRewritePatternList &patterns) { patterns.insert< diff --git a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt --- a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt @@ -1,4 +1,5 @@ add_mlir_dialect_library(MLIRLinalgTransforms + Bufferize.cpp CodegenStrategy.cpp DropUnitDims.cpp Fusion.cpp @@ -7,7 +8,6 @@ Interchange.cpp Loops.cpp Promotion.cpp - TensorsToBuffers.cpp Tiling.cpp Transforms.cpp Vectorization.cpp diff --git a/mlir/test/Dialect/Linalg/tensors-to-buffers.mlir b/mlir/test/Dialect/Linalg/bufferize.mlir rename from mlir/test/Dialect/Linalg/tensors-to-buffers.mlir rename to mlir/test/Dialect/Linalg/bufferize.mlir --- a/mlir/test/Dialect/Linalg/tensors-to-buffers.mlir +++ b/mlir/test/Dialect/Linalg/bufferize.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt -convert-linalg-on-tensors-to-buffers -buffer-placement -split-input-file %s | FileCheck %s +// RUN: mlir-opt -linalg-bufferize -buffer-placement -split-input-file %s | FileCheck %s #map0 = affine_map<(d0) -> (d0)>