Scalar.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- Scalar.h - Scalar 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 Scalar transformations library.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_SCALAR_H
  19. #define LLVM_TRANSFORMS_SCALAR_H
  20. #include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
  21. #include <functional>
  22. namespace llvm {
  23. class Function;
  24. class FunctionPass;
  25. class ModulePass;
  26. class Pass;
  27. //===----------------------------------------------------------------------===//
  28. //
  29. // AlignmentFromAssumptions - Use assume intrinsics to set load/store
  30. // alignments.
  31. //
  32. FunctionPass *createAlignmentFromAssumptionsPass();
  33. //===----------------------------------------------------------------------===//
  34. //
  35. // AnnotationRemarks - Emit remarks for !annotation metadata.
  36. //
  37. FunctionPass *createAnnotationRemarksLegacyPass();
  38. //===----------------------------------------------------------------------===//
  39. //
  40. // SCCP - Sparse conditional constant propagation.
  41. //
  42. FunctionPass *createSCCPPass();
  43. //===----------------------------------------------------------------------===//
  44. //
  45. // RedundantDbgInstElimination - This pass removes redundant dbg intrinsics
  46. // without modifying the CFG of the function. It is a FunctionPass.
  47. //
  48. Pass *createRedundantDbgInstEliminationPass();
  49. //===----------------------------------------------------------------------===//
  50. //
  51. // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
  52. // because it is worklist driven that can potentially revisit instructions when
  53. // their other instructions become dead, to eliminate chains of dead
  54. // computations.
  55. //
  56. FunctionPass *createDeadCodeEliminationPass();
  57. //===----------------------------------------------------------------------===//
  58. //
  59. // DeadStoreElimination - This pass deletes stores that are post-dominated by
  60. // must-aliased stores and are not loaded used between the stores.
  61. //
  62. FunctionPass *createDeadStoreEliminationPass();
  63. //===----------------------------------------------------------------------===//
  64. //
  65. // CallSiteSplitting - This pass split call-site based on its known argument
  66. // values.
  67. FunctionPass *createCallSiteSplittingPass();
  68. //===----------------------------------------------------------------------===//
  69. //
  70. // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
  71. // algorithm assumes instructions are dead until proven otherwise, which makes
  72. // it more successful are removing non-obviously dead instructions.
  73. //
  74. FunctionPass *createAggressiveDCEPass();
  75. //===----------------------------------------------------------------------===//
  76. //
  77. // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
  78. // that (optimistically) combines multiple guards into one to have fewer checks
  79. // at runtime.
  80. //
  81. FunctionPass *createGuardWideningPass();
  82. //===----------------------------------------------------------------------===//
  83. //
  84. // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
  85. // single loop at a time for use within a LoopPassManager. Desired effect is
  86. // to widen guards into preheader or a single guard within loop if that's not
  87. // possible.
  88. //
  89. Pass *createLoopGuardWideningPass();
  90. //===----------------------------------------------------------------------===//
  91. //
  92. // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
  93. // remove computations of dead bits.
  94. //
  95. FunctionPass *createBitTrackingDCEPass();
  96. //===----------------------------------------------------------------------===//
  97. //
  98. // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
  99. //
  100. FunctionPass *createSROAPass();
  101. //===----------------------------------------------------------------------===//
  102. //
  103. // InductiveRangeCheckElimination - Transform loops to elide range checks on
  104. // linear functions of the induction variable.
  105. //
  106. Pass *createInductiveRangeCheckEliminationPass();
  107. //===----------------------------------------------------------------------===//
  108. //
  109. // InductionVariableSimplify - Transform induction variables in a program to all
  110. // use a single canonical induction variable per loop.
  111. //
  112. Pass *createIndVarSimplifyPass();
  113. //===----------------------------------------------------------------------===//
  114. //
  115. // LICM - This pass is a loop invariant code motion and memory promotion pass.
  116. //
  117. Pass *createLICMPass();
  118. Pass *createLICMPass(unsigned LicmMssaOptCap,
  119. unsigned LicmMssaNoAccForPromotionCap,
  120. bool AllowSpeculation);
  121. //===----------------------------------------------------------------------===//
  122. //
  123. // LoopSink - This pass sinks invariants from preheader to loop body where
  124. // frequency is lower than loop preheader.
  125. //
  126. Pass *createLoopSinkPass();
  127. //===----------------------------------------------------------------------===//
  128. //
  129. // LoopPredication - This pass does loop predication on guards.
  130. //
  131. Pass *createLoopPredicationPass();
  132. //===----------------------------------------------------------------------===//
  133. //
  134. // LoopInterchange - This pass interchanges loops to provide a more
  135. // cache-friendly memory access patterns.
  136. //
  137. Pass *createLoopInterchangePass();
  138. //===----------------------------------------------------------------------===//
  139. //
  140. // LoopFlatten - This pass flattens nested loops into a single loop.
  141. //
  142. FunctionPass *createLoopFlattenPass();
  143. //===----------------------------------------------------------------------===//
  144. //
  145. // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
  146. // a loop's canonical induction variable as one of their indices.
  147. //
  148. Pass *createLoopStrengthReducePass();
  149. //===----------------------------------------------------------------------===//
  150. //
  151. // LoopUnswitch - This pass is a simple loop unswitching pass.
  152. //
  153. Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
  154. bool hasBranchDivergence = false);
  155. //===----------------------------------------------------------------------===//
  156. //
  157. // LoopInstSimplify - This pass simplifies instructions in a loop's body.
  158. //
  159. Pass *createLoopInstSimplifyPass();
  160. //===----------------------------------------------------------------------===//
  161. //
  162. // LoopUnroll - This pass is a simple loop unrolling pass.
  163. //
  164. Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
  165. bool ForgetAllSCEV = false, int Threshold = -1,
  166. int Count = -1, int AllowPartial = -1,
  167. int Runtime = -1, int UpperBound = -1,
  168. int AllowPeeling = -1);
  169. // Create an unrolling pass for full unrolling that uses exact trip count only
  170. // and also does peeling.
  171. Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
  172. bool ForgetAllSCEV = false);
  173. //===----------------------------------------------------------------------===//
  174. //
  175. // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
  176. //
  177. Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
  178. //===----------------------------------------------------------------------===//
  179. //
  180. // LoopReroll - This pass is a simple loop rerolling pass.
  181. //
  182. Pass *createLoopRerollPass();
  183. //===----------------------------------------------------------------------===//
  184. //
  185. // LoopRotate - This pass is a simple loop rotating pass.
  186. //
  187. Pass *createLoopRotatePass(int MaxHeaderSize = -1, bool PrepareForLTO = false);
  188. //===----------------------------------------------------------------------===//
  189. //
  190. // LoopIdiom - This pass recognizes and replaces idioms in loops.
  191. //
  192. Pass *createLoopIdiomPass();
  193. //===----------------------------------------------------------------------===//
  194. //
  195. // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
  196. //
  197. Pass *createLoopVersioningLICMPass();
  198. //===----------------------------------------------------------------------===//
  199. //
  200. // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
  201. // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
  202. // hacking easier.
  203. //
  204. FunctionPass *createDemoteRegisterToMemoryPass();
  205. extern char &DemoteRegisterToMemoryID;
  206. //===----------------------------------------------------------------------===//
  207. //
  208. // Reassociate - This pass reassociates commutative expressions in an order that
  209. // is designed to promote better constant propagation, GCSE, LICM, PRE...
  210. //
  211. // For example: 4 + (x + 5) -> x + (4 + 5)
  212. //
  213. FunctionPass *createReassociatePass();
  214. //===----------------------------------------------------------------------===//
  215. //
  216. // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
  217. // preds always go to some succ. If FreezeSelectCond is true, unfold the
  218. // condition of a select that unfolds to branch. Thresholds other than minus one
  219. // override the internal BB duplication default threshold.
  220. //
  221. FunctionPass *createJumpThreadingPass(bool FreezeSelectCond = false,
  222. int Threshold = -1);
  223. //===----------------------------------------------------------------------===//
  224. //
  225. // DFAJumpThreading - When a switch statement inside a loop is used to
  226. // implement a deterministic finite automata we can jump thread the switch
  227. // statement reducing number of conditional jumps.
  228. //
  229. FunctionPass *createDFAJumpThreadingPass();
  230. //===----------------------------------------------------------------------===//
  231. //
  232. // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
  233. // simplify terminator instructions, convert switches to lookup tables, etc.
  234. //
  235. FunctionPass *createCFGSimplificationPass(
  236. SimplifyCFGOptions Options = SimplifyCFGOptions(),
  237. std::function<bool(const Function &)> Ftor = nullptr);
  238. //===----------------------------------------------------------------------===//
  239. //
  240. // FlattenCFG - flatten CFG, reduce number of conditional branches by using
  241. // parallel-and and parallel-or mode, etc...
  242. //
  243. FunctionPass *createFlattenCFGPass();
  244. //===----------------------------------------------------------------------===//
  245. //
  246. // CFG Structurization - Remove irreducible control flow
  247. //
  248. ///
  249. /// When \p SkipUniformRegions is true the structizer will not structurize
  250. /// regions that only contain uniform branches.
  251. Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
  252. //===----------------------------------------------------------------------===//
  253. //
  254. // TailCallElimination - This pass eliminates call instructions to the current
  255. // function which occur immediately before return instructions.
  256. //
  257. FunctionPass *createTailCallEliminationPass();
  258. //===----------------------------------------------------------------------===//
  259. //
  260. // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
  261. // tree.
  262. //
  263. FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
  264. //===----------------------------------------------------------------------===//
  265. //
  266. // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
  267. // tree to hoist common expressions from sibling branches.
  268. //
  269. FunctionPass *createGVNHoistPass();
  270. //===----------------------------------------------------------------------===//
  271. //
  272. // GVNSink - This pass uses an "inverted" value numbering to decide the
  273. // similarity of expressions and sinks similar expressions into successors.
  274. //
  275. FunctionPass *createGVNSinkPass();
  276. //===----------------------------------------------------------------------===//
  277. //
  278. // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
  279. // are hoisted into the header, while stores sink into the footer.
  280. //
  281. FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false);
  282. //===----------------------------------------------------------------------===//
  283. //
  284. // GVN - This pass performs global value numbering and redundant load
  285. // elimination cotemporaneously.
  286. //
  287. FunctionPass *createNewGVNPass();
  288. //===----------------------------------------------------------------------===//
  289. //
  290. // DivRemPairs - Hoist/decompose integer division and remainder instructions.
  291. //
  292. FunctionPass *createDivRemPairsPass();
  293. //===----------------------------------------------------------------------===//
  294. //
  295. // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
  296. // calls and/or combining multiple stores into memset's.
  297. //
  298. FunctionPass *createMemCpyOptPass();
  299. //===----------------------------------------------------------------------===//
  300. //
  301. // LoopDeletion - This pass performs DCE of non-infinite loops that it
  302. // can prove are dead.
  303. //
  304. Pass *createLoopDeletionPass();
  305. //===----------------------------------------------------------------------===//
  306. //
  307. // ConstantHoisting - This pass prepares a function for expensive constants.
  308. //
  309. FunctionPass *createConstantHoistingPass();
  310. //===----------------------------------------------------------------------===//
  311. //
  312. // ConstraintElimination - This pass eliminates conditions based on found
  313. // constraints.
  314. //
  315. FunctionPass *createConstraintEliminationPass();
  316. //===----------------------------------------------------------------------===//
  317. //
  318. // Sink - Code Sinking
  319. //
  320. FunctionPass *createSinkingPass();
  321. //===----------------------------------------------------------------------===//
  322. //
  323. // LowerAtomic - Lower atomic intrinsics to non-atomic form
  324. //
  325. Pass *createLowerAtomicPass();
  326. //===----------------------------------------------------------------------===//
  327. //
  328. // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
  329. //
  330. Pass *createLowerGuardIntrinsicPass();
  331. //===----------------------------------------------------------------------===//
  332. //
  333. // LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations.
  334. //
  335. Pass *createLowerMatrixIntrinsicsPass();
  336. //===----------------------------------------------------------------------===//
  337. //
  338. // LowerMatrixIntrinsicsMinimal - Lower matrix intrinsics to vector operations
  339. // (lightweight, does not require extra analysis)
  340. //
  341. Pass *createLowerMatrixIntrinsicsMinimalPass();
  342. //===----------------------------------------------------------------------===//
  343. //
  344. // LowerWidenableCondition - Lower widenable condition to i1 true.
  345. //
  346. Pass *createLowerWidenableConditionPass();
  347. //===----------------------------------------------------------------------===//
  348. //
  349. // MergeICmps - Merge integer comparison chains into a memcmp
  350. //
  351. Pass *createMergeICmpsLegacyPass();
  352. //===----------------------------------------------------------------------===//
  353. //
  354. // ValuePropagation - Propagate CFG-derived value information
  355. //
  356. Pass *createCorrelatedValuePropagationPass();
  357. //===----------------------------------------------------------------------===//
  358. //
  359. // InferAddressSpaces - Modify users of addrspacecast instructions with values
  360. // in the source address space if using the destination address space is slower
  361. // on the target. If AddressSpace is left to its default value, it will be
  362. // obtained from the TargetTransformInfo.
  363. //
  364. FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
  365. extern char &InferAddressSpacesID;
  366. //===----------------------------------------------------------------------===//
  367. //
  368. // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
  369. // "block_weights" metadata.
  370. FunctionPass *createLowerExpectIntrinsicPass();
  371. //===----------------------------------------------------------------------===//
  372. //
  373. // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and
  374. // llvm.is.constant intrinsic calls, even for the unknown cases.
  375. //
  376. FunctionPass *createLowerConstantIntrinsicsPass();
  377. //===----------------------------------------------------------------------===//
  378. //
  379. // PartiallyInlineLibCalls - Tries to inline the fast path of library
  380. // calls such as sqrt.
  381. //
  382. FunctionPass *createPartiallyInlineLibCallsPass();
  383. //===----------------------------------------------------------------------===//
  384. //
  385. // SeparateConstOffsetFromGEP - Split GEPs for better CSE
  386. //
  387. FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
  388. //===----------------------------------------------------------------------===//
  389. //
  390. // SpeculativeExecution - Aggressively hoist instructions to enable
  391. // speculative execution on targets where branches are expensive.
  392. //
  393. FunctionPass *createSpeculativeExecutionPass();
  394. // Same as createSpeculativeExecutionPass, but does nothing unless
  395. // TargetTransformInfo::hasBranchDivergence() is true.
  396. FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
  397. //===----------------------------------------------------------------------===//
  398. //
  399. // StraightLineStrengthReduce - This pass strength-reduces some certain
  400. // instruction patterns in straight-line code.
  401. //
  402. FunctionPass *createStraightLineStrengthReducePass();
  403. //===----------------------------------------------------------------------===//
  404. //
  405. // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
  406. // safepoint polls (method entry, backedge) that might be required. This pass
  407. // does not generate explicit relocation sequences - that's handled by
  408. // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
  409. // order following this pass.
  410. //
  411. FunctionPass *createPlaceSafepointsPass();
  412. //===----------------------------------------------------------------------===//
  413. //
  414. // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
  415. // explicit relocations to include explicit relocations.
  416. //
  417. ModulePass *createRewriteStatepointsForGCLegacyPass();
  418. //===----------------------------------------------------------------------===//
  419. //
  420. // Float2Int - Demote floats to ints where possible.
  421. //
  422. FunctionPass *createFloat2IntPass();
  423. //===----------------------------------------------------------------------===//
  424. //
  425. // NaryReassociate - Simplify n-ary operations by reassociation.
  426. //
  427. FunctionPass *createNaryReassociatePass();
  428. //===----------------------------------------------------------------------===//
  429. //
  430. // LoopDistribute - Distribute loops.
  431. //
  432. FunctionPass *createLoopDistributePass();
  433. //===----------------------------------------------------------------------===//
  434. //
  435. // LoopFuse - Fuse loops.
  436. //
  437. FunctionPass *createLoopFusePass();
  438. //===----------------------------------------------------------------------===//
  439. //
  440. // LoopLoadElimination - Perform loop-aware load elimination.
  441. //
  442. FunctionPass *createLoopLoadEliminationPass();
  443. //===----------------------------------------------------------------------===//
  444. //
  445. // LoopVersioning - Perform loop multi-versioning.
  446. //
  447. FunctionPass *createLoopVersioningPass();
  448. //===----------------------------------------------------------------------===//
  449. //
  450. // LoopDataPrefetch - Perform data prefetching in loops.
  451. //
  452. FunctionPass *createLoopDataPrefetchPass();
  453. ///===---------------------------------------------------------------------===//
  454. ModulePass *createNameAnonGlobalPass();
  455. ModulePass *createCanonicalizeAliasesPass();
  456. //===----------------------------------------------------------------------===//
  457. //
  458. // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
  459. // used.
  460. //
  461. FunctionPass *createLibCallsShrinkWrapPass();
  462. //===----------------------------------------------------------------------===//
  463. //
  464. // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
  465. // primarily to help other loop passes.
  466. //
  467. Pass *createLoopSimplifyCFGPass();
  468. //===----------------------------------------------------------------------===//
  469. //
  470. // WarnMissedTransformations - This pass emits warnings for leftover forced
  471. // transformations.
  472. //
  473. Pass *createWarnMissedTransformationsPass();
  474. //===----------------------------------------------------------------------===//
  475. //
  476. // This pass does instruction simplification on each
  477. // instruction in a function.
  478. //
  479. FunctionPass *createInstSimplifyLegacyPass();
  480. //===----------------------------------------------------------------------===//
  481. //
  482. // createScalarizeMaskedMemIntrinPass - Replace masked load, store, gather
  483. // and scatter intrinsics with scalar code when target doesn't support them.
  484. //
  485. FunctionPass *createScalarizeMaskedMemIntrinLegacyPass();
  486. } // End llvm namespace
  487. #endif
  488. #ifdef __GNUC__
  489. #pragma GCC diagnostic pop
  490. #endif