[all-commits] [llvm/llvm-project] ffdbec: [mlir][bufferization] Add bufferization.alloc_tens...

Matthias Springer via All-commits all-commits at lists.llvm.org
Fri May 20 17:57:31 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ffdbecccafdf96c37921e3e74bb436aa169faefa
      https://github.com/llvm/llvm-project/commit/ffdbecccafdf96c37921e3e74bb436aa169faefa
  Author: Matthias Springer <springerm at google.com>
  Date:   2022-05-21 (Sat, 21 May 2022)

  Changed paths:
    M mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h
    M mlir/include/mlir/Dialect/Bufferization/IR/BufferizationBase.td
    M mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
    A mlir/include/mlir/Dialect/Bufferization/Transforms/AllocTensorElimination.h
    M mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
    M mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
    M mlir/include/mlir/Dialect/Linalg/Passes.h
    M mlir/include/mlir/Dialect/Linalg/Passes.td
    M mlir/include/mlir/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.h
    M mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
    M mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
    M mlir/lib/Dialect/Bufferization/IR/CMakeLists.txt
    A mlir/lib/Dialect/Bufferization/Transforms/AllocTensorElimination.cpp
    M mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
    M mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
    M mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
    M mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
    M mlir/lib/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.cpp
    M mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
    R mlir/lib/Dialect/Linalg/Transforms/InitTensorElimination.cpp
    A mlir/lib/Dialect/Linalg/Transforms/InitTensorToAllocTensor.cpp
    A mlir/python/mlir/dialects/BufferizationOps.td
    A mlir/python/mlir/dialects/_bufferization_ops_ext.py
    A mlir/test/Dialect/Bufferization/Transforms/one-shot-bufferize-alloc-tensor-elimination.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-bufferize-allow-return-allocs.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-bufferize-partial.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-bufferize.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-allow-return-allocs.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
    M mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir
    M mlir/test/Dialect/Bufferization/canonicalize.mlir
    A mlir/test/Dialect/Bufferization/invalid.mlir
    M mlir/test/Dialect/Linalg/one-shot-bufferize-analysis-2fill-extract-matmul-all-perms.mlir
    M mlir/test/Dialect/Linalg/one-shot-bufferize-analysis-init-tensor-elimination.mlir
    R mlir/test/Dialect/Linalg/one-shot-bufferize-init-tensor-elimination.mlir
    M mlir/test/Dialect/Linalg/one-shot-bufferize.mlir
    M mlir/test/Dialect/SCF/one-shot-bufferize-analysis.mlir
    M mlir/test/Dialect/SCF/one-shot-bufferize.mlir
    M mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
    M mlir/test/Integration/Dialect/Linalg/CPU/test-one-shot-bufferize.mlir
    M mlir/test/Integration/Dialect/Linalg/CPU/test-padtensor.mlir
    M utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

  Log Message:
  -----------
  [mlir][bufferization] Add bufferization.alloc_tensor op

This change adds a new op `alloc_tensor` to the bufferization dialect. During bufferization, this op is always lowered to a buffer allocation (unless it is "eliminated" by a pre-processing pass). It is useful to have such an op in tensor land, because it allows users to model tensor SSA use-def chains (which drive bufferization decisions) and because tensor SSA use-def chains can be analyzed by One-Shot Bufferize, while memref values cannot.

This change also replaces all uses of linalg.init_tensor in bufferization-related code with bufferization.alloc_tensor.

linalg.init_tensor and bufferization.alloc_tensor are similar, but the purpose of the former one is just to carry a shape. It does not indicate a memory allocation.

linalg.init_tensor is not suitable for modelling SSA use-def chains for bufferization purposes, because linalg.init_tensor is marked as not having side effects (in contrast to alloc_tensor). As such, it is legal to move linalg.init_tensor ops around/CSE them/etc. This is not desirable for alloc_tensor; it represents an explicit buffer allocation while still in tensor land and such allocations should not suddenly disappear or get moved around when running the canonicalizer/CSE/etc.

BEGIN_PUBLIC
No public commit message needed for presubmit.
END_PUBLIC

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




More information about the All-commits mailing list