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