LLVM  10.0.0svn
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 //===----------------------------------------------------------------------===//
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringRef.h"
23 namespace llvm {
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;
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 /// @}
48 const Loop* addClonedBlockToLoopInfo(BasicBlock *OriginalBB,
49  BasicBlock *ClonedBB, LoopInfo *LI,
50  NewLoopsMap &NewLoops);
52 /// Represents the result of a \c UnrollLoop invocation.
53 enum class LoopUnrollResult {
54  /// The loop was not modified.
55  Unmodified,
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.
62  /// The loop was fully unrolled into straight-line code. We no longer have
63  /// any back-edges.
65 };
68  unsigned Count;
69  unsigned TripCount;
70  bool Force;
75  unsigned TripMultiple;
76  unsigned PeelCount;
79 };
84  bool PreserveLCSSA, Loop **RemainderLoop = nullptr);
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);
94 void computePeelCount(Loop *L, unsigned LoopSize,
96  unsigned &TripCount, ScalarEvolution &SE);
98 bool canPeel(Loop *L);
100 bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
101  DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA);
103 LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount,
104  unsigned TripMultiple, bool UnrollRemainder,
105  LoopInfo *LI, ScalarEvolution *SE,
108  Loop **EpilogueLoop = nullptr);
111  DependenceInfo &DI);
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, bool MaxOrZero,
118  unsigned &TripMultiple, unsigned LoopSize,
120  bool &UseUpperBound);
124 void simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
126  AssumptionCache *AC);
131  Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
132  BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, int OptLevel,
133  Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
134  Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
135  Optional<bool> UserUpperBound, Optional<bool> UserAllowPeeling,
136  Optional<bool> UserAllowProfileBasedPeeling,
137  Optional<unsigned> UserFullUnrollMaxCount);
139 unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls,
140  bool &NotDuplicatable, bool &Convergent,
141  const TargetTransformInfo &TTI,
142  const SmallPtrSetImpl<const Value *> &EphValues,
143  unsigned BEInsns);
145 } // end namespace llvm
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.
Metadata node.
Definition: Metadata.h:863
DependenceInfo - This class is the main dependence-analysis driver.
const char *const LLVMLoopUnrollFollowupUnrolled
Definition: UnrollLoop.h:42
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, Optional< bool > UserAllowProfileBasedPeeling, Optional< unsigned > UserFullUnrollMaxCount)
Gather the various unrolling parameters based on the defaults, compiler flags, TTI overrides and user...
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)
bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const SmallPtrSetImpl< const Value *> &EphValues, OptimizationRemarkEmitter *ORE, unsigned &TripCount, unsigned MaxTripCount, bool MaxOrZero, unsigned &TripMultiple, unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP, bool &UseUpperBound)
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:67
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:131
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:962
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
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:276
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.
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:199