Scalar.h 21 KB

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