Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- llvm/Transforms/IPO.h - Interprocedural Transformations --*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This header file defines prototypes for accessor functions that expose passes |
| 10 | // in the IPO transformations library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_TRANSFORMS_IPO_H |
| 15 | #define LLVM_TRANSFORMS_IPO_H |
| 16 | |
| 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | #include <functional> |
| 19 | #include <vector> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | struct InlineParams; |
| 24 | class StringRef; |
| 25 | class ModuleSummaryIndex; |
| 26 | class ModulePass; |
| 27 | class Pass; |
| 28 | class Function; |
| 29 | class BasicBlock; |
| 30 | class GlobalValue; |
| 31 | class raw_ostream; |
| 32 | |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | // |
| 35 | // These functions removes symbols from functions and modules. If OnlyDebugInfo |
| 36 | // is true, only debugging information is removed from the module. |
| 37 | // |
| 38 | ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false); |
| 39 | |
| 40 | //===----------------------------------------------------------------------===// |
| 41 | // |
| 42 | // These functions strips symbols from functions and modules. |
| 43 | // Only debugging information is not stripped. |
| 44 | // |
| 45 | ModulePass *createStripNonDebugSymbolsPass(); |
| 46 | |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | // |
| 49 | // This pass removes llvm.dbg.declare intrinsics. |
| 50 | ModulePass *createStripDebugDeclarePass(); |
| 51 | |
| 52 | //===----------------------------------------------------------------------===// |
| 53 | // |
| 54 | // This pass removes unused symbols' debug info. |
| 55 | ModulePass *createStripDeadDebugInfoPass(); |
| 56 | |
| 57 | //===----------------------------------------------------------------------===// |
| 58 | /// createConstantMergePass - This function returns a new pass that merges |
| 59 | /// duplicate global constants together into a single constant that is shared. |
| 60 | /// This is useful because some passes (ie TraceValues) insert a lot of string |
| 61 | /// constants into the program, regardless of whether or not they duplicate an |
| 62 | /// existing string. |
| 63 | /// |
| 64 | ModulePass *createConstantMergePass(); |
| 65 | |
| 66 | //===----------------------------------------------------------------------===// |
| 67 | /// createGlobalOptimizerPass - This function returns a new pass that optimizes |
| 68 | /// non-address taken internal globals. |
| 69 | /// |
| 70 | ModulePass *createGlobalOptimizerPass(); |
| 71 | |
| 72 | //===----------------------------------------------------------------------===// |
| 73 | /// createGlobalDCEPass - This transform is designed to eliminate unreachable |
| 74 | /// internal globals (functions or global variables) |
| 75 | /// |
| 76 | ModulePass *createGlobalDCEPass(); |
| 77 | |
| 78 | //===----------------------------------------------------------------------===// |
| 79 | /// This transform is designed to eliminate available external globals |
| 80 | /// (functions or global variables) |
| 81 | /// |
| 82 | ModulePass *createEliminateAvailableExternallyPass(); |
| 83 | |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | /// createGVExtractionPass - If deleteFn is true, this pass deletes |
| 86 | /// the specified global values. Otherwise, it deletes as much of the module as |
| 87 | /// possible, except for the global values specified. |
| 88 | /// |
| 89 | ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool |
| 90 | deleteFn = false); |
| 91 | |
| 92 | //===----------------------------------------------------------------------===// |
| 93 | /// This pass performs iterative function importing from other modules. |
| 94 | Pass *createFunctionImportPass(); |
| 95 | |
| 96 | //===----------------------------------------------------------------------===// |
| 97 | /// createFunctionInliningPass - Return a new pass object that uses a heuristic |
| 98 | /// to inline direct function calls to small functions. |
| 99 | /// |
| 100 | /// The Threshold can be passed directly, or asked to be computed from the |
| 101 | /// given optimization and size optimization arguments. |
| 102 | /// |
| 103 | /// The -inline-threshold command line option takes precedence over the |
| 104 | /// threshold given here. |
| 105 | Pass *createFunctionInliningPass(); |
| 106 | Pass *createFunctionInliningPass(int Threshold); |
| 107 | Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel, |
| 108 | bool DisableInlineHotCallSite); |
| 109 | Pass *createFunctionInliningPass(InlineParams &Params); |
| 110 | |
| 111 | //===----------------------------------------------------------------------===// |
| 112 | /// createPruneEHPass - Return a new pass object which transforms invoke |
| 113 | /// instructions into calls, if the callee can _not_ unwind the stack. |
| 114 | /// |
| 115 | Pass *createPruneEHPass(); |
| 116 | |
| 117 | //===----------------------------------------------------------------------===// |
| 118 | /// createInternalizePass - This pass loops over all of the functions in the |
| 119 | /// input module, internalizing all globals (functions and variables) it can. |
| 120 | //// |
| 121 | /// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and |
| 122 | /// gives to the client the ability to prevent internalizing specific symbols. |
| 123 | /// |
| 124 | /// The symbol in DSOList are internalized if it is safe to drop them from |
| 125 | /// the symbol table. |
| 126 | /// |
| 127 | /// Note that commandline options that are used with the above function are not |
| 128 | /// used now! |
| 129 | ModulePass * |
| 130 | createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV); |
| 131 | |
| 132 | /// createInternalizePass - Same as above, but with an empty exportList. |
| 133 | ModulePass *createInternalizePass(); |
| 134 | |
| 135 | //===----------------------------------------------------------------------===// |
| 136 | /// createDeadArgEliminationPass - This pass removes arguments from functions |
| 137 | /// which are not used by the body of the function. |
| 138 | /// |
| 139 | ModulePass *createDeadArgEliminationPass(); |
| 140 | |
| 141 | /// DeadArgHacking pass - Same as DAE, but delete arguments of external |
| 142 | /// functions as well. This is definitely not safe, and should only be used by |
| 143 | /// bugpoint. |
| 144 | ModulePass *createDeadArgHackingPass(); |
| 145 | |
| 146 | //===----------------------------------------------------------------------===// |
| 147 | /// createArgumentPromotionPass - This pass promotes "by reference" arguments to |
| 148 | /// be passed by value if the number of elements passed is smaller or |
| 149 | /// equal to maxElements (maxElements == 0 means always promote). |
| 150 | /// |
| 151 | Pass *createArgumentPromotionPass(unsigned maxElements = 3); |
| 152 | |
| 153 | //===----------------------------------------------------------------------===// |
| 154 | /// createIPConstantPropagationPass - This pass propagates constants from call |
| 155 | /// sites into the bodies of functions. |
| 156 | /// |
| 157 | ModulePass *createIPConstantPropagationPass(); |
| 158 | |
| 159 | //===----------------------------------------------------------------------===// |
| 160 | /// createIPSCCPPass - This pass propagates constants from call sites into the |
| 161 | /// bodies of functions, and keeps track of whether basic blocks are executable |
| 162 | /// in the process. |
| 163 | /// |
| 164 | ModulePass *createIPSCCPPass(); |
| 165 | |
| 166 | //===----------------------------------------------------------------------===// |
| 167 | // |
| 168 | /// createLoopExtractorPass - This pass extracts all natural loops from the |
| 169 | /// program into a function if it can. |
| 170 | /// |
| 171 | Pass *createLoopExtractorPass(); |
| 172 | |
| 173 | /// createSingleLoopExtractorPass - This pass extracts one natural loop from the |
| 174 | /// program into a function if it can. This is used by bugpoint. |
| 175 | /// |
| 176 | Pass *createSingleLoopExtractorPass(); |
| 177 | |
| 178 | /// createBlockExtractorPass - This pass extracts all the specified blocks |
| 179 | /// from the functions in the module. |
| 180 | /// |
| 181 | ModulePass *createBlockExtractorPass(); |
| 182 | ModulePass * |
| 183 | createBlockExtractorPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract, |
| 184 | bool EraseFunctions); |
| 185 | |
| 186 | /// createStripDeadPrototypesPass - This pass removes any function declarations |
| 187 | /// (prototypes) that are not used. |
| 188 | ModulePass *createStripDeadPrototypesPass(); |
| 189 | |
| 190 | //===----------------------------------------------------------------------===// |
| 191 | /// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call |
| 192 | /// graph in RPO to deduce and propagate function attributes. Currently it |
| 193 | /// only handles synthesizing norecurse attributes. |
| 194 | /// |
| 195 | Pass *createReversePostOrderFunctionAttrsPass(); |
| 196 | |
| 197 | //===----------------------------------------------------------------------===// |
| 198 | /// createMergeFunctionsPass - This pass discovers identical functions and |
| 199 | /// collapses them. |
| 200 | /// |
| 201 | ModulePass *createMergeFunctionsPass(); |
| 202 | |
| 203 | //===----------------------------------------------------------------------===// |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 204 | /// createHotColdSplittingPass - This pass outlines cold blocks into a separate |
| 205 | /// function(s). |
| 206 | ModulePass *createHotColdSplittingPass(); |
| 207 | |
| 208 | //===----------------------------------------------------------------------===// |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 209 | /// createPartialInliningPass - This pass inlines parts of functions. |
| 210 | /// |
| 211 | ModulePass *createPartialInliningPass(); |
| 212 | |
| 213 | //===----------------------------------------------------------------------===// |
| 214 | /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass |
| 215 | /// manager. |
| 216 | ModulePass *createBarrierNoopPass(); |
| 217 | |
| 218 | /// createCalledValuePropagationPass - Attach metadata to indirct call sites |
| 219 | /// indicating the set of functions they may target at run-time. |
| 220 | ModulePass *createCalledValuePropagationPass(); |
| 221 | |
| 222 | /// What to do with the summary when running passes that operate on it. |
| 223 | enum class PassSummaryAction { |
| 224 | None, ///< Do nothing. |
| 225 | Import, ///< Import information from summary. |
| 226 | Export, ///< Export information to summary. |
| 227 | }; |
| 228 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 229 | /// This pass lowers type metadata and the llvm.type.test intrinsic to |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 230 | /// bitsets. |
| 231 | /// |
| 232 | /// The behavior depends on the summary arguments: |
| 233 | /// - If ExportSummary is non-null, this pass will export type identifiers to |
| 234 | /// the given summary. |
| 235 | /// - Otherwise, if ImportSummary is non-null, this pass will import type |
| 236 | /// identifiers from the given summary. |
| 237 | /// - Otherwise it does neither. |
| 238 | /// It is invalid for both ExportSummary and ImportSummary to be non-null. |
| 239 | ModulePass *createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary, |
| 240 | const ModuleSummaryIndex *ImportSummary); |
| 241 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 242 | /// This pass export CFI checks for use by external modules. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 243 | ModulePass *createCrossDSOCFIPass(); |
| 244 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 245 | /// This pass implements whole-program devirtualization using type |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 246 | /// metadata. |
| 247 | /// |
| 248 | /// The behavior depends on the summary arguments: |
| 249 | /// - If ExportSummary is non-null, this pass will export type identifiers to |
| 250 | /// the given summary. |
| 251 | /// - Otherwise, if ImportSummary is non-null, this pass will import type |
| 252 | /// identifiers from the given summary. |
| 253 | /// - Otherwise it does neither. |
| 254 | /// It is invalid for both ExportSummary and ImportSummary to be non-null. |
| 255 | ModulePass * |
| 256 | createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary, |
| 257 | const ModuleSummaryIndex *ImportSummary); |
| 258 | |
| 259 | /// This pass splits globals into pieces for the benefit of whole-program |
| 260 | /// devirtualization and control-flow integrity. |
| 261 | ModulePass *createGlobalSplitPass(); |
| 262 | |
| 263 | //===----------------------------------------------------------------------===// |
| 264 | // SampleProfilePass - Loads sample profile data from disk and generates |
| 265 | // IR metadata to reflect the profile. |
| 266 | ModulePass *createSampleProfileLoaderPass(); |
| 267 | ModulePass *createSampleProfileLoaderPass(StringRef Name); |
| 268 | |
| 269 | /// Write ThinLTO-ready bitcode to Str. |
| 270 | ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str, |
| 271 | raw_ostream *ThinLinkOS = nullptr); |
| 272 | |
| 273 | } // End llvm namespace |
| 274 | |
| 275 | #endif |