LLVM 23.0.0git
LoopUnrollAndJamPass.cpp
Go to the documentation of this file.
1//===- LoopUnrollAndJam.cpp - Loop unroll and jam pass --------------------===//
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 pass implements an unroll and jam pass. Most of the work is done by
10// Utils/UnrollLoopAndJam.cpp.
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/StringRef.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/Dominators.h"
31#include "llvm/IR/Function.h"
33#include "llvm/IR/Metadata.h"
34#include "llvm/IR/PassManager.h"
37#include "llvm/Support/Debug.h"
43#include <cassert>
44#include <cstdint>
45
46namespace llvm {
47class Instruction;
48class Value;
49} // namespace llvm
50
51using namespace llvm;
52
53#define DEBUG_TYPE "loop-unroll-and-jam"
54
55/// @{
56/// Metadata attribute names
57static const char *const LLVMLoopUnrollAndJamFollowupAll =
58 "llvm.loop.unroll_and_jam.followup_all";
59static const char *const LLVMLoopUnrollAndJamFollowupInner =
60 "llvm.loop.unroll_and_jam.followup_inner";
61static const char *const LLVMLoopUnrollAndJamFollowupOuter =
62 "llvm.loop.unroll_and_jam.followup_outer";
64 "llvm.loop.unroll_and_jam.followup_remainder_inner";
66 "llvm.loop.unroll_and_jam.followup_remainder_outer";
67/// @}
68
69static cl::opt<bool>
70 AllowUnrollAndJam("allow-unroll-and-jam", cl::Hidden,
71 cl::desc("Allows loops to be unroll-and-jammed."));
72
74 "unroll-and-jam-count", cl::Hidden,
75 cl::desc("Use this unroll count for all loops including those with "
76 "unroll_and_jam_count pragma values, for testing purposes"));
77
79 "unroll-and-jam-threshold", cl::init(60), cl::Hidden,
80 cl::desc("Threshold to use for inner loop when doing unroll and jam."));
81
83 "pragma-unroll-and-jam-threshold", cl::init(1024), cl::Hidden,
84 cl::desc("Unrolled size limit for loops with an unroll_and_jam(full) or "
85 "unroll_count pragma."));
86
87// Returns the loop hint metadata node with the given name (for example,
88// "llvm.loop.unroll.count"). If no such metadata node exists, then nullptr is
89// returned.
91 if (MDNode *LoopID = L->getLoopID())
92 return GetUnrollMetadata(LoopID, Name);
93 return nullptr;
94}
95
96// Returns true if the loop has any metadata starting with Prefix. For example a
97// Prefix of "llvm.loop.unroll." returns true if we have any unroll metadata.
98static bool hasAnyUnrollPragma(const Loop *L, StringRef Prefix) {
99 if (MDNode *LoopID = L->getLoopID()) {
100 // First operand should refer to the loop id itself.
101 assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
102 assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
103
104 for (unsigned I = 1, E = LoopID->getNumOperands(); I < E; ++I) {
105 MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(I));
106 if (!MD)
107 continue;
108
110 if (!S)
111 continue;
112
113 if (S->getString().starts_with(Prefix))
114 return true;
115 }
116 }
117 return false;
118}
119
120// Returns true if the loop has an unroll_and_jam(enable) pragma.
121static bool hasUnrollAndJamEnablePragma(const Loop *L) {
122 return getUnrollMetadataForLoop(L, "llvm.loop.unroll_and_jam.enable");
123}
124
125// If loop has an unroll_and_jam_count pragma return the (necessarily
126// positive) value from the pragma. Otherwise return 0.
127static unsigned unrollAndJamCountPragmaValue(const Loop *L) {
128 MDNode *MD = getUnrollMetadataForLoop(L, "llvm.loop.unroll_and_jam.count");
129 if (MD) {
130 assert(MD->getNumOperands() == 2 &&
131 "Unroll count hint metadata should have two operands.");
132 unsigned Count =
133 mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue();
134 assert(Count >= 1 && "Unroll count must be positive.");
135 return Count;
136 }
137 return 0;
138}
139
140// Returns loop size estimation for unrolled loop.
141static uint64_t
144 assert(LoopSize >= UP.BEInsns && "LoopSize should not be less than BEInsns!");
145 return static_cast<uint64_t>(LoopSize - UP.BEInsns) * UP.Count + UP.BEInsns;
146}
147
148// Calculates unroll and jam count and writes it to UP.Count. Returns true if
149// unroll count was set explicitly.
151 Loop *L, Loop *SubLoop, const TargetTransformInfo &TTI, DominatorTree &DT,
153 const SmallPtrSetImpl<const Value *> &EphValues,
154 OptimizationRemarkEmitter *ORE, unsigned OuterTripCount,
155 unsigned OuterTripMultiple, const UnrollCostEstimator &OuterUCE,
156 unsigned InnerTripCount, unsigned InnerLoopSize,
159 unsigned OuterLoopSize = OuterUCE.getRolledLoopSize();
160 // First up use computeUnrollCount from the loop unroller to get a count
161 // for unrolling the outer loop, plus any loops requiring explicit
162 // unrolling we leave to the unroller. This uses UP.Threshold /
163 // UP.PartialThreshold / UP.MaxCount to come up with sensible loop values.
164 // We have already checked that the loop has no unroll.* pragmas.
165 bool ExplicitUnroll =
166 computeUnrollCount(L, TTI, DT, LI, AC, SE, EphValues, ORE, OuterTripCount,
167 /*MaxTripCount*/ 0, /*MaxOrZero*/ false,
168 OuterTripMultiple, OuterUCE, UP, PP);
169 if (ExplicitUnroll) {
170 // If the user explicitly set the loop as unrolled, dont UnJ it. Leave it
171 // for the unroller instead.
172 LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; explicit count set by "
173 "computeUnrollCount\n");
174 UP.Count = 0;
175 return false;
176 }
177
178 // Override with any explicit Count from the "unroll-and-jam-count" option.
179 bool UserUnrollCount = UnrollAndJamCount.getNumOccurrences() > 0;
180 if (UserUnrollCount) {
182 UP.Force = true;
183 if (UP.AllowRemainder &&
184 getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
185 getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
187 return true;
188 }
189
190 // Check for unroll_and_jam pragmas
191 unsigned PragmaCount = unrollAndJamCountPragmaValue(L);
192 if (PragmaCount > 0) {
193 UP.Count = PragmaCount;
194 UP.Runtime = true;
195 UP.Force = true;
196 if ((UP.AllowRemainder || (OuterTripMultiple % PragmaCount == 0)) &&
197 getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
198 getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
200 return true;
201 }
202
203 bool PragmaEnableUnroll = hasUnrollAndJamEnablePragma(L);
204 bool ExplicitUnrollAndJamCount = PragmaCount > 0 || UserUnrollCount;
205 bool ExplicitUnrollAndJam = PragmaEnableUnroll || ExplicitUnrollAndJamCount;
206
207 // If the loop has an unrolling pragma, we want to be more aggressive with
208 // unrolling limits.
209 if (ExplicitUnrollAndJam)
211
212 if (!UP.AllowRemainder && getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
214 LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; can't create remainder and "
215 "inner loop too large\n");
216 UP.Count = 0;
217 return false;
218 }
219
220 // We have a sensible limit for the outer loop, now adjust it for the inner
221 // loop and UP.UnrollAndJamInnerLoopThreshold. If the outer limit was set
222 // explicitly, we want to stick to it.
223 if (!ExplicitUnrollAndJamCount && UP.AllowRemainder) {
224 while (UP.Count != 0 && getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
226 UP.Count--;
227 }
228
229 // If we are explicitly unroll and jamming, we are done. Otherwise there are a
230 // number of extra performance heuristics to check.
231 if (ExplicitUnrollAndJam)
232 return true;
233
234 // If the inner loop count is known and small, leave the entire loop nest to
235 // be the unroller
236 if (InnerTripCount && InnerLoopSize * InnerTripCount < UP.Threshold) {
237 LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; small inner loop count is "
238 "being left for the unroller\n");
239 UP.Count = 0;
240 return false;
241 }
242
243 // Check for situations where UnJ is likely to be unprofitable. Including
244 // subloops with more than 1 block.
245 if (SubLoop->getBlocks().size() != 1) {
247 dbgs() << "Won't unroll-and-jam; More than one inner loop block\n");
248 UP.Count = 0;
249 return false;
250 }
251
252 // Limit to loops where there is something to gain from unrolling and
253 // jamming the loop. In this case, look for loads that are invariant in the
254 // outer loop and can become shared.
255 unsigned NumInvariant = 0;
256 for (BasicBlock *BB : SubLoop->getBlocks()) {
257 for (Instruction &I : *BB) {
258 if (auto *Ld = dyn_cast<LoadInst>(&I)) {
259 Value *V = Ld->getPointerOperand();
260 const SCEV *LSCEV = SE.getSCEVAtScope(V, L);
261 if (SE.isLoopInvariant(LSCEV, L))
262 NumInvariant++;
263 }
264 }
265 }
266 if (NumInvariant == 0) {
267 LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; No loop invariant loads\n");
268 UP.Count = 0;
269 return false;
270 }
271
272 return false;
273}
274
275static LoopUnrollResult
279 OptimizationRemarkEmitter &ORE, int OptLevel) {
281 L, SE, TTI, nullptr, nullptr, ORE, OptLevel, std::nullopt, std::nullopt,
282 std::nullopt, std::nullopt, std::nullopt, std::nullopt);
284 gatherPeelingPreferences(L, SE, TTI, std::nullopt, std::nullopt);
285
287 if (EnableMode & TM_Disable)
289 if (EnableMode & TM_ForcedByUser)
290 UP.UnrollAndJam = true;
291
292 if (AllowUnrollAndJam.getNumOccurrences() > 0)
294 if (UnrollAndJamThreshold.getNumOccurrences() > 0)
296 // Exit early if unrolling is disabled.
299
300 LLVM_DEBUG(dbgs() << "Loop Unroll and Jam: F["
301 << L->getHeader()->getParent()->getName() << "] Loop %"
302 << L->getHeader()->getName() << "\n");
303
304 // A loop with any unroll pragma (enabling/disabling/count/etc) is left for
305 // the unroller, so long as it does not explicitly have unroll_and_jam
306 // metadata. This means #pragma nounroll will disable unroll and jam as well
307 // as unrolling
308 if (hasAnyUnrollPragma(L, "llvm.loop.unroll.") &&
309 !hasAnyUnrollPragma(L, "llvm.loop.unroll_and_jam.")) {
310 LLVM_DEBUG(dbgs() << " Disabled due to pragma.\n");
312 }
313
314 if (!isSafeToUnrollAndJam(L, SE, DT, DI, *LI)) {
315 LLVM_DEBUG(dbgs() << " Disabled due to not being safe.\n");
317 }
318
319 // Approximate the loop size and collect useful info
321 CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
322 Loop *SubLoop = L->getSubLoops()[0];
323 UnrollCostEstimator InnerUCE(SubLoop, TTI, EphValues, UP.BEInsns);
324 UnrollCostEstimator OuterUCE(L, TTI, EphValues, UP.BEInsns);
325
326 if (!InnerUCE.canUnroll() || !OuterUCE.canUnroll()) {
327 LLVM_DEBUG(dbgs() << " Loop not considered unrollable\n");
329 }
330
331 unsigned InnerLoopSize = InnerUCE.getRolledLoopSize();
332 LLVM_DEBUG(dbgs() << " Outer Loop Size: " << OuterUCE.getRolledLoopSize()
333 << "\n");
334 LLVM_DEBUG(dbgs() << " Inner Loop Size: " << InnerLoopSize << "\n");
335
336 if (InnerUCE.NumInlineCandidates != 0 || OuterUCE.NumInlineCandidates != 0) {
337 LLVM_DEBUG(dbgs() << " Not unrolling loop with inlinable calls.\n");
339 }
340 // FIXME: The call to canUnroll() allows some controlled convergent
341 // operations, but we block them here for future changes.
342 if (InnerUCE.Convergence != ConvergenceKind::None ||
345 dbgs() << " Not unrolling loop with convergent instructions.\n");
347 }
348
349 // Save original loop IDs for after the transformation.
350 MDNode *OrigOuterLoopID = L->getLoopID();
351 MDNode *OrigSubLoopID = SubLoop->getLoopID();
352
353 // To assign the loop id of the epilogue, assign it before unrolling it so it
354 // is applied to every inner loop of the epilogue. We later apply the loop ID
355 // for the jammed inner loop.
356 std::optional<MDNode *> NewInnerEpilogueLoopID = makeFollowupLoopID(
357 OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
359 if (NewInnerEpilogueLoopID)
360 SubLoop->setLoopID(*NewInnerEpilogueLoopID);
361
362 // Find trip count and trip multiple
363 BasicBlock *Latch = L->getLoopLatch();
364 BasicBlock *SubLoopLatch = SubLoop->getLoopLatch();
365 unsigned OuterTripCount = SE.getSmallConstantTripCount(L, Latch);
366 unsigned OuterTripMultiple = SE.getSmallConstantTripMultiple(L, Latch);
367 unsigned InnerTripCount = SE.getSmallConstantTripCount(SubLoop, SubLoopLatch);
368
369 // Decide if, and by how much, to unroll
370 bool IsCountSetExplicitly = computeUnrollAndJamCount(
371 L, SubLoop, TTI, DT, LI, &AC, SE, EphValues, &ORE, OuterTripCount,
372 OuterTripMultiple, OuterUCE, InnerTripCount, InnerLoopSize, UP, PP);
373 if (UP.Count <= 1)
375 // Unroll factor (Count) must be less or equal to TripCount.
376 if (OuterTripCount && UP.Count > OuterTripCount)
377 UP.Count = OuterTripCount;
378
379 Loop *EpilogueOuterLoop = nullptr;
380 LoopUnrollResult UnrollResult = UnrollAndJamLoop(
381 L, UP.Count, OuterTripCount, OuterTripMultiple, UP.UnrollRemainder, LI,
382 &SE, &DT, &AC, &TTI, &ORE, &EpilogueOuterLoop);
383
384 // Assign new loop attributes.
385 if (EpilogueOuterLoop) {
386 std::optional<MDNode *> NewOuterEpilogueLoopID = makeFollowupLoopID(
387 OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
389 if (NewOuterEpilogueLoopID)
390 EpilogueOuterLoop->setLoopID(*NewOuterEpilogueLoopID);
391 }
392
393 std::optional<MDNode *> NewInnerLoopID =
396 if (NewInnerLoopID)
397 SubLoop->setLoopID(*NewInnerLoopID);
398 else
399 SubLoop->setLoopID(OrigSubLoopID);
400
401 if (UnrollResult == LoopUnrollResult::PartiallyUnrolled) {
402 std::optional<MDNode *> NewOuterLoopID = makeFollowupLoopID(
403 OrigOuterLoopID,
405 if (NewOuterLoopID) {
406 L->setLoopID(*NewOuterLoopID);
407
408 // Do not setLoopAlreadyUnrolled if a followup was given.
409 return UnrollResult;
410 }
411 }
412
413 // If loop has an unroll count pragma or unrolled by explicitly set count
414 // mark loop as unrolled to prevent unrolling beyond that requested.
415 if (UnrollResult != LoopUnrollResult::FullyUnrolled && IsCountSetExplicitly)
416 L->setLoopAlreadyUnrolled();
417
418 return UnrollResult;
419}
420
422 ScalarEvolution &SE,
425 OptimizationRemarkEmitter &ORE, int OptLevel,
426 LPMUpdater &U, bool &AnyLoopRemoved) {
427 bool DidSomething = false;
429 Loop *OutmostLoop = &LN.getOutermostLoop();
430
431 // Add the loop nests in the reverse order of LN. See method
432 // declaration.
434 appendLoopsToWorklist(Loops, Worklist);
435 while (!Worklist.empty()) {
436 Loop *L = Worklist.pop_back_val();
437 std::string LoopName = std::string(L->getName());
438 LoopUnrollResult Result =
439 tryToUnrollAndJamLoop(L, DT, &LI, SE, TTI, AC, DI, ORE, OptLevel);
440 if (Result != LoopUnrollResult::Unmodified)
441 DidSomething = true;
442 if (Result == LoopUnrollResult::FullyUnrolled) {
443 if (L == OutmostLoop)
444 U.markLoopAsDeleted(*L, LoopName);
445 AnyLoopRemoved = true;
446 }
447 }
448
449 return DidSomething;
450}
451
455 LPMUpdater &U) {
456 Function &F = *LN.getParent();
457
458 DependenceInfo DI(&F, &AR.AA, &AR.SE, &AR.LI);
460
461 bool AnyLoopRemoved = false;
462 if (!tryToUnrollAndJamLoop(LN, AR.DT, AR.LI, AR.SE, AR.TTI, AR.AC, DI, ORE,
463 OptLevel, U, AnyLoopRemoved))
464 return PreservedAnalyses::all();
465
467 if (!AnyLoopRemoved)
468 PA.preserve<LoopNestAnalysis>();
469 return PA;
470}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Hexagon Hardware Loops
This header defines various interfaces for pass management in LLVM.
This header provides classes for managing per-loop analyses.
This file defines the interface for the loop nest analysis.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
static const char *const LLVMLoopUnrollAndJamFollowupInner
static const char *const LLVMLoopUnrollAndJamFollowupRemainderInner
static const char *const LLVMLoopUnrollAndJamFollowupRemainderOuter
static MDNode * getUnrollMetadataForLoop(const Loop *L, StringRef Name)
static const char *const LLVMLoopUnrollAndJamFollowupOuter
static bool computeUnrollAndJamCount(Loop *L, Loop *SubLoop, const TargetTransformInfo &TTI, DominatorTree &DT, LoopInfo *LI, AssumptionCache *AC, ScalarEvolution &SE, const SmallPtrSetImpl< const Value * > &EphValues, OptimizationRemarkEmitter *ORE, unsigned OuterTripCount, unsigned OuterTripMultiple, const UnrollCostEstimator &OuterUCE, unsigned InnerTripCount, unsigned InnerLoopSize, TargetTransformInfo::UnrollingPreferences &UP, TargetTransformInfo::PeelingPreferences &PP)
static cl::opt< bool > AllowUnrollAndJam("allow-unroll-and-jam", cl::Hidden, cl::desc("Allows loops to be unroll-and-jammed."))
static uint64_t getUnrollAndJammedLoopSize(unsigned LoopSize, TargetTransformInfo::UnrollingPreferences &UP)
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"))
static LoopUnrollResult tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const TargetTransformInfo &TTI, AssumptionCache &AC, DependenceInfo &DI, OptimizationRemarkEmitter &ORE, int OptLevel)
static bool hasAnyUnrollPragma(const Loop *L, StringRef Prefix)
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."))
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."))
static unsigned unrollAndJamCountPragmaValue(const Loop *L)
static bool hasUnrollAndJamEnablePragma(const Loop *L)
static const char *const LLVMLoopUnrollAndJamFollowupAll
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
This file provides a priority worklist.
This file defines the SmallPtrSet class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
This pass exposes codegen information to IR-level passes.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
DependenceInfo - This class is the main dependence-analysis driver.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:164
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
This analysis provides information for a loop nest.
This class represents a loop nest and can be used to query its properties.
ArrayRef< Loop * > getLoops() const
Get the loops in the nest.
Function * getParent() const
Return the function to which the loop-nest belongs.
Loop & getOutermostLoop() const
Return the outermost loop in the loop nest.
PreservedAnalyses run(LoopNest &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
void setLoopID(MDNode *LoopID) const
Set the llvm.loop loop id metadata for this loop.
Definition LoopInfo.cpp:548
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
Definition LoopInfo.cpp:524
Metadata node.
Definition Metadata.h:1080
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1444
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1450
A single uniqued string.
Definition Metadata.h:722
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:632
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
bool empty() const
Determine if the PriorityWorklist is empty or not.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
LLVM_ABI const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
LLVM_ABI unsigned getSmallConstantTripMultiple(const Loop *L, const SCEV *ExitCount)
Returns the largest constant divisor of the trip count as a normal unsigned value,...
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Produce an estimate of the unrolled cost of the specified loop.
Definition UnrollLoop.h:135
ConvergenceKind Convergence
Definition UnrollLoop.h:141
LLVM_ABI bool canUnroll() const
Whether it is legal to unroll this loop.
uint64_t getRolledLoopSize() const
Definition UnrollLoop.h:151
LLVM Value Representation.
Definition Value.h:75
initializer< Ty > init(const Ty &Val)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:668
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI bool isSafeToUnrollAndJam(Loop *L, ScalarEvolution &SE, DominatorTree &DT, DependenceInfo &DI, LoopInfo &LI)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, DominatorTree &DT, LoopInfo *LI, AssumptionCache *AC, ScalarEvolution &SE, const SmallPtrSetImpl< const Value * > &EphValues, OptimizationRemarkEmitter *ORE, unsigned TripCount, unsigned MaxTripCount, bool MaxOrZero, unsigned TripMultiple, const UnrollCostEstimator &UCE, TargetTransformInfo::UnrollingPreferences &UP, TargetTransformInfo::PeelingPreferences &PP)
LLVM_ABI std::optional< MDNode * > makeFollowupLoopID(MDNode *OrigLoopID, ArrayRef< StringRef > FollowupAttrs, const char *InheritOptionsAttrsPrefix="", bool AlwaysNew=false)
Create a new loop identifier for a loop created from a loop transformation.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
TargetTransformInfo::PeelingPreferences gatherPeelingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, std::optional< bool > UserAllowPeeling, std::optional< bool > UserAllowProfileBasedPeeling, bool UnrollingSpecficValues=false)
LLVM_ABI TransformationMode hasUnrollAndJamTransformation(const Loop *L)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_TEMPLATE_ABI void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
LoopUnrollResult
Represents the result of a UnrollLoop invocation.
Definition UnrollLoop.h:58
@ PartiallyUnrolled
The loop was partially unrolled – we still have a loop, but with a smaller trip count.
Definition UnrollLoop.h:65
@ Unmodified
The loop was not modified.
Definition UnrollLoop.h:60
@ FullyUnrolled
The loop was fully unrolled into straight-line code.
Definition UnrollLoop.h:69
TargetTransformInfo TTI
TransformationMode
The mode sets how eager a transformation should be applied.
Definition LoopUtils.h:283
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition LoopUtils.h:300
@ TM_Disable
The transformation should not be applied.
Definition LoopUtils.h:292
LLVM_ABI TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, llvm::OptimizationRemarkEmitter &ORE, int OptLevel, std::optional< unsigned > UserThreshold, std::optional< unsigned > UserCount, std::optional< bool > UserAllowPartial, std::optional< bool > UserRuntime, std::optional< bool > UserUpperBound, std::optional< unsigned > UserFullUnrollMaxCount)
Gather the various unrolling parameters based on the defaults, compiler flags, TTI overrides and user...
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
LLVM_ABI LoopUnrollResult UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount, unsigned TripMultiple, bool UnrollRemainder, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const TargetTransformInfo *TTI, OptimizationRemarkEmitter *ORE, Loop **EpilogueLoop=nullptr)
LLVM_ABI 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...
static LLVM_ABI void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop).
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
Parameters that control the generic loop unrolling transformation.
unsigned Count
A forced unrolling factor (the number of concatenated bodies of the original loop in the unrolled loo...
unsigned Threshold
The cost threshold for the unrolled loop.
bool Force
Apply loop unroll on any kind of loop (mainly to loops that fail runtime unrolling).
unsigned UnrollAndJamInnerLoopThreshold
Threshold for unroll and jam, for inner loop size.
bool AllowRemainder
Allow generation of a loop remainder (extra iterations after unroll).
bool UnrollAndJam
Allow unroll and jam. Used to enable unroll and jam for the target.
bool UnrollRemainder
Allow unrolling of all the iterations of the runtime loop remainder.
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...