LoopUtils.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Transforms/Utils/LoopUtils.h - Loop utilities -------*- 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 file defines some loop transformation utilities.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
  18. #define LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/Analysis/IVDescriptors.h"
  21. #include "llvm/Analysis/TargetTransformInfo.h"
  22. #include "llvm/Transforms/Utils/ValueMapper.h"
  23. namespace llvm {
  24. template <typename T> class DomTreeNodeBase;
  25. using DomTreeNode = DomTreeNodeBase<BasicBlock>;
  26. class AAResults;
  27. class AliasSet;
  28. class AliasSetTracker;
  29. class BasicBlock;
  30. class BlockFrequencyInfo;
  31. class ICFLoopSafetyInfo;
  32. class IRBuilderBase;
  33. class Loop;
  34. class LoopInfo;
  35. class MemoryAccess;
  36. class MemorySSA;
  37. class MemorySSAUpdater;
  38. class OptimizationRemarkEmitter;
  39. class PredIteratorCache;
  40. class ScalarEvolution;
  41. class SCEV;
  42. class SCEVExpander;
  43. class TargetLibraryInfo;
  44. class LPPassManager;
  45. class Instruction;
  46. struct RuntimeCheckingPtrGroup;
  47. typedef std::pair<const RuntimeCheckingPtrGroup *,
  48. const RuntimeCheckingPtrGroup *>
  49. RuntimePointerCheck;
  50. template <typename T> class Optional;
  51. template <typename T, unsigned N> class SmallSetVector;
  52. template <typename T, unsigned N> class SmallVector;
  53. template <typename T> class SmallVectorImpl;
  54. template <typename T, unsigned N> class SmallPriorityWorklist;
  55. BasicBlock *InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI,
  56. MemorySSAUpdater *MSSAU, bool PreserveLCSSA);
  57. /// Ensure that all exit blocks of the loop are dedicated exits.
  58. ///
  59. /// For any loop exit block with non-loop predecessors, we split the loop
  60. /// predecessors to use a dedicated loop exit block. We update the dominator
  61. /// tree and loop info if provided, and will preserve LCSSA if requested.
  62. bool formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
  63. MemorySSAUpdater *MSSAU, bool PreserveLCSSA);
  64. /// Ensures LCSSA form for every instruction from the Worklist in the scope of
  65. /// innermost containing loop.
  66. ///
  67. /// For the given instruction which have uses outside of the loop, an LCSSA PHI
  68. /// node is inserted and the uses outside the loop are rewritten to use this
  69. /// node.
  70. ///
  71. /// LoopInfo and DominatorTree are required and, since the routine makes no
  72. /// changes to CFG, preserved.
  73. ///
  74. /// Returns true if any modifications are made.
  75. ///
  76. /// This function may introduce unused PHI nodes. If \p PHIsToRemove is not
  77. /// nullptr, those are added to it (before removing, the caller has to check if
  78. /// they still do not have any uses). Otherwise the PHIs are directly removed.
  79. bool formLCSSAForInstructions(
  80. SmallVectorImpl<Instruction *> &Worklist, const DominatorTree &DT,
  81. const LoopInfo &LI, ScalarEvolution *SE, IRBuilderBase &Builder,
  82. SmallVectorImpl<PHINode *> *PHIsToRemove = nullptr);
  83. /// Put loop into LCSSA form.
  84. ///
  85. /// Looks at all instructions in the loop which have uses outside of the
  86. /// current loop. For each, an LCSSA PHI node is inserted and the uses outside
  87. /// the loop are rewritten to use this node. Sub-loops must be in LCSSA form
  88. /// already.
  89. ///
  90. /// LoopInfo and DominatorTree are required and preserved.
  91. ///
  92. /// If ScalarEvolution is passed in, it will be preserved.
  93. ///
  94. /// Returns true if any modifications are made to the loop.
  95. bool formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
  96. ScalarEvolution *SE);
  97. /// Put a loop nest into LCSSA form.
  98. ///
  99. /// This recursively forms LCSSA for a loop nest.
  100. ///
  101. /// LoopInfo and DominatorTree are required and preserved.
  102. ///
  103. /// If ScalarEvolution is passed in, it will be preserved.
  104. ///
  105. /// Returns true if any modifications are made to the loop.
  106. bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
  107. ScalarEvolution *SE);
  108. /// Flags controlling how much is checked when sinking or hoisting
  109. /// instructions. The number of memory access in the loop (and whether there
  110. /// are too many) is determined in the constructors when using MemorySSA.
  111. class SinkAndHoistLICMFlags {
  112. public:
  113. // Explicitly set limits.
  114. SinkAndHoistLICMFlags(unsigned LicmMssaOptCap,
  115. unsigned LicmMssaNoAccForPromotionCap, bool IsSink,
  116. Loop *L = nullptr, MemorySSA *MSSA = nullptr);
  117. // Use default limits.
  118. SinkAndHoistLICMFlags(bool IsSink, Loop *L = nullptr,
  119. MemorySSA *MSSA = nullptr);
  120. void setIsSink(bool B) { IsSink = B; }
  121. bool getIsSink() { return IsSink; }
  122. bool tooManyMemoryAccesses() { return NoOfMemAccTooLarge; }
  123. bool tooManyClobberingCalls() { return LicmMssaOptCounter >= LicmMssaOptCap; }
  124. void incrementClobberingCalls() { ++LicmMssaOptCounter; }
  125. protected:
  126. bool NoOfMemAccTooLarge = false;
  127. unsigned LicmMssaOptCounter = 0;
  128. unsigned LicmMssaOptCap;
  129. unsigned LicmMssaNoAccForPromotionCap;
  130. bool IsSink;
  131. };
  132. /// Walk the specified region of the CFG (defined by all blocks
  133. /// dominated by the specified block, and that are in the current loop) in
  134. /// reverse depth first order w.r.t the DominatorTree. This allows us to visit
  135. /// uses before definitions, allowing us to sink a loop body in one pass without
  136. /// iteration. Takes DomTreeNode, AAResults, LoopInfo, DominatorTree,
  137. /// BlockFrequencyInfo, TargetLibraryInfo, Loop, AliasSet information for all
  138. /// instructions of the loop and loop safety information as
  139. /// arguments. Diagnostics is emitted via \p ORE. It returns changed status.
  140. bool sinkRegion(DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *,
  141. BlockFrequencyInfo *, TargetLibraryInfo *,
  142. TargetTransformInfo *, Loop *, AliasSetTracker *,
  143. MemorySSAUpdater *, ICFLoopSafetyInfo *,
  144. SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *);
  145. /// Walk the specified region of the CFG (defined by all blocks
  146. /// dominated by the specified block, and that are in the current loop) in depth
  147. /// first order w.r.t the DominatorTree. This allows us to visit definitions
  148. /// before uses, allowing us to hoist a loop body in one pass without iteration.
  149. /// Takes DomTreeNode, AAResults, LoopInfo, DominatorTree,
  150. /// BlockFrequencyInfo, TargetLibraryInfo, Loop, AliasSet information for all
  151. /// instructions of the loop and loop safety information as arguments.
  152. /// Diagnostics is emitted via \p ORE. It returns changed status.
  153. bool hoistRegion(DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *,
  154. BlockFrequencyInfo *, TargetLibraryInfo *, Loop *,
  155. AliasSetTracker *, MemorySSAUpdater *, ScalarEvolution *,
  156. ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &,
  157. OptimizationRemarkEmitter *);
  158. /// This function deletes dead loops. The caller of this function needs to
  159. /// guarantee that the loop is infact dead.
  160. /// The function requires a bunch or prerequisites to be present:
  161. /// - The loop needs to be in LCSSA form
  162. /// - The loop needs to have a Preheader
  163. /// - A unique dedicated exit block must exist
  164. ///
  165. /// This also updates the relevant analysis information in \p DT, \p SE, \p LI
  166. /// and \p MSSA if pointers to those are provided.
  167. /// It also updates the loop PM if an updater struct is provided.
  168. void deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
  169. LoopInfo *LI, MemorySSA *MSSA = nullptr);
  170. /// Remove the backedge of the specified loop. Handles loop nests and general
  171. /// loop structures subject to the precondition that the loop has no parent
  172. /// loop and has a single latch block. Preserves all listed analyses.
  173. void breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
  174. LoopInfo &LI, MemorySSA *MSSA);
  175. /// Try to promote memory values to scalars by sinking stores out of
  176. /// the loop and moving loads to before the loop. We do this by looping over
  177. /// the stores in the loop, looking for stores to Must pointers which are
  178. /// loop invariant. It takes a set of must-alias values, Loop exit blocks
  179. /// vector, loop exit blocks insertion point vector, PredIteratorCache,
  180. /// LoopInfo, DominatorTree, Loop, AliasSet information for all instructions
  181. /// of the loop and loop safety information as arguments.
  182. /// Diagnostics is emitted via \p ORE. It returns changed status.
  183. bool promoteLoopAccessesToScalars(
  184. const SmallSetVector<Value *, 8> &, SmallVectorImpl<BasicBlock *> &,
  185. SmallVectorImpl<Instruction *> &, SmallVectorImpl<MemoryAccess *> &,
  186. PredIteratorCache &, LoopInfo *, DominatorTree *, const TargetLibraryInfo *,
  187. Loop *, AliasSetTracker *, MemorySSAUpdater *, ICFLoopSafetyInfo *,
  188. OptimizationRemarkEmitter *);
  189. /// Does a BFS from a given node to all of its children inside a given loop.
  190. /// The returned vector of nodes includes the starting point.
  191. SmallVector<DomTreeNode *, 16> collectChildrenInLoop(DomTreeNode *N,
  192. const Loop *CurLoop);
  193. /// Returns the instructions that use values defined in the loop.
  194. SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
  195. /// Find string metadata for loop
  196. ///
  197. /// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
  198. /// operand or null otherwise. If the string metadata is not found return
  199. /// Optional's not-a-value.
  200. Optional<const MDOperand *> findStringMetadataForLoop(const Loop *TheLoop,
  201. StringRef Name);
  202. /// Find named metadata for a loop with an integer value.
  203. llvm::Optional<int> getOptionalIntLoopAttribute(Loop *TheLoop, StringRef Name);
  204. /// Find a combination of metadata ("llvm.loop.vectorize.width" and
  205. /// "llvm.loop.vectorize.scalable.enable") for a loop and use it to construct a
  206. /// ElementCount. If the metadata "llvm.loop.vectorize.width" cannot be found
  207. /// then None is returned.
  208. Optional<ElementCount>
  209. getOptionalElementCountLoopAttribute(Loop *TheLoop);
  210. /// Create a new loop identifier for a loop created from a loop transformation.
  211. ///
  212. /// @param OrigLoopID The loop ID of the loop before the transformation.
  213. /// @param FollowupAttrs List of attribute names that contain attributes to be
  214. /// added to the new loop ID.
  215. /// @param InheritOptionsAttrsPrefix Selects which attributes should be inherited
  216. /// from the original loop. The following values
  217. /// are considered:
  218. /// nullptr : Inherit all attributes from @p OrigLoopID.
  219. /// "" : Do not inherit any attribute from @p OrigLoopID; only use
  220. /// those specified by a followup attribute.
  221. /// "<prefix>": Inherit all attributes except those which start with
  222. /// <prefix>; commonly used to remove metadata for the
  223. /// applied transformation.
  224. /// @param AlwaysNew If true, do not try to reuse OrigLoopID and never return
  225. /// None.
  226. ///
  227. /// @return The loop ID for the after-transformation loop. The following values
  228. /// can be returned:
  229. /// None : No followup attribute was found; it is up to the
  230. /// transformation to choose attributes that make sense.
  231. /// @p OrigLoopID: The original identifier can be reused.
  232. /// nullptr : The new loop has no attributes.
  233. /// MDNode* : A new unique loop identifier.
  234. Optional<MDNode *>
  235. makeFollowupLoopID(MDNode *OrigLoopID, ArrayRef<StringRef> FollowupAttrs,
  236. const char *InheritOptionsAttrsPrefix = "",
  237. bool AlwaysNew = false);
  238. /// Look for the loop attribute that disables all transformation heuristic.
  239. bool hasDisableAllTransformsHint(const Loop *L);
  240. /// Look for the loop attribute that disables the LICM transformation heuristics.
  241. bool hasDisableLICMTransformsHint(const Loop *L);
  242. /// Look for the loop attribute that requires progress within the loop.
  243. bool hasMustProgress(const Loop *L);
  244. /// The mode sets how eager a transformation should be applied.
  245. enum TransformationMode {
  246. /// The pass can use heuristics to determine whether a transformation should
  247. /// be applied.
  248. TM_Unspecified,
  249. /// The transformation should be applied without considering a cost model.
  250. TM_Enable,
  251. /// The transformation should not be applied.
  252. TM_Disable,
  253. /// Force is a flag and should not be used alone.
  254. TM_Force = 0x04,
  255. /// The transformation was directed by the user, e.g. by a #pragma in
  256. /// the source code. If the transformation could not be applied, a
  257. /// warning should be emitted.
  258. TM_ForcedByUser = TM_Enable | TM_Force,
  259. /// The transformation must not be applied. For instance, `#pragma clang loop
  260. /// unroll(disable)` explicitly forbids any unrolling to take place. Unlike
  261. /// general loop metadata, it must not be dropped. Most passes should not
  262. /// behave differently under TM_Disable and TM_SuppressedByUser.
  263. TM_SuppressedByUser = TM_Disable | TM_Force
  264. };
  265. /// @{
  266. /// Get the mode for LLVM's supported loop transformations.
  267. TransformationMode hasUnrollTransformation(Loop *L);
  268. TransformationMode hasUnrollAndJamTransformation(Loop *L);
  269. TransformationMode hasVectorizeTransformation(Loop *L);
  270. TransformationMode hasDistributeTransformation(Loop *L);
  271. TransformationMode hasLICMVersioningTransformation(Loop *L);
  272. /// @}
  273. /// Set input string into loop metadata by keeping other values intact.
  274. /// If the string is already in loop metadata update value if it is
  275. /// different.
  276. void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
  277. unsigned V = 0);
  278. /// Returns true if Name is applied to TheLoop and enabled.
  279. bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name);
  280. /// Returns a loop's estimated trip count based on branch weight metadata.
  281. /// In addition if \p EstimatedLoopInvocationWeight is not null it is
  282. /// initialized with weight of loop's latch leading to the exit.
  283. /// Returns 0 when the count is estimated to be 0, or None when a meaningful
  284. /// estimate can not be made.
  285. Optional<unsigned>
  286. getLoopEstimatedTripCount(Loop *L,
  287. unsigned *EstimatedLoopInvocationWeight = nullptr);
  288. /// Set a loop's branch weight metadata to reflect that loop has \p
  289. /// EstimatedTripCount iterations and \p EstimatedLoopInvocationWeight exits
  290. /// through latch. Returns true if metadata is successfully updated, false
  291. /// otherwise. Note that loop must have a latch block which controls loop exit
  292. /// in order to succeed.
  293. bool setLoopEstimatedTripCount(Loop *L, unsigned EstimatedTripCount,
  294. unsigned EstimatedLoopInvocationWeight);
  295. /// Check inner loop (L) backedge count is known to be invariant on all
  296. /// iterations of its outer loop. If the loop has no parent, this is trivially
  297. /// true.
  298. bool hasIterationCountInvariantInParent(Loop *L, ScalarEvolution &SE);
  299. /// Helper to consistently add the set of standard passes to a loop pass's \c
  300. /// AnalysisUsage.
  301. ///
  302. /// All loop passes should call this as part of implementing their \c
  303. /// getAnalysisUsage.
  304. void getLoopAnalysisUsage(AnalysisUsage &AU);
  305. /// Returns true if is legal to hoist or sink this instruction disregarding the
  306. /// possible introduction of faults. Reasoning about potential faulting
  307. /// instructions is the responsibility of the caller since it is challenging to
  308. /// do efficiently from within this routine.
  309. /// \p TargetExecutesOncePerLoop is true only when it is guaranteed that the
  310. /// target executes at most once per execution of the loop body. This is used
  311. /// to assess the legality of duplicating atomic loads. Generally, this is
  312. /// true when moving out of loop and not true when moving into loops.
  313. /// If \p ORE is set use it to emit optimization remarks.
  314. bool canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
  315. Loop *CurLoop, AliasSetTracker *CurAST,
  316. MemorySSAUpdater *MSSAU, bool TargetExecutesOncePerLoop,
  317. SinkAndHoistLICMFlags *LICMFlags = nullptr,
  318. OptimizationRemarkEmitter *ORE = nullptr);
  319. /// Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
  320. Value *createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
  321. Value *Right);
  322. /// Generates an ordered vector reduction using extracts to reduce the value.
  323. Value *getOrderedReduction(IRBuilderBase &Builder, Value *Acc, Value *Src,
  324. unsigned Op, RecurKind MinMaxKind = RecurKind::None,
  325. ArrayRef<Value *> RedOps = None);
  326. /// Generates a vector reduction using shufflevectors to reduce the value.
  327. /// Fast-math-flags are propagated using the IRBuilder's setting.
  328. Value *getShuffleReduction(IRBuilderBase &Builder, Value *Src, unsigned Op,
  329. RecurKind MinMaxKind = RecurKind::None,
  330. ArrayRef<Value *> RedOps = None);
  331. /// Create a target reduction of the given vector. The reduction operation
  332. /// is described by the \p Opcode parameter. min/max reductions require
  333. /// additional information supplied in \p RdxKind.
  334. /// The target is queried to determine if intrinsics or shuffle sequences are
  335. /// required to implement the reduction.
  336. /// Fast-math-flags are propagated using the IRBuilder's setting.
  337. Value *createSimpleTargetReduction(IRBuilderBase &B,
  338. const TargetTransformInfo *TTI, Value *Src,
  339. RecurKind RdxKind,
  340. ArrayRef<Value *> RedOps = None);
  341. /// Create a generic target reduction using a recurrence descriptor \p Desc
  342. /// The target is queried to determine if intrinsics or shuffle sequences are
  343. /// required to implement the reduction.
  344. /// Fast-math-flags are propagated using the RecurrenceDescriptor.
  345. Value *createTargetReduction(IRBuilderBase &B, const TargetTransformInfo *TTI,
  346. RecurrenceDescriptor &Desc, Value *Src);
  347. /// Get the intersection (logical and) of all of the potential IR flags
  348. /// of each scalar operation (VL) that will be converted into a vector (I).
  349. /// If OpValue is non-null, we only consider operations similar to OpValue
  350. /// when intersecting.
  351. /// Flag set: NSW, NUW, exact, and all of fast-math.
  352. void propagateIRFlags(Value *I, ArrayRef<Value *> VL, Value *OpValue = nullptr);
  353. /// Returns true if we can prove that \p S is defined and always negative in
  354. /// loop \p L.
  355. bool isKnownNegativeInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE);
  356. /// Returns true if we can prove that \p S is defined and always non-negative in
  357. /// loop \p L.
  358. bool isKnownNonNegativeInLoop(const SCEV *S, const Loop *L,
  359. ScalarEvolution &SE);
  360. /// Returns true if \p S is defined and never is equal to signed/unsigned max.
  361. bool cannotBeMaxInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE,
  362. bool Signed);
  363. /// Returns true if \p S is defined and never is equal to signed/unsigned min.
  364. bool cannotBeMinInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE,
  365. bool Signed);
  366. enum ReplaceExitVal { NeverRepl, OnlyCheapRepl, NoHardUse, AlwaysRepl };
  367. /// If the final value of any expressions that are recurrent in the loop can
  368. /// be computed, substitute the exit values from the loop into any instructions
  369. /// outside of the loop that use the final values of the current expressions.
  370. /// Return the number of loop exit values that have been replaced, and the
  371. /// corresponding phi node will be added to DeadInsts.
  372. int rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
  373. ScalarEvolution *SE, const TargetTransformInfo *TTI,
  374. SCEVExpander &Rewriter, DominatorTree *DT,
  375. ReplaceExitVal ReplaceExitValue,
  376. SmallVector<WeakTrackingVH, 16> &DeadInsts);
  377. /// Set weights for \p UnrolledLoop and \p RemainderLoop based on weights for
  378. /// \p OrigLoop and the following distribution of \p OrigLoop iteration among \p
  379. /// UnrolledLoop and \p RemainderLoop. \p UnrolledLoop receives weights that
  380. /// reflect TC/UF iterations, and \p RemainderLoop receives weights that reflect
  381. /// the remaining TC%UF iterations.
  382. ///
  383. /// Note that \p OrigLoop may be equal to either \p UnrolledLoop or \p
  384. /// RemainderLoop in which case weights for \p OrigLoop are updated accordingly.
  385. /// Note also behavior is undefined if \p UnrolledLoop and \p RemainderLoop are
  386. /// equal. \p UF must be greater than zero.
  387. /// If \p OrigLoop has no profile info associated nothing happens.
  388. ///
  389. /// This utility may be useful for such optimizations as unroller and
  390. /// vectorizer as it's typical transformation for them.
  391. void setProfileInfoAfterUnrolling(Loop *OrigLoop, Loop *UnrolledLoop,
  392. Loop *RemainderLoop, uint64_t UF);
  393. /// Utility that implements appending of loops onto a worklist given a range.
  394. /// We want to process loops in postorder, but the worklist is a LIFO data
  395. /// structure, so we append to it in *reverse* postorder.
  396. /// For trees, a preorder traversal is a viable reverse postorder, so we
  397. /// actually append using a preorder walk algorithm.
  398. template <typename RangeT>
  399. void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist<Loop *, 4> &);
  400. /// Utility that implements appending of loops onto a worklist given a range.
  401. /// It has the same behavior as appendLoopsToWorklist, but assumes the range of
  402. /// loops has already been reversed, so it processes loops in the given order.
  403. template <typename RangeT>
  404. void appendReversedLoopsToWorklist(RangeT &&,
  405. SmallPriorityWorklist<Loop *, 4> &);
  406. /// Utility that implements appending of loops onto a worklist given LoopInfo.
  407. /// Calls the templated utility taking a Range of loops, handing it the Loops
  408. /// in LoopInfo, iterated in reverse. This is because the loops are stored in
  409. /// RPO w.r.t. the control flow graph in LoopInfo. For the purpose of unrolling,
  410. /// loop deletion, and LICM, we largely want to work forward across the CFG so
  411. /// that we visit defs before uses and can propagate simplifications from one
  412. /// loop nest into the next. Calls appendReversedLoopsToWorklist with the
  413. /// already reversed loops in LI.
  414. /// FIXME: Consider changing the order in LoopInfo.
  415. void appendLoopsToWorklist(LoopInfo &, SmallPriorityWorklist<Loop *, 4> &);
  416. /// Recursively clone the specified loop and all of its children,
  417. /// mapping the blocks with the specified map.
  418. Loop *cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM,
  419. LoopInfo *LI, LPPassManager *LPM);
  420. /// Add code that checks at runtime if the accessed arrays in \p PointerChecks
  421. /// overlap.
  422. ///
  423. /// Returns a pair of instructions where the first element is the first
  424. /// instruction generated in possibly a sequence of instructions and the
  425. /// second value is the final comparator value or NULL if no check is needed.
  426. std::pair<Instruction *, Instruction *>
  427. addRuntimeChecks(Instruction *Loc, Loop *TheLoop,
  428. const SmallVectorImpl<RuntimePointerCheck> &PointerChecks,
  429. ScalarEvolution *SE);
  430. } // end namespace llvm
  431. #endif // LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
  432. #ifdef __GNUC__
  433. #pragma GCC diagnostic pop
  434. #endif