xref: /llvm-project/mlir/lib/Dialect/Bufferization/Pipelines/BufferizationPipelines.cpp (revision c08d972a0043fe67de65ba331a144425c8cea449)
108b7a71bSMartin Erhart //===- BufferizationPipelines.cpp - Pipelines for bufferization -----------===//
208b7a71bSMartin Erhart //
308b7a71bSMartin Erhart // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
408b7a71bSMartin Erhart // See https://llvm.org/LICENSE.txt for license information.
508b7a71bSMartin Erhart // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
608b7a71bSMartin Erhart //
708b7a71bSMartin Erhart //===----------------------------------------------------------------------===//
808b7a71bSMartin Erhart 
908b7a71bSMartin Erhart #include "mlir/Dialect/Bufferization/Pipelines/Passes.h"
1008b7a71bSMartin Erhart 
1108b7a71bSMartin Erhart #include "mlir/Dialect/Bufferization/Transforms/Passes.h"
1208b7a71bSMartin Erhart #include "mlir/Dialect/Func/IR/FuncOps.h"
1308b7a71bSMartin Erhart #include "mlir/Dialect/MemRef/Transforms/Passes.h"
1408b7a71bSMartin Erhart #include "mlir/Pass/PassManager.h"
1508b7a71bSMartin Erhart #include "mlir/Transforms/Passes.h"
1608b7a71bSMartin Erhart 
1708b7a71bSMartin Erhart //===----------------------------------------------------------------------===//
1808b7a71bSMartin Erhart // Pipeline implementation.
1908b7a71bSMartin Erhart //===----------------------------------------------------------------------===//
2008b7a71bSMartin Erhart 
buildBufferDeallocationPipeline(OpPassManager & pm,const BufferDeallocationPipelineOptions & options)2108b7a71bSMartin Erhart void mlir::bufferization::buildBufferDeallocationPipeline(
2208b7a71bSMartin Erhart     OpPassManager &pm, const BufferDeallocationPipelineOptions &options) {
235109cb28SMatthias Springer   pm.addPass(memref::createExpandReallocPass(/*emitDeallocs=*/false));
245109cb28SMatthias Springer   pm.addPass(createCanonicalizerPass());
25*c08d972aSMatthias Springer   pm.addPass(createOwnershipBasedBufferDeallocationPass(options));
265109cb28SMatthias Springer   pm.addPass(createCanonicalizerPass());
275109cb28SMatthias Springer   pm.addPass(createBufferDeallocationSimplificationPass());
2808b7a71bSMartin Erhart   pm.addPass(createLowerDeallocationsPass());
295109cb28SMatthias Springer   pm.addPass(createCSEPass());
305109cb28SMatthias Springer   pm.addPass(createCanonicalizerPass());
3108b7a71bSMartin Erhart }
3208b7a71bSMartin Erhart 
3308b7a71bSMartin Erhart //===----------------------------------------------------------------------===//
3408b7a71bSMartin Erhart // Pipeline registration.
3508b7a71bSMartin Erhart //===----------------------------------------------------------------------===//
3608b7a71bSMartin Erhart 
registerBufferizationPipelines()3708b7a71bSMartin Erhart void mlir::bufferization::registerBufferizationPipelines() {
3808b7a71bSMartin Erhart   PassPipelineRegistration<BufferDeallocationPipelineOptions>(
3908b7a71bSMartin Erhart       "buffer-deallocation-pipeline",
4008b7a71bSMartin Erhart       "The default pipeline for automatically inserting deallocation "
4108b7a71bSMartin Erhart       "operations after one-shot bufferization. Deallocation operations "
4208b7a71bSMartin Erhart       "(except `memref.realloc`) may not be present already.",
4308b7a71bSMartin Erhart       buildBufferDeallocationPipeline);
4408b7a71bSMartin Erhart }
45