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/Pass/PassManager.h" 19 #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 20 #include "mlir/Transforms/LocationSnapshot.h" 21 #include "mlir/Transforms/ViewOpGraph.h" 22 #include "llvm/Support/Debug.h" 23 #include <limits> 24 #include <memory> 25 26 namespace mlir { 27 28 class GreedyRewriteConfig; 29 30 //===----------------------------------------------------------------------===// 31 // Passes 32 //===----------------------------------------------------------------------===// 33 34 #define GEN_PASS_DECL_CANONICALIZER 35 #define GEN_PASS_DECL_CONTROLFLOWSINK 36 #define GEN_PASS_DECL_CSE 37 #define GEN_PASS_DECL_INLINER 38 #define GEN_PASS_DECL_LOOPINVARIANTCODEMOTION 39 #define GEN_PASS_DECL_MEM2REG 40 #define GEN_PASS_DECL_PRINTIRPASS 41 #define GEN_PASS_DECL_PRINTOPSTATS 42 #define GEN_PASS_DECL_SROA 43 #define GEN_PASS_DECL_STRIPDEBUGINFO 44 #define GEN_PASS_DECL_SCCP 45 #define GEN_PASS_DECL_SYMBOLDCE 46 #define GEN_PASS_DECL_SYMBOLPRIVATIZE 47 #define GEN_PASS_DECL_TOPOLOGICALSORT 48 #define GEN_PASS_DECL_COMPOSITEFIXEDPOINTPASS 49 #include "mlir/Transforms/Passes.h.inc" 50 51 /// Creates an instance of the Canonicalizer pass, configured with default 52 /// settings (which can be overridden by pass options on the command line). 53 std::unique_ptr<Pass> createCanonicalizerPass(); 54 55 /// Creates an instance of the Canonicalizer pass with the specified config. 56 /// `disabledPatterns` is a set of labels used to filter out input patterns with 57 /// a debug label or debug name in this set. `enabledPatterns` is a set of 58 /// labels used to filter out input patterns that do not have one of the labels 59 /// in this set. Debug labels must be set explicitly on patterns or when adding 60 /// them with `RewritePatternSet::addWithLabel`. Debug names may be empty, but 61 /// patterns created with `RewritePattern::create` have their default debug name 62 /// set to their type name. 63 std::unique_ptr<Pass> 64 createCanonicalizerPass(const GreedyRewriteConfig &config, 65 ArrayRef<std::string> disabledPatterns = std::nullopt, 66 ArrayRef<std::string> enabledPatterns = std::nullopt); 67 68 /// Creates a pass to perform control-flow sinking. 69 std::unique_ptr<Pass> createControlFlowSinkPass(); 70 71 /// Creates a pass to perform common sub expression elimination. 72 std::unique_ptr<Pass> createCSEPass(); 73 74 /// Creates a pass to print IR on the debug stream. 75 std::unique_ptr<Pass> createPrintIRPass(const PrintIRPassOptions & = {}); 76 77 /// Creates a pass that generates IR to verify ops at runtime. 78 std::unique_ptr<Pass> createGenerateRuntimeVerificationPass(); 79 80 /// Creates a loop invariant code motion pass that hoists loop invariant 81 /// instructions out of the loop. 82 std::unique_ptr<Pass> createLoopInvariantCodeMotionPass(); 83 84 /// Creates a pass that hoists loop-invariant subset ops. 85 std::unique_ptr<Pass> createLoopInvariantSubsetHoistingPass(); 86 87 /// Creates a pass to strip debug information from a function. 88 std::unique_ptr<Pass> createStripDebugInfoPass(); 89 90 /// Creates a pass which prints the list of ops and the number of occurrences in 91 /// the module. 92 std::unique_ptr<Pass> createPrintOpStatsPass(raw_ostream &os = llvm::errs()); 93 94 /// Creates a pass which prints the list of ops and the number of occurrences in 95 /// the module with the output format option. 96 std::unique_ptr<Pass> createPrintOpStatsPass(raw_ostream &os, bool printAsJSON); 97 98 /// Creates a pass which inlines calls and callable operations as defined by 99 /// the CallGraph. 100 std::unique_ptr<Pass> createInlinerPass(); 101 /// Creates an instance of the inliner pass, and use the provided pass managers 102 /// when optimizing callable operations with names matching the key type. 103 /// Callable operations with a name not within the provided map will use the 104 /// default inliner pipeline during optimization. 105 std::unique_ptr<Pass> 106 createInlinerPass(llvm::StringMap<OpPassManager> opPipelines); 107 /// Creates an instance of the inliner pass, and use the provided pass managers 108 /// when optimizing callable operations with names matching the key type. 109 /// Callable operations with a name not within the provided map will use the 110 /// provided default pipeline builder. 111 std::unique_ptr<Pass> 112 createInlinerPass(llvm::StringMap<OpPassManager> opPipelines, 113 std::function<void(OpPassManager &)> defaultPipelineBuilder); 114 115 /// Creates an optimization pass to remove dead values. 116 std::unique_ptr<Pass> createRemoveDeadValuesPass(); 117 118 /// Creates a pass which performs sparse conditional constant propagation over 119 /// nested operations. 120 std::unique_ptr<Pass> createSCCPPass(); 121 122 /// Creates a pass which delete symbol operations that are unreachable. This 123 /// pass may *only* be scheduled on an operation that defines a SymbolTable. 124 std::unique_ptr<Pass> createSymbolDCEPass(); 125 126 /// Creates a pass which marks top-level symbol operations as `private` unless 127 /// listed in `excludeSymbols`. 128 std::unique_ptr<Pass> 129 createSymbolPrivatizePass(ArrayRef<std::string> excludeSymbols = {}); 130 131 /// Creates a pass that recursively sorts nested regions without SSA dominance 132 /// topologically such that, as much as possible, users of values appear after 133 /// their producers. 134 std::unique_ptr<Pass> createTopologicalSortPass(); 135 136 /// Create composite pass, which runs provided set of passes until fixed point 137 /// or maximum number of iterations reached. 138 std::unique_ptr<Pass> createCompositeFixedPointPass( 139 std::string name, llvm::function_ref<void(OpPassManager &)> populateFunc, 140 int maxIterations = 10); 141 142 //===----------------------------------------------------------------------===// 143 // Registration 144 //===----------------------------------------------------------------------===// 145 146 /// Generate the code for registering passes. 147 #define GEN_PASS_REGISTRATION 148 #include "mlir/Transforms/Passes.h.inc" 149 150 } // namespace mlir 151 152 #endif // MLIR_TRANSFORMS_PASSES_H 153