Scalar.h 19 KB

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