1 | //===- BufferizableOpInterfaceImpl.h - Impl. of BufferizableOpInterface ---===// |
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_BUFFERIZATION_TRANSFORMS_FUNCBUFFERIZABLEOPINTERFACEIMPL_H |
10 | #define MLIR_BUFFERIZATION_TRANSFORMS_FUNCBUFFERIZABLEOPINTERFACEIMPL_H |
11 | |
12 | #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h" |
13 | #include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h" |
14 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
15 | |
16 | namespace mlir { |
17 | class DialectRegistry; |
18 | |
19 | namespace func { |
20 | class FuncOp; |
21 | } // namespace func |
22 | |
23 | namespace bufferization { |
24 | namespace func_ext { |
25 | /// The state of analysis of a FuncOp. |
26 | enum class FuncOpAnalysisState { NotAnalyzed, InProgress, Analyzed }; |
27 | |
28 | using func::FuncOp; |
29 | |
30 | /// Extra analysis state that is required for bufferization of function |
31 | /// boundaries. |
32 | struct FuncAnalysisState : public OneShotAnalysisState::Extension { |
33 | FuncAnalysisState(OneShotAnalysisState &state) |
34 | : OneShotAnalysisState::Extension(state) {} |
35 | |
36 | // Note: Function arguments and/or function return values may disappear during |
37 | // bufferization. Functions and their CallOps are analyzed and bufferized |
38 | // separately. To ensure that a CallOp analysis/bufferization can access an |
39 | // already bufferized function's analysis results, we store bbArg/return value |
40 | // indices instead of BlockArguments/OpOperand pointers. |
41 | |
42 | /// A set of block argument indices. |
43 | using BbArgIndexSet = DenseSet<int64_t>; |
44 | |
45 | /// A mapping of indices to indices. |
46 | using IndexMapping = DenseMap<int64_t, int64_t>; |
47 | |
48 | /// A mapping of indices to a list of indices. |
49 | using IndexToIndexListMapping = DenseMap<int64_t, SmallVector<int64_t>>; |
50 | |
51 | /// A mapping of ReturnOp OpOperand indices to equivalent FuncOp BBArg |
52 | /// indices. |
53 | DenseMap<FuncOp, IndexMapping> equivalentFuncArgs; |
54 | |
55 | /// A mapping of FuncOp BBArg indices to aliasing ReturnOp OpOperand indices. |
56 | DenseMap<FuncOp, IndexToIndexListMapping> aliasingReturnVals; |
57 | |
58 | /// A set of all read BlockArguments of FuncOps. |
59 | DenseMap<FuncOp, BbArgIndexSet> readBbArgs; |
60 | |
61 | /// A set of all written-to BlockArguments of FuncOps. |
62 | DenseMap<FuncOp, BbArgIndexSet> writtenBbArgs; |
63 | |
64 | /// Keep track of which FuncOps are fully analyzed or currently being |
65 | /// analyzed. |
66 | DenseMap<FuncOp, FuncOpAnalysisState> analyzedFuncOps; |
67 | |
68 | /// This function is called right before analyzing the given FuncOp. It |
69 | /// initializes the data structures for the FuncOp in this state object. |
70 | void startFunctionAnalysis(FuncOp funcOp); |
71 | }; |
72 | |
73 | void registerBufferizableOpInterfaceExternalModels(DialectRegistry ®istry); |
74 | } // namespace func_ext |
75 | } // namespace bufferization |
76 | } // namespace mlir |
77 | |
78 | #endif // MLIR_BUFFERIZATION_TRANSFORMS_FUNCBUFFERIZABLEOPINTERFACEIMPL_H |
79 | |