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