xref: /llvm-project/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h (revision db791b278a414fb6df1acc1799adcf11d8fb9169)
1 //===- OneShotModuleBufferize.h - Bufferization across Func. Boundaries ---===//
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 #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H
10 #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H
11 
12 namespace llvm {
13 struct LogicalResult;
14 } // namespace llvm
15 
16 namespace mlir {
17 class ModuleOp;
18 
19 namespace bufferization {
20 struct BufferizationStatistics;
21 class OneShotAnalysisState;
22 struct OneShotBufferizationOptions;
23 
24 /// Analyze `moduleOp` and its nested ops. Bufferization decisions are stored in
25 /// `state`.
26 llvm::LogicalResult
27 analyzeModuleOp(ModuleOp moduleOp, OneShotAnalysisState &state,
28                 BufferizationStatistics *statistics = nullptr);
29 
30 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
31 ///
32 /// Note: This function does not run One-Shot Analysis. No buffer copies are
33 /// inserted except two cases:
34 /// - `options.copyBeforeWrite` is set, in which case buffers are copied before
35 ///   every write.
36 /// - `options.copyBeforeWrite` is not set and `options.noAnalysisFuncFilter`
37 ///   is not empty. The FuncOps it contains were not analyzed. Buffer copies
38 ///   will be inserted only to these FuncOps.
39 llvm::LogicalResult
40 bufferizeModuleOp(ModuleOp moduleOp, const OneShotBufferizationOptions &options,
41                   BufferizationStatistics *statistics = nullptr);
42 
43 /// Remove bufferization attributes on every FuncOp arguments in the ModuleOp.
44 void removeBufferizationAttributesInModule(ModuleOp moduleOp);
45 
46 /// Run One-Shot Module Bufferization on the given module. Performs a simple
47 /// function call analysis to determine which function arguments are
48 /// inplaceable. Then analyzes and bufferizes FuncOps one-by-one with One-Shot
49 /// Bufferize.
50 llvm::LogicalResult runOneShotModuleBufferize(
51     ModuleOp moduleOp,
52     const bufferization::OneShotBufferizationOptions &options,
53     BufferizationStatistics *statistics = nullptr);
54 
55 } // namespace bufferization
56 } // namespace mlir
57 
58 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H
59