1 //===- llvm/Transforms/Utils/UnrollLoop.h - Unrolling utilities -*- 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 file defines some loop unrolling utilities. It does not define any 11 // actual pass or policy, but provides a single function to perform loop 12 // unrolling. 13 // 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H 17 #define LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H 18 19 // Needed because we can't forward-declare the nested struct 20 // TargetTransformInfo::UnrollingPreferences 21 #include "llvm/Analysis/TargetTransformInfo.h" 22 23 namespace llvm { 24 25 class StringRef; 26 class AssumptionCache; 27 class DominatorTree; 28 class Loop; 29 class LoopInfo; 30 class LPPassManager; 31 class MDNode; 32 class Pass; 33 class OptimizationRemarkEmitter; 34 class ScalarEvolution; 35 36 typedef SmallDenseMap<const Loop *, Loop *, 4> NewLoopsMap; 37 38 const Loop* addClonedBlockToLoopInfo(BasicBlock *OriginalBB, 39 BasicBlock *ClonedBB, LoopInfo *LI, 40 NewLoopsMap &NewLoops); 41 42 /// Represents the result of a \c UnrollLoop invocation. 43 enum class LoopUnrollResult { 44 /// The loop was not modified. 45 Unmodified, 46 47 /// The loop was partially unrolled -- we still have a loop, but with a 48 /// smaller trip count. We may also have emitted epilogue loop if the loop 49 /// had a non-constant trip count. 50 PartiallyUnrolled, 51 52 /// The loop was fully unrolled into straight-line code. We no longer have 53 /// any back-edges. 54 FullyUnrolled 55 }; 56 57 LoopUnrollResult UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, 58 bool Force, bool AllowRuntime, 59 bool AllowExpensiveTripCount, bool PreserveCondBr, 60 bool PreserveOnlyFirst, unsigned TripMultiple, 61 unsigned PeelCount, bool UnrollRemainder, 62 LoopInfo *LI, ScalarEvolution *SE, 63 DominatorTree *DT, AssumptionCache *AC, 64 OptimizationRemarkEmitter *ORE, bool PreserveLCSSA); 65 66 bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, 67 bool AllowExpensiveTripCount, 68 bool UseEpilogRemainder, bool UnrollRemainder, 69 LoopInfo *LI, 70 ScalarEvolution *SE, DominatorTree *DT, 71 AssumptionCache *AC, 72 OptimizationRemarkEmitter *ORE, 73 bool PreserveLCSSA); 74 75 void computePeelCount(Loop *L, unsigned LoopSize, 76 TargetTransformInfo::UnrollingPreferences &UP, 77 unsigned &TripCount); 78 79 bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE, 80 DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA); 81 82 MDNode *GetUnrollMetadata(MDNode *LoopID, StringRef Name); 83 } 84 85 #endif 86