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 #define GEN_PASS_DECL
21 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
22 
23 /// Creates an instance of the BufferDeallocation pass to free all allocated
24 /// buffers.
25 std::unique_ptr<Pass> createBufferDeallocationPass();
26 
27 /// Run buffer deallocation.
28 LogicalResult deallocateBuffers(Operation *op);
29 
30 /// Creates a pass that moves allocations upwards to reduce the number of
31 /// required copies that are inserted during the BufferDeallocation pass.
32 std::unique_ptr<Pass> createBufferHoistingPass();
33 
34 /// Creates a pass that moves allocations upwards out of loops. This avoids
35 /// reallocations inside of loops.
36 std::unique_ptr<Pass> createBufferLoopHoistingPass();
37 
38 // Options struct for BufferResultsToOutParams pass.
39 // Note: defined only here, not in tablegen.
41  // Filter function; returns true if the function should be converted.
42  // Defaults to true, i.e. all functions are converted.
43  llvm::function_ref<bool(func::FuncOp *)> filterFn = [](func::FuncOp *func) {
44  return true;
45  };
46 };
47 
48 /// Creates a pass that converts memref function results to out-params.
49 std::unique_ptr<Pass> createBufferResultsToOutParamsPass(
50  const BufferResultsToOutParamsOptions &options = {});
51 
52 /// Replace buffers that are returned from a function with an out parameter.
53 /// Also update all call sites.
54 LogicalResult
55 promoteBufferResultsToOutParams(ModuleOp module,
56  const BufferResultsToOutParamsOptions &options);
57 
58 /// Creates a pass that drops memref function results that are equivalent to a
59 /// function argument.
60 std::unique_ptr<Pass> createDropEquivalentBufferResultsPass();
61 
62 /// Create a pass that rewrites tensor.empty to bufferization.alloc_tensor.
63 std::unique_ptr<Pass> createEmptyTensorToAllocTensorPass();
64 
65 /// Drop all memref function results that are equivalent to a function argument.
66 LogicalResult dropEquivalentBufferResults(ModuleOp module);
67 
68 /// Creates a pass that finalizes a partial bufferization by removing remaining
69 /// bufferization.to_tensor and bufferization.to_memref operations.
70 std::unique_ptr<OperationPass<func::FuncOp>> createFinalizingBufferizePass();
71 
72 /// Create a pass that bufferizes all ops that implement BufferizableOpInterface
73 /// with One-Shot Bufferize.
74 std::unique_ptr<Pass> createOneShotBufferizePass();
75 
76 /// Create a pass that bufferizes all ops that implement BufferizableOpInterface
77 /// with One-Shot Bufferize and the specified bufferization options.
78 std::unique_ptr<Pass>
79 createOneShotBufferizePass(const OneShotBufferizationOptions &options);
80 
81 /// Creates a pass that promotes heap-based allocations to stack-based ones.
82 /// Only buffers smaller than the provided size are promoted.
83 /// Dynamic shaped buffers are promoted up to the given rank.
84 std::unique_ptr<Pass>
85 createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes = 1024,
86  unsigned maxRankOfAllocatedMemRef = 1);
87 
88 /// Creates a pass that promotes heap-based allocations to stack-based ones.
89 /// Only buffers smaller with `isSmallAlloc(alloc) == true` are promoted.
90 std::unique_ptr<Pass>
91 createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc);
92 
93 /// Create a pass that tries to eliminate tensor.empty ops that are anchored on
94 /// insert_slice ops.
95 std::unique_ptr<Pass> createEmptyTensorEliminationPass();
96 
97 /// Create a pass that bufferizes ops from the bufferization dialect.
98 std::unique_ptr<Pass> createBufferizationBufferizePass();
99 
100 /// Create a pass that resolves out-of-place tensor OpOperands with copies.
101 std::unique_ptr<Pass> createTensorCopyInsertionPass();
102 std::unique_ptr<Pass>
103 createTensorCopyInsertionPass(const OneShotBufferizationOptions &options);
104 
105 //===----------------------------------------------------------------------===//
106 // Registration
107 //===----------------------------------------------------------------------===//
108 
109 /// Register external models for AllocationOpInterface.
110 void registerAllocationOpInterfaceExternalModels(DialectRegistry &registry);
111 
112 /// Generate the code for registering passes.
113 #define GEN_PASS_REGISTRATION
114 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
115 
116 } // namespace bufferization
117 } // namespace mlir
118 
119 #endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES_H
static llvm::ManagedStatic< PassManagerOptions > options
std::unique_ptr< Pass > createDropEquivalentBufferResultsPass()
Creates a pass that drops memref function results that are equivalent to a function argument.
std::unique_ptr< Pass > createTensorCopyInsertionPass()
Create a pass that resolves out-of-place tensor OpOperands with copies.
std::unique_ptr< Pass > createBufferHoistingPass()
Creates a pass that moves allocations upwards to reduce the number of required copies that are insert...
void registerAllocationOpInterfaceExternalModels(DialectRegistry &registry)
Register external models for AllocationOpInterface.
LogicalResult promoteBufferResultsToOutParams(ModuleOp module, const BufferResultsToOutParamsOptions &options)
Replace buffers that are returned from a function with an out parameter.
std::unique_ptr< OperationPass< func::FuncOp > > createFinalizingBufferizePass()
Creates a pass that finalizes a partial bufferization by removing remaining bufferization....
Definition: Bufferize.cpp:309
std::unique_ptr< Pass > createOneShotBufferizePass()
Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize.
Definition: Bufferize.cpp:299
LogicalResult deallocateBuffers(Operation *op)
Run buffer deallocation.
std::unique_ptr< Pass > createBufferLoopHoistingPass()
Creates a pass that moves allocations upwards out of loops.
std::unique_ptr< Pass > createBufferResultsToOutParamsPass(const BufferResultsToOutParamsOptions &options={})
Creates a pass that converts memref function results to out-params.
std::unique_ptr< Pass > createEmptyTensorEliminationPass()
Create a pass that tries to eliminate tensor.empty ops that are anchored on insert_slice ops.
std::unique_ptr< Pass > createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes=1024, unsigned maxRankOfAllocatedMemRef=1)
Creates a pass that promotes heap-based allocations to stack-based ones.
std::unique_ptr< Pass > createBufferDeallocationPass()
Creates an instance of the BufferDeallocation pass to free all allocated buffers.
LogicalResult dropEquivalentBufferResults(ModuleOp module)
Drop all memref function results that are equivalent to a function argument.
std::unique_ptr< Pass > createEmptyTensorToAllocTensorPass()
Create a pass that rewrites tensor.empty to bufferization.alloc_tensor.
std::unique_ptr< Pass > createBufferizationBufferizePass()
Create a pass that bufferizes ops from the bufferization dialect.
Definition: Bufferize.cpp:295
Include the generated interface declarations.
llvm::function_ref< bool(func::FuncOp *)> filterFn
Definition: Passes.h:43