1//===- Bufferize.cpp - Bufferization for `tensor` dialect ops -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements bufferization of `tensor` dialect ops
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
14#include "mlir/Dialect/Arith/IR/Arith.h"
15#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
16#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
17#include "mlir/Dialect/Func/IR/FuncOps.h"
18#include "mlir/Dialect/MemRef/IR/MemRef.h"
19#include "mlir/Dialect/SCF/IR/SCF.h"
20#include "mlir/Dialect/Tensor/IR/Tensor.h"
21#include "mlir/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.h"
22#include "mlir/Dialect/Tensor/Transforms/Passes.h"
23#include "mlir/IR/ImplicitLocOpBuilder.h"
24#include "mlir/Transforms/DialectConversion.h"
25
26namespace mlir {
27namespace tensor {
28#define GEN_PASS_DEF_TENSORBUFFERIZE
29#include "mlir/Dialect/Tensor/Transforms/Passes.h.inc"
30} // namespace tensor
31} // namespace mlir
32
33using namespace mlir;
34using namespace bufferization;
35
36namespace {
37struct TensorBufferizePass
38 : public tensor::impl::TensorBufferizeBase<TensorBufferizePass> {
39 void runOnOperation() override {
40 BufferizationOptions options = getPartialBufferizationOptions();
41 options.opFilter.allowDialect<tensor::TensorDialect>();
42
43 if (failed(bufferizeOp(getOperation(), options)))
44 signalPassFailure();
45 }
46
47 void getDependentDialects(DialectRegistry &registry) const override {
48 registry
49 .insert<bufferization::BufferizationDialect, memref::MemRefDialect,
50 tensor::TensorDialect, scf::SCFDialect, arith::ArithDialect>();
51 tensor::registerBufferizableOpInterfaceExternalModels(registry);
52 }
53};
54} // namespace
55
56std::unique_ptr<Pass> mlir::tensor::createTensorBufferizePass() {
57 return std::make_unique<TensorBufferizePass>();
58}
59

source code of mlir/lib/Dialect/Tensor/Transforms/Bufferize.cpp