Scalar.h 20 KB

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