MLIR  16.0.0git
Passes.h
Go to the documentation of this file.
1 #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES_H
2 #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES_H
3 
4 #include "mlir/Pass/Pass.h"
5 
6 namespace mlir {
7 class ModuleOp;
8 
9 namespace func {
10 class FuncOp;
11 } // namespace func
12 
13 namespace bufferization {
14 struct OneShotBufferizationOptions;
15 
16 //===----------------------------------------------------------------------===//
17 // Passes
18 //===----------------------------------------------------------------------===//
19 
20 /// Creates an instance of the BufferDeallocation pass to free all allocated
21 /// buffers.
22 std::unique_ptr<Pass> createBufferDeallocationPass();
23 
24 /// Run buffer deallocation.
25 LogicalResult deallocateBuffers(Operation *op);
26 
27 /// Creates a pass that moves allocations upwards to reduce the number of
28 /// required copies that are inserted during the BufferDeallocation pass.
29 std::unique_ptr<Pass> createBufferHoistingPass();
30 
31 /// Creates a pass that moves allocations upwards out of loops. This avoids
32 /// reallocations inside of loops.
33 std::unique_ptr<Pass> createBufferLoopHoistingPass();
34 
35 /// Creates a pass that converts memref function results to out-params.
36 std::unique_ptr<Pass> createBufferResultsToOutParamsPass();
37 
38 /// Replace buffers that are returned from a function with an out parameter.
39 /// Also update all call sites.
40 LogicalResult promoteBufferResultsToOutParams(ModuleOp module);
41 
42 /// Creates a pass that drops memref function results that are equivalent to a
43 /// function argument.
44 std::unique_ptr<Pass> createDropEquivalentBufferResultsPass();
45 
46 /// Drop all memref function results that are equivalent to a function argument.
47 LogicalResult dropEquivalentBufferResults(ModuleOp module);
48 
49 /// Creates a pass that finalizes a partial bufferization by removing remaining
50 /// bufferization.to_tensor and bufferization.to_memref operations.
51 std::unique_ptr<OperationPass<func::FuncOp>> createFinalizingBufferizePass();
52 
53 /// Create a pass that bufferizes all ops that implement BufferizableOpInterface
54 /// with One-Shot Bufferize.
55 std::unique_ptr<Pass> createOneShotBufferizePass();
56 
57 /// Create a pass that bufferizes all ops that implement BufferizableOpInterface
58 /// with One-Shot Bufferize and the specified bufferization options.
59 std::unique_ptr<Pass>
60 createOneShotBufferizePass(const OneShotBufferizationOptions &options);
61 
62 /// Creates a pass that promotes heap-based allocations to stack-based ones.
63 /// Only buffers smaller than the provided size are promoted.
64 /// Dynamic shaped buffers are promoted up to the given rank.
65 std::unique_ptr<Pass>
66 createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes = 1024,
67  unsigned maxRankOfAllocatedMemRef = 1);
68 
69 /// Creates a pass that promotes heap-based allocations to stack-based ones.
70 /// Only buffers smaller with `isSmallAlloc(alloc) == true` are promoted.
71 std::unique_ptr<Pass>
72 createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc);
73 
74 /// Create a pass that tries to eliminate alloc_tensor ops that are anchored on
75 /// insert_slice ops.
76 std::unique_ptr<Pass> createAllocTensorEliminationPass();
77 
78 /// Create a pass that bufferizes ops from the bufferization dialect.
79 std::unique_ptr<Pass> createBufferizationBufferizePass();
80 
81 /// Create a pass that resolves out-of-place tensor OpOperands with copies.
82 std::unique_ptr<Pass> createTensorCopyInsertionPass();
83 std::unique_ptr<Pass>
84 createTensorCopyInsertionPass(const OneShotBufferizationOptions &options);
85 
86 //===----------------------------------------------------------------------===//
87 // Registration
88 //===----------------------------------------------------------------------===//
89 
90 /// Register external models for AllocationOpInterface.
91 void registerAllocationOpInterfaceExternalModels(DialectRegistry &registry);
92 
93 /// Generate the code for registering passes.
94 #define GEN_PASS_REGISTRATION
95 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
96 
97 } // namespace bufferization
98 } // namespace mlir
99 
100 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES_H
Include the generated interface declarations.
LogicalResult dropEquivalentBufferResults(ModuleOp module)
Drop all memref function results that are equivalent to a function argument.
std::unique_ptr< Pass > createTensorCopyInsertionPass(const OneShotBufferizationOptions &options)
std::unique_ptr< Pass > createPromoteBuffersToStackPass(std::function< bool(Value)> isSmallAlloc)
Creates a pass that promotes heap-based allocations to stack-based ones.
LogicalResult promoteBufferResultsToOutParams(ModuleOp module)
Replace buffers that are returned from a function with an out parameter.
std::unique_ptr< Pass > createBufferDeallocationPass()
Creates an instance of the BufferDeallocation pass to free all allocated buffers. ...
void registerAllocationOpInterfaceExternalModels(DialectRegistry &registry)
Register external models for AllocationOpInterface.
LogicalResult deallocateBuffers(Operation *op)
Run buffer deallocation.
std::unique_ptr< Pass > createDropEquivalentBufferResultsPass()
Creates a pass that drops memref function results that are equivalent to a function argument...
std::unique_ptr< Pass > createBufferResultsToOutParamsPass()
Creates a pass that converts memref function results to out-params.
std::unique_ptr< Pass > createBufferHoistingPass()
Creates a pass that moves allocations upwards to reduce the number of required copies that are insert...
std::unique_ptr< Pass > createBufferizationBufferizePass()
Create a pass that bufferizes ops from the bufferization dialect.
Definition: Bufferize.cpp:274
std::unique_ptr< Pass > createBufferLoopHoistingPass()
Creates a pass that moves allocations upwards out of loops.
static llvm::ManagedStatic< PassManagerOptions > options
std::unique_ptr< OperationPass< func::FuncOp > > createFinalizingBufferizePass()
Creates a pass that finalizes a partial bufferization by removing remaining bufferization.to_tensor and bufferization.to_memref operations.
Definition: Bufferize.cpp:288
std::unique_ptr< Pass > createOneShotBufferizePass(const OneShotBufferizationOptions &options)
Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize ...
Definition: Bufferize.cpp:282
std::unique_ptr< Pass > createAllocTensorEliminationPass()
Create a pass that tries to eliminate alloc_tensor ops that are anchored on insert_slice ops...