1 //===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===// 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 // This header file defines prototypes that expose pass constructors in the loop 10 // transformation library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_TRANSFORMS_PASSES_H 15 #define MLIR_TRANSFORMS_PASSES_H 16 17 #include "mlir/Pass/Pass.h" 18 #include "mlir/Transforms/LocationSnapshot.h" 19 #include "mlir/Transforms/ViewOpGraph.h" 20 #include "mlir/Transforms/ViewRegionGraph.h" 21 #include <limits> 22 23 namespace mlir { 24 25 class AffineForOp; 26 class GreedyRewriteConfig; 27 28 //===----------------------------------------------------------------------===// 29 // Passes 30 //===----------------------------------------------------------------------===// 31 32 /// Creates an instance of the BufferDeallocation pass to free all allocated 33 /// buffers. 34 std::unique_ptr<Pass> createBufferDeallocationPass(); 35 36 /// Creates a pass that moves allocations upwards to reduce the number of 37 /// required copies that are inserted during the BufferDeallocation pass. 38 std::unique_ptr<Pass> createBufferHoistingPass(); 39 40 /// Creates a pass that moves allocations upwards out of loops. This avoids 41 /// reallocations inside of loops. 42 std::unique_ptr<Pass> createBufferLoopHoistingPass(); 43 44 /// Creates a pass that promotes heap-based allocations to stack-based ones. 45 /// Only buffers smaller than the provided size are promoted. 46 /// Dynamic shaped buffers are promoted up to the given rank. 47 std::unique_ptr<Pass> 48 createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes = 1024, 49 unsigned bitwidthOfIndexType = 64, 50 unsigned maxRankOfAllocatedMemRef = 1); 51 52 /// Creates a pass that promotes heap-based allocations to stack-based ones. 53 /// Only buffers smaller with `isSmallAlloc(alloc) == true` are promoted. 54 std::unique_ptr<Pass> 55 createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc); 56 57 /// Creates a pass that finalizes a partial bufferization by removing remaining 58 /// tensor_load and buffer_cast operations. 59 std::unique_ptr<FunctionPass> createFinalizingBufferizePass(); 60 61 /// Creates a pass that converts memref function results to out-params. 62 std::unique_ptr<Pass> createBufferResultsToOutParamsPass(); 63 64 /// Creates an instance of the Canonicalizer pass, configured with default 65 /// settings (which can be overridden by pass options on the command line). 66 std::unique_ptr<Pass> createCanonicalizerPass(); 67 68 /// Creates an instance of the Canonicalizer pass with the specified config. 69 std::unique_ptr<Pass> 70 createCanonicalizerPass(const GreedyRewriteConfig &config); 71 72 /// Creates a pass to perform common sub expression elimination. 73 std::unique_ptr<Pass> createCSEPass(); 74 75 /// Creates a loop fusion pass which fuses loops. Buffers of size less than or 76 /// equal to `localBufSizeThreshold` are promoted to memory space 77 /// `fastMemorySpace'. 78 std::unique_ptr<OperationPass<FuncOp>> 79 createLoopFusionPass(unsigned fastMemorySpace = 0, 80 uint64_t localBufSizeThreshold = 0, 81 bool maximalFusion = false); 82 83 /// Creates a loop invariant code motion pass that hoists loop invariant 84 /// instructions out of the loop. 85 std::unique_ptr<Pass> createLoopInvariantCodeMotionPass(); 86 87 /// Creates a pass to pipeline explicit movement of data across levels of the 88 /// memory hierarchy. 89 std::unique_ptr<OperationPass<FuncOp>> createPipelineDataTransferPass(); 90 91 /// Creates a pass that transforms perfectly nested loops with independent 92 /// bounds into a single loop. 93 std::unique_ptr<OperationPass<FuncOp>> createLoopCoalescingPass(); 94 95 /// Creates a pass that transforms a single ParallelLoop over N induction 96 /// variables into another ParallelLoop over less than N induction variables. 97 std::unique_ptr<Pass> createParallelLoopCollapsingPass(); 98 99 /// Creates a pass to strip debug information from a function. 100 std::unique_ptr<Pass> createStripDebugInfoPass(); 101 102 /// Creates a pass which prints the list of ops and the number of occurrences in 103 /// the module. 104 std::unique_ptr<Pass> createPrintOpStatsPass(); 105 106 /// Creates a pass which inlines calls and callable operations as defined by 107 /// the CallGraph. 108 std::unique_ptr<Pass> createInlinerPass(); 109 /// Creates an instance of the inliner pass, and use the provided pass managers 110 /// when optimizing callable operations with names matching the key type. 111 /// Callable operations with a name not within the provided map will use the 112 /// default inliner pipeline during optimization. 113 std::unique_ptr<Pass> 114 createInlinerPass(llvm::StringMap<OpPassManager> opPipelines); 115 /// Creates an instance of the inliner pass, and use the provided pass managers 116 /// when optimizing callable operations with names matching the key type. 117 /// Callable operations with a name not within the provided map will use the 118 /// provided default pipeline builder. 119 std::unique_ptr<Pass> 120 createInlinerPass(llvm::StringMap<OpPassManager> opPipelines, 121 std::function<void(OpPassManager &)> defaultPipelineBuilder); 122 123 /// Creates a pass which performs sparse conditional constant propagation over 124 /// nested operations. 125 std::unique_ptr<Pass> createSCCPPass(); 126 127 /// Creates a pass which delete symbol operations that are unreachable. This 128 /// pass may *only* be scheduled on an operation that defines a SymbolTable. 129 std::unique_ptr<Pass> createSymbolDCEPass(); 130 131 /// Creates an interprocedural pass to normalize memrefs to have a trivial 132 /// (identity) layout map. 133 std::unique_ptr<OperationPass<ModuleOp>> createNormalizeMemRefsPass(); 134 135 //===----------------------------------------------------------------------===// 136 // Registration 137 //===----------------------------------------------------------------------===// 138 139 /// Generate the code for registering passes. 140 #define GEN_PASS_REGISTRATION 141 #include "mlir/Transforms/Passes.h.inc" 142 143 } // end namespace mlir 144 145 #endif // MLIR_TRANSFORMS_PASSES_H 146