IPO.h 12 KB

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