IPO.h 12 KB

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