LLVM  7.0.0
LoopUnrollAndJamPass.cpp
Go to the documentation of this file.
1 //===- LoopUnrollAndJam.cpp - Loop unroll and jam pass --------------------===//
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 pass implements an unroll and jam pass. Most of the work is done by
11 // Utils/UnrollLoopAndJam.cpp.
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/None.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Analysis/LoopInfo.h"
24 #include "llvm/Analysis/LoopPass.h"
28 #include "llvm/IR/BasicBlock.h"
29 #include "llvm/IR/CFG.h"
30 #include "llvm/IR/Constant.h"
31 #include "llvm/IR/Constants.h"
32 #include "llvm/IR/Dominators.h"
33 #include "llvm/IR/Function.h"
34 #include "llvm/IR/Instruction.h"
35 #include "llvm/IR/Instructions.h"
36 #include "llvm/IR/IntrinsicInst.h"
37 #include "llvm/IR/Metadata.h"
38 #include "llvm/IR/PassManager.h"
39 #include "llvm/Pass.h"
40 #include "llvm/Support/Casting.h"
42 #include "llvm/Support/Debug.h"
45 #include "llvm/Transforms/Scalar.h"
47 #include "llvm/Transforms/Utils.h"
50 #include <algorithm>
51 #include <cassert>
52 #include <cstdint>
53 #include <string>
54 
55 using namespace llvm;
56 
57 #define DEBUG_TYPE "loop-unroll-and-jam"
58 
59 static cl::opt<bool>
60  AllowUnrollAndJam("allow-unroll-and-jam", cl::Hidden,
61  cl::desc("Allows loops to be unroll-and-jammed."));
62 
64  "unroll-and-jam-count", cl::Hidden,
65  cl::desc("Use this unroll count for all loops including those with "
66  "unroll_and_jam_count pragma values, for testing purposes"));
67 
69  "unroll-and-jam-threshold", cl::init(60), cl::Hidden,
70  cl::desc("Threshold to use for inner loop when doing unroll and jam."));
71 
73  "pragma-unroll-and-jam-threshold", cl::init(1024), cl::Hidden,
74  cl::desc("Unrolled size limit for loops with an unroll_and_jam(full) or "
75  "unroll_count pragma."));
76 
77 // Returns the loop hint metadata node with the given name (for example,
78 // "llvm.loop.unroll.count"). If no such metadata node exists, then nullptr is
79 // returned.
81  if (MDNode *LoopID = L->getLoopID())
82  return GetUnrollMetadata(LoopID, Name);
83  return nullptr;
84 }
85 
86 // Returns true if the loop has any metadata starting with Prefix. For example a
87 // Prefix of "llvm.loop.unroll." returns true if we have any unroll metadata.
88 static bool HasAnyUnrollPragma(const Loop *L, StringRef Prefix) {
89  if (MDNode *LoopID = L->getLoopID()) {
90  // First operand should refer to the loop id itself.
91  assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
92  assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
93 
94  for (unsigned i = 1, e = LoopID->getNumOperands(); i < e; ++i) {
95  MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
96  if (!MD)
97  continue;
98 
99  MDString *S = dyn_cast<MDString>(MD->getOperand(0));
100  if (!S)
101  continue;
102 
103  if (S->getString().startswith(Prefix))
104  return true;
105  }
106  }
107  return false;
108 }
109 
110 // Returns true if the loop has an unroll_and_jam(enable) pragma.
111 static bool HasUnrollAndJamEnablePragma(const Loop *L) {
112  return GetUnrollMetadataForLoop(L, "llvm.loop.unroll_and_jam.enable");
113 }
114 
115 // Returns true if the loop has an unroll_and_jam(disable) pragma.
116 static bool HasUnrollAndJamDisablePragma(const Loop *L) {
117  return GetUnrollMetadataForLoop(L, "llvm.loop.unroll_and_jam.disable");
118 }
119 
120 // If loop has an unroll_and_jam_count pragma return the (necessarily
121 // positive) value from the pragma. Otherwise return 0.
122 static unsigned UnrollAndJamCountPragmaValue(const Loop *L) {
123  MDNode *MD = GetUnrollMetadataForLoop(L, "llvm.loop.unroll_and_jam.count");
124  if (MD) {
125  assert(MD->getNumOperands() == 2 &&
126  "Unroll count hint metadata should have two operands.");
127  unsigned Count =
128  mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue();
129  assert(Count >= 1 && "Unroll count must be positive.");
130  return Count;
131  }
132  return 0;
133 }
134 
135 // Returns loop size estimation for unrolled loop.
136 static uint64_t
137 getUnrollAndJammedLoopSize(unsigned LoopSize,
139  assert(LoopSize >= UP.BEInsns && "LoopSize should not be less than BEInsns!");
140  return static_cast<uint64_t>(LoopSize - UP.BEInsns) * UP.Count + UP.BEInsns;
141 }
142 
143 // Calculates unroll and jam count and writes it to UP.Count. Returns true if
144 // unroll count was set explicitly.
146  Loop *L, Loop *SubLoop, const TargetTransformInfo &TTI, DominatorTree &DT,
147  LoopInfo *LI, ScalarEvolution &SE,
148  const SmallPtrSetImpl<const Value *> &EphValues,
149  OptimizationRemarkEmitter *ORE, unsigned OuterTripCount,
150  unsigned OuterTripMultiple, unsigned OuterLoopSize, unsigned InnerTripCount,
151  unsigned InnerLoopSize, TargetTransformInfo::UnrollingPreferences &UP) {
152  // Check for explicit Count from the "unroll-and-jam-count" option.
153  bool UserUnrollCount = UnrollAndJamCount.getNumOccurrences() > 0;
154  if (UserUnrollCount) {
156  UP.Force = true;
157  if (UP.AllowRemainder &&
158  getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
159  getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
161  return true;
162  }
163 
164  // Check for unroll_and_jam pragmas
165  unsigned PragmaCount = UnrollAndJamCountPragmaValue(L);
166  if (PragmaCount > 0) {
167  UP.Count = PragmaCount;
168  UP.Runtime = true;
169  UP.Force = true;
170  if ((UP.AllowRemainder || (OuterTripMultiple % PragmaCount == 0)) &&
171  getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
172  getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
174  return true;
175  }
176 
177  // Use computeUnrollCount from the loop unroller to get a sensible count
178  // for the unrolling the outer loop. This uses UP.Threshold /
179  // UP.PartialThreshold / UP.MaxCount to come up with sensible loop values.
180  // We have already checked that the loop has no unroll.* pragmas.
181  unsigned MaxTripCount = 0;
182  bool UseUpperBound = false;
183  bool ExplicitUnroll = computeUnrollCount(
184  L, TTI, DT, LI, SE, EphValues, ORE, OuterTripCount, MaxTripCount,
185  OuterTripMultiple, OuterLoopSize, UP, UseUpperBound);
186  if (ExplicitUnroll || UseUpperBound) {
187  // If the user explicitly set the loop as unrolled, dont UnJ it. Leave it
188  // for the unroller instead.
189  UP.Count = 0;
190  return false;
191  }
192 
193  bool PragmaEnableUnroll = HasUnrollAndJamEnablePragma(L);
194  ExplicitUnroll = PragmaCount > 0 || PragmaEnableUnroll || UserUnrollCount;
195 
196  // If the loop has an unrolling pragma, we want to be more aggressive with
197  // unrolling limits.
198  if (ExplicitUnroll && OuterTripCount != 0)
200 
201  if (!UP.AllowRemainder && getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
203  UP.Count = 0;
204  return false;
205  }
206 
207  // If the inner loop count is known and small, leave the entire loop nest to
208  // be the unroller
209  if (!ExplicitUnroll && InnerTripCount &&
210  InnerLoopSize * InnerTripCount < UP.Threshold) {
211  UP.Count = 0;
212  return false;
213  }
214 
215  // We have a sensible limit for the outer loop, now adjust it for the inner
216  // loop and UP.UnrollAndJamInnerLoopThreshold.
217  while (UP.Count != 0 && UP.AllowRemainder &&
218  getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
220  UP.Count--;
221 
222  if (!ExplicitUnroll) {
223  // Check for situations where UnJ is likely to be unprofitable. Including
224  // subloops with more than 1 block.
225  if (SubLoop->getBlocks().size() != 1) {
226  UP.Count = 0;
227  return false;
228  }
229 
230  // Limit to loops where there is something to gain from unrolling and
231  // jamming the loop. In this case, look for loads that are invariant in the
232  // outer loop and can become shared.
233  unsigned NumInvariant = 0;
234  for (BasicBlock *BB : SubLoop->getBlocks()) {
235  for (Instruction &I : *BB) {
236  if (auto *Ld = dyn_cast<LoadInst>(&I)) {
237  Value *V = Ld->getPointerOperand();
238  const SCEV *LSCEV = SE.getSCEVAtScope(V, L);
239  if (SE.isLoopInvariant(LSCEV, L))
240  NumInvariant++;
241  }
242  }
243  }
244  if (NumInvariant == 0) {
245  UP.Count = 0;
246  return false;
247  }
248  }
249 
250  return ExplicitUnroll;
251 }
252 
253 static LoopUnrollResult
255  ScalarEvolution &SE, const TargetTransformInfo &TTI,
257  OptimizationRemarkEmitter &ORE, int OptLevel) {
258  // Quick checks of the correct loop form
259  if (!L->isLoopSimplifyForm() || L->getSubLoops().size() != 1)
261  Loop *SubLoop = L->getSubLoops()[0];
262  if (!SubLoop->isLoopSimplifyForm())
264 
265  BasicBlock *Latch = L->getLoopLatch();
266  BasicBlock *Exit = L->getExitingBlock();
267  BasicBlock *SubLoopLatch = SubLoop->getLoopLatch();
268  BasicBlock *SubLoopExit = SubLoop->getExitingBlock();
269 
270  if (Latch != Exit || SubLoopLatch != SubLoopExit)
272 
274  L, SE, TTI, OptLevel, None, None, None, None, None, None);
275  if (AllowUnrollAndJam.getNumOccurrences() > 0)
277  if (UnrollAndJamThreshold.getNumOccurrences() > 0)
279  // Exit early if unrolling is disabled.
282 
283  LLVM_DEBUG(dbgs() << "Loop Unroll and Jam: F["
284  << L->getHeader()->getParent()->getName() << "] Loop %"
285  << L->getHeader()->getName() << "\n");
286 
287  // A loop with any unroll pragma (enabling/disabling/count/etc) is left for
288  // the unroller, so long as it does not explicitly have unroll_and_jam
289  // metadata. This means #pragma nounroll will disable unroll and jam as well
290  // as unrolling
292  (HasAnyUnrollPragma(L, "llvm.loop.unroll.") &&
293  !HasAnyUnrollPragma(L, "llvm.loop.unroll_and_jam."))) {
294  LLVM_DEBUG(dbgs() << " Disabled due to pragma.\n");
296  }
297 
298  if (!isSafeToUnrollAndJam(L, SE, DT, DI)) {
299  LLVM_DEBUG(dbgs() << " Disabled due to not being safe.\n");
301  }
302 
303  // Approximate the loop size and collect useful info
304  unsigned NumInlineCandidates;
305  bool NotDuplicatable;
306  bool Convergent;
308  CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
309  unsigned InnerLoopSize =
310  ApproximateLoopSize(SubLoop, NumInlineCandidates, NotDuplicatable,
311  Convergent, TTI, EphValues, UP.BEInsns);
312  unsigned OuterLoopSize =
313  ApproximateLoopSize(L, NumInlineCandidates, NotDuplicatable, Convergent,
314  TTI, EphValues, UP.BEInsns);
315  LLVM_DEBUG(dbgs() << " Outer Loop Size: " << OuterLoopSize << "\n");
316  LLVM_DEBUG(dbgs() << " Inner Loop Size: " << InnerLoopSize << "\n");
317  if (NotDuplicatable) {
318  LLVM_DEBUG(dbgs() << " Not unrolling loop which contains non-duplicatable "
319  "instructions.\n");
321  }
322  if (NumInlineCandidates != 0) {
323  LLVM_DEBUG(dbgs() << " Not unrolling loop with inlinable calls.\n");
325  }
326  if (Convergent) {
327  LLVM_DEBUG(
328  dbgs() << " Not unrolling loop with convergent instructions.\n");
330  }
331 
332  // Find trip count and trip multiple
333  unsigned OuterTripCount = SE.getSmallConstantTripCount(L, Latch);
334  unsigned OuterTripMultiple = SE.getSmallConstantTripMultiple(L, Latch);
335  unsigned InnerTripCount = SE.getSmallConstantTripCount(SubLoop, SubLoopLatch);
336 
337  // Decide if, and by how much, to unroll
338  bool IsCountSetExplicitly = computeUnrollAndJamCount(
339  L, SubLoop, TTI, DT, LI, SE, EphValues, &ORE, OuterTripCount,
340  OuterTripMultiple, OuterLoopSize, InnerTripCount, InnerLoopSize, UP);
341  if (UP.Count <= 1)
343  // Unroll factor (Count) must be less or equal to TripCount.
344  if (OuterTripCount && UP.Count > OuterTripCount)
345  UP.Count = OuterTripCount;
346 
347  LoopUnrollResult UnrollResult =
348  UnrollAndJamLoop(L, UP.Count, OuterTripCount, OuterTripMultiple,
349  UP.UnrollRemainder, LI, &SE, &DT, &AC, &ORE);
350 
351  // If loop has an unroll count pragma or unrolled by explicitly set count
352  // mark loop as unrolled to prevent unrolling beyond that requested.
353  if (UnrollResult != LoopUnrollResult::FullyUnrolled && IsCountSetExplicitly)
355 
356  return UnrollResult;
357 }
358 
359 namespace {
360 
361 class LoopUnrollAndJam : public LoopPass {
362 public:
363  static char ID; // Pass ID, replacement for typeid
364  unsigned OptLevel;
365 
366  LoopUnrollAndJam(int OptLevel = 2) : LoopPass(ID), OptLevel(OptLevel) {
368  }
369 
370  bool runOnLoop(Loop *L, LPPassManager &LPM) override {
371  if (skipLoop(L))
372  return false;
373 
374  Function &F = *L->getHeader()->getParent();
375 
376  auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
377  LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
378  ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
379  const TargetTransformInfo &TTI =
380  getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
381  auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
382  auto &DI = getAnalysis<DependenceAnalysisWrapperPass>().getDI();
383  // For the old PM, we can't use OptimizationRemarkEmitter as an analysis
384  // pass. Function analyses need to be preserved across loop transformations
385  // but ORE cannot be preserved (see comment before the pass definition).
387 
389  tryToUnrollAndJamLoop(L, DT, LI, SE, TTI, AC, DI, ORE, OptLevel);
390 
391  if (Result == LoopUnrollResult::FullyUnrolled)
392  LPM.markLoopAsDeleted(*L);
393 
394  return Result != LoopUnrollResult::Unmodified;
395  }
396 
397  /// This transformation requires natural loop information & requires that
398  /// loop preheaders be inserted into the CFG...
399  void getAnalysisUsage(AnalysisUsage &AU) const override {
404  }
405 };
406 
407 } // end anonymous namespace
408 
409 char LoopUnrollAndJam::ID = 0;
410 
411 INITIALIZE_PASS_BEGIN(LoopUnrollAndJam, "loop-unroll-and-jam",
412  "Unroll and Jam loops", false, false)
417 INITIALIZE_PASS_END(LoopUnrollAndJam, "loop-unroll-and-jam",
418  "Unroll and Jam loops", false, false)
419 
421  return new LoopUnrollAndJam(OptLevel);
422 }
423 
426  LPMUpdater &) {
427  const auto &FAM =
428  AM.getResult<FunctionAnalysisManagerLoopProxy>(L, AR).getManager();
429  Function *F = L.getHeader()->getParent();
430 
431  auto *ORE = FAM.getCachedResult<OptimizationRemarkEmitterAnalysis>(*F);
432  // FIXME: This should probably be optional rather than required.
433  if (!ORE)
435  "LoopUnrollAndJamPass: OptimizationRemarkEmitterAnalysis not cached at "
436  "a higher level");
437 
438  DependenceInfo DI(F, &AR.AA, &AR.SE, &AR.LI);
439 
441  &L, AR.DT, &AR.LI, AR.SE, AR.TTI, AR.AC, DI, *ORE, OptLevel);
442 
443  if (Result == LoopUnrollResult::Unmodified)
444  return PreservedAnalyses::all();
445 
447 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value *> &EphValues)
Collect a loop&#39;s ephemeral values (those used only by an assume or similar intrinsics in the loop)...
Definition: CodeMetrics.cpp:72
const NoneType None
Definition: None.h:24
unsigned getSmallConstantTripCount(const Loop *L)
Returns the maximum trip count of the loop if it is a single-exit loop and we can compute a small max...
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
Definition: LoopInfoImpl.h:225
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
unsigned getSmallConstantTripMultiple(const Loop *L)
Returns the largest constant divisor of the trip count of the loop if it is a single-exit loop and we...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:687
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:119
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
static bool HasUnrollAndJamEnablePragma(const Loop *L)
INITIALIZE_PASS_BEGIN(LoopUnrollAndJam, "loop-unroll-and-jam", "Unroll and Jam loops", false, false) INITIALIZE_PASS_END(LoopUnrollAndJam
static cl::opt< unsigned > UnrollAndJamCount("unroll-and-jam-count", cl::Hidden, cl::desc("Use this unroll count for all loops including those with " "unroll_and_jam_count pragma values, for testing purposes"))
Legacy pass manager pass to access dependence information.
The main scalar evolution driver.
This file contains the declarations for metadata subclasses.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
bool Force
Apply loop unroll on any kind of loop (mainly to loops that fail runtime unrolling).
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
Metadata node.
Definition: Metadata.h:862
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
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.
bool UnrollAndJam
Allow unroll and jam. Used to enable unroll and jam for the target.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
static cl::opt< bool > AllowUnrollAndJam("allow-unroll-and-jam", cl::Hidden, cl::desc("Allows loops to be unroll-and-jammed."))
static LoopUnrollResult tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const TargetTransformInfo &TTI, AssumptionCache &AC, DependenceInfo &DI, OptimizationRemarkEmitter &ORE, int OptLevel)
BlockT * getHeader() const
Definition: LoopInfo.h:100
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
static bool HasUnrollAndJamDisablePragma(const Loop *L)
LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, unsigned TripMultiple, bool UnrollRemainder, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, OptimizationRemarkEmitter *ORE)
bool isSafeToUnrollAndJam(Loop *L, ScalarEvolution &SE, DominatorTree &DT, DependenceInfo &DI)
This header provides classes for managing per-loop analyses.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:142
bool AllowRemainder
Allow generation of a loop remainder (extra iterations after unroll).
Pass * createLoopUnrollAndJamPass(int OptLevel=2)
StringRef getString() const
Definition: Metadata.cpp:464
loop unroll and Unroll and Jam loops
The loop was fully unrolled into straight-line code.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
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...
Wrapper pass for TargetTransformInfo.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
unsigned UnrollAndJamInnerLoopThreshold
Threshold for unroll and jam, for inner loop size.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void setLoopAlreadyUnrolled()
Add llvm.loop.unroll.disable to this loop&#39;s loop id metadata.
Definition: LoopInfo.cpp:272
static bool computeUnrollAndJamCount(Loop *L, Loop *SubLoop, const TargetTransformInfo &TTI, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const SmallPtrSetImpl< const Value *> &EphValues, OptimizationRemarkEmitter *ORE, unsigned OuterTripCount, unsigned OuterTripMultiple, unsigned OuterLoopSize, unsigned InnerTripCount, unsigned InnerLoopSize, TargetTransformInfo::UnrollingPreferences &UP)
const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
Represent the analysis usage information of a pass.
static unsigned UnrollAndJamCountPragmaValue(const Loop *L)
unsigned Count
A forced unrolling factor (the number of concatenated bodies of the original loop in the unrolled loo...
static MDNode * GetUnrollMetadataForLoop(const Loop *L, StringRef Name)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
static uint64_t getUnrollAndJammedLoopSize(unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP)
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 class provides an interface for updating the loop pass manager based on mutations to the loop ne...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1062
void markLoopAsDeleted(Loop &L)
Definition: LoopPass.cpp:142
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
bool UnrollRemainder
Allow unrolling of all the iterations of the runtime loop remainder.
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:887
loop unroll and jam
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
Definition: LoopInfo.h:131
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to...
Definition: LoopInfo.cpp:192
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
Definition: LoopInfo.cpp:214
unsigned Threshold
The cost threshold for the unrolled loop.
This class represents an analyzed expression in the program.
static cl::opt< unsigned > UnrollAndJamThreshold("unroll-and-jam-threshold", cl::init(60), cl::Hidden, cl::desc("Threshold to use for inner loop when doing unroll and jam."))
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:459
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
Definition: LoopInfo.h:149
static cl::opt< unsigned > PragmaUnrollAndJamThreshold("pragma-unroll-and-jam-threshold", cl::init(1024), cl::Hidden, cl::desc("Unrolled size limit for loops with an unroll_and_jam(full) or " "unroll_count pragma."))
Parameters that control the generic loop unrolling transformation.
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
#define I(x, y, z)
Definition: MD5.cpp:58
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass&#39;s AnalysisUsage.
Definition: LoopUtils.cpp:1226
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
The loop was not modified.
void initializeLoopUnrollAndJamPass(PassRegistry &)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:602
A container for analyses that lazily runs them and caches their results.
static bool HasAnyUnrollPragma(const Loop *L, StringRef Prefix)
This pass exposes codegen information to IR-level passes.
This header defines various interfaces for pass management in LLVM.
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
#define LLVM_DEBUG(X)
Definition: Debug.h:119
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
Definition: LoopInfoImpl.h:50
The optimization diagnostic interface.
LoopUnrollResult
Represents the result of a UnrollLoop invocation.
Definition: UnrollLoop.h:43