Scalar.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. //===-- Scalar.h - Scalar 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 Scalar transformations library.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TRANSFORMS_SCALAR_H
  15. #define LLVM_TRANSFORMS_SCALAR_H
  16. #include "llvm/ADT/StringRef.h"
  17. #include <functional>
  18. namespace llvm {
  19. class BasicBlockPass;
  20. class Function;
  21. class FunctionPass;
  22. class ModulePass;
  23. class Pass;
  24. class GetElementPtrInst;
  25. class PassInfo;
  26. class TerminatorInst;
  27. class TargetLowering;
  28. class TargetMachine;
  29. class PassRegistry; // HLSL Change - need this for registrations
  30. //===----------------------------------------------------------------------===//
  31. //
  32. // ConstantPropagation - A worklist driven constant propagation pass
  33. //
  34. FunctionPass *createConstantPropagationPass();
  35. //===----------------------------------------------------------------------===//
  36. //
  37. // AlignmentFromAssumptions - Use assume intrinsics to set load/store
  38. // alignments.
  39. //
  40. FunctionPass *createAlignmentFromAssumptionsPass();
  41. //===----------------------------------------------------------------------===//
  42. //
  43. // SCCP - Sparse conditional constant propagation.
  44. //
  45. FunctionPass *createSCCPPass();
  46. //===----------------------------------------------------------------------===//
  47. //
  48. // DeadInstElimination - This pass quickly removes trivially dead instructions
  49. // without modifying the CFG of the function. It is a BasicBlockPass, so it
  50. // runs efficiently when queued next to other BasicBlockPass's.
  51. //
  52. Pass *createDeadInstEliminationPass();
  53. //===----------------------------------------------------------------------===//
  54. //
  55. // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
  56. // because it is worklist driven that can potentially revisit instructions when
  57. // their other instructions become dead, to eliminate chains of dead
  58. // computations.
  59. //
  60. FunctionPass *createDeadCodeEliminationPass();
  61. //===----------------------------------------------------------------------===//
  62. //
  63. // DeadStoreElimination - This pass deletes stores that are post-dominated by
  64. // must-aliased stores and are not loaded used between the stores.
  65. //
  66. FunctionPass *createDeadStoreEliminationPass(unsigned ScanLimit = 0); // HLSL Change - Add ScanLimit
  67. //===----------------------------------------------------------------------===//
  68. //
  69. // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
  70. // algorithm assumes instructions are dead until proven otherwise, which makes
  71. // it more successful are removing non-obviously dead instructions.
  72. //
  73. FunctionPass *createAggressiveDCEPass();
  74. //===----------------------------------------------------------------------===//
  75. //
  76. // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
  77. // remove computations of dead bits.
  78. //
  79. FunctionPass *createBitTrackingDCEPass();
  80. //===----------------------------------------------------------------------===//
  81. //
  82. // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
  83. //
  84. FunctionPass *createSROAPass(bool RequiresDomTree = true,
  85. bool SkipHLSLMat = true);
  86. //===----------------------------------------------------------------------===//
  87. //
  88. // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
  89. // if possible.
  90. //
  91. FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
  92. bool UseDomTree = true,
  93. signed StructMemberThreshold = -1,
  94. signed ArrayElementThreshold = -1,
  95. signed ScalarLoadThreshold = -1);
  96. // HLSL Change Begins
  97. FunctionPass* createHLExpandStoreIntrinsicsPass();
  98. void initializeHLExpandStoreIntrinsicsPass(PassRegistry&);
  99. //===----------------------------------------------------------------------===//
  100. //
  101. // ScalarReplAggregatesHLSL - Break up alloca's of aggregates into multiple allocas
  102. // for hlsl. Array will not change, all structures will be broken up.
  103. //
  104. FunctionPass *createScalarReplAggregatesHLSLPass(bool UseDomTree = true,
  105. bool Promote = false);
  106. void initializeSROA_DT_HLSLPass(PassRegistry&);
  107. //===----------------------------------------------------------------------===//
  108. //
  109. // ScalarReplAggregatesHLSL - Break up argument's of aggregates into multiple arguments
  110. // for hlsl. Array will not change, all structures will be broken up.
  111. //
  112. ModulePass *createSROA_Parameter_HLSL();
  113. void initializeSROA_Parameter_HLSLPass(PassRegistry&);
  114. //===----------------------------------------------------------------------===//
  115. //
  116. // Cleans up constant stores that didn't get a chance to be turned into initializers
  117. //
  118. Pass *createDxilFixConstArrayInitializerPass();
  119. void initializeDxilFixConstArrayInitializerPass(PassRegistry&);
  120. Pass *createDxilConditionalMem2RegPass(bool NoOpt);
  121. void initializeDxilConditionalMem2RegPass(PassRegistry&);
  122. Pass *createDxilLoopUnrollPass(unsigned MaxIterationAttempt);
  123. void initializeDxilLoopUnrollPass(PassRegistry&);
  124. Pass *createDxilEraseDeadRegionPass();
  125. void initializeDxilEraseDeadRegionPass(PassRegistry&);
  126. Pass *createDxilEliminateVectorPass();
  127. void initializeDxilEliminateVectorPass(PassRegistry&);
  128. Pass *createDxilInsertPreservesPass();
  129. void initializeDxilInsertPreservesPass(PassRegistry&);
  130. Pass *createDxilFinalizePreservesPass();
  131. void initializeDxilFinalizePreservesPass(PassRegistry&);
  132. Pass *createDxilPreserveToSelectPass();
  133. void initializeDxilPreserveToSelectPass(PassRegistry&);
  134. Pass *createDxilRemoveDeadBlocksPass();
  135. void initializeDxilRemoveDeadBlocksPass(PassRegistry&);
  136. //===----------------------------------------------------------------------===//
  137. //
  138. // LowerStaticGlobalIntoAlloca. Replace static globals with alloca if only used
  139. // in one function.
  140. //
  141. ModulePass *createLowerStaticGlobalIntoAlloca();
  142. void initializeLowerStaticGlobalIntoAllocaPass(PassRegistry&);
  143. //===----------------------------------------------------------------------===//
  144. //
  145. // DynamicIndexingVectorToArray
  146. // Replace vector with array if it has dynamic indexing.
  147. //
  148. ModulePass *createDynamicIndexingVectorToArrayPass(bool ReplaceAllVector = false);
  149. void initializeDynamicIndexingVectorToArrayPass(PassRegistry&);
  150. //===----------------------------------------------------------------------===//
  151. // Flatten multi dim array into 1 dim.
  152. //
  153. ModulePass *createMultiDimArrayToOneDimArrayPass();
  154. void initializeMultiDimArrayToOneDimArrayPass(PassRegistry&);
  155. //===----------------------------------------------------------------------===//
  156. // Flatten resource into handle.
  157. //
  158. ModulePass *createResourceToHandlePass();
  159. void initializeResourceToHandlePass(PassRegistry&);
  160. //===----------------------------------------------------------------------===//
  161. // Hoist a local array initialized with constant values to a global array with
  162. // a constant initializer.
  163. //
  164. ModulePass *createHoistConstantArrayPass();
  165. void initializeHoistConstantArrayPass(PassRegistry&);
  166. // HLSL Change Ends
  167. //===----------------------------------------------------------------------===//
  168. //
  169. // InductiveRangeCheckElimination - Transform loops to elide range checks on
  170. // linear functions of the induction variable.
  171. //
  172. Pass *createInductiveRangeCheckEliminationPass();
  173. //===----------------------------------------------------------------------===//
  174. //
  175. // InductionVariableSimplify - Transform induction variables in a program to all
  176. // use a single canonical induction variable per loop.
  177. //
  178. Pass *createIndVarSimplifyPass();
  179. //===----------------------------------------------------------------------===//
  180. //
  181. // InstructionCombining - Combine instructions to form fewer, simple
  182. // instructions. This pass does not modify the CFG, and has a tendency to make
  183. // instructions dead, so a subsequent DCE pass is useful.
  184. //
  185. // This pass combines things like:
  186. // %Y = add int 1, %X
  187. // %Z = add int 1, %Y
  188. // into:
  189. // %Z = add int 2, %X
  190. //
  191. FunctionPass *createInstructionCombiningPass();
  192. //===----------------------------------------------------------------------===//
  193. //
  194. // LICM - This pass is a loop invariant code motion and memory promotion pass.
  195. //
  196. Pass *createLICMPass();
  197. //===----------------------------------------------------------------------===//
  198. //
  199. // LoopInterchange - This pass interchanges loops to provide a more
  200. // cache-friendly memory access patterns.
  201. //
  202. Pass *createLoopInterchangePass();
  203. //===----------------------------------------------------------------------===//
  204. //
  205. // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
  206. // a loop's canonical induction variable as one of their indices.
  207. //
  208. Pass *createLoopStrengthReducePass();
  209. //===----------------------------------------------------------------------===//
  210. //
  211. // GlobalMerge - This pass merges internal (by default) globals into structs
  212. // to enable reuse of a base pointer by indexed addressing modes.
  213. // It can also be configured to focus on size optimizations only.
  214. //
  215. Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
  216. bool OnlyOptimizeForSize = false);
  217. //===----------------------------------------------------------------------===//
  218. //
  219. // LoopUnswitch - This pass is a simple loop unswitching pass.
  220. //
  221. Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
  222. //===----------------------------------------------------------------------===//
  223. //
  224. // LoopInstSimplify - This pass simplifies instructions in a loop's body.
  225. //
  226. Pass *createLoopInstSimplifyPass();
  227. //===----------------------------------------------------------------------===//
  228. //
  229. // LoopUnroll - This pass is a simple loop unrolling pass.
  230. //
  231. Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
  232. int AllowPartial = -1, int Runtime = -1);
  233. // Create an unrolling pass for full unrolling only.
  234. Pass *createSimpleLoopUnrollPass();
  235. //===----------------------------------------------------------------------===//
  236. //
  237. // LoopReroll - This pass is a simple loop rerolling pass.
  238. //
  239. Pass *createLoopRerollPass();
  240. //===----------------------------------------------------------------------===//
  241. //
  242. // LoopRotate - This pass is a simple loop rotating pass.
  243. //
  244. Pass *createLoopRotatePass(int MaxHeaderSize = -1);
  245. //===----------------------------------------------------------------------===//
  246. //
  247. // LoopIdiom - This pass recognizes and replaces idioms in loops.
  248. //
  249. Pass *createLoopIdiomPass();
  250. //===----------------------------------------------------------------------===//
  251. //
  252. // PromoteMemoryToRegister - This pass is used to promote memory references to
  253. // be register references. A simple example of the transformation performed by
  254. // this pass is:
  255. //
  256. // FROM CODE TO CODE
  257. // %X = alloca i32, i32 1 ret i32 42
  258. // store i32 42, i32 *%X
  259. // %Y = load i32* %X
  260. // ret i32 %Y
  261. //
  262. FunctionPass *createPromoteMemoryToRegisterPass();
  263. //===----------------------------------------------------------------------===//
  264. //
  265. // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
  266. // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
  267. // hacking easier.
  268. //
  269. FunctionPass *createDemoteRegisterToMemoryPass();
  270. extern char &DemoteRegisterToMemoryID;
  271. // HLSL Change start
  272. // Relaxed version (for HLSL usage).
  273. FunctionPass *createDemoteRegisterToMemoryHlslPass();
  274. extern char &DemoteRegisterToMemoryHlslID;
  275. // HLSL Change end
  276. //===----------------------------------------------------------------------===//
  277. //
  278. // Reassociate - This pass reassociates commutative expressions in an order that
  279. // is designed to promote better constant propagation, GCSE, LICM, PRE...
  280. //
  281. // For example: 4 + (x + 5) -> x + (4 + 5)
  282. //
  283. FunctionPass *createReassociatePass();
  284. //===----------------------------------------------------------------------===//
  285. //
  286. // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
  287. // preds always go to some succ. Thresholds other than minus one override the
  288. // internal BB duplication default threshold.
  289. //
  290. FunctionPass *createJumpThreadingPass(int Threshold = -1);
  291. //===----------------------------------------------------------------------===//
  292. //
  293. // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
  294. // simplify terminator instructions, etc...
  295. //
  296. FunctionPass *createCFGSimplificationPass(
  297. int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
  298. //===----------------------------------------------------------------------===//
  299. //
  300. // FlattenCFG - flatten CFG, reduce number of conditional branches by using
  301. // parallel-and and parallel-or mode, etc...
  302. //
  303. FunctionPass *createFlattenCFGPass();
  304. //===----------------------------------------------------------------------===//
  305. //
  306. // CFG Structurization - Remove irreducible control flow
  307. //
  308. Pass *createStructurizeCFGPass();
  309. //===----------------------------------------------------------------------===//
  310. //
  311. // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
  312. // a dummy basic block. This pass may be "required" by passes that cannot deal
  313. // with critical edges. For this usage, a pass must call:
  314. //
  315. // AU.addRequiredID(BreakCriticalEdgesID);
  316. //
  317. // This pass obviously invalidates the CFG, but can update forward dominator
  318. // (set, immediate dominators, tree, and frontier) information.
  319. //
  320. FunctionPass *createBreakCriticalEdgesPass();
  321. extern char &BreakCriticalEdgesID;
  322. //===----------------------------------------------------------------------===//
  323. //
  324. // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
  325. // the module. This pass updates dominator information, loop information, and
  326. // does not add critical edges to the CFG.
  327. //
  328. // AU.addRequiredID(LoopSimplifyID);
  329. //
  330. Pass *createLoopSimplifyPass();
  331. extern char &LoopSimplifyID;
  332. //===----------------------------------------------------------------------===//
  333. //
  334. // TailCallElimination - This pass eliminates call instructions to the current
  335. // function which occur immediately before return instructions.
  336. //
  337. FunctionPass *createTailCallEliminationPass();
  338. //===----------------------------------------------------------------------===//
  339. //
  340. // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
  341. // chained binary branch instructions.
  342. //
  343. FunctionPass *createLowerSwitchPass();
  344. extern char &LowerSwitchID;
  345. //===----------------------------------------------------------------------===//
  346. //
  347. // LowerInvoke - This pass removes invoke instructions, converting them to call
  348. // instructions.
  349. //
  350. FunctionPass *createLowerInvokePass();
  351. extern char &LowerInvokePassID;
  352. //===----------------------------------------------------------------------===//
  353. //
  354. // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
  355. // optimizations.
  356. //
  357. Pass *createLCSSAPass();
  358. extern char &LCSSAID;
  359. //===----------------------------------------------------------------------===//
  360. //
  361. // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
  362. // tree.
  363. //
  364. FunctionPass *createEarlyCSEPass();
  365. //===----------------------------------------------------------------------===//
  366. //
  367. // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
  368. // are hoisted into the header, while stores sink into the footer.
  369. //
  370. FunctionPass *createMergedLoadStoreMotionPass();
  371. //===----------------------------------------------------------------------===//
  372. //
  373. // GVN - This pass performs global value numbering and redundant load
  374. // elimination cotemporaneously.
  375. //
  376. FunctionPass *createGVNPass(bool NoLoads = false);
  377. //===----------------------------------------------------------------------===//
  378. //
  379. // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
  380. // calls and/or combining multiple stores into memset's.
  381. //
  382. FunctionPass *createMemCpyOptPass();
  383. //===----------------------------------------------------------------------===//
  384. //
  385. // LoopDeletion - This pass performs DCE of non-infinite loops that it
  386. // can prove are dead.
  387. //
  388. Pass *createLoopDeletionPass();
  389. //===----------------------------------------------------------------------===//
  390. //
  391. // ConstantHoisting - This pass prepares a function for expensive constants.
  392. //
  393. FunctionPass *createConstantHoistingPass();
  394. //===----------------------------------------------------------------------===//
  395. //
  396. // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
  397. //
  398. FunctionPass *createInstructionNamerPass();
  399. extern char &InstructionNamerID;
  400. //===----------------------------------------------------------------------===//
  401. //
  402. // Sink - Code Sinking
  403. //
  404. FunctionPass *createSinkingPass();
  405. //===----------------------------------------------------------------------===//
  406. //
  407. // LowerAtomic - Lower atomic intrinsics to non-atomic form
  408. //
  409. Pass *createLowerAtomicPass();
  410. //===----------------------------------------------------------------------===//
  411. //
  412. // ValuePropagation - Propagate CFG-derived value information
  413. //
  414. Pass *createCorrelatedValuePropagationPass();
  415. //===----------------------------------------------------------------------===//
  416. //
  417. // InstructionSimplifier - Remove redundant instructions.
  418. //
  419. FunctionPass *createInstructionSimplifierPass();
  420. extern char &InstructionSimplifierID;
  421. //===----------------------------------------------------------------------===//
  422. //
  423. // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
  424. // "block_weights" metadata.
  425. FunctionPass *createLowerExpectIntrinsicPass();
  426. //===----------------------------------------------------------------------===//
  427. //
  428. // PartiallyInlineLibCalls - Tries to inline the fast path of library
  429. // calls such as sqrt.
  430. //
  431. FunctionPass *createPartiallyInlineLibCallsPass();
  432. //===----------------------------------------------------------------------===//
  433. //
  434. // SampleProfilePass - Loads sample profile data from disk and generates
  435. // IR metadata to reflect the profile.
  436. FunctionPass *createSampleProfileLoaderPass();
  437. FunctionPass *createSampleProfileLoaderPass(StringRef Name);
  438. //===----------------------------------------------------------------------===//
  439. //
  440. // ScalarizerPass - Converts vector operations into scalar operations
  441. //
  442. FunctionPass *createScalarizerPass();
  443. FunctionPass *createScalarizerPass(bool NoOpt);
  444. //===----------------------------------------------------------------------===//
  445. //
  446. // AddDiscriminators - Add DWARF path discriminators to the IR.
  447. FunctionPass *createAddDiscriminatorsPass();
  448. //===----------------------------------------------------------------------===//
  449. //
  450. // SeparateConstOffsetFromGEP - Split GEPs for better CSE
  451. //
  452. FunctionPass *
  453. createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
  454. bool LowerGEP = false);
  455. //===----------------------------------------------------------------------===//
  456. //
  457. // SpeculativeExecution - Aggressively hoist instructions to enable
  458. // speculative execution on targets where branches are expensive.
  459. //
  460. FunctionPass *createSpeculativeExecutionPass();
  461. //===----------------------------------------------------------------------===//
  462. //
  463. // LoadCombine - Combine loads into bigger loads.
  464. //
  465. BasicBlockPass *createLoadCombinePass();
  466. //===----------------------------------------------------------------------===//
  467. //
  468. // StraightLineStrengthReduce - This pass strength-reduces some certain
  469. // instruction patterns in straight-line code.
  470. //
  471. FunctionPass *createStraightLineStrengthReducePass();
  472. //===----------------------------------------------------------------------===//
  473. //
  474. // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
  475. // safepoint polls (method entry, backedge) that might be required. This pass
  476. // does not generate explicit relocation sequences - that's handled by
  477. // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
  478. // order following this pass.
  479. //
  480. FunctionPass *createPlaceSafepointsPass();
  481. //===----------------------------------------------------------------------===//
  482. //
  483. // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
  484. // explicit relocations to include explicit relocations.
  485. //
  486. ModulePass *createRewriteStatepointsForGCPass();
  487. //===----------------------------------------------------------------------===//
  488. //
  489. // Float2Int - Demote floats to ints where possible.
  490. //
  491. FunctionPass *createFloat2IntPass();
  492. //===----------------------------------------------------------------------===//
  493. //
  494. // NaryReassociate - Simplify n-ary operations by reassociation.
  495. //
  496. FunctionPass *createNaryReassociatePass();
  497. // //
  498. ///////////////////////////////////////////////////////////////////////////////
  499. //
  500. // LoopDistribute - Distribute loops.
  501. //
  502. FunctionPass *createLoopDistributePass();
  503. } // End llvm namespace
  504. #endif