LLVM  9.0.0svn
UnrollLoop.h
Go to the documentation of this file.
1 //===- llvm/Transforms/Utils/UnrollLoop.h - Unrolling utilities -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines some loop unrolling utilities. It does not define any
10 // actual pass or policy, but provides a single function to perform loop
11 // unrolling.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H
16 #define LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringRef.h"
22 
23 namespace llvm {
24 
25 class AssumptionCache;
26 class BasicBlock;
27 class BlockFrequencyInfo;
28 class DependenceInfo;
29 class DominatorTree;
30 class Loop;
31 class LoopInfo;
32 class MDNode;
33 class ProfileSummaryInfo;
34 class OptimizationRemarkEmitter;
35 class ScalarEvolution;
36 
38 
39 /// @{
40 /// Metadata attribute names
41 const char *const LLVMLoopUnrollFollowupAll = "llvm.loop.unroll.followup_all";
42 const char *const LLVMLoopUnrollFollowupUnrolled =
43  "llvm.loop.unroll.followup_unrolled";
45  "llvm.loop.unroll.followup_remainder";
46 /// @}
47 
48 const Loop* addClonedBlockToLoopInfo(BasicBlock *OriginalBB,
49  BasicBlock *ClonedBB, LoopInfo *LI,
50  NewLoopsMap &NewLoops);
51 
52 /// Represents the result of a \c UnrollLoop invocation.
53 enum class LoopUnrollResult {
54  /// The loop was not modified.
55  Unmodified,
56 
57  /// The loop was partially unrolled -- we still have a loop, but with a
58  /// smaller trip count. We may also have emitted epilogue loop if the loop
59  /// had a non-constant trip count.
61 
62  /// The loop was fully unrolled into straight-line code. We no longer have
63  /// any back-edges.
65 };
66 
68  unsigned Count;
69  unsigned TripCount;
70  bool Force;
75  unsigned TripMultiple;
76  unsigned PeelCount;
79 };
80 
84  bool PreserveLCSSA, Loop **RemainderLoop = nullptr);
85 
86 bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
87  bool AllowExpensiveTripCount,
88  bool UseEpilogRemainder, bool UnrollRemainder,
89  bool ForgetAllSCEV, LoopInfo *LI,
91  AssumptionCache *AC, bool PreserveLCSSA,
92  Loop **ResultLoop = nullptr);
93 
94 void computePeelCount(Loop *L, unsigned LoopSize,
96  unsigned &TripCount, ScalarEvolution &SE);
97 
98 bool canPeel(Loop *L);
99 
100 bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
101  DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA);
102 
103 LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount,
104  unsigned TripMultiple, bool UnrollRemainder,
105  LoopInfo *LI, ScalarEvolution *SE,
108  Loop **EpilogueLoop = nullptr);
109 
111  DependenceInfo &DI);
112 
113 bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI,
114  DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
115  const SmallPtrSetImpl<const Value *> &EphValues,
116  OptimizationRemarkEmitter *ORE, unsigned &TripCount,
117  unsigned MaxTripCount, unsigned &TripMultiple,
118  unsigned LoopSize,
120  bool &UseUpperBound);
121 
123  ScalarEvolution *SE, DominatorTree *DT);
124 
126 
127 void simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
129  AssumptionCache *AC);
130 
132 
134  Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
135  BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, int OptLevel,
136  Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
137  Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
138  Optional<bool> UserUpperBound, Optional<bool> UserAllowPeeling);
139 
140 unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls,
141  bool &NotDuplicatable, bool &Convergent,
142  const TargetTransformInfo &TTI,
143  const SmallPtrSetImpl<const Value *> &EphValues,
144  unsigned BEInsns);
145 
146 } // end namespace llvm
147 
148 #endif // LLVM_TRANSFORMS_UTILS_UNROLLLOOP_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Analysis providing profile information.
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:99
Metadata node.
Definition: Metadata.h:863
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.
TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, 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...
const char *const LLVMLoopUnrollFollowupUnrolled
Definition: UnrollLoop.h:42
void computePeelCount(Loop *L, unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP, unsigned &TripCount, ScalarEvolution &SE)
const char *const LLVMLoopUnrollFollowupRemainder
Definition: UnrollLoop.h:44
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:144
void remapInstruction(Instruction *I, ValueToValueMapTy &VMap)
Convert the instruction operands from referencing the current values into those specified by VMap...
Definition: LoopUnroll.cpp:65
The loop was fully unrolled into straight-line code.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
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:41
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.
bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, bool AllowExpensiveTripCount, bool UseEpilogRemainder, bool UnrollRemainder, bool ForgetAllSCEV, 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 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:189
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:902
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:464
Parameters that control the generic loop unrolling transformation.
#define I(x, y, z)
Definition: MD5.cpp:58
LoopUnrollResult UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, OptimizationRemarkEmitter *ORE, bool PreserveLCSSA, Loop **RemainderLoop=nullptr)
Unroll the given loop by Count.
Definition: LoopUnroll.cpp:334
The loop was not modified.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
This pass exposes codegen information to IR-level passes.
The optimization diagnostic interface.
LoopUnrollResult
Represents the result of a UnrollLoop invocation.
Definition: UnrollLoop.h:53
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:257