1//===- BufferizationPipelines.cpp - Pipelines for bufferization -----------===//
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#include "mlir/Dialect/Bufferization/Pipelines/Passes.h"
10
11#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
12#include "mlir/Dialect/MemRef/Transforms/Passes.h"
13#include "mlir/Pass/PassManager.h"
14#include "mlir/Transforms/Passes.h"
15
16//===----------------------------------------------------------------------===//
17// Pipeline implementation.
18//===----------------------------------------------------------------------===//
19
20void mlir::bufferization::buildBufferDeallocationPipeline(OpPassManager &pm) {
21 buildBufferDeallocationPipeline(pm, options: BufferDeallocationPipelineOptions());
22}
23
24void mlir::bufferization::buildBufferDeallocationPipeline(
25 OpPassManager &pm, const BufferDeallocationPipelineOptions &options) {
26 memref::ExpandReallocPassOptions expandAllocPassOptions{
27 /*emitDeallocs=*/false};
28 pm.addPass(pass: memref::createExpandReallocPass(options: expandAllocPassOptions));
29 pm.addPass(pass: createCanonicalizerPass());
30
31 OwnershipBasedBufferDeallocationPassOptions deallocationOptions{
32 .privateFuncDynamicOwnership: options.privateFunctionDynamicOwnership};
33 pm.addPass(pass: createOwnershipBasedBufferDeallocationPass(options: deallocationOptions));
34 pm.addPass(pass: createCanonicalizerPass());
35 pm.addPass(pass: createBufferDeallocationSimplificationPass());
36 pm.addPass(pass: createLowerDeallocationsPass());
37 pm.addPass(pass: createCSEPass());
38 pm.addPass(pass: createCanonicalizerPass());
39}
40
41//===----------------------------------------------------------------------===//
42// Pipeline registration.
43//===----------------------------------------------------------------------===//
44
45void mlir::bufferization::registerBufferizationPipelines() {
46 PassPipelineRegistration<BufferDeallocationPipelineOptions>(
47 "buffer-deallocation-pipeline",
48 "The default pipeline for automatically inserting deallocation "
49 "operations after one-shot bufferization. Deallocation operations "
50 "(except `memref.realloc`) may not be present already.",
51 [](OpPassManager &pm, const BufferDeallocationPipelineOptions &options) {
52 buildBufferDeallocationPipeline(pm, options);
53 });
54}
55