LLVM  8.0.1
UnrollLoop.h
Go to the documentation of this file.
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 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringRef.h"
23 
24 namespace llvm {
25 
26 class AssumptionCache;
27 class BasicBlock;
28 class DependenceInfo;
29 class DominatorTree;
30 class Loop;
31 class LoopInfo;
32 class MDNode;
33 class OptimizationRemarkEmitter;
34 class ScalarEvolution;
35 
37 
38 /// @{
39 /// Metadata attribute names
40 const char *const LLVMLoopUnrollFollowupAll = "llvm.loop.unroll.followup_all";
41 const char *const LLVMLoopUnrollFollowupUnrolled =
42  "llvm.loop.unroll.followup_unrolled";
44  "llvm.loop.unroll.followup_remainder";
45 /// @}
46 
47 const Loop* addClonedBlockToLoopInfo(BasicBlock *OriginalBB,
48  BasicBlock *ClonedBB, LoopInfo *LI,
49  NewLoopsMap &NewLoops);
50 
51 /// Represents the result of a \c UnrollLoop invocation.
52 enum class LoopUnrollResult {
53  /// The loop was not modified.
54  Unmodified,
55 
56  /// The loop was partially unrolled -- we still have a loop, but with a
57  /// smaller trip count. We may also have emitted epilogue loop if the loop
58  /// had a non-constant trip count.
60 
61  /// The loop was fully unrolled into straight-line code. We no longer have
62  /// any back-edges.
64 };
65 
66 LoopUnrollResult UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
67  bool Force, bool AllowRuntime,
68  bool AllowExpensiveTripCount, bool PreserveCondBr,
69  bool PreserveOnlyFirst, unsigned TripMultiple,
70  unsigned PeelCount, bool UnrollRemainder,
71  LoopInfo *LI, ScalarEvolution *SE,
73  OptimizationRemarkEmitter *ORE, bool PreserveLCSSA,
74  Loop **RemainderLoop = nullptr);
75 
76 bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
77  bool AllowExpensiveTripCount,
78  bool UseEpilogRemainder, bool UnrollRemainder,
79  LoopInfo *LI, ScalarEvolution *SE,
81  bool PreserveLCSSA,
82  Loop **ResultLoop = nullptr);
83 
84 void computePeelCount(Loop *L, unsigned LoopSize,
86  unsigned &TripCount, ScalarEvolution &SE);
87 
88 bool canPeel(Loop *L);
89 
90 bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
91  DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA);
92 
93 LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount,
94  unsigned TripMultiple, bool UnrollRemainder,
95  LoopInfo *LI, ScalarEvolution *SE,
98  Loop **EpilogueLoop = nullptr);
99 
101  DependenceInfo &DI);
102 
103 bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI,
104  DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
105  const SmallPtrSetImpl<const Value *> &EphValues,
106  OptimizationRemarkEmitter *ORE, unsigned &TripCount,
107  unsigned MaxTripCount, unsigned &TripMultiple,
108  unsigned LoopSize,
110  bool &UseUpperBound);
111 
113  ScalarEvolution *SE, DominatorTree *DT);
114 
116 
117 void simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
119  AssumptionCache *AC);
120 
122 
124  Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, int OptLevel,
125  Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
126  Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
127  Optional<bool> UserUpperBound, Optional<bool> UserAllowPeeling);
128 
129 unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls,
130  bool &NotDuplicatable, bool &Convergent,
131  const TargetTransformInfo &TTI,
132  const SmallPtrSetImpl<const Value *> &EphValues,
133  unsigned BEInsns);
134 
135 } // end namespace llvm
136 
137 #endif // LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H
bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, bool AllowExpensiveTripCount, bool UseEpilogRemainder, bool UnrollRemainder, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA, Loop **ResultLoop=nullptr)
Insert code in the prolog/epilog code when unrolling a loop with a run-time trip-count.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
The main scalar evolution driver.
A cache of @llvm.assume calls within a function.
BasicBlock * foldBlockIntoPredecessor(BasicBlock *BB, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT)
Folds a basic block into its predecessor if it only has one predecessor, and that predecessor only ha...
Definition: LoopUnroll.cpp:100
Metadata node.
Definition: Metadata.h:864
bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const SmallPtrSetImpl< const Value *> &EphValues, OptimizationRemarkEmitter *ORE, unsigned &TripCount, unsigned MaxTripCount, unsigned &TripMultiple, unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP, bool &UseUpperBound)
DependenceInfo - This class is the main dependence-analysis driver.
LoopUnrollResult UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, bool Force, bool AllowRuntime, bool AllowExpensiveTripCount, bool PreserveCondBr, bool PreserveOnlyFirst, unsigned TripMultiple, unsigned PeelCount, bool UnrollRemainder, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, OptimizationRemarkEmitter *ORE, bool PreserveLCSSA, Loop **RemainderLoop=nullptr)
Unroll the given loop by Count.
Definition: LoopUnroll.cpp:335
const char *const LLVMLoopUnrollFollowupUnrolled
Definition: UnrollLoop.h:41
amdgpu Simplify well known AMD library false Value Value const Twine & Name
void computePeelCount(Loop *L, unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP, unsigned &TripCount, ScalarEvolution &SE)
const char *const LLVMLoopUnrollFollowupRemainder
Definition: UnrollLoop.h:43
bool isSafeToUnrollAndJam(Loop *L, ScalarEvolution &SE, DominatorTree &DT, DependenceInfo &DI)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
void remapInstruction(Instruction *I, ValueToValueMapTy &VMap)
Convert the instruction operands from referencing the current values into those specified by VMap...
Definition: LoopUnroll.cpp:66
The loop was fully unrolled into straight-line code.
TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, int OptLevel, Optional< unsigned > UserThreshold, Optional< unsigned > UserCount, Optional< bool > UserAllowPartial, Optional< bool > UserRuntime, Optional< bool > UserUpperBound, Optional< bool > UserAllowPeeling)
Gather the various unrolling parameters based on the defaults, compiler flags, TTI overrides and user...
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA)
Peel off the first PeelCount iterations of loop L.
The loop was partially unrolled – we still have a loop, but with a smaller trip count.
const char *const LLVMLoopUnrollFollowupAll
Definition: UnrollLoop.h:40
unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls, bool &NotDuplicatable, bool &Convergent, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value *> &EphValues, unsigned BEInsns)
ApproximateLoopSize - Approximate the size of the loop.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool canPeel(Loop *L)
const Loop * addClonedBlockToLoopInfo(BasicBlock *OriginalBB, BasicBlock *ClonedBB, LoopInfo *LI, NewLoopsMap &NewLoops)
Adds ClonedBB to LoopInfo, creates a new loop for ClonedBB if necessary and adds a mapping from the o...
Definition: LoopUnroll.cpp:190
MDNode * GetUnrollMetadata(MDNode *LoopID, StringRef Name)
Given an llvm.loop loop id metadata node, returns the loop hint metadata node with the given name (fo...
Definition: LoopUnroll.cpp:896
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
Parameters that control the generic loop unrolling transformation.
#define I(x, y, z)
Definition: MD5.cpp:58
The loop was not modified.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
This pass exposes codegen information to IR-level passes.
The optimization diagnostic interface.
LoopUnrollResult
Represents the result of a UnrollLoop invocation.
Definition: UnrollLoop.h:52
LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, unsigned TripMultiple, bool UnrollRemainder, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, OptimizationRemarkEmitter *ORE, Loop **EpilogueLoop=nullptr)
void simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC)
Perform some cleanup and simplifications on loops after unrolling.
Definition: LoopUnroll.cpp:258